align Hikvision camera with lgv device interfaces
This commit is contained in:
parent
06cda57311
commit
1153391670
@ -34,6 +34,10 @@ namespace cmvr::device {
|
|||||||
virtual bool start() { return true; }
|
virtual bool start() { return true; }
|
||||||
virtual bool stop() { return true; }
|
virtual bool stop() { return true; }
|
||||||
virtual bool update() { return true; }
|
virtual bool update() { return true; }
|
||||||
|
virtual bool executeJsonCommand(const std::string& request_json, std::string& response_json) {
|
||||||
|
response_json = R"({"success":false,"error_message":"JSON command unsupported"})";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string id_; // 设备名称
|
std::string id_; // 设备名称
|
||||||
|
|||||||
@ -95,25 +95,7 @@ namespace cmvr::device {
|
|||||||
~AbstractCamera() override = default;
|
~AbstractCamera() override = default;
|
||||||
|
|
||||||
DeviceKind kind() const noexcept override { return DeviceKind::Camera; }
|
DeviceKind kind() const noexcept override { return DeviceKind::Camera; }
|
||||||
// Every implementation must take the same lock used by its state_
|
|
||||||
// writers; CameraState contains std::string and cannot be snapshotted
|
|
||||||
// safely while another thread mutates it.
|
|
||||||
virtual void getState(CameraState &state) = 0;
|
virtual void getState(CameraState &state) = 0;
|
||||||
DeviceHealthSnapshot healthSnapshot() override {
|
|
||||||
CameraState state{};
|
|
||||||
getState(state);
|
|
||||||
|
|
||||||
DeviceHealthSnapshot health;
|
|
||||||
health.error_message = state.error_message;
|
|
||||||
if (state.is_error) {
|
|
||||||
health.state = DeviceHealthState::Fault;
|
|
||||||
} else if (!state.error_message.empty()) {
|
|
||||||
health.state = DeviceHealthState::Degraded;
|
|
||||||
} else if (state.is_initialized) {
|
|
||||||
health.state = DeviceHealthState::Healthy;
|
|
||||||
}
|
|
||||||
return health;
|
|
||||||
}
|
|
||||||
virtual void getRGBImage(cv::Mat &color, Rs2Intrinsics& intrinsics) {}
|
virtual void getRGBImage(cv::Mat &color, Rs2Intrinsics& intrinsics) {}
|
||||||
virtual void getDepthImage(cv::Mat &depth, Rs2Intrinsics& intrinsics) {}
|
virtual void getDepthImage(cv::Mat &depth, Rs2Intrinsics& intrinsics) {}
|
||||||
virtual void getRGBDImages(cv::Mat &color, cv::Mat &depth, Rs2Intrinsics& intrinsics) {}
|
virtual void getRGBDImages(cv::Mat &color, cv::Mat &depth, Rs2Intrinsics& intrinsics) {}
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
@ -466,13 +467,17 @@ bool HikvisionCamera::waitEncodedFrame(
|
|||||||
if (!stream_frame_buffer_) {
|
if (!stream_frame_buffer_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto frame = stream_frame_buffer_->waitPop(index, timeout);
|
const auto deadline = std::chrono::steady_clock::now() + timeout;
|
||||||
if (!frame) {
|
do {
|
||||||
return false;
|
auto frame = stream_frame_buffer_->pop(index);
|
||||||
}
|
if (frame) {
|
||||||
frame_data = std::move(*frame);
|
frame_data = std::move(*frame);
|
||||||
return !frame_data.rgbFrame.empty() || !frame_data.depthFrame.empty();
|
return !frame_data.rgbFrame.empty() || !frame_data.depthFrame.empty();
|
||||||
}
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
|
} while (std::chrono::steady_clock::now() < deadline);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool HikvisionCamera::getLatestEncodedFrame(StreamFrameData& frame_data, size_t& next_index)
|
bool HikvisionCamera::getLatestEncodedFrame(StreamFrameData& frame_data, size_t& next_index)
|
||||||
{
|
{
|
||||||
@ -480,12 +485,17 @@ bool HikvisionCamera::getLatestEncodedFrame(StreamFrameData& frame_data, size_t&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto frame = stream_frame_buffer_->getLatest(next_index);
|
const size_t head = stream_frame_buffer_->getHead();
|
||||||
|
if (head == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
next_index = head - 1;
|
||||||
|
auto frame = stream_frame_buffer_->pop(next_index);
|
||||||
if (!frame.has_value()) {
|
if (!frame.has_value()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame_data = frame.value();
|
frame_data = std::move(*frame);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user