Skip to content

Commit

Permalink
Roll back the jitter buffer changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Feb 8, 2018
1 parent f8c85a8 commit e6ed2e1
Show file tree
Hide file tree
Showing 26 changed files with 256 additions and 750 deletions.
8 changes: 0 additions & 8 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ m_dmrNetworkLocal(0U),
m_dmrNetworkPassword(),
m_dmrNetworkOptions(),
m_dmrNetworkDebug(false),
m_dmrNetworkJitterEnabled(false),
m_dmrNetworkJitter(300U),
m_dmrNetworkSlot1(true),
m_dmrNetworkSlot2(true),
Expand Down Expand Up @@ -551,8 +550,6 @@ 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 @@ -1164,11 +1161,6 @@ 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: 0 additions & 2 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ 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 @@ -328,7 +327,6 @@ 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
4 changes: 2 additions & 2 deletions DMRControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <cassert>
#include <algorithm>

CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, unsigned int callHang, bool selfOnly, bool embeddedLCOnly, bool dumpTAData, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blacklist, const std::vector<unsigned int>& whitelist, const std::vector<unsigned int>& slot1TGWhitelist, const std::vector<unsigned int>& slot2TGWhitelist, unsigned int timeout, CModem* modem, CDMRNetwork* network, CDisplay* display, bool duplex, CDMRLookup* lookup, CRSSIInterpolator* rssi) :
CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, unsigned int callHang, bool selfOnly, bool embeddedLCOnly, bool dumpTAData, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blacklist, const std::vector<unsigned int>& whitelist, const std::vector<unsigned int>& slot1TGWhitelist, const std::vector<unsigned int>& slot2TGWhitelist, unsigned int timeout, CModem* modem, CDMRNetwork* network, CDisplay* display, bool duplex, CDMRLookup* lookup, CRSSIInterpolator* rssi, unsigned int jitter) :
m_colorCode(colorCode),
m_modem(modem),
m_network(network),
Expand All @@ -38,7 +38,7 @@ m_lookup(lookup)
// Load black and white lists to DMRAccessControl
CDMRAccessControl::init(blacklist, whitelist, slot1TGWhitelist, slot2TGWhitelist, selfOnly, prefixes, id);

CDMRSlot::init(colorCode, embeddedLCOnly, dumpTAData, callHang, modem, network, display, duplex, m_lookup, rssi);
CDMRSlot::init(colorCode, embeddedLCOnly, dumpTAData, callHang, modem, network, display, duplex, m_lookup, rssi, jitter);
}

CDMRControl::~CDMRControl()
Expand Down
2 changes: 1 addition & 1 deletion DMRControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class CDMRControl {
public:
CDMRControl(unsigned int id, unsigned int colorCode, unsigned int callHang, bool selfOnly, bool embeddedLCOnly, bool dumpTAData, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blacklist, const std::vector<unsigned int>& whitelist, const std::vector<unsigned int>& slot1TGWhitelist, const std::vector<unsigned int>& slot2TGWhitelist, unsigned int timeout, CModem* modem, CDMRNetwork* network, CDisplay* display, bool duplex, CDMRLookup* lookup, CRSSIInterpolator* rssi);
CDMRControl(unsigned int id, unsigned int colorCode, unsigned int callHang, bool selfOnly, bool embeddedLCOnly, bool dumpTAData, const std::vector<unsigned int>& prefixes, const std::vector<unsigned int>& blacklist, const std::vector<unsigned int>& whitelist, const std::vector<unsigned int>& slot1TGWhitelist, const std::vector<unsigned int>& slot2TGWhitelist, unsigned int timeout, CModem* modem, CDMRNetwork* network, CDisplay* display, bool duplex, CDMRLookup* lookup, CRSSIInterpolator* rssi, unsigned int jitter);
~CDMRControl();

bool processWakeup(const unsigned char* data);
Expand Down
13 changes: 0 additions & 13 deletions DMRData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ m_dstId(data.m_dstId),
m_flco(data.m_flco),
m_dataType(data.m_dataType),
m_seqNo(data.m_seqNo),
m_missing(data.m_missing),
m_n(data.m_n),
m_ber(data.m_ber),
m_rssi(data.m_rssi)
Expand All @@ -46,7 +45,6 @@ m_dstId(0U),
m_flco(FLCO_GROUP),
m_dataType(0U),
m_seqNo(0U),
m_missing(false),
m_n(0U),
m_ber(0U),
m_rssi(0U)
Expand All @@ -70,7 +68,6 @@ CDMRData& CDMRData::operator=(const CDMRData& data)
m_flco = data.m_flco;
m_dataType = data.m_dataType;
m_seqNo = data.m_seqNo;
m_missing = data.m_missing;
m_n = data.m_n;
m_ber = data.m_ber;
m_rssi = data.m_rssi;
Expand Down Expand Up @@ -141,16 +138,6 @@ void CDMRData::setSeqNo(unsigned char seqNo)
m_seqNo = seqNo;
}

bool CDMRData::isMissing() const
{
return m_missing;
}

void CDMRData::setMissing(bool missing)
{
m_missing = missing;
}

unsigned char CDMRData::getN() const
{
return m_n;
Expand Down
4 changes: 0 additions & 4 deletions DMRData.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class CDMRData {
unsigned char getDataType() const;
void setDataType(unsigned char dataType);

bool isMissing() const;
void setMissing(bool missing);

unsigned char getBER() const;
void setBER(unsigned char ber);

Expand All @@ -65,7 +62,6 @@ class CDMRData {
FLCO m_flco;
unsigned char m_dataType;
unsigned char m_seqNo;
bool m_missing;
unsigned char m_n;
unsigned char m_ber;
unsigned char m_rssi;
Expand Down
179 changes: 56 additions & 123 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, bool jitterEnabled, 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) :
m_address(),
m_port(port),
m_id(NULL),
Expand All @@ -44,16 +44,14 @@ m_socket(local),
m_enabled(false),
m_slot1(slot1),
m_slot2(slot2),
m_jitterEnabled(jitterEnabled),
m_jitterBuffers(NULL),
m_delayBuffers(NULL),
m_hwType(hwType),
m_status(WAITING_CONNECT),
m_retryTimer(1000U, 10U),
m_timeoutTimer(1000U, 60U),
m_buffer(NULL),
m_salt(NULL),
m_streamId(NULL),
m_rxData(1000U, "DMR Network"),
m_options(),
m_callsign(),
m_rxFrequency(0U),
Expand All @@ -72,23 +70,13 @@ m_beacon(false)
assert(port > 0U);
assert(id > 1000U);
assert(!password.empty());
assert(jitter > 0U);

m_address = CUDPSocket::lookup(address);

m_buffer = new unsigned char[BUFFER_LENGTH];
m_salt = new unsigned char[sizeof(uint32_t)];
m_id = new uint8_t[4U];
m_streamId = new uint32_t[2U];

m_jitterBuffers = new CJitterBuffer*[3U];
m_delayBuffers = new CDelayBuffer*[3U];

m_jitterBuffers[1U] = new CJitterBuffer("DMR Slot 1", 60U, DMR_SLOT_TIME, jitter, 256U, debug);
m_jitterBuffers[2U] = new CJitterBuffer("DMR Slot 2", 60U, DMR_SLOT_TIME, jitter, 256U, debug);

m_delayBuffers[1U] = new CDelayBuffer("DMR Slot 1", HOMEBREW_DATA_PACKET_LENGTH, DMR_SLOT_TIME, jitter, debug);
m_delayBuffers[2U] = new CDelayBuffer("DMR Slot 2", HOMEBREW_DATA_PACKET_LENGTH, DMR_SLOT_TIME, jitter, debug);
m_buffer = new unsigned char[BUFFER_LENGTH];
m_salt = new unsigned char[sizeof(uint32_t)];
m_id = new uint8_t[4U];
m_streamId = new uint32_t[2U];

m_id[0U] = id >> 24;
m_id[1U] = id >> 16;
Expand All @@ -104,19 +92,10 @@ m_beacon(false)

CDMRNetwork::~CDMRNetwork()
{
delete m_jitterBuffers[1U];
delete m_jitterBuffers[2U];

delete m_delayBuffers[1U];
delete m_delayBuffers[2U];

delete[] m_buffer;
delete[] m_salt;
delete[] m_streamId;
delete[] m_id;

delete[] m_jitterBuffers;
delete[] m_delayBuffers;
}

void CDMRNetwork::setOptions(const std::string& options)
Expand Down Expand Up @@ -160,55 +139,63 @@ bool CDMRNetwork::read(CDMRData& data)
if (m_status != RUNNING)
return false;

for (unsigned int slotNo = 1U; slotNo <= 2U; slotNo++) {
unsigned int length = 0U;
B_STATUS status = BS_NO_DATA;
if (m_rxData.isEmpty())
return false;

if (m_jitterEnabled)
status = m_jitterBuffers[slotNo]->getData(m_buffer, length);
else
status = m_delayBuffers[slotNo]->getData(m_buffer, length);
unsigned char length = 0U;
m_rxData.getData(&length, 1U);
m_rxData.getData(m_buffer, length);

if (status != BS_NO_DATA) {
unsigned char seqNo = m_buffer[4U];
// Is this a data packet?
if (::memcmp(m_buffer, "DMRD", 4U) != 0)
return false;

unsigned int srcId = (m_buffer[5U] << 16) | (m_buffer[6U] << 8) | (m_buffer[7U] << 0);
unsigned char seqNo = m_buffer[4U];

unsigned int dstId = (m_buffer[8U] << 16) | (m_buffer[9U] << 8) | (m_buffer[10U] << 0);
unsigned int srcId = (m_buffer[5U] << 16) | (m_buffer[6U] << 8) | (m_buffer[7U] << 0);

FLCO flco = (m_buffer[15U] & 0x40U) == 0x40U ? FLCO_USER_USER : FLCO_GROUP;
unsigned int dstId = (m_buffer[8U] << 16) | (m_buffer[9U] << 8) | (m_buffer[10U] << 0);

data.setSeqNo(seqNo);
data.setSlotNo(slotNo);
data.setSrcId(srcId);
data.setDstId(dstId);
data.setFLCO(flco);
data.setMissing(status == BS_MISSING);
unsigned int slotNo = (m_buffer[15U] & 0x80U) == 0x80U ? 2U : 1U;

bool dataSync = (m_buffer[15U] & 0x20U) == 0x20U;
bool voiceSync = (m_buffer[15U] & 0x10U) == 0x10U;
// DMO mode slot disabling
if (slotNo == 1U && !m_duplex)
return false;

if (dataSync) {
unsigned char dataType = m_buffer[15U] & 0x0FU;
data.setData(m_buffer + 20U);
data.setDataType(dataType);
data.setN(0U);
} else if (voiceSync) {
data.setData(m_buffer + 20U);
data.setDataType(DT_VOICE_SYNC);
data.setN(0U);
} else {
unsigned char n = m_buffer[15U] & 0x0FU;
data.setData(m_buffer + 20U);
data.setDataType(DT_VOICE);
data.setN(n);
}
// Individual slot disabling
if (slotNo == 1U && !m_slot1)
return false;
if (slotNo == 2U && !m_slot2)
return false;

return true;
}
FLCO flco = (m_buffer[15U] & 0x40U) == 0x40U ? FLCO_USER_USER : FLCO_GROUP;

data.setSeqNo(seqNo);
data.setSlotNo(slotNo);
data.setSrcId(srcId);
data.setDstId(dstId);
data.setFLCO(flco);

bool dataSync = (m_buffer[15U] & 0x20U) == 0x20U;
bool voiceSync = (m_buffer[15U] & 0x10U) == 0x10U;

if (dataSync) {
unsigned char dataType = m_buffer[15U] & 0x0FU;
data.setData(m_buffer + 20U);
data.setDataType(dataType);
data.setN(0U);
} else if (voiceSync) {
data.setData(m_buffer + 20U);
data.setDataType(DT_VOICE_SYNC);
data.setN(0U);
} else {
unsigned char n = m_buffer[15U] & 0x0FU;
data.setData(m_buffer + 20U);
data.setDataType(DT_VOICE);
data.setN(n);
}

return false;
return true;
}

bool CDMRNetwork::write(const CDMRData& data)
Expand Down Expand Up @@ -345,12 +332,6 @@ void CDMRNetwork::close()

void CDMRNetwork::clock(unsigned int ms)
{
m_jitterBuffers[1U]->clock(ms);
m_jitterBuffers[2U]->clock(ms);

m_delayBuffers[1U]->clock(ms);
m_delayBuffers[2U]->clock(ms);

if (m_status == WAITING_CONNECT) {
m_retryTimer.clock(ms);
if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) {
Expand Down Expand Up @@ -388,7 +369,10 @@ void CDMRNetwork::clock(unsigned int ms)
if (m_enabled) {
if (m_debug)
CUtils::dump(1U, "Network Received", m_buffer, length);
receiveData(m_buffer, length);

unsigned char len = length;
m_rxData.addData(&len, 1U);
m_rxData.addData(m_buffer, len);
}
} else if (::memcmp(m_buffer, "MSTNAK", 6U) == 0) {
if (m_status == RUNNING) {
Expand Down Expand Up @@ -489,57 +473,6 @@ void CDMRNetwork::clock(unsigned int ms)
}
}

void CDMRNetwork::reset(unsigned int slotNo)
{
assert(slotNo == 1U || slotNo == 2U);

if (slotNo == 1U) {
m_jitterBuffers[1U]->reset();
m_delayBuffers[1U]->reset();
m_streamId[0U] = ::rand() + 1U;
} else {
m_jitterBuffers[2U]->reset();
m_delayBuffers[2U]->reset();
m_streamId[1U] = ::rand() + 1U;
}
}

void CDMRNetwork::receiveData(const unsigned char* data, unsigned int length)
{
assert(data != NULL);
assert(length > 0U);

unsigned int slotNo = (data[15U] & 0x80U) == 0x80U ? 2U : 1U;

// DMO mode slot disabling
if (slotNo == 1U && !m_duplex)
return;

// Individual slot disabling
if (slotNo == 1U && !m_slot1)
return;
if (slotNo == 2U && !m_slot2)
return;

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 {
m_delayBuffers[slotNo]->addData(data, length);
}
}

bool CDMRNetwork::writeLogin()
{
unsigned char buffer[8U];
Expand Down
Loading

0 comments on commit e6ed2e1

Please sign in to comment.