better sequence counting in CM17Protocol

unstable
Tom Early 4 years ago
parent bf6ed1d3a8
commit f11cb695a1

@ -54,14 +54,14 @@ CCodecStream::~CCodecStream()
} }
// display stats // display stats
if (m_RTMin >= 0.0) if (m_RTCount > 0)
{ {
double min = m_RTMin * 1000.0; double min = 1000.0 * m_RTMin;
double max = m_RTMax * 1000.0; double max = 1000.0 * m_RTMax;
double ave = (m_RTCount > 0) ? m_RTSum / m_RTCount * 1000.0 : 0.0; double ave = 1000.0 * m_RTSum / double(m_RTCount);
auto prec = std::cout.precision(); auto prec = std::cout.precision();
std::cout.precision(1); 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); std::cout.precision(prec);
} }
} }
@ -103,7 +103,7 @@ void CCodecStream::Task(void)
if (m_TCReader->Receive(&pack, 5)) if (m_TCReader->Receive(&pack, 5))
{ {
// update statistics // update statistics
double rt = pack.rt_timer.time(); double rt = pack.rt_timer.time(); // the round-trip time
if ( m_RTMin == -1 ) if ( m_RTMin == -1 )
{ {
m_RTMin = rt; m_RTMin = rt;
@ -117,7 +117,7 @@ void CCodecStream::Task(void)
} }
m_RTSum += rt; m_RTSum += rt;
m_RTCount += 1; m_RTCount++;
if ( m_LocalQueue.empty() ) if ( m_LocalQueue.empty() )
{ {

@ -65,9 +65,9 @@ protected:
std::future<void> m_Future; std::future<void> m_Future;
// statistics // statistics
double m_RTMin; double m_RTMin;
double m_RTMax; double m_RTMax;
double m_RTSum; double m_RTSum;
double m_RTCount; unsigned int m_RTCount;
uint32_t m_uiTotalPackets; uint32_t m_uiTotalPackets;
}; };

@ -236,32 +236,36 @@ void CM17Protocol::HandleQueue(void)
m_StreamsCache[module].m_dvHeader = CDvHeaderPacket((const CDvHeaderPacket &)*packet.get()); m_StreamsCache[module].m_dvHeader = CDvHeaderPacket((const CDvHeaderPacket &)*packet.get());
m_StreamsCache[module].m_iSeqCounter = 0; 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 if ((1 == m_StreamsCache[module].m_iSeqCounter % 2) || packet->IsLastPacket())
SM17Frame frame; {
// 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 // push it to all our clients linked to the module and who are not streaming in
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
auto it = clients->begin(); auto it = clients->begin();
std::shared_ptr<CClient>client = nullptr; std::shared_ptr<CClient>client = nullptr;
while ( (client = clients->FindNextClient(EProtocol::m17, it)) != nullptr ) while ( (client = clients->FindNextClient(EProtocol::m17, it)) != nullptr )
{
// is this client busy ?
if ( !client->IsAMaster() && (client->GetReflectorModule() == module) )
{ {
// set the destination // is this client busy ?
client->GetCallsign().CodeOut(frame.lich.addr_dst); if ( !client->IsAMaster() && (client->GetReflectorModule() == module) )
// set the crc {
frame.crc = htons(m17crc.CalcCRC(frame.magic, sizeof(SM17Frame)-2)); // set the destination
// now send the packet client->GetCallsign().CodeOut(frame.lich.addr_dst);
Send(frame, client->GetIp()); // 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(); m_Queue.Unlock();

Loading…
Cancel
Save

Powered by TurnKey Linux.