2025-09-08 14:55:07 +08:00
|
|
|
// rtsp_manager.hpp
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
#include <gst/rtsp-server/rtsp-server.h>
|
|
|
|
|
#include "app_config.hpp"
|
2025-09-09 10:38:25 +08:00
|
|
|
#include <mutex>
|
2025-09-08 14:55:07 +08:00
|
|
|
|
|
|
|
|
// RTSP 管理器,负责启动/关闭 RTSP 服务器
|
|
|
|
|
class RTSPManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static void init();
|
|
|
|
|
static void start(const std::vector<Camera> &cameras);
|
|
|
|
|
static void stop();
|
|
|
|
|
|
2025-09-09 10:38:25 +08:00
|
|
|
// === 按需挂载/卸载摄像头 ===
|
2025-09-09 09:57:24 +08:00
|
|
|
static void mount_camera(const Camera &cam);
|
|
|
|
|
static void unmount_camera(const Camera &cam);
|
|
|
|
|
|
2025-09-09 10:38:25 +08:00
|
|
|
// === 查询播放状态 ===
|
2025-09-09 09:57:24 +08:00
|
|
|
static bool is_streaming(const std::string &cam_name);
|
|
|
|
|
|
2025-09-08 14:55:07 +08:00
|
|
|
private:
|
|
|
|
|
static GMainLoop *loop;
|
|
|
|
|
static GstRTSPServer *server;
|
|
|
|
|
|
2025-09-09 10:38:25 +08:00
|
|
|
// 播放状态表
|
2025-09-09 09:57:24 +08:00
|
|
|
static std::unordered_map<std::string, bool> streaming_status;
|
|
|
|
|
|
2025-09-09 10:38:25 +08:00
|
|
|
// 创建 MediaFactory
|
2025-09-08 14:55:07 +08:00
|
|
|
static GstRTSPMediaFactory *create_media_factory(const Camera &cam);
|
2025-09-09 10:38:25 +08:00
|
|
|
|
|
|
|
|
// --- 新增:在 main loop 中执行挂载/卸载 ---
|
|
|
|
|
static gboolean mount_camera_in_main(gpointer data);
|
|
|
|
|
static gboolean unmount_camera_in_main(gpointer data);
|
|
|
|
|
|
|
|
|
|
// --- 已挂载的 factory 指针表(用于卸载) ---
|
|
|
|
|
static std::unordered_map<std::string, GstRTSPMediaFactory *> mounted_factories;
|
|
|
|
|
static std::mutex mounted_factories_mutex;
|
2025-09-08 14:55:07 +08:00
|
|
|
};
|