diff --git a/reflector/CodecStream.cpp b/reflector/CodecStream.cpp index 301ad12..a45a391 100644 --- a/reflector/CodecStream.cpp +++ b/reflector/CodecStream.cpp @@ -62,7 +62,7 @@ CCodecStream::~CCodecStream() bool CCodecStream::Init() { - m_TCWriter.SetUp("ReftoTC"); + m_TCWriter.SetUp(REF2TC); keep_running = true; m_Future = std::async(std::launch::async, &CCodecStream::Thread, this); @@ -128,9 +128,13 @@ void CCodecStream::Task(void) m_fPingSum += ping; m_fPingCount += 1; - // pop the original packet - if ( !m_LocalQueue.empty() ) + if ( m_LocalQueue.empty() ) { + std::cout << "Unexpected transcoded packet received from transcoder" << std::endl; + } + else + { + // pop the original packet auto Packet = m_LocalQueue.pop(); auto Frame = (CDvFramePacket *)Packet.get(); // todo: check the PID @@ -148,10 +152,6 @@ void CCodecStream::Task(void) m_PacketStream->push(Packet); m_PacketStream->Unlock(); } - else - { - std::cout << "Unexpected transcoded packet received from transcoder" << std::endl; - } } // anything in our queue @@ -159,9 +159,14 @@ void CCodecStream::Task(void) { // yes, pop it from queue auto Packet = pop(); + + // we need a CDvFramePacket pointer to access Frame stuff auto Frame = (CDvFramePacket *)Packet.get(); - // yes, send to transcoder + // update important stuff in Frame->m_TCPack for the transcoder + Frame->SetTCParams(); + + // now send to transcoder // this assume that thread pushing the Packet // have verified that the CodecStream is connected // and that the packet needs transcoding diff --git a/reflector/DVFramePacket.cpp b/reflector/DVFramePacket.cpp index 55cc0bb..2258971 100644 --- a/reflector/DVFramePacket.cpp +++ b/reflector/DVFramePacket.cpp @@ -142,30 +142,17 @@ void CDvFramePacket::SetDvData(const uint8_t *DvData) memcpy(m_uiDvData, DvData, 3); } -void CDvFramePacket::SetCodecData(ECodecType type, const uint8_t *data) -{ - switch (type) - { - case ECodecType::dstar: - memcpy(m_TCPack.dstar, data, 9); - break; - case ECodecType::dmr: - memcpy(m_TCPack.dmr, data, 3); - break; - case ECodecType::c2_1600: - memcpy(m_TCPack.m17, data, 8); - break; - case ECodecType::c2_3200: - memcpy(m_TCPack.m17, data, 16); - break; - } -} - void CDvFramePacket::SetCodecData(const STCPacket *pack) { memcpy(&m_TCPack, pack, sizeof(STCPacket)); } +void CDvFramePacket::SetTCParams() +{ + m_TCPack.streamid = m_uiStreamId; + m_TCPack.is_second = m_bIsSecond; + m_TCPack.is_last = m_bLastPacket; +} //////////////////////////////////////////////////////////////////////////////////////// // operators diff --git a/reflector/DVFramePacket.h b/reflector/DVFramePacket.h index e7a3d9b..8a7cc6c 100644 --- a/reflector/DVFramePacket.h +++ b/reflector/DVFramePacket.h @@ -67,8 +67,8 @@ public: // set void SetDvData(const uint8_t *); - void SetCodecData(ECodecType, const uint8_t *); void SetCodecData(const STCPacket *pack); + void SetTCParams(void); // operators bool operator ==(const CDvFramePacket &) const; diff --git a/reflector/Reflector.cpp b/reflector/Reflector.cpp index 5a2ddf9..17fc240 100644 --- a/reflector/Reflector.cpp +++ b/reflector/Reflector.cpp @@ -87,12 +87,13 @@ bool CReflector::Start(void) for (auto it=m_Modules.cbegin(); it!=m_Modules.cend(); it++) { m_TCReader[*it] = std::make_shared(); - std::string readername("TCtoRef"); + std::string readername(TC2REF); readername.append(1, *it); if (m_TCReader[*it]->Open(readername.c_str())) { std::cerr << "ERROR: Reflector can't open " << readername << std::endl; m_TCReader[*it].reset(); + return false; } m_Stream[*it] = std::make_shared(m_TCReader[*it]); m_RouterFuture[*it] = std::async(std::launch::async, &CReflector::RouterThread, this, *it); diff --git a/reflector/TCPacketDef.h b/reflector/TCPacketDef.h index ed13d70..52c5c82 100644 --- a/reflector/TCPacketDef.h +++ b/reflector/TCPacketDef.h @@ -18,10 +18,15 @@ #include +#define TC2REF "TC2URFMod" +#define REF2TC "URF2TC" + enum class ECodecType : std::uint8_t { none = 0, dstar = 1, dmr = 2, c2_1600 = 3, c2_3200 = 4 }; using STCPacket = struct tcpacket_tag { char module; + bool is_second, is_last; + uint16_t streamid; ECodecType codec_in; uint8_t dstar[9]; uint8_t dmr[9];