kunlang_video/include/rtmp_manager.hpp
2025-10-14 17:51:05 +08:00

44 lines
1.3 KiB
C++

// rtsp_manager.hpp
#pragma once
#include <gst/gst.h>
#include "app_config.hpp"
#include <unordered_map>
#include <string>
#include <mutex>
#include <thread>
#include <atomic>
class RTMPManager
{
public:
static void init();
static void start_camera(const Camera &cam, StreamType type);
static void stop_camera(const std::string &cam_name, StreamType type);
static void stop_all();
static bool is_streaming(const std::string &cam_name, StreamType type);
static bool is_any_streaming();
static std::string get_stream_url(const std::string &cam_name, StreamType type);
private:
struct StreamContext
{
std::atomic<bool> running;
std::thread thread;
StreamContext() : running(false) {}
StreamContext(StreamContext &&) = default; // 允许移动
StreamContext &operator=(StreamContext &&) = default;
StreamContext(const StreamContext &) = delete;
StreamContext &operator=(const StreamContext &) = delete;
};
static std::unordered_map<std::string, StreamContext> streams;
static std::mutex streams_mutex;
static void stream_loop(Camera cam, StreamType type);
static GstElement *create_pipeline(const Camera &cam, StreamType type);
static std::string make_stream_key(const std::string &cam_name, StreamType type);
};