Add USRP transcoding

main
Doug McLain 3 years ago
parent 955d126058
commit a2f2068fe7

@ -56,7 +56,8 @@ bool CController::Start()
reflectorFuture = std::async(std::launch::async, &CController::ReadReflectorThread, this); reflectorFuture = std::async(std::launch::async, &CController::ReadReflectorThread, this);
c2Future = std::async(std::launch::async, &CController::ProcessC2Thread, this); c2Future = std::async(std::launch::async, &CController::ProcessC2Thread, this);
swambe2Future = std::async(std::launch::async, &CController::ProcessSWAMBE2Thread,this); swambe2Future = std::async(std::launch::async, &CController::ProcessSWAMBE2Thread,this);
imbeFuture = std::async(std::launch::async, &CController::ProcessIMBEThread,this); imbeFuture = std::async(std::launch::async, &CController::ProcessIMBEThread, this);
usrpFuture = std::async(std::launch::async, &CController::ProcessUSRPThread, this);
return false; return false;
} }
@ -266,6 +267,9 @@ void CController::ReadReflectorThread()
case ECodecType::p25: case ECodecType::p25:
imbe_queue.push(packet); imbe_queue.push(packet);
break; break;
case ECodecType::usrp:
usrp_queue.push(packet);
break;
case ECodecType::c2_1600: case ECodecType::c2_1600:
case ECodecType::c2_3200: case ECodecType::c2_3200:
codec2_queue.push(packet); codec2_queue.push(packet);
@ -303,6 +307,7 @@ void CController::AudiotoCodec2(std::shared_ptr<CTranscoderPacket> packet)
// set the m17_is_set flag if this is the last packet // set the m17_is_set flag if this is the last packet
packet->SetM17Data(m17data); packet->SetM17Data(m17data);
} }
// we might be all done... // we might be all done...
send_mux.lock(); send_mux.lock();
if (packet->AllCodecsAreSet() && packet->HasNotBeenSent()) SendToReflector(packet); if (packet->AllCodecsAreSet() && packet->HasNotBeenSent()) SendToReflector(packet);
@ -363,6 +368,7 @@ void CController::Codec2toAudio(std::shared_ptr<CTranscoderPacket> packet)
packet->SetDMRData(ambe2); packet->SetDMRData(ambe2);
p25vocoder.encode_4400((int16_t*)packet->GetAudioSamples(), imbe); p25vocoder.encode_4400((int16_t*)packet->GetAudioSamples(), imbe);
packet->SetP25Data(imbe); packet->SetP25Data(imbe);
packet->SetUSRPData((int16_t*)packet->GetAudioSamples());
} }
void CController::ProcessC2Thread() void CController::ProcessC2Thread()
@ -383,6 +389,7 @@ void CController::ProcessC2Thread()
case ECodecType::dstar: case ECodecType::dstar:
case ECodecType::dmr: case ECodecType::dmr:
case ECodecType::p25: case ECodecType::p25:
case ECodecType::usrp:
// codec_in was AMBE, so we need to calculate the the M17 data // codec_in was AMBE, so we need to calculate the the M17 data
AudiotoCodec2(packet); AudiotoCodec2(packet);
break; break;
@ -424,6 +431,7 @@ void CController::SWAMBE2toAudio(std::shared_ptr<CTranscoderPacket> packet)
dstar_device->AddPacket(packet); dstar_device->AddPacket(packet);
codec2_queue.push(packet); codec2_queue.push(packet);
imbe_queue.push(packet); imbe_queue.push(packet);
usrp_queue.push(packet);
} }
void CController::ProcessSWAMBE2Thread() void CController::ProcessSWAMBE2Thread()
@ -438,6 +446,7 @@ void CController::ProcessSWAMBE2Thread()
case ECodecType::c2_3200: case ECodecType::c2_3200:
case ECodecType::dstar: case ECodecType::dstar:
case ECodecType::p25: case ECodecType::p25:
case ECodecType::usrp:
AudiotoSWAMBE2(packet); AudiotoSWAMBE2(packet);
break; break;
@ -465,9 +474,8 @@ void CController::AudiotoIMBE(std::shared_ptr<CTranscoderPacket> packet)
} }
} }
p25vocoder.encode_4400(tmp, imbe); p25vocoder.encode_4400((int16_t*)p, imbe);
packet->SetP25Data(imbe); packet->SetP25Data(imbe);
// we might be all done... // we might be all done...
send_mux.lock(); send_mux.lock();
if (packet->AllCodecsAreSet() && packet->HasNotBeenSent()) SendToReflector(packet); if (packet->AllCodecsAreSet() && packet->HasNotBeenSent()) SendToReflector(packet);
@ -482,6 +490,7 @@ void CController::IMBEtoAudio(std::shared_ptr<CTranscoderPacket> packet)
dstar_device->AddPacket(packet); dstar_device->AddPacket(packet);
codec2_queue.push(packet); codec2_queue.push(packet);
swambe2_queue.push(packet); swambe2_queue.push(packet);
usrp_queue.push(packet);
} }
void CController::ProcessIMBEThread() void CController::ProcessIMBEThread()
@ -496,6 +505,7 @@ void CController::ProcessIMBEThread()
case ECodecType::c2_3200: case ECodecType::c2_3200:
case ECodecType::dstar: case ECodecType::dstar:
case ECodecType::dmr: case ECodecType::dmr:
case ECodecType::usrp:
AudiotoIMBE(packet); AudiotoIMBE(packet);
break; break;
@ -506,6 +516,62 @@ void CController::ProcessIMBEThread()
} }
} }
void CController::AudiotoUSRP(std::shared_ptr<CTranscoderPacket> packet)
{
const auto m = packet->GetModule();
int16_t tmp[160];
const int16_t *p = packet->GetAudioSamples();
const uint32_t g = abs(gain);
for(int i = 0; i < 160; ++i){
if(gain < 0){
tmp[i] = p[i] / g;
}
else{
tmp[i] = p[i] * g;
}
}
packet->SetUSRPData(p);
// we might be all done...
send_mux.lock();
if (packet->AllCodecsAreSet() && packet->HasNotBeenSent()) SendToReflector(packet);
send_mux.unlock();
}
void CController::USRPtoAudio(std::shared_ptr<CTranscoderPacket> packet)
{
packet->SetAudioSamples(packet->GetUSRPData(), false);
dstar_device->AddPacket(packet);
codec2_queue.push(packet);
swambe2_queue.push(packet);
imbe_queue.push(packet);
}
void CController::ProcessUSRPThread()
{
while (keep_running)
{
auto packet = usrp_queue.pop();
switch (packet->GetCodecIn())
{
case ECodecType::c2_1600:
case ECodecType::c2_3200:
case ECodecType::dstar:
case ECodecType::dmr:
case ECodecType::p25:
AudiotoUSRP(packet);
break;
case ECodecType::usrp:
USRPtoAudio(packet);
break;
}
}
}
void CController::SendToReflector(std::shared_ptr<CTranscoderPacket> packet) void CController::SendToReflector(std::shared_ptr<CTranscoderPacket> packet)
{ {
// open a socket to the reflector channel // open a socket to the reflector channel
@ -526,6 +592,7 @@ void CController::RouteDstPacket(std::shared_ptr<CTranscoderPacket> packet)
// codec_in is dstar, the audio has just completed, so now calc the M17 and DMR // codec_in is dstar, the audio has just completed, so now calc the M17 and DMR
codec2_queue.push(packet); codec2_queue.push(packet);
imbe_queue.push(packet); imbe_queue.push(packet);
usrp_queue.push(packet);
if(swambe2) if(swambe2)
swambe2_queue.push(packet); swambe2_queue.push(packet);
else else
@ -545,6 +612,7 @@ void CController::RouteDmrPacket(std::shared_ptr<CTranscoderPacket> packet)
{ {
codec2_queue.push(packet); codec2_queue.push(packet);
imbe_queue.push(packet); imbe_queue.push(packet);
usrp_queue.push(packet);
dstar_device->AddPacket(packet); dstar_device->AddPacket(packet);
} }
else else

@ -46,7 +46,7 @@ public:
protected: protected:
std::atomic<bool> keep_running; std::atomic<bool> keep_running;
std::future<void> reflectorFuture, c2Future, swambe2Future, imbeFuture; std::future<void> reflectorFuture, c2Future, swambe2Future, imbeFuture, usrpFuture;
std::unordered_map<char, int16_t[160]> audio_store; std::unordered_map<char, int16_t[160]> audio_store;
std::unordered_map<char, uint8_t[8]> data_store; std::unordered_map<char, uint8_t[8]> data_store;
CUnixDgramReader reader; CUnixDgramReader reader;
@ -57,6 +57,7 @@ protected:
CPacketQueue codec2_queue; CPacketQueue codec2_queue;
CPacketQueue swambe2_queue; CPacketQueue swambe2_queue;
CPacketQueue imbe_queue; CPacketQueue imbe_queue;
CPacketQueue usrp_queue;
std::mutex send_mux; std::mutex send_mux;
int16_t gain; int16_t gain;
bool swambe2; bool swambe2;
@ -69,11 +70,14 @@ protected:
void ProcessC2Thread(); void ProcessC2Thread();
void ProcessSWAMBE2Thread(); void ProcessSWAMBE2Thread();
void ProcessIMBEThread(); void ProcessIMBEThread();
void ProcessUSRPThread();
void Codec2toAudio(std::shared_ptr<CTranscoderPacket> packet); void Codec2toAudio(std::shared_ptr<CTranscoderPacket> packet);
void AudiotoCodec2(std::shared_ptr<CTranscoderPacket> packet); void AudiotoCodec2(std::shared_ptr<CTranscoderPacket> packet);
void SWAMBE2toAudio(std::shared_ptr<CTranscoderPacket> packet); void SWAMBE2toAudio(std::shared_ptr<CTranscoderPacket> packet);
void AudiotoSWAMBE2(std::shared_ptr<CTranscoderPacket> packet); void AudiotoSWAMBE2(std::shared_ptr<CTranscoderPacket> packet);
void IMBEtoAudio(std::shared_ptr<CTranscoderPacket> packet); void IMBEtoAudio(std::shared_ptr<CTranscoderPacket> packet);
void AudiotoIMBE(std::shared_ptr<CTranscoderPacket> packet); void AudiotoIMBE(std::shared_ptr<CTranscoderPacket> packet);
void USRPtoAudio(std::shared_ptr<CTranscoderPacket> packet);
void AudiotoUSRP(std::shared_ptr<CTranscoderPacket> packet);
void SendToReflector(std::shared_ptr<CTranscoderPacket> packet); void SendToReflector(std::shared_ptr<CTranscoderPacket> packet);
}; };

@ -19,7 +19,7 @@
#include "TranscoderPacket.h" #include "TranscoderPacket.h"
CTranscoderPacket::CTranscoderPacket(const STCPacket &tcp) : dstar_set(false), dmr_set(false), p25_set(false), m17_set(false), not_sent(true) CTranscoderPacket::CTranscoderPacket(const STCPacket &tcp) : dstar_set(false), dmr_set(false), p25_set(false), m17_set(false), usrp_set(false), not_sent(true)
{ {
tcpacket.module = tcp.module; tcpacket.module = tcp.module;
tcpacket.is_last = tcp.is_last; tcpacket.is_last = tcp.is_last;
@ -37,6 +37,9 @@ CTranscoderPacket::CTranscoderPacket(const STCPacket &tcp) : dstar_set(false), d
case ECodecType::p25: case ECodecType::p25:
SetP25Data(tcp.p25); SetP25Data(tcp.p25);
break; break;
case ECodecType::usrp:
SetUSRPData(tcp.usrp);
break;
case ECodecType::c2_1600: case ECodecType::c2_1600:
case ECodecType::c2_3200: case ECodecType::c2_3200:
SetM17Data(tcp.m17); SetM17Data(tcp.m17);
@ -67,6 +70,11 @@ const uint8_t *CTranscoderPacket::GetP25Data() const
return tcpacket.p25; return tcpacket.p25;
} }
const int16_t *CTranscoderPacket::GetUSRPData() const
{
return tcpacket.usrp;
}
const uint8_t *CTranscoderPacket::GetM17Data() const const uint8_t *CTranscoderPacket::GetM17Data() const
{ {
return tcpacket.m17; return tcpacket.m17;
@ -101,6 +109,14 @@ void CTranscoderPacket::SetP25Data(const uint8_t *p25)
p25_set = true; p25_set = true;
} }
void CTranscoderPacket::SetUSRPData(const int16_t *usrp)
{
for(int i = 0; i < 160; ++i){
tcpacket.usrp[i] = usrp[i];
}
usrp_set = true;
}
void CTranscoderPacket::SetAudioSamples(const int16_t *sample, bool swap) void CTranscoderPacket::SetAudioSamples(const int16_t *sample, bool swap)
{ {
for (unsigned int i=0; i<160; i++) for (unsigned int i=0; i<160; i++)
@ -157,6 +173,11 @@ bool CTranscoderPacket::P25IsSet() const
return p25_set; return p25_set;
} }
bool CTranscoderPacket::USRPIsSet() const
{
return usrp_set;
}
bool CTranscoderPacket::M17IsSet() const bool CTranscoderPacket::M17IsSet() const
{ {
return m17_set; return m17_set;
@ -164,7 +185,7 @@ bool CTranscoderPacket::M17IsSet() const
bool CTranscoderPacket::AllCodecsAreSet() const bool CTranscoderPacket::AllCodecsAreSet() const
{ {
return (dstar_set && dmr_set && m17_set && p25_set); return (dstar_set && dmr_set && m17_set && p25_set && usrp_set);
} }
void CTranscoderPacket::Sent() void CTranscoderPacket::Sent()

@ -37,10 +37,12 @@ public:
const uint8_t *GetDMRData() const; const uint8_t *GetDMRData() const;
const uint8_t *GetP25Data() const; const uint8_t *GetP25Data() const;
const uint8_t *GetM17Data() const; const uint8_t *GetM17Data() const;
const int16_t *GetUSRPData() const;
void SetDStarData(const uint8_t *dstar); void SetDStarData(const uint8_t *dstar);
void SetDMRData(const uint8_t *dmr); void SetDMRData(const uint8_t *dmr);
void SetP25Data(const uint8_t *p25); void SetP25Data(const uint8_t *p25);
void SetM17Data(const uint8_t *m17); void SetM17Data(const uint8_t *m17);
void SetUSRPData(const int16_t *usrp);
void SetAudioSamples(const int16_t *samples, bool swap); void SetAudioSamples(const int16_t *samples, bool swap);
// audio // audio
@ -57,6 +59,7 @@ public:
bool DMRIsSet() const; bool DMRIsSet() const;
bool P25IsSet() const; bool P25IsSet() const;
bool M17IsSet() const; bool M17IsSet() const;
bool USRPIsSet() const;
bool AllCodecsAreSet() const; bool AllCodecsAreSet() const;
void Sent(); void Sent();
bool HasNotBeenSent() const; bool HasNotBeenSent() const;
@ -67,5 +70,5 @@ public:
private: private:
STCPacket tcpacket; STCPacket tcpacket;
int16_t audio[160]; int16_t audio[160];
std::atomic_bool dstar_set, dmr_set, p25_set, m17_set, not_sent; std::atomic_bool dstar_set, dmr_set, p25_set, m17_set, usrp_set, not_sent;
}; };

Loading…
Cancel
Save

Powered by TurnKey Linux.