|
|
@@ -1,6 +1,8 @@
|
|
|
#include "receiver_tcp.h"
|
|
|
+#include "simple_mq.h"
|
|
|
#include "receiver_utility.hpp"
|
|
|
#include "utility.hpp"
|
|
|
+#include "variable_defs.h"
|
|
|
|
|
|
#include <boost/asio/ip/tcp.hpp>
|
|
|
#include <boost/asio/read.hpp>
|
|
|
@@ -13,6 +15,7 @@ using boost::asio::buffer;
|
|
|
using boost::asio::io_context;
|
|
|
using boost::asio::post;
|
|
|
using boost::asio::read;
|
|
|
+using namespace simple_mq_singleton;
|
|
|
|
|
|
struct receiver_tcp::impl {
|
|
|
|
|
|
@@ -23,18 +26,38 @@ struct receiver_tcp::impl {
|
|
|
smart_buffer<uint8_t> in_buf;
|
|
|
|
|
|
void receive_one_frame() {
|
|
|
- auto frame = std::make_unique<video_nal>();
|
|
|
- in_buf.create(sizeof(frame->length));
|
|
|
+ // read packet length
|
|
|
+ uint64_t packet_length;
|
|
|
+ in_buf.create(sizeof(packet_length));
|
|
|
+ read(*socket, buffer(in_buf.ptr, in_buf.length));
|
|
|
+ read_binary_number(in_buf.ptr, &packet_length);
|
|
|
+
|
|
|
+ // read full packet
|
|
|
+ in_buf.create(packet_length);
|
|
|
read(*socket, buffer(in_buf.ptr, in_buf.length));
|
|
|
- read_binary_number(in_buf.ptr, &frame->length);
|
|
|
- frame->create(nullptr, frame->length, true);
|
|
|
- read(*socket, buffer(frame->ptr, frame->length));
|
|
|
+
|
|
|
+ // read frame id
|
|
|
+ uint64_t frame_id;
|
|
|
+ auto ptr = read_binary_number(in_buf.ptr, &frame_id);
|
|
|
+ auto frame_length = packet_length
|
|
|
+ - sizeof(frame_id);
|
|
|
+
|
|
|
+ // read frame content
|
|
|
+ auto frame = std::make_unique<video_nal>();
|
|
|
+ frame->create(ptr, frame_length);
|
|
|
+ q_this->log_frame_received(frame_id);
|
|
|
decoder->decode(std::move(frame));
|
|
|
+ SPDLOG_TRACE("Frame {} decoded.", frame_id);
|
|
|
}
|
|
|
|
|
|
void receive_frames() {
|
|
|
try {
|
|
|
for (;;) {
|
|
|
+ // check if stop requested
|
|
|
+ if (mq().query_variable<bool>(RECEIVER_SHOULD_STOP)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
receive_one_frame();
|
|
|
}
|
|
|
} catch (std::exception &e) {
|