first commit
This commit is contained in:
parent
d98f8d3f66
commit
8ad6e94f01
@ -74,7 +74,8 @@ void RTSPManager::on_media_created(GstRTSPMediaFactory *factory, GstRTSPMedia *m
|
||||
g_object_ref(media); // 增加引用计数,防止意外销毁
|
||||
|
||||
// 连接 unprepared 信号,以便在媒体销毁时从列表中移除
|
||||
g_signal_connect_data(media, "unprepared", G_CALLBACK(on_media_unprepared), g_strdup(cam_name), (GClosureNotify)g_free, 0);
|
||||
g_signal_connect_data(media, "unprepared", G_CALLBACK(on_media_unprepared),
|
||||
g_strdup(cam_name), (GClosureNotify)g_free, static_cast<GConnectFlags>(0));
|
||||
}
|
||||
|
||||
// 媒体 unprepared 信号处理函数
|
||||
@ -148,21 +149,7 @@ gboolean RTSPManager::unmount_camera_in_main(gpointer data)
|
||||
std::string cam_name = cam->name;
|
||||
std::string mount_point = "/" + cam_name;
|
||||
|
||||
// 停止所有相关的媒体会话
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(media_map_mutex);
|
||||
auto it = media_map.find(cam_name);
|
||||
if (it != media_map.end())
|
||||
{
|
||||
for (GstRTSPMedia *media : it->second)
|
||||
{
|
||||
gst_rtsp_media_stop(media);
|
||||
}
|
||||
it->second.clear();
|
||||
media_map.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
// 卸载 factory(自动断开客户端)
|
||||
GstRTSPMountPoints *mounts = gst_rtsp_server_get_mount_points(server);
|
||||
if (mounts)
|
||||
{
|
||||
@ -170,13 +157,20 @@ gboolean RTSPManager::unmount_camera_in_main(gpointer data)
|
||||
g_object_unref(mounts);
|
||||
}
|
||||
|
||||
// 清理 media_map
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(media_map_mutex);
|
||||
media_map.erase(cam_name);
|
||||
}
|
||||
|
||||
// 释放 factory 对象
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mounted_factories_mutex);
|
||||
auto it = mounted_factories.find(cam_name);
|
||||
if (it != mounted_factories.end())
|
||||
{
|
||||
if (it->second && G_IS_OBJECT(it->second))
|
||||
g_object_unref(it->second); // 安全 unref
|
||||
g_object_unref(it->second);
|
||||
mounted_factories.erase(it);
|
||||
}
|
||||
streaming_status[cam_name] = false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user