From efa604935f4319f451d5ffc955a3c651e96f8519 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sun, 30 Jan 2022 17:35:20 -0700 Subject: [PATCH] only return packet once --- Controller.cpp | 7 ++++--- TranscoderPacket.cpp | 12 +++++++++++- TranscoderPacket.h | 4 +++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Controller.cpp b/Controller.cpp index 21ee4bf..26060bf 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -258,7 +258,7 @@ void CController::AudiotoCodec2(std::shared_ptr packet) } // we might be all done... send_mux.lock(); - if (packet->AllCodecsAreSet()) SendToReflector(packet); + if (packet->AllCodecsAreSet() && packet->HasNotBeenSent()) SendToReflector(packet); send_mux.unlock(); } @@ -345,6 +345,7 @@ void CController::SendToReflector(std::shared_ptr packet) // send the packet over the socket socket.Send(packet->GetTCPacket()); // the socket will automatically close after sending + packet->Sent(); } void CController::RouteDstPacket(std::shared_ptr packet) @@ -358,7 +359,7 @@ void CController::RouteDstPacket(std::shared_ptr packet) else { send_mux.lock(); - if (packet->AllCodecsAreSet()) SendToReflector(packet); + if (packet->AllCodecsAreSet() && packet->HasNotBeenSent()) SendToReflector(packet); send_mux.unlock(); } } @@ -373,7 +374,7 @@ void CController::RouteDmrPacket(std::shared_ptr packet) else { send_mux.lock(); - if (packet->AllCodecsAreSet()) SendToReflector(packet); + if (packet->AllCodecsAreSet() && packet->HasNotBeenSent()) SendToReflector(packet); send_mux.unlock(); } } diff --git a/TranscoderPacket.cpp b/TranscoderPacket.cpp index 0b95fe1..76df4a0 100644 --- a/TranscoderPacket.cpp +++ b/TranscoderPacket.cpp @@ -19,7 +19,7 @@ #include "TranscoderPacket.h" -CTranscoderPacket::CTranscoderPacket(const STCPacket &tcp) : dstar_set(false), dmr_set(false), m17_set(false) +CTranscoderPacket::CTranscoderPacket(const STCPacket &tcp) : dstar_set(false), dmr_set(false), m17_set(false), not_sent(true) { tcpacket.module = tcp.module; tcpacket.is_last = tcp.is_last; @@ -147,3 +147,13 @@ bool CTranscoderPacket::AllCodecsAreSet() const { return (dstar_set && dmr_set && m17_set); } + +void CTranscoderPacket::Sent() +{ + not_sent = false; +} + +bool CTranscoderPacket::HasNotBeenSent() const +{ + return not_sent; +} diff --git a/TranscoderPacket.h b/TranscoderPacket.h index 43e3e34..4986b41 100644 --- a/TranscoderPacket.h +++ b/TranscoderPacket.h @@ -55,6 +55,8 @@ public: bool DMRIsSet() const; bool M17IsSet() const; bool AllCodecsAreSet() const; + void Sent(); + bool HasNotBeenSent() const; // the all important packet const STCPacket *GetTCPacket() const; @@ -62,5 +64,5 @@ public: private: STCPacket tcpacket; int16_t audio[160]; - std::atomic dstar_set, dmr_set, m17_set; + std::atomic_bool dstar_set, dmr_set, m17_set, not_sent; };