Skip to content

Commit

Permalink
Make the jitter buffer switchable.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Feb 1, 2018
1 parent 63a2ea3 commit 43fdb77
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
8 changes: 8 additions & 0 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ m_dmrNetworkLocal(0U),
m_dmrNetworkPassword(),
m_dmrNetworkOptions(),
m_dmrNetworkDebug(false),
m_dmrNetworkJitterEnabled(true),
m_dmrNetworkJitter(300U),
m_dmrNetworkSlot1(true),
m_dmrNetworkSlot2(true),
Expand Down Expand Up @@ -550,6 +551,8 @@ bool CConf::read()
m_dmrNetworkOptions = value;
else if (::strcmp(key, "Debug") == 0)
m_dmrNetworkDebug = ::atoi(value) == 1;
else if (::strcmp(key, "JitterEnabled") == 0)
m_dmrNetworkJitterEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "Jitter") == 0)
m_dmrNetworkJitter = (unsigned int)::atoi(value);
else if (::strcmp(key, "Slot1") == 0)
Expand Down Expand Up @@ -1161,6 +1164,11 @@ bool CConf::getDMRNetworkDebug() const
return m_dmrNetworkDebug;
}

bool CConf::getDMRNetworkJitterEnabled() const
{
return m_dmrNetworkJitterEnabled;
}

unsigned int CConf::getDMRNetworkJitter() const
{
return m_dmrNetworkJitter;
Expand Down
2 changes: 2 additions & 0 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class CConf
std::string getDMRNetworkPassword() const;
std::string getDMRNetworkOptions() const;
bool getDMRNetworkDebug() const;
bool getDMRNetworkJitterEnabled() const;
unsigned int getDMRNetworkJitter() const;
bool getDMRNetworkSlot1() const;
bool getDMRNetworkSlot2() const;
Expand Down Expand Up @@ -327,6 +328,7 @@ class CConf
std::string m_dmrNetworkPassword;
std::string m_dmrNetworkOptions;
bool m_dmrNetworkDebug;
bool m_dmrNetworkJitterEnabled;
unsigned int m_dmrNetworkJitter;
bool m_dmrNetworkSlot1;
bool m_dmrNetworkSlot2;
Expand Down
33 changes: 17 additions & 16 deletions DMRNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const unsigned int BUFFER_LENGTH = 500U;
const unsigned int HOMEBREW_DATA_PACKET_LENGTH = 55U;


CDMRNetwork::CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType, unsigned int jitter) :
CDMRNetwork::CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType, bool jitterEnabled, unsigned int jitter) :
m_address(),
m_port(port),
m_id(NULL),
Expand All @@ -44,6 +44,7 @@ m_socket(local),
m_enabled(false),
m_slot1(slot1),
m_slot2(slot2),
m_jitterEnabled(jitterEnabled),
m_jitterBuffers(NULL),
m_hwType(hwType),
m_status(WAITING_CONNECT),
Expand Down Expand Up @@ -498,23 +499,23 @@ void CDMRNetwork::receiveData(const unsigned char* data, unsigned int length)
if (slotNo == 2U && !m_slot2)
return;

m_jitterBuffers[slotNo]->appendData(data, length);

/*
unsigned char dataType = data[15U] & 0x3FU;
if (dataType == (0x20U | DT_CSBK) ||
dataType == (0x20U | DT_DATA_HEADER) ||
dataType == (0x20U | DT_RATE_1_DATA) ||
dataType == (0x20U | DT_RATE_34_DATA) ||
dataType == (0x20U | DT_RATE_12_DATA)) {
// Data & CSBK frames
m_jitterBuffers[slotNo]->appendData(data, length);
if (m_jitterEnabled) {
unsigned char dataType = data[15U] & 0x3FU;
if (dataType == (0x20U | DT_CSBK) ||
dataType == (0x20U | DT_DATA_HEADER) ||
dataType == (0x20U | DT_RATE_1_DATA) ||
dataType == (0x20U | DT_RATE_34_DATA) ||
dataType == (0x20U | DT_RATE_12_DATA)) {
// Data & CSBK frames
m_jitterBuffers[slotNo]->appendData(data, length);
} else {
// Voice frames
unsigned char seqNo = data[4U];
m_jitterBuffers[slotNo]->addData(data, length, seqNo);
}
} else {
// Voice frames
unsigned char seqNo = data[4U];
m_jitterBuffers[slotNo]->addData(data, length, seqNo);
m_jitterBuffers[slotNo]->appendData(data, length);
}
*/
}

bool CDMRNetwork::writeLogin()
Expand Down
3 changes: 2 additions & 1 deletion DMRNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class CDMRNetwork
{
public:
CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType, unsigned int jitter);
CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType, bool jitterEnabled, unsigned int jitter);
~CDMRNetwork();

void setOptions(const std::string& options);
Expand Down Expand Up @@ -70,6 +70,7 @@ class CDMRNetwork
bool m_enabled;
bool m_slot1;
bool m_slot2;
bool m_jitterEnabled;
CJitterBuffer** m_jitterBuffers;
HW_TYPE m_hwType;

Expand Down
1 change: 1 addition & 0 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Debug=0
Enable=1
Address=44.131.4.1
Port=62031
JitterEnabled=1
Jitter=500
# Local=62032
Password=PASSWORD
Expand Down
4 changes: 3 additions & 1 deletion MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ bool CMMDVMHost::createDMRNetwork()
unsigned int id = m_conf.getDMRId();
std::string password = m_conf.getDMRNetworkPassword();
bool debug = m_conf.getDMRNetworkDebug();
bool jitterEnabled = m_conf.getDMRNetworkJitterEnabled();
unsigned int jitter = m_conf.getDMRNetworkJitter();
bool slot1 = m_conf.getDMRNetworkSlot1();
bool slot2 = m_conf.getDMRNetworkSlot2();
Expand All @@ -957,12 +958,13 @@ bool CMMDVMHost::createDMRNetwork()
LogInfo(" Local: %u", local);
else
LogInfo(" Local: random");
LogInfo(" Jitter Buffer: %s", jitterEnabled ? "enabled" : "disabled");
LogInfo(" Jitter: %ums", jitter);
LogInfo(" Slot 1: %s", slot1 ? "enabled" : "disabled");
LogInfo(" Slot 2: %s", slot2 ? "enabled" : "disabled");
LogInfo(" Mode Hang: %us", m_dmrNetModeHang);

m_dmrNetwork = new CDMRNetwork(address, port, local, id, password, m_duplex, VERSION, debug, slot1, slot2, hwType, jitter);
m_dmrNetwork = new CDMRNetwork(address, port, local, id, password, m_duplex, VERSION, debug, slot1, slot2, hwType, jitterEnabled, jitter);

std::string options = m_conf.getDMRNetworkOptions();
if (!options.empty()) {
Expand Down

0 comments on commit 43fdb77

Please sign in to comment.