Skip to content

Commit

Permalink
Refactor method
Browse files Browse the repository at this point in the history
  • Loading branch information
Geeoon committed Jul 18, 2024
1 parent a11c024 commit 3cfdc55
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/network/MissionControlTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,14 @@ void CameraStreamTask::closeStream(const CameraID& cam) {
}

void CameraStreamTask::sendCurrentFrame(const robot::types::CameraID& cam) {
std::string b64_data = "";
{
std::lock_guard lg(_mutex);
if (_open_streams.find(cam) != _open_streams.end()) {
auto camDP = robot::readCamera(cam);
if (camDP) {
auto data = camDP.getData();
cv::Mat frame = data.first;
b64_data = base64::encodeMat(frame, ".jpg");
}
}
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);
}
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<std::mutex>&) {
Expand Down

0 comments on commit 3cfdc55

Please sign in to comment.