fixed preceived concurance issues

main
Tom Early 4 years ago
parent 394c228c91
commit 9d6d9ef582

@ -109,10 +109,14 @@ void CController::ReadReflectorThread()
switch (packet->GetCodecIn()) switch (packet->GetCodecIn())
{ {
case ECodecType::dstar: case ECodecType::dstar:
add_dst_mux.lock();
dstar_device.AddPacket(packet); dstar_device.AddPacket(packet);
add_dst_mux.unlock();
break; break;
case ECodecType::dmr: case ECodecType::dmr:
add_dmr_mux.lock();
dmr_device.AddPacket(packet); dmr_device.AddPacket(packet);
add_dmr_mux.unlock();
break; break;
case ECodecType::c2_1600: case ECodecType::c2_1600:
case ECodecType::c2_3200: case ECodecType::c2_3200:
@ -200,8 +204,12 @@ void CController::Codec2toAudio(std::shared_ptr<CTranscoderPacket> packet)
} }
} }
// the only thing left is to encode the two ambe, so push the packet onto both AMBE queues // the only thing left is to encode the two ambe, so push the packet onto both AMBE queues
add_dst_mux.lock();
dstar_device.AddPacket(packet); dstar_device.AddPacket(packet);
add_dst_mux.unlock();
add_dmr_mux.lock();
dmr_device.AddPacket(packet); dmr_device.AddPacket(packet);
add_dmr_mux.unlock();
} }
void CController::ProcessC2Thread() void CController::ProcessC2Thread()
@ -243,15 +251,20 @@ 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 //#ifdef DEBUG
//AppendWave(packet); //AppendWave(packet);
#endif //#endif
} }
void CController::RouteDstPacket(std::shared_ptr<CTranscoderPacket> packet) void CController::RouteDstPacket(std::shared_ptr<CTranscoderPacket> packet)
{ {
if (ECodecType::dstar == packet->GetCodecIn()) if (ECodecType::dstar == packet->GetCodecIn())
{
// codec_in is dstar, the audio has just completed, so now calc the DMR
add_dmr_mux.lock();
dmr_device.AddPacket(packet); dmr_device.AddPacket(packet);
add_dmr_mux.unlock();
}
else if (packet->AllCodecsAreSet()) else if (packet->AllCodecsAreSet())
{ {
send_mux.lock(); send_mux.lock();
@ -263,7 +276,11 @@ void CController::RouteDstPacket(std::shared_ptr<CTranscoderPacket> packet)
void CController::RouteDmrPacket(std::shared_ptr<CTranscoderPacket> packet) void CController::RouteDmrPacket(std::shared_ptr<CTranscoderPacket> packet)
{ {
if (ECodecType::dmr == packet->GetCodecIn()) if (ECodecType::dmr == packet->GetCodecIn())
{
add_dst_mux.lock();
dstar_device.AddPacket(packet); dstar_device.AddPacket(packet);
add_dst_mux.unlock();
}
else if (packet->AllCodecsAreSet()) else if (packet->AllCodecsAreSet())
{ {
send_mux.lock(); send_mux.lock();

@ -53,7 +53,7 @@ protected:
CDV3003 dmr_device{Encoding::dmr}; CDV3003 dmr_device{Encoding::dmr};
CPacketQueue codec2_queue; CPacketQueue codec2_queue;
std::mutex c2_mux, send_mux; std::mutex add_dst_mux, add_dmr_mux, c2_mux, send_mux;
bool InitDevices(); bool InitDevices();
// processing threads // processing threads

@ -384,28 +384,28 @@ void CDV3003::FeedDevice()
in_mux.unlock(); in_mux.unlock();
if (packet) if (packet)
{ {
bool device_is_full = true; bool device_is_ready = false;
bool has_ambe = (Encoding::dstar==type) ? packet->DStarIsSet() : packet->DMRIsSet(); bool has_ambe = (Encoding::dstar==type) ? packet->DStarIsSet() : packet->DMRIsSet();
while (keep_running && device_is_full) // wait until there is room while (keep_running && (! device_is_ready)) // wait until there is room
{ {
if (has_ambe) if (has_ambe)
{ {
// we need to decode ambe to audio // we need to decode ambe to audio
if (ch_depth < 2) if (ch_depth < 2)
device_is_full = false; device_is_ready = true;
} }
else else
{ {
// we need to encode audio to ambe // we need to encode audio to ambe
if (sp_depth < 2) if (sp_depth < 2)
device_is_full = false; device_is_ready = true;
} }
if (device_is_full) if (! device_is_ready)
std::this_thread::sleep_for(std::chrono::milliseconds(2)); std::this_thread::sleep_for(std::chrono::milliseconds(2));
} }
if (keep_running) if (keep_running && device_is_ready)
{ {
voc_mux[current_vocoder].lock(); voc_mux[current_vocoder].lock();
vocq->push(packet); vocq->push(packet);
@ -414,11 +414,17 @@ void CDV3003::FeedDevice()
{ {
SendAudio(current_vocoder, packet->GetAudio()); SendAudio(current_vocoder, packet->GetAudio());
sp_depth++; sp_depth++;
#ifdef DEBUG
std::cout << "Sent audio to " << devicepath << std::endl;
#endif
} }
else else
{ {
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
std::cout << "Sent AMBE to " << devicepath << std::endl;
#endif
} }
if(++current_vocoder > 2) if(++current_vocoder > 2)
current_vocoder = 0; current_vocoder = 0;
@ -440,8 +446,8 @@ void CDV3003::ReadDevice()
FD_SET(fd, &FdSet); FD_SET(fd, &FdSet);
struct timeval tv; struct timeval tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 400000; tv.tv_usec = 400000; // wait for 0.4 sec for something to read
auto rval = select(fd+1, &FdSet, 0, 0, &tv); // wait for 0.4 sec for something to read auto rval = select(fd+1, &FdSet, 0, 0, &tv);
if (rval < 0) if (rval < 0)
{ {
@ -480,7 +486,7 @@ void CDV3003::ReadDevice()
dump("ReadDevice() ERROR: Read an unexpected device packet:", &p, packet_size(p)); dump("ReadDevice() ERROR: Read an unexpected device packet:", &p, packet_size(p));
continue; continue;
} }
if (Encoding::dstar == type) if (Encoding::dstar == type) // is this a DMR or a DStar device?
{ {
Controller.dstar_mux.lock(); Controller.dstar_mux.lock();
Controller.RouteDstPacket(packet); Controller.RouteDstPacket(packet);

@ -18,7 +18,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cstring> #include <cstring>
#include <stdint.h> #include <cstdint>
#include <atomic>
#include "TCPacketDef.h" #include "TCPacketDef.h"
@ -58,5 +59,5 @@ public:
private: private:
STCPacket tcpacket; STCPacket tcpacket;
int16_t audio[160]; int16_t audio[160];
bool dstar_set, dmr_set, m17_set; std::atomic<bool> dstar_set, dmr_set, m17_set;
}; };

Loading…
Cancel
Save

Powered by TurnKey Linux.