From 85e65ee17160ade86b2179d27b387b27f7e4396f Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 15 Nov 2019 16:14:11 +0100 Subject: Fix PAD UDP send bug --- src/AVTInput.cpp | 26 +++++++++++++++----------- src/AVTInput.h | 4 ++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/AVTInput.cpp b/src/AVTInput.cpp index 3bf1bd6..2610b5c 100644 --- a/src/AVTInput.cpp +++ b/src/AVTInput.cpp @@ -57,7 +57,7 @@ AVTInput::AVTInput(const std::string& input_uri, _jitterBufferSize(jitterBufferSize), _output_packet(2048), - _input_pad_packet(2048), + _pad_packet(2048), _ordered(5000, _jitterBufferSize), _lastInfoFrameType(_typeCantExtract) { } @@ -313,10 +313,12 @@ void AVTInput::_sendPADFrame() 0xAD, static_cast(frame.size())}); - Socket::UDPPacket packet; - packet.buffer = buf; - copy(frame.begin(), frame.end(), back_inserter(packet.buffer)); - _input_pad_socket.send(packet); + // Always keep the same packet, as it contains the destination address. + // This function only gets called from _interpretMessage(), which + // only gets called after a successful packet reception. + _pad_packet.buffer = move(buf); + copy(frame.begin(), frame.end(), back_inserter(_pad_packet.buffer)); + _input_pad_socket.send(_pad_packet); } } @@ -326,7 +328,7 @@ void AVTInput::_sendPADFrame() * Command code : 1 Byte * * 0x17 = Request for 1 PAD Frame */ -void AVTInput::_interpretMessage(const uint8_t* data, size_t size) +void AVTInput::_interpretMessage(const uint8_t *data, size_t size) { if (size >= 2) { if (data[0] == 0xFD) { @@ -341,12 +343,12 @@ void AVTInput::_interpretMessage(const uint8_t* data, size_t size) bool AVTInput::_checkMessage() { - const auto packet = _input_pad_socket.receive(2048); - if (packet.buffer.empty()) { + _pad_packet = _input_pad_socket.receive(2048); + if (_pad_packet.buffer.empty()) { return false; } - _interpretMessage(packet.buffer.data(), packet.buffer.size()); + _interpretMessage(_pad_packet.buffer.data(), _pad_packet.buffer.size()); return true; } @@ -354,9 +356,11 @@ bool AVTInput::_checkMessage() void AVTInput::_purgeMessages() { int nb = 0; - while (not _input_pad_socket.receive(2048).buffer.empty()) { + do { + _pad_packet = _input_pad_socket.receive(2048); nb++; - } + } while (not _pad_packet.buffer.empty()); + if (nb>0) DEBUG("%d messages purged\n", nb); } diff --git a/src/AVTInput.h b/src/AVTInput.h index 0f58418..2921160 100644 --- a/src/AVTInput.h +++ b/src/AVTInput.h @@ -105,7 +105,7 @@ class AVTInput Socket::UDPSocket _output_socket; Socket::UDPPacket _output_packet; Socket::UDPSocket _input_pad_socket; - Socket::UDPPacket _input_pad_packet; + Socket::UDPPacket _pad_packet; OrderedQueue _ordered; std::queue > _padFrameQueue; @@ -128,7 +128,7 @@ class AVTInput void _sendCtrlMessage(); void _sendPADFrame(); - void _interpretMessage(const uint8_t* data, size_t size); + void _interpretMessage(const uint8_t *data, size_t size); bool _checkMessage(); void _purgeMessages(); -- cgit v1.2.3