sweeper_video/include/rtsp_manager.hpp

48 lines
1.4 KiB
C++
Raw Normal View History

2025-09-09 13:28:05 +08:00
// rtsp_manager.hpp
2025-09-08 14:55:07 +08:00
#pragma once
#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#include "app_config.hpp"
2025-09-09 11:02:41 +08:00
#include <unordered_map>
#include <string>
2025-09-09 10:38:25 +08:00
#include <mutex>
2025-09-09 13:28:05 +08:00
#include <vector>
2025-09-08 14:55:07 +08:00
class RTSPManager
{
public:
static void init();
static void start(const std::vector<Camera> &cameras);
static void stop();
2025-09-09 09:57:24 +08:00
static void mount_camera(const Camera &cam);
static void unmount_camera(const Camera &cam);
static bool is_streaming(const std::string &cam_name);
2025-09-10 13:12:27 +08:00
static bool is_any_streaming();
2025-09-09 09:57:24 +08:00
2025-09-08 14:55:07 +08:00
private:
static GMainLoop *loop;
2025-09-09 11:02:41 +08:00
static GMainContext *main_context;
2025-09-08 14:55:07 +08:00
static GstRTSPServer *server;
2025-09-09 09:57:24 +08:00
static std::unordered_map<std::string, bool> streaming_status;
2025-09-09 11:02:41 +08:00
// 工厂创建函数
2025-09-08 14:55:07 +08:00
static GstRTSPMediaFactory *create_media_factory(const Camera &cam);
2025-09-09 11:02:41 +08:00
2025-09-09 11:34:17 +08:00
// 挂载/卸载函数
2025-09-09 11:02:41 +08:00
static gboolean mount_camera_in_main(gpointer data);
static gboolean unmount_camera_in_main(gpointer data);
2025-09-09 11:34:17 +08:00
// 静态 mutex 和工厂表
2025-09-09 11:02:41 +08:00
static std::unordered_map<std::string, GstRTSPMediaFactory *> mounted_factories;
static std::mutex mounted_factories_mutex;
2025-09-09 13:28:05 +08:00
// 媒体对象跟踪
static std::unordered_map<std::string, std::vector<GstRTSPMedia *>> media_map;
static std::mutex media_map_mutex;
// 信号处理函数
static void on_media_created(GstRTSPMediaFactory *factory, GstRTSPMedia *media, gpointer user_data);
static void on_media_unprepared(GstRTSPMedia *media, gpointer user_data);
};