From d01bed9bd969a77b0a8092b1612ee8b225861c5b Mon Sep 17 00:00:00 2001 From: narspt Date: Wed, 14 Apr 2021 00:59:43 +0100 Subject: [PATCH 1/2] Update cdextraprotocol.h --- src/cdextraprotocol.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cdextraprotocol.h b/src/cdextraprotocol.h index 3c623fc..8ebc81c 100644 --- a/src/cdextraprotocol.h +++ b/src/cdextraprotocol.h @@ -55,6 +55,15 @@ //////////////////////////////////////////////////////////////////////////////////////// // class +class CDextraStreamCacheItem +{ +public: + CDextraStreamCacheItem() {} + ~CDextraStreamCacheItem() {} + + CDvHeaderPacket m_dvHeader; +}; + class CDextraProtocol : public CProtocol { public: @@ -101,6 +110,9 @@ protected: protected: // time CTimePoint m_LastKeepaliveTime; + + // for queue header caches + std::array m_StreamsCache; }; //////////////////////////////////////////////////////////////////////////////////////// From e6a5c7aed110a1605abef216393cb54c2a1e2119 Mon Sep 17 00:00:00 2001 From: narspt Date: Wed, 14 Apr 2021 01:55:26 +0100 Subject: [PATCH 2/2] Update cdextraprotocol.cpp --- src/cdextraprotocol.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/cdextraprotocol.cpp b/src/cdextraprotocol.cpp index 8aa88ab..4b05e57 100644 --- a/src/cdextraprotocol.cpp +++ b/src/cdextraprotocol.cpp @@ -118,6 +118,27 @@ void CDextraProtocol::Task(void) // acknowledge the request EncodeConnectAckPacket(&Buffer, ProtRev); m_Socket.Send(Buffer, Ip); + + // check if any client currently streaming on the module + CClients *clients = g_Reflector.GetClients(); + for ( int i = 0; i < clients->GetSize(); i++ ) + { + if ( clients->GetClient(i)->IsAMaster() && (clients->GetClient(i)->GetReflectorModule() == ToLinkModule) ) + { + // found a client streaming on the module, encode a copy of the cached header packet + CBuffer buffer2; + if ( EncodeDvPacket(m_StreamsCache[g_Reflector.GetModuleIndex(ToLinkModule)].m_dvHeader, &buffer2) ) + { + // and send it to the connecting client, so it can listen the already streaming client + for ( int j = 0; j < 5; j++ ) + { + m_Socket.Send(buffer2, Ip); + } + } + break; // done, stop here + } + } + g_Reflector.ReleaseClients(); // create the client CDextraClient *client = new CDextraClient(Callsign, Ip, ToLinkModule, ProtRev); @@ -216,6 +237,16 @@ void CDextraProtocol::HandleQueue(void) CPacket *packet = m_Queue.front(); m_Queue.pop(); + // get our sender's id + int iModId = g_Reflector.GetModuleIndex(packet->GetModuleId()); + + // check if it's header and update cache + if ( packet->IsDvHeader() ) + { + // this relies on queue feeder setting valid module id + m_StreamsCache[iModId].m_dvHeader = CDvHeaderPacket((const CDvHeaderPacket &)*packet); + } + // encode it CBuffer buffer; if ( EncodeDvPacket(*packet, &buffer) )