From f11cb695a103e48f908756126031c3e32159d512 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Tue, 28 Dec 2021 08:03:44 -0700 Subject: [PATCH] better sequence counting in CM17Protocol --- reflector/CodecStream.cpp | 14 ++++++------- reflector/CodecStream.h | 10 ++++----- reflector/M17Protocol.cpp | 44 +++++++++++++++++++++------------------ 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/reflector/CodecStream.cpp b/reflector/CodecStream.cpp index dc92c13..9f10bd9 100644 --- a/reflector/CodecStream.cpp +++ b/reflector/CodecStream.cpp @@ -54,14 +54,14 @@ CCodecStream::~CCodecStream() } // display stats - if (m_RTMin >= 0.0) + if (m_RTCount > 0) { - double min = m_RTMin * 1000.0; - double max = m_RTMax * 1000.0; - double ave = (m_RTCount > 0) ? m_RTSum / m_RTCount * 1000.0 : 0.0; + double min = 1000.0 * m_RTMin; + double max = 1000.0 * m_RTMax; + double ave = 1000.0 * m_RTSum / double(m_RTCount); auto prec = std::cout.precision(); std::cout.precision(1); - std::cout << std::fixed << "Transcoder Stats (ms): " << min << "/" << ave << "/" << max << std::endl; + std::cout << std::fixed << "TC round-trip time(ms): " << min << "/" << ave << "/" << max << ", " << m_RTCount << " total packets" << std::endl; std::cout.precision(prec); } } @@ -103,7 +103,7 @@ void CCodecStream::Task(void) if (m_TCReader->Receive(&pack, 5)) { // update statistics - double rt = pack.rt_timer.time(); + double rt = pack.rt_timer.time(); // the round-trip time if ( m_RTMin == -1 ) { m_RTMin = rt; @@ -117,7 +117,7 @@ void CCodecStream::Task(void) } m_RTSum += rt; - m_RTCount += 1; + m_RTCount++; if ( m_LocalQueue.empty() ) { diff --git a/reflector/CodecStream.h b/reflector/CodecStream.h index fc729b7..863954c 100644 --- a/reflector/CodecStream.h +++ b/reflector/CodecStream.h @@ -65,9 +65,9 @@ protected: std::future m_Future; // statistics - double m_RTMin; - double m_RTMax; - double m_RTSum; - double m_RTCount; - uint32_t m_uiTotalPackets; + double m_RTMin; + double m_RTMax; + double m_RTSum; + unsigned int m_RTCount; + uint32_t m_uiTotalPackets; }; diff --git a/reflector/M17Protocol.cpp b/reflector/M17Protocol.cpp index a9c5133..94a1d57 100644 --- a/reflector/M17Protocol.cpp +++ b/reflector/M17Protocol.cpp @@ -236,32 +236,36 @@ void CM17Protocol::HandleQueue(void) m_StreamsCache[module].m_dvHeader = CDvHeaderPacket((const CDvHeaderPacket &)*packet.get()); m_StreamsCache[module].m_iSeqCounter = 0; } - else if ( packet->IsDvFrame() && ((1 == m_StreamsCache[module].m_iSeqCounter++ % 2) || packet->IsLastPacket())) + else if (packet->IsDvFrame()) { - // encode it - SM17Frame frame; + if ((1 == m_StreamsCache[module].m_iSeqCounter % 2) || packet->IsLastPacket()) + { + // encode it + SM17Frame frame; - EncodeM17Packet(frame, m_StreamsCache[module].m_dvHeader, (CDvFramePacket *)packet.get(), m_StreamsCache[module].m_iSeqCounter-1); + EncodeM17Packet(frame, m_StreamsCache[module].m_dvHeader, (CDvFramePacket *)packet.get(), m_StreamsCache[module].m_iSeqCounter); - // push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Reflector.GetClients(); - auto it = clients->begin(); - std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(EProtocol::m17, it)) != nullptr ) - { - // is this client busy ? - if ( !client->IsAMaster() && (client->GetReflectorModule() == module) ) + // push it to all our clients linked to the module and who are not streaming in + CClients *clients = g_Reflector.GetClients(); + auto it = clients->begin(); + std::shared_ptrclient = nullptr; + while ( (client = clients->FindNextClient(EProtocol::m17, it)) != nullptr ) { - // set the destination - client->GetCallsign().CodeOut(frame.lich.addr_dst); - // set the crc - frame.crc = htons(m17crc.CalcCRC(frame.magic, sizeof(SM17Frame)-2)); - // now send the packet - Send(frame, client->GetIp()); - + // is this client busy ? + if ( !client->IsAMaster() && (client->GetReflectorModule() == module) ) + { + // set the destination + client->GetCallsign().CodeOut(frame.lich.addr_dst); + // set the crc + frame.crc = htons(m17crc.CalcCRC(frame.magic, sizeof(SM17Frame)-2)); + // now send the packet + Send(frame, client->GetIp()); + + } } + g_Reflector.ReleaseClients(); } - g_Reflector.ReleaseClients(); + m_StreamsCache[module].m_iSeqCounter++; } } m_Queue.Unlock();