1
This commit is contained in:
parent
a8fa69dfb2
commit
c850b2d2ee
10
src/main.cpp
10
src/main.cpp
@ -49,16 +49,6 @@ int main()
|
||||
// 初始化 GStreamer
|
||||
RTSPManager::init();
|
||||
|
||||
// ⭐ 程序启动 → 强制 mount 所有摄像头(RTSP 永远在线)
|
||||
for (const auto &cam : g_app_config.cameras)
|
||||
{
|
||||
if (cam.enabled)
|
||||
{
|
||||
RTSPManager::mount_camera(cam);
|
||||
LOG_INFO("[INIT] Mounted camera: " + cam.name);
|
||||
}
|
||||
}
|
||||
|
||||
std::thread rtsp_thread;
|
||||
std::thread mqtt_thread;
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ GstRTSPMediaFactory *RTSPManager::create_media_factory(const Camera &cam)
|
||||
return factory;
|
||||
}
|
||||
|
||||
void RTSPManager::start(const std::vector<Camera> &)
|
||||
void RTSPManager::start(const std::vector<Camera> &cams)
|
||||
{
|
||||
server = gst_rtsp_server_new();
|
||||
gst_rtsp_server_set_service(server, "8554");
|
||||
@ -66,9 +66,35 @@ void RTSPManager::start(const std::vector<Camera> &)
|
||||
loop = g_main_loop_new(nullptr, FALSE);
|
||||
main_context = g_main_loop_get_context(loop);
|
||||
|
||||
// 先获取 mountpoints
|
||||
GstRTSPMountPoints *mounts = gst_rtsp_server_get_mount_points(server);
|
||||
|
||||
// 在这里统一挂载所有 enabled 摄像头
|
||||
for (const auto &cam : cams)
|
||||
{
|
||||
if (!cam.enabled)
|
||||
continue;
|
||||
|
||||
GstRTSPMediaFactory *factory = create_media_factory(cam);
|
||||
std::string mount_point = "/" + cam.name;
|
||||
|
||||
gst_rtsp_mount_points_add_factory(mounts, mount_point.c_str(), factory);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mounted_factories_mutex);
|
||||
mounted_factories[cam.name] = factory;
|
||||
streaming_status[cam.name] = true;
|
||||
}
|
||||
|
||||
LOG_INFO("[RTSP] Camera '" + cam.name +
|
||||
"' mounted at rtsp://0.0.0.0:8554" + mount_point);
|
||||
}
|
||||
|
||||
g_object_unref(mounts);
|
||||
|
||||
gst_rtsp_server_attach(server, nullptr);
|
||||
|
||||
LOG_INFO("[RTSP] Server running on rtsp://localhost:8554");
|
||||
LOG_INFO("[RTSP] Server running on rtsp://0.0.0.0:8554");
|
||||
g_main_loop_run(loop);
|
||||
|
||||
if (server)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user