kunlang_video/include/rtmp_manager.hpp

54 lines
1.3 KiB
C++
Raw Normal View History

2025-10-15 15:36:48 +08:00
// rtmp_manager.hpp
2025-10-15 15:03:10 +08:00
#pragma once
#include <atomic>
2025-10-15 17:01:43 +08:00
#include <condition_variable>
2025-10-15 15:33:00 +08:00
#include <future>
2025-10-15 08:57:40 +08:00
#include <memory>
2025-10-15 15:01:55 +08:00
#include <mutex>
2025-10-15 17:01:43 +08:00
#include <queue>
2025-10-15 15:01:55 +08:00
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>
2025-10-15 08:50:01 +08:00
#include "app_config.hpp"
2025-10-15 11:27:53 +08:00
#include "mqtt_client_wrapper.hpp"
2025-10-15 15:03:10 +08:00
class RTMPManager
{
2025-10-15 15:01:55 +08:00
public:
struct StreamResultInfo
{
int loc{-1};
std::string url;
2025-10-15 17:01:43 +08:00
int result{1}; // 0=成功, 1=失败
2025-10-15 15:01:55 +08:00
std::string reason;
};
static void init();
2025-10-15 17:01:43 +08:00
static void enqueue_video_push_request(const VideoPushRequest &req);
static void stop_all();
2025-10-15 15:01:55 +08:00
private:
struct StreamContext
{
2025-10-15 08:50:01 +08:00
std::atomic<bool> running{false};
std::thread thread;
2025-10-15 15:33:00 +08:00
std::promise<StreamResultInfo> start_result;
};
2025-10-15 17:01:43 +08:00
static void rtmp_worker_thread();
static StreamResultInfo start_camera(const Camera &cam, int streamType);
static StreamResultInfo stop_camera(const Camera &cam, int streamType);
2025-10-15 14:14:00 +08:00
static std::unordered_map<std::string, std::unique_ptr<StreamContext>> streams;
static std::mutex streams_mutex;
2025-10-15 17:01:43 +08:00
static std::queue<VideoPushRequest> request_queue;
static std::mutex queue_mutex;
static std::condition_variable queue_cv;
static std::thread worker_thread;
static std::atomic<bool> running;
2025-10-15 15:36:48 +08:00
};