temp
This commit is contained in:
parent
cb37ca9eb3
commit
4de32c3487
118
config.json
118
config.json
@ -7,79 +7,79 @@
|
|||||||
"client_id": "20004_vehmedia",
|
"client_id": "20004_vehmedia",
|
||||||
"username": "20004_4A:69:BE:32:59:AE",
|
"username": "20004_4A:69:BE:32:59:AE",
|
||||||
"password": "31d6bb29f177d5bf8560756c0f0e63c63fd412e52c5b9ea59476024eab893884a5f34f0637e0fe3ad42b802c16edb6feb37cde613957c3540c060c07b230cb0aa6b4547bb86fcae43d484179d3a11a1969a2f367ec0ceede4c10510757a89927af4c2d0c0484476be3241a9ff9242e7401f3fbcd824b5cfb19674663b7045e32dd2f97b4",
|
"password": "31d6bb29f177d5bf8560756c0f0e63c63fd412e52c5b9ea59476024eab893884a5f34f0637e0fe3ad42b802c16edb6feb37cde613957c3540c060c07b230cb0aa6b4547bb86fcae43d484179d3a11a1969a2f367ec0ceede4c10510757a89927af4c2d0c0484476be3241a9ff9242e7401f3fbcd824b5cfb19674663b7045e32dd2f97b4",
|
||||||
"mqtt_heart_threshold": 2000
|
"mqtt_heart_threshold": 1000
|
||||||
},
|
},
|
||||||
"cameras": [
|
"cameras": [
|
||||||
{
|
{
|
||||||
"device": "/dev/video11",
|
"device": "/dev/video0",
|
||||||
"name": "AHD1",
|
"name": "AHD1",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"resolution": "720p",
|
"resolution": "960p",
|
||||||
"width": 1280,
|
"width": 1280,
|
||||||
"height": 720,
|
"height": 960,
|
||||||
"fps": 30
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"device": "/dev/video12",
|
|
||||||
"name": "AHD2",
|
|
||||||
"enabled": false,
|
|
||||||
"resolution": "720p",
|
|
||||||
"width": 1280,
|
|
||||||
"height": 720,
|
|
||||||
"fps": 30
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"device": "/dev/video13",
|
|
||||||
"name": "AHD3",
|
|
||||||
"enabled": false,
|
|
||||||
"resolution": "720p",
|
|
||||||
"width": 1280,
|
|
||||||
"height": 720,
|
|
||||||
"fps": 30
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"device": "/dev/video14",
|
|
||||||
"name": "AHD4",
|
|
||||||
"enabled": false,
|
|
||||||
"resolution": "720p",
|
|
||||||
"width": 1280,
|
|
||||||
"height": 720,
|
|
||||||
"fps": 30
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"device": "/dev/video3",
|
|
||||||
"name": "AHD5",
|
|
||||||
"enabled": false,
|
|
||||||
"resolution": "1080p",
|
|
||||||
"width": 1920,
|
|
||||||
"height": 1080,
|
|
||||||
"fps": 30
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"device": "/dev/video2",
|
|
||||||
"name": "AHD6",
|
|
||||||
"enabled": false,
|
|
||||||
"resolution": "1080p",
|
|
||||||
"width": 1920,
|
|
||||||
"height": 1080,
|
|
||||||
"fps": 30
|
"fps": 30
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"device": "/dev/video1",
|
"device": "/dev/video1",
|
||||||
"name": "AHD7",
|
"name": "AHD2",
|
||||||
"enabled": false,
|
"enabled": true,
|
||||||
"resolution": "1080p",
|
"resolution": "960p",
|
||||||
"width": 1920,
|
"width": 1280,
|
||||||
"height": 1080,
|
"height": 960,
|
||||||
"fps": 30
|
"fps": 30
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"device": "/dev/video0",
|
"device": "/dev/video2",
|
||||||
|
"name": "AHD3",
|
||||||
|
"enabled": true,
|
||||||
|
"resolution": "960p",
|
||||||
|
"width": 1280,
|
||||||
|
"height": 960,
|
||||||
|
"fps": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"device": "/dev/video3",
|
||||||
|
"name": "AHD4",
|
||||||
|
"enabled": true,
|
||||||
|
"resolution": "960p",
|
||||||
|
"width": 1280,
|
||||||
|
"height": 960,
|
||||||
|
"fps": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"device": "/dev/video11",
|
||||||
|
"name": "AHD5",
|
||||||
|
"enabled": true,
|
||||||
|
"resolution": "960p",
|
||||||
|
"width": 1280,
|
||||||
|
"height": 960,
|
||||||
|
"fps": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"device": "/dev/video12",
|
||||||
|
"name": "AHD6",
|
||||||
|
"enabled": true,
|
||||||
|
"resolution": "960p",
|
||||||
|
"width": 1280,
|
||||||
|
"height": 960,
|
||||||
|
"fps": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"device": "/dev/video13",
|
||||||
|
"name": "AHD7",
|
||||||
|
"enabled": true,
|
||||||
|
"resolution": "960p",
|
||||||
|
"width": 1280,
|
||||||
|
"height": 960,
|
||||||
|
"fps": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"device": "/dev/video14",
|
||||||
"name": "AHD8",
|
"name": "AHD8",
|
||||||
"enabled": false,
|
"enabled": true,
|
||||||
"resolution": "1080p",
|
"resolution": "960p",
|
||||||
"width": 1920,
|
"width": 1280,
|
||||||
"height": 1080,
|
"height": 960,
|
||||||
"fps": 30
|
"fps": 30
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -82,26 +82,12 @@ void RTMPManager::stream_loop(Camera cam, StreamType type)
|
|||||||
std::string key = make_stream_key(cam.name, type);
|
std::string key = make_stream_key(cam.name, type);
|
||||||
LOG_INFO("[RTMP] Stream loop started for " + key);
|
LOG_INFO("[RTMP] Stream loop started for " + key);
|
||||||
|
|
||||||
const int MAX_RETRIES = 5;
|
|
||||||
int retry_count = 0;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(streams_mutex);
|
|
||||||
auto it = streams.find(key);
|
|
||||||
if (it == streams.end() || !it->second->running.load())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
GstElement *pipeline = create_pipeline(cam, type);
|
GstElement *pipeline = create_pipeline(cam, type);
|
||||||
if (!pipeline)
|
if (!pipeline)
|
||||||
{
|
{
|
||||||
update_status(key, {false, StreamResult::PIPELINE_ERROR, "Failed to create pipeline"});
|
update_status(key, {false, StreamResult::PIPELINE_ERROR, "Failed to create pipeline"});
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
LOG_ERROR("[RTMP] " + key + " pipeline creation failed. Exiting stream loop.");
|
||||||
if (++retry_count > MAX_RETRIES)
|
return;
|
||||||
break;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GstBus *bus = gst_element_get_bus(pipeline);
|
GstBus *bus = gst_element_get_bus(pipeline);
|
||||||
@ -109,23 +95,17 @@ void RTMPManager::stream_loop(Camera cam, StreamType type)
|
|||||||
update_status(key, {true, StreamResult::OK, ""});
|
update_status(key, {true, StreamResult::OK, ""});
|
||||||
LOG_INFO("[RTMP] " + key + " is streaming.");
|
LOG_INFO("[RTMP] " + key + " is streaming.");
|
||||||
|
|
||||||
bool stop_flag = false;
|
|
||||||
GstMessage *msg = nullptr;
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
|
GstMessage *msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE,
|
||||||
static_cast<GstMessageType>(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));
|
static_cast<GstMessageType>(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(streams_mutex);
|
std::lock_guard<std::mutex> lock(streams_mutex);
|
||||||
auto it = streams.find(key);
|
auto it = streams.find(key);
|
||||||
if (it == streams.end() || !it->second->running.load())
|
if (it == streams.end() || !it->second->running.load())
|
||||||
{
|
|
||||||
stop_flag = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!msg)
|
if (!msg)
|
||||||
continue;
|
continue;
|
||||||
@ -142,18 +122,18 @@ void RTMPManager::stream_loop(Camera cam, StreamType type)
|
|||||||
g_error_free(err);
|
g_error_free(err);
|
||||||
if (debug)
|
if (debug)
|
||||||
g_free(debug);
|
g_free(debug);
|
||||||
stop_flag = true;
|
gst_message_unref(msg);
|
||||||
|
break; // 出错立即退出
|
||||||
}
|
}
|
||||||
else if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_EOS)
|
else if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_EOS)
|
||||||
{
|
{
|
||||||
LOG_WARN("[RTMP] EOS on " + key);
|
LOG_WARN("[RTMP] EOS on " + key);
|
||||||
update_status(key, {false, StreamResult::EOS_RECEIVED, "EOS"});
|
update_status(key, {false, StreamResult::EOS_RECEIVED, "EOS"});
|
||||||
stop_flag = true;
|
gst_message_unref(msg);
|
||||||
|
break; // EOS 退出
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_message_unref(msg);
|
gst_message_unref(msg);
|
||||||
if (stop_flag)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_element_set_state(pipeline, GST_STATE_NULL);
|
gst_element_set_state(pipeline, GST_STATE_NULL);
|
||||||
@ -161,21 +141,8 @@ void RTMPManager::stream_loop(Camera cam, StreamType type)
|
|||||||
gst_object_unref(bus);
|
gst_object_unref(bus);
|
||||||
gst_object_unref(pipeline);
|
gst_object_unref(pipeline);
|
||||||
|
|
||||||
if (!stop_flag)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (++retry_count > MAX_RETRIES)
|
|
||||||
{
|
|
||||||
LOG_ERROR("[RTMP] " + key + " reached max retries. Giving up.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_WARN("[RTMP] Reconnecting " + key + " in 3s...");
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
update_status(key, {false, StreamResult::UNKNOWN, "Stream loop exited"});
|
|
||||||
LOG_INFO("[RTMP] Stream loop ended for " + key);
|
LOG_INFO("[RTMP] Stream loop ended for " + key);
|
||||||
|
update_status(key, {false, StreamResult::UNKNOWN, "Stream loop exited"});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTMPManager::start_camera(const Camera &cam, StreamType type)
|
void RTMPManager::start_camera(const Camera &cam, StreamType type)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user