main
Tom Early 4 years ago
parent de5decceb7
commit 6600750911

@ -109,29 +109,17 @@ void CController::ReadReflectorThread()
switch (packet->GetCodecIn()) switch (packet->GetCodecIn())
{ {
case ECodecType::dstar: case ECodecType::dstar:
#ifdef DEBUG
if (packet->IsLast())
Dump(packet, "Ref packet to dstar device:");
#endif
add_dst_mux.lock(); add_dst_mux.lock();
dstar_device.AddPacket(packet); dstar_device.AddPacket(packet);
add_dst_mux.unlock(); add_dst_mux.unlock();
break; break;
case ECodecType::dmr: case ECodecType::dmr:
#ifdef DEBUG
if (packet->IsLast())
Dump(packet, "Ref packet to dmr device:");
#endif
add_dmr_mux.lock(); add_dmr_mux.lock();
dmr_device.AddPacket(packet); dmr_device.AddPacket(packet);
add_dmr_mux.unlock(); add_dmr_mux.unlock();
break; break;
case ECodecType::c2_1600: case ECodecType::c2_1600:
case ECodecType::c2_3200: case ECodecType::c2_3200:
#ifdef DEBUG
if (packet->IsLast())
Dump(packet, "Ref packet to Codec2 vocoder:");
#endif
c2_mux.lock(); c2_mux.lock();
codec2_queue.push(packet); codec2_queue.push(packet);
c2_mux.unlock(); c2_mux.unlock();
@ -157,6 +145,7 @@ void CController::AudiotoCodec2(std::shared_ptr<CTranscoderPacket> packet)
memcpy(m17data, data_store[packet->GetModule()], 8); memcpy(m17data, data_store[packet->GetModule()], 8);
// and then calculate the second half // and then calculate the second half
c2_32.codec2_encode(m17data+8, packet->GetAudio()); c2_32.codec2_encode(m17data+8, packet->GetAudio());
packet->SetM17Data(m17data, true);
} }
else /* the packet is first */ else /* the packet is first */
{ {
@ -164,13 +153,9 @@ void CController::AudiotoCodec2(std::shared_ptr<CTranscoderPacket> packet)
c2_32.codec2_encode(m17data, packet->GetAudio()); c2_32.codec2_encode(m17data, packet->GetAudio());
// and then copy the calculated data to the data_store // and then copy the calculated data to the data_store
memcpy(data_store[packet->GetModule()], m17data, 8); memcpy(data_store[packet->GetModule()], m17data, 8);
// set the m17_is_set flag if this is the last packet
packet->SetM17Data(m17data, packet->IsLast());
} }
// put the M17 data into the packet
packet->SetM17Data(m17data);
#ifdef DEBUG
if (packet->IsLast())
Dump(packet, "Encoded M17:");
#endif
// we might be all done... // we might be all done...
if (packet->AllCodecsAreSet()) if (packet->AllCodecsAreSet())
{ {
@ -226,10 +211,6 @@ void CController::Codec2toAudio(std::shared_ptr<CTranscoderPacket> packet)
add_dmr_mux.lock(); add_dmr_mux.lock();
dmr_device.AddPacket(packet); dmr_device.AddPacket(packet);
add_dmr_mux.unlock(); add_dmr_mux.unlock();
#ifdef DEBUG
if (packet->IsLast())
Dump(packet, "Sent to both dstar and dmr device:");
#endif
} }
void CController::ProcessC2Thread() void CController::ProcessC2Thread()
@ -271,10 +252,6 @@ void CController::SendToReflector(std::shared_ptr<CTranscoderPacket> packet)
// send the packet over the socket // send the packet over the socket
socket.Send(packet->GetTCPacket()); socket.Send(packet->GetTCPacket());
// the socket will automatically close after sending // the socket will automatically close after sending
#ifdef DEBUG
if (packet->IsLast())
Dump(packet, "Sent to reflector:");
#endif
} }
void CController::RouteDstPacket(std::shared_ptr<CTranscoderPacket> packet) void CController::RouteDstPacket(std::shared_ptr<CTranscoderPacket> packet)
@ -288,10 +265,6 @@ void CController::RouteDstPacket(std::shared_ptr<CTranscoderPacket> packet)
add_dmr_mux.lock(); add_dmr_mux.lock();
dmr_device.AddPacket(packet); dmr_device.AddPacket(packet);
add_dmr_mux.unlock(); add_dmr_mux.unlock();
#ifdef DEBUG
if (packet->IsLast())
Dump(packet, "DStar audio routed to codec2 and dmr:");
#endif
} }
else if (packet->AllCodecsAreSet()) else if (packet->AllCodecsAreSet())
{ {
@ -311,16 +284,15 @@ void CController::RouteDmrPacket(std::shared_ptr<CTranscoderPacket> packet)
add_dst_mux.lock(); add_dst_mux.lock();
dstar_device.AddPacket(packet); dstar_device.AddPacket(packet);
add_dst_mux.unlock(); add_dst_mux.unlock();
#ifdef DEBUG
if (packet->IsLast())
Dump(packet, "DMR audio routed to dstar:");
#endif
} }
else if (packet->AllCodecsAreSet()) else if (packet->AllCodecsAreSet())
{ {
send_mux.lock(); send_mux.lock();
SendToReflector(packet); SendToReflector(packet);
send_mux.unlock(); send_mux.unlock();
#ifdef DEBUG
AppendWave(packet);
#endif
} }
} }

@ -138,14 +138,14 @@ bool CDV3003::OpenDevice(const std::string &ttyname, int baudrate)
if (SetBaudRate(baudrate)) if (SetBaudRate(baudrate))
return true; return true;
#ifdef DEBUG #ifdef DEBUG
std::cout << ttyname << " baudrate it set to " << baudrate << std::endl; std::cout << ttyname << " baudrate it set to " << baudrate << std::endl;
#endif #endif
devicepath.assign(ttyname); devicepath.assign(ttyname);
#ifdef DEBUG #ifdef DEBUG
std::cout << "Opened " << devicepath << " using fd " << fd << std::endl; std::cout << "Opened " << devicepath << " using fd " << fd << std::endl;
#endif #endif
if (InitDV3003()) if (InitDV3003())
return true; return true;
@ -183,9 +183,9 @@ bool CDV3003::InitDV3003()
std::cerr << "InitDV3003: invalid response to reset" << std::endl; std::cerr << "InitDV3003: invalid response to reset" << std::endl;
return true; return true;
} }
#ifdef DEBUG #ifdef DEBUG
std::cout << "Successfully reset " << devicepath << std::endl; std::cout << "Successfully reset " << devicepath << std::endl;
#endif #endif
// ********** turn off parity ********* // ********** turn off parity *********
ctrlPacket.header.payload_length = htons(4); ctrlPacket.header.payload_length = htons(4);
@ -211,9 +211,9 @@ bool CDV3003::InitDV3003()
return true; return true;
} }
#ifdef DEBUG #ifdef DEBUG
std::cout << "Successfully disabled parity on " << devicepath << std::endl; std::cout << "Successfully disabled parity on " << devicepath << std::endl;
#endif #endif
// ********* Product ID and Version ************* // ********* Product ID and Version *************
ctrlPacket.header.payload_length = htons(1); ctrlPacket.header.payload_length = htons(1);
@ -314,9 +314,9 @@ bool CDV3003::ConfigureVocoder(uint8_t pkt_ch, Encoding type)
dump("Configuration response was:", &responsePacket, sizeof(responsePacket)); dump("Configuration response was:", &responsePacket, sizeof(responsePacket));
return true; return true;
}; };
#ifdef DEBUG #ifdef DEBUG
std::cout << devicepath << " channel " << (unsigned int)(pkt_ch - PKT_CHANNEL0) << " is now configured for " << ((Encoding::dstar == type) ? "D-Star" : "DMR") << std::endl; std::cout << devicepath << " channel " << (unsigned int)(pkt_ch - PKT_CHANNEL0) << " is now configured for " << ((Encoding::dstar == type) ? "D-Star" : "DMR") << std::endl;
#endif #endif
return false; return false;
} }
@ -383,11 +383,6 @@ void CDV3003::FeedDevice()
auto packet = inq.pop(); auto packet = inq.pop();
if (packet) if (packet)
{ {
#ifdef DEBUG
if (packet->IsLast())
Controller.Dump(packet, "FeedDevice got a packet from inq:");
#endif
const bool needs_audio = (Encoding::dstar==type) ? packet->DStarIsSet() : packet->DMRIsSet(); const bool needs_audio = (Encoding::dstar==type) ? packet->DStarIsSet() : packet->DMRIsSet();
while (keep_running) // wait until there is room while (keep_running) // wait until there is room
@ -416,19 +411,11 @@ void CDV3003::FeedDevice()
{ {
SendData(current_vocoder, (Encoding::dstar==type) ? packet->GetDStarData() : packet->GetDMRData()); SendData(current_vocoder, (Encoding::dstar==type) ? packet->GetDStarData() : packet->GetDMRData());
ch_depth++; ch_depth++;
#ifdef DEBUG
if (packet->IsLast())
Controller.Dump(packet, "Queued for decoding:");
#endif
} }
else else
{ {
SendAudio(current_vocoder, packet->GetAudio()); SendAudio(current_vocoder, packet->GetAudio());
sp_depth++; sp_depth++;
#ifdef DEBUG
if (packet->IsLast())
Controller.Dump(packet, "Queued for encoding:");
#endif
} }
if(++current_vocoder > 2) if(++current_vocoder > 2)
current_vocoder = 0; current_vocoder = 0;
@ -476,10 +463,6 @@ void CDV3003::ReadDevice()
else else
packet->SetDMRData(p.payload.ambe.data); packet->SetDMRData(p.payload.ambe.data);
#ifdef DEBUG
if (packet->IsLast())
Controller.Dump(packet, "Data from device is now set:");
#endif
} }
else if (PKT_SPEECH == p.header.packet_type) else if (PKT_SPEECH == p.header.packet_type)
{ {
@ -488,10 +471,6 @@ void CDV3003::ReadDevice()
for (unsigned int i=0; i<160; i++) for (unsigned int i=0; i<160; i++)
pPCM[i] = ntohs(p.payload.audio.samples[i]); pPCM[i] = ntohs(p.payload.audio.samples[i]);
#ifdef DEBUG
if (packet->IsLast())
Controller.Dump(packet, "Audio from device is now set:");
#endif
} }
else else
{ {
@ -517,7 +496,7 @@ void CDV3003::ReadDevice()
void CDV3003::AddPacket(const std::shared_ptr<CTranscoderPacket> packet) void CDV3003::AddPacket(const std::shared_ptr<CTranscoderPacket> packet)
{ {
inq.push(packet); inq.push(packet);
#ifdef DEBUG #ifdef DEBUG
static unsigned int maxsize = 0; static unsigned int maxsize = 0;
unsigned int s = inq.size(); unsigned int s = inq.size();
if (s > maxsize) if (s > maxsize)
@ -525,7 +504,7 @@ void CDV3003::AddPacket(const std::shared_ptr<CTranscoderPacket> packet)
std::cout << "inq size=" << s << std::endl; std::cout << "inq size=" << s << std::endl;
maxsize = s; maxsize = s;
} }
#endif #endif
} }
bool CDV3003::SendAudio(const uint8_t channel, const int16_t *audio) const bool CDV3003::SendAudio(const uint8_t channel, const int16_t *audio) const

@ -35,7 +35,7 @@ CTranscoderPacket::CTranscoderPacket(const STCPacket &tcp) : dstar_set(false), d
break; break;
case ECodecType::c2_1600: case ECodecType::c2_1600:
case ECodecType::c2_3200: case ECodecType::c2_3200:
SetM17Data(tcp.m17); SetM17Data(tcp.m17, true);
break; break;
default: default:
std::cerr << "Trying to allocate CTranscoderPacket with an unknown codec type!" << std::endl; std::cerr << "Trying to allocate CTranscoderPacket with an unknown codec type!" << std::endl;
@ -68,10 +68,10 @@ const STCPacket *CTranscoderPacket::GetTCPacket() const
return &tcpacket; return &tcpacket;
} }
void CTranscoderPacket::SetM17Data(const uint8_t *data) void CTranscoderPacket::SetM17Data(const uint8_t *data, bool is_set)
{ {
memcpy(tcpacket.m17, data, 16); memcpy(tcpacket.m17, data, 16);
m17_set = true; m17_set = is_set;
} }
void CTranscoderPacket::SetDStarData(const uint8_t *dstar) void CTranscoderPacket::SetDStarData(const uint8_t *dstar)

@ -38,7 +38,7 @@ public:
const uint8_t *GetM17Data() const; const uint8_t *GetM17Data() 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 SetM17Data(const uint8_t *m17); void SetM17Data(const uint8_t *m17, bool is_set);
// audio // audio
int16_t *GetAudio(); int16_t *GetAudio();

Loading…
Cancel
Save

Powered by TurnKey Linux.