118 lines
4.1 KiB
C++
118 lines
4.1 KiB
C++
#ifndef CMVR_ES_HIKVISION_CAMERA_H
|
|
#define CMVR_ES_HIKVISION_CAMERA_H
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "common/base/ring_buffer.h"
|
|
#include "devices/camera/abstract_camera.h"
|
|
|
|
namespace cmvr::device {
|
|
|
|
class HikvisionCamera final : public AbstractCamera {
|
|
public:
|
|
explicit HikvisionCamera(const cmvr::config::HikvisionCameraConfig& camera);
|
|
~HikvisionCamera() override;
|
|
|
|
std::string typeName() const override { return "HikvisionCamera"; }
|
|
bool init() override;
|
|
bool start() override;
|
|
bool stop() override;
|
|
void getState(CameraState& state) override;
|
|
|
|
void getRGBImage(cv::Mat& color, Rs2Intrinsics& intrinsics) override;
|
|
void getDepthImage(cv::Mat& depth, Rs2Intrinsics& intrinsics) override;
|
|
void getRGBDImages(cv::Mat& color, cv::Mat& depth, Rs2Intrinsics& intrinsics) override;
|
|
|
|
void startRecording(const std::string& video_path) override;
|
|
void stopRecording() override;
|
|
void pauseRecording() override;
|
|
void resumeRecording() override;
|
|
void getEncodedFrame(StreamFrameData& frame_data, size_t& index) override;
|
|
bool waitEncodedFrame(StreamFrameData& frame_data, size_t& index, std::chrono::milliseconds timeout) override;
|
|
bool getLatestEncodedFrame(StreamFrameData& frame_data, size_t& next_index) override;
|
|
bool startStreaming() override;
|
|
void stopStreaming() override;
|
|
bool controlPtz(PtzCommand command, bool stop, int speed) override;
|
|
bool executeJsonCommand(const std::string& request_json, std::string& response_json) override;
|
|
bool requestKeyFrame() override;
|
|
|
|
void onEsData(long real_handle,
|
|
unsigned int packet_type,
|
|
unsigned char* buffer,
|
|
unsigned int buffer_size,
|
|
unsigned int width,
|
|
unsigned int height,
|
|
uint64_t source_timestamp,
|
|
uint64_t source_frame_number,
|
|
unsigned int source_frame_rate,
|
|
unsigned int source_packet_mode);
|
|
|
|
private:
|
|
bool initSdk_();
|
|
void releaseSdk_();
|
|
bool login_();
|
|
bool startPreview_();
|
|
void stopPreview_();
|
|
bool requestKeyFrame_();
|
|
void stopRecordingUnlocked_();
|
|
void fillIntrinsics_(Rs2Intrinsics& intrinsics) const;
|
|
void setError_(const std::string& message);
|
|
std::string sdkError_(const std::string& action) const;
|
|
void pushEncodedFrame_(const unsigned char* buffer,
|
|
unsigned int buffer_size,
|
|
bool is_key_frame,
|
|
unsigned int width,
|
|
unsigned int height,
|
|
uint64_t source_timestamp,
|
|
uint64_t source_frame_number,
|
|
unsigned int source_frame_rate,
|
|
unsigned int source_packet_mode);
|
|
void resetStreamState_();
|
|
|
|
config::HikvisionCameraConfig camera_;
|
|
std::string ip_;
|
|
std::string username_;
|
|
std::string password_;
|
|
std::string sdk_path_;
|
|
|
|
int port_ = 8000;
|
|
int channel_ = 1;
|
|
int stream_type_ = 0;
|
|
int link_mode_ = 0;
|
|
int fps_ = 25;
|
|
int width_ = 0;
|
|
int height_ = 0;
|
|
size_t buffer_size_ = 30;
|
|
std::string codec_ = "H264";
|
|
|
|
int user_id_ = -1;
|
|
int real_handle_ = -1;
|
|
bool sdk_acquired_ = false;
|
|
|
|
std::shared_ptr<SPMCRingBuffer<StreamFrameData>> stream_frame_buffer_;
|
|
std::string current_video_path_;
|
|
|
|
mutable std::mutex ctrl_mtx_;
|
|
// SDK callbacks must never take ctrl_mtx_: NET_DVR_StopRealPlay may wait
|
|
// for an in-flight callback while stop() owns that mutex. This mutex is the
|
|
// single synchronization domain for callback publication and stream state.
|
|
mutable std::mutex callback_mtx_;
|
|
bool callback_publishing_enabled_ = false;
|
|
long callback_preview_handle_ = -1;
|
|
std::vector<uint8_t> es_stream_header_;
|
|
bool has_es_stream_header_ = false;
|
|
bool awaiting_key_frame_ = false;
|
|
int stream_count_ = 0;
|
|
uint64_t stream_epoch_ = 0;
|
|
uint64_t stream_sequence_ = 0;
|
|
uint32_t codec_config_generation_ = 0;
|
|
};
|
|
|
|
} // namespace cmvr::device
|
|
|
|
#endif // CMVR_ES_HIKVISION_CAMERA_H
|