From 338a88feaf7925275e15de74422cfd891fcbc6e0 Mon Sep 17 00:00:00 2001 From: Geeoon Chung Date: Thu, 18 Jul 2024 13:42:40 -0700 Subject: [PATCH] Remove sendCurrentFrame --- src/network/MissionControlProtocol.cpp | 10 +++++++++- src/network/MissionControlTasks.cpp | 12 ------------ src/network/MissionControlTasks.h | 7 ------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/network/MissionControlProtocol.cpp b/src/network/MissionControlProtocol.cpp index 0c2f09a0..367858d2 100644 --- a/src/network/MissionControlProtocol.cpp +++ b/src/network/MissionControlProtocol.cpp @@ -6,6 +6,7 @@ #include "../control_interface.h" #include "../utils/core.h" #include "../utils/json.h" +#include "../base64/base64_img.h" #include "../world_interface/data.h" #include "../world_interface/world_interface.h" #include "MissionControlMessages.h" @@ -325,7 +326,14 @@ static bool validateCameraFrameRequest(const json& j) { void MissionControlProtocol::handleCameraFrameRequest(const json& j) { CameraID cam = j["camera"]; - _camera_stream_task.sendCurrentFrame(cam); + auto camDP = robot::readCamera(cam); + if (camDP) { + auto data = camDP.getData(); + cv::Mat frame = data.first; + std::string b64_data = base64::encodeMat(frame, ".jpg"); + json msg = {{"type", CAMERA_FRAME_REP_TYPE}, {"camera", cam}, {"data", b64_data}}; + _server.sendJSON(Constants::MC_PROTOCOL_NAME, msg); + } } void MissionControlProtocol::sendArmIKEnabledReport(bool enabled) { diff --git a/src/network/MissionControlTasks.cpp b/src/network/MissionControlTasks.cpp index 68a96463..7b4cf874 100644 --- a/src/network/MissionControlTasks.cpp +++ b/src/network/MissionControlTasks.cpp @@ -2,7 +2,6 @@ #include "../Constants.h" #include "../Globals.h" -#include "../base64/base64_img.h" #include "../control_interface.h" #include "../utils/core.h" #include "../world_interface/world_interface.h" @@ -142,17 +141,6 @@ void CameraStreamTask::closeStream(const CameraID& cam) { _camera_encoders.erase(cam); } -void CameraStreamTask::sendCurrentFrame(const robot::types::CameraID& cam) { - auto camDP = robot::readCamera(cam); - if (camDP) { - auto data = camDP.getData(); - cv::Mat frame = data.first; - std::string b64_data = base64::encodeMat(frame, ".jpg"); - json msg = {{"type", CAMERA_FRAME_REP_TYPE}, {"camera", cam}, {"data", b64_data}}; - _server.sendJSON(Constants::MC_PROTOCOL_NAME, msg); - } -} - void CameraStreamTask::task(std::unique_lock&) { while (isRunningInternal()) { { diff --git a/src/network/MissionControlTasks.h b/src/network/MissionControlTasks.h index 927e6346..8915cd20 100644 --- a/src/network/MissionControlTasks.h +++ b/src/network/MissionControlTasks.h @@ -88,13 +88,6 @@ class CameraStreamTask : public util::AsyncTask<> { */ void closeStream(const robot::types::CameraID& cam); - /** - * @brief Send the current frame of an open stream to Mission Control as a - * base64 encoded string. - * @param cam The camera that should be sent. - */ - void sendCurrentFrame(const robot::types::CameraID& cam); - protected: void task(std::unique_lock& lock) override;