diff --git a/reflector/CodecStream.cpp b/reflector/CodecStream.cpp index 8c1c520..dc92c13 100644 --- a/reflector/CodecStream.cpp +++ b/reflector/CodecStream.cpp @@ -31,12 +31,11 @@ CCodecStream::CCodecStream(CPacketStream *PacketStream, uint16_t streamid, ECode m_uiStreamId = streamid; m_uiPid = 0; m_eCodecIn = type; - m_fPingMin = -1; - m_fPingMax = -1; - m_fPingSum = 0; - m_fPingCount = 0; + m_RTMin = -1; + m_RTMax = -1; + m_RTSum = 0; + m_RTCount = 0; m_uiTotalPackets = 0; - m_uiTimeoutPackets = 0; m_PacketStream = PacketStream; m_TCReader = reader; InitCodecStream(); @@ -55,20 +54,16 @@ CCodecStream::~CCodecStream() } // display stats - if (m_fPingMin >= 0.0) + if (m_RTMin >= 0.0) { - double min = m_fPingMin * 1000.0; - double max = m_fPingMax * 1000.0; - double ave = (m_fPingCount > 0) ? m_fPingSum / m_fPingCount * 1000.0 : 0.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; auto prec = std::cout.precision(); std::cout.precision(1); std::cout << std::fixed << "Transcoder Stats (ms): " << min << "/" << ave << "/" << max << std::endl; std::cout.precision(prec); } - if (m_uiTimeoutPackets) - { - std::cout << m_uiTimeoutPackets << " of " << m_uiTotalPackets << " packets timed out" << std::endl; - } } //////////////////////////////////////////////////////////////////////////////////////// @@ -107,25 +102,22 @@ void CCodecStream::Task(void) // any packet from transcoder if (m_TCReader->Receive(&pack, 5)) { - // tickle - m_TimeoutTimer.start(); - // update statistics - double ping = m_StatsTimer.time(); - if ( m_fPingMin == -1 ) + double rt = pack.rt_timer.time(); + if ( m_RTMin == -1 ) { - m_fPingMin = ping; - m_fPingMax = ping; + m_RTMin = rt; + m_RTMax = rt; } else { - m_fPingMin = MIN(m_fPingMin, ping); - m_fPingMax = MAX(m_fPingMax, ping); + m_RTMin = MIN(m_RTMin, rt); + m_RTMax = MAX(m_RTMax, rt); } - m_fPingSum += ping; - m_fPingCount += 1; + m_RTSum += rt; + m_RTCount += 1; if ( m_LocalQueue.empty() ) { @@ -136,13 +128,19 @@ void CCodecStream::Task(void) // pop the original packet auto Packet = m_LocalQueue.pop(); auto Frame = (CDvFramePacket *)Packet.get(); - // todo: check the PID + + // do things look okay? + if (pack.sequence != Frame->GetCodecPacket()->sequence) + std::cerr << "Sequence mismatch: this voice frame=" << Frame->GetCodecPacket()->sequence << " returned transcoder packet=" << pack.sequence << std::endl; + if (pack.streamid != Frame->GetCodecPacket()->streamid) + std::cerr << std::hex << std::showbase << "StreamID mismatch: this voice frame=" << ntohs(Frame->GetCodecPacket()->streamid) << " returned transcoder packet=" << ntohs(pack.streamid) << std::dec << std::noshowbase << std::endl; + // update content with transcoded data Frame->SetCodecData(&pack); // mark the DStar sync frames if the source isn't dstar if (ECodecType::dstar!=Frame->GetCodecIn() && 0==Frame->GetPacketId()%21) { - const uint8_t DStarSync[] = { 0x55,0x2D,0x16 }; + const uint8_t DStarSync[] = { 0x55, 0x2D, 0x16 }; Frame->SetDvData(DStarSync); } @@ -163,25 +161,16 @@ void CCodecStream::Task(void) auto Frame = (CDvFramePacket *)Packet.get(); // update important stuff in Frame->m_TCPack for the transcoder - Frame->SetTCParams(); + Frame->SetTCParams(m_uiTotalPackets); // now send to transcoder // this assume that thread pushing the Packet // have verified that the CodecStream is connected // and that the packet needs transcoding - m_StatsTimer.start(); m_uiTotalPackets++; m_TCWriter.Send(Frame->GetCodecPacket()); // and push to our local queue m_LocalQueue.push(Packet); } - - // handle timeout - if ( !m_LocalQueue.empty() && (m_TimeoutTimer.time() >= (TRANSCODER_AMBEPACKET_TIMEOUT/1000.0f)) ) - { - //std::cout << "transcoder packet timeout" << std::endl; - m_uiTimeoutPackets++; - m_TimeoutTimer.start(); - } } diff --git a/reflector/CodecStream.h b/reflector/CodecStream.h index 70caa67..fc729b7 100644 --- a/reflector/CodecStream.h +++ b/reflector/CodecStream.h @@ -63,14 +63,11 @@ protected: // thread std::atomic keep_running; std::future m_Future; - CTimer m_TimeoutTimer; - CTimer m_StatsTimer; // statistics - double m_fPingMin; - double m_fPingMax; - double m_fPingSum; - double m_fPingCount; + double m_RTMin; + double m_RTMax; + double m_RTSum; + double m_RTCount; uint32_t m_uiTotalPackets; - uint32_t m_uiTimeoutPackets; }; diff --git a/reflector/DVFramePacket.cpp b/reflector/DVFramePacket.cpp index a244832..aee8940 100644 --- a/reflector/DVFramePacket.cpp +++ b/reflector/DVFramePacket.cpp @@ -147,12 +147,14 @@ void CDvFramePacket::SetCodecData(const STCPacket *pack) memcpy(&m_TCPack, pack, sizeof(STCPacket)); } -void CDvFramePacket::SetTCParams() +void CDvFramePacket::SetTCParams(uint32_t seq) { + m_TCPack.sequence = seq; m_TCPack.streamid = m_uiStreamId; m_TCPack.is_second = m_bIsSecond; m_TCPack.is_last = m_bLastPacket; m_TCPack.module = m_cModule; + m_TCPack.rt_timer.start(); } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/reflector/DVFramePacket.h b/reflector/DVFramePacket.h index 11c10bb..1af47a2 100644 --- a/reflector/DVFramePacket.h +++ b/reflector/DVFramePacket.h @@ -67,7 +67,7 @@ public: // set void SetDvData(const uint8_t *); void SetCodecData(const STCPacket *pack); - void SetTCParams(void); + void SetTCParams(uint32_t seq); // operators bool operator ==(const CDvFramePacket &) const; diff --git a/reflector/M17Protocol.cpp b/reflector/M17Protocol.cpp index 658da55..d39dd39 100644 --- a/reflector/M17Protocol.cpp +++ b/reflector/M17Protocol.cpp @@ -76,7 +76,7 @@ void CM17Protocol::Task(void) // xrf needs a voice frame every 20 ms and an M17 frame is 40 ms, so we need a duplicate auto secondFrame = std::unique_ptr(new CDvFramePacket(*Frame.get())); - // This is a "first" packet, so clear the last packet status, since the real last packet it the secondFrame + // This is not a second packet, so clear the last packet status, since the real last packet it the secondFrame if (Frame->IsLastPacket()) Frame->SetLastPacket(false); diff --git a/reflector/TCPacketDef.h b/reflector/TCPacketDef.h index 712d414..5ffb3fe 100644 --- a/reflector/TCPacketDef.h +++ b/reflector/TCPacketDef.h @@ -17,6 +17,8 @@ #include +#include "Timer.h" + // unix socket names #define TC2REF "TC2URFMod" #define REF2TC "URF2TC" @@ -24,6 +26,8 @@ enum class ECodecType : std::uint8_t { none = 0, dstar = 1, dmr = 2, c2_1600 = 3, c2_3200 = 4 }; using STCPacket = struct tcpacket_tag { + CTimer rt_timer; + uint32_t sequence; char module; bool is_second, is_last; uint16_t streamid;