50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
// rtmp_manager.hpp
|
|
#pragma once
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <atomic>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
#include "app_config.hpp"
|
|
#include "logger.hpp"
|
|
|
|
class RTMPManager
|
|
{
|
|
public:
|
|
struct StreamStatus
|
|
{
|
|
bool running{false};
|
|
std::string last_error;
|
|
};
|
|
|
|
static void init();
|
|
static void start_all();
|
|
static void stop_all();
|
|
static bool is_streaming(const std::string &cam_name);
|
|
static std::string get_stream_url(const std::string &cam_name);
|
|
static std::vector<std::pair<std::string, bool>> get_all_status();
|
|
|
|
private:
|
|
struct StreamContext
|
|
{
|
|
std::atomic<bool> running{false};
|
|
std::thread thread;
|
|
StreamStatus status;
|
|
};
|
|
|
|
static void stream_loop(Camera cam, StreamContext *ctx);
|
|
static GstElement *create_pipeline(const Camera &cam);
|
|
static std::string make_key(const std::string &name);
|
|
|
|
static std::unordered_map<std::string, std::unique_ptr<StreamContext>> streams;
|
|
static std::mutex streams_mutex;
|
|
|
|
// 参数
|
|
static constexpr int RETRY_BASE_DELAY_MS = 3000;
|
|
};
|