24#include "frame_with_timestamp_recorder.hpp"
27namespace presage::smartspectra::grpc_bindings {
30template<container::settings::IntegrationMode TIntegrationMode>
31FrameWithTimestampRecorder<TIntegrationMode>::FrameWithTimestampRecorder(
32 std::shared_ptr<BackgroundContainer> container,
35 container(std::move(container)),
36 input_transformer{input_transform_mode} {
37 StartRead(&this->frame_with_timestamp);
40template<container::settings::IntegrationMode TIntegrationMode>
41void FrameWithTimestampRecorder<TIntegrationMode>::SwapContainer(std::shared_ptr<BackgroundContainer> new_container) {
42 this->container.reset();
43 this->container = std::move(new_container);
46inline cv::Mat BuildOpenCVMatFromProtoBuf(
const smartspectra::Mat& mat_protobuf) {
47 cv::Mat mat_cv(mat_protobuf.rows(), mat_protobuf.cols(), mat_protobuf.element_type());
48 size_t data_bytesize = mat_cv.rows * mat_cv.cols * mat_cv.elemSize();
49 auto data_protobuf =
const_cast<char*
>(mat_protobuf.data().data());
50 std::copy(
reinterpret_cast<unsigned char*
>(data_protobuf),
51 reinterpret_cast<unsigned char*
>(data_protobuf + data_bytesize),
56template<container::settings::IntegrationMode TIntegrationMode>
57void FrameWithTimestampRecorder<TIntegrationMode>::OnReadDone(
bool ok) {
59 if (this->container ==
nullptr || !this->container->GraphIsRunning()) {
60 Finish(grpc::Status(grpc::StatusCode::FAILED_PRECONDITION,
61 "Physiology Preprocessing is not running, unable to add frame."));
63 cv::Mat frame = BuildOpenCVMatFromProtoBuf(frame_with_timestamp.frame());
64 frame = this->input_transformer.apply(frame);
65 rpc::StatusAdapter status_adapter = container
66 ->AddFrameWithTimestamp(frame, frame_with_timestamp.timestamp());
67 if (!status_adapter.ok()) {
68 Finish(status_adapter);
70 StartRead(&this->frame_with_timestamp);
73 Finish(grpc::Status(grpc::StatusCode::INTERNAL,
"Unexpected failure reading frame with timestamp."));
InputTransformMode
Transformation applied to frames prior to processing.
Definition input_transform.hpp:19