83 lines
2.6 KiB
C++
83 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <memory>
|
|
#include <thread>
|
|
#include <mutex>
|
|
#include <map>
|
|
#include <atomic>
|
|
#include <opencv2/core/mat.hpp>
|
|
#include "video_reader.hpp"
|
|
#include "rtsp_reader.hpp"
|
|
#include "frame_queue.hpp"
|
|
|
|
namespace pipeline {
|
|
|
|
struct SourceStatus {
|
|
bool is_connected{false};
|
|
int frame_count{0};
|
|
float current_fps{0.0f};
|
|
int error_count{0};
|
|
std::string last_error;
|
|
};
|
|
|
|
class InputManager {
|
|
public:
|
|
explicit InputManager(size_t queue_capacity = 30);
|
|
~InputManager();
|
|
|
|
// 禁用拷贝
|
|
InputManager(const InputManager&) = delete;
|
|
InputManager& operator=(const InputManager&) = delete;
|
|
|
|
// 添加源
|
|
bool addSource(const std::string& name, const RtspReader::Config& config,
|
|
const std::string& url, const std::vector<std::string>& output_targets = {});
|
|
bool addVideoSource(const std::string& name, const VideoReader::Config& config,
|
|
const std::string& path, const std::vector<std::string>& output_targets = {});
|
|
|
|
// 移除源
|
|
bool removeSource(const std::string& name);
|
|
|
|
// 获取下一批帧
|
|
bool getNextBatch(std::vector<cv::Mat>& frames, int timeout_ms = 1000);
|
|
|
|
// 获取源状态
|
|
bool getSourceStatus(const std::string& name, SourceStatus& status);
|
|
|
|
// 获取源名称列表
|
|
std::vector<std::string> getSourceNames() const;
|
|
|
|
// 获取源数量
|
|
size_t getSourceCount() const;
|
|
|
|
// 获取源的输出目标
|
|
std::vector<std::string> getSourceOutputTargets(const std::string& name) const;
|
|
|
|
// 清空所有源
|
|
void clear();
|
|
|
|
private:
|
|
enum class SourceType {
|
|
RTSP,
|
|
VIDEO
|
|
};
|
|
|
|
mutable std::mutex sources_mutex_;
|
|
std::unordered_map<std::string, std::unique_ptr<RtspReader>> rtsp_sources_;
|
|
std::unordered_map<std::string, std::unique_ptr<VideoReader>> video_sources_;
|
|
std::unordered_map<std::string, std::unique_ptr<std::thread>> source_threads_;
|
|
std::unordered_map<std::string, SourceType> source_types_;
|
|
std::unordered_map<std::string, SourceStatus> source_status_;
|
|
std::unordered_map<std::string, std::unique_ptr<FrameQueue>> source_queues_;
|
|
std::unordered_map<std::string, std::vector<std::string>> source_output_targets_;
|
|
std::atomic<bool> running_{true};
|
|
std::atomic<int> active_threads_{0};
|
|
|
|
void sourceThread(const std::string& name);
|
|
void videoSourceThread(const std::string& name);
|
|
void updateSourceStatus(const std::string& name, const SourceStatus& status);
|
|
};
|
|
|
|
} // namespace pipeline
|