- 创建基本项目结构和目录 - 添加CMake构建系统 - 实现基础的配置解析功能 - 添加YOLO推理框架支持 - 集成RTSP和视频流处理功能 - 添加性能监控和日志系统
77 lines
2.2 KiB
C++
77 lines
2.2 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);
|
|
bool addVideoSource(const std::string& name, const VideoReader::Config& config, const std::string& path);
|
|
|
|
// 移除源
|
|
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;
|
|
|
|
// 清空所有源
|
|
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::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
|