Files
AILab/sentinel/src/service/rtsp_grabber copy.h
T
2026-04-02 09:24:45 +08:00

54 lines
1.0 KiB
C++

#pragma once
#include <atomic>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <unordered_map>
class RtspFrameGrabber {
public:
explicit RtspFrameGrabber(const std::string &rtsp_url);
~RtspFrameGrabber();
bool start();
void stop();
bool capture_jpeg(const std::string &filename);
bool is_ready() const;
const std::string &get_rtsp_url() const { return rtsp_url_; }
private:
void decode_loop();
private:
std::string rtsp_url_;
std::thread worker_;
std::atomic<bool> running_{false};
std::atomic<bool> ready_{false};
mutable std::mutex frame_mutex_;
void *opaque_impl_ = nullptr;
};
class RtspManager {
public:
RtspManager() = default;
~RtspManager();
void configure(const std::unordered_map<int, std::string> &side_sources);
void shutdown();
std::string capture_side_frame(int source_id);
bool is_ready(int source_id) const;
private:
std::unordered_map<int, std::unique_ptr<RtspFrameGrabber>> side_grabbers_;
mutable std::mutex mgr_mutex_;
};