Compare commits

...

16 commits

Author SHA1 Message Date
Jonathan Naylor f9ed879186 Add better log messages got DMR jitter buffer. 2018-01-08 19:44:18 +00:00
Jonathan Naylor 0df2445fb4 Add protocol name to the logging. 2018-01-03 07:22:17 +00:00
Jonathan Naylor dc24abb23e Fix the lost frames count and the data type when a frame is missing. 2017-12-14 13:53:09 +00:00
Jonathan Naylor 828a83d7a3 Update the way that jitter buffer logging works. 2017-12-06 13:00:32 +00:00
Jonathan Naylor f5b10d4015 Control the jitter logging better. 2017-12-05 13:14:11 +00:00
Jonathan Naylor d4a0885a98 Increase the jitter buffer size and the default jitter buffer delay. 2017-12-03 21:52:29 +00:00
Jonathan Naylor 3c0809bc19 Repeat the last audio for 60ms then silence after that. 2017-11-30 11:40:45 +00:00
Jonathan Naylor 6a935e9c70 Fix a compile error. 2017-11-30 11:27:16 +00:00
Jonathan Naylor 5db4dbc210 Be slightly less agressive in front loading the returned data. 2017-11-29 22:03:10 +00:00
Jonathan Naylor c6bb33924b Add the better embedded GPS code. 2017-11-29 22:01:43 +00:00
Jonathan Naylor 4f63a798c1 Add extra debugging parameters. 2017-11-29 21:58:23 +00:00
Jonathan Naylor 69ce8d11b9 Insert silence instead of repeating the last good frame. 2017-11-28 21:41:01 +00:00
Jonathan Naylor 0c4729b416 Remove compilation warnings. 2017-11-28 21:36:48 +00:00
Jonathan Naylor 556f82a4cf Add a lot more debugging to the jitter buffer. 2017-11-28 10:57:19 +00:00
Jonathan Naylor fc43a65c6f Front load the output from the jitter buffer. 2017-11-28 10:51:39 +00:00
Jonathan Naylor cec99dd561 Remove the ring buffer and use the jitter buffer alone. 2017-11-28 10:48:55 +00:00
7 changed files with 106 additions and 88 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2017 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,6 +25,7 @@
#include <cstdio>
#include <cassert>
#include <cstring>
const unsigned int BUFFER_LENGTH = 500U;
@ -51,7 +52,6 @@ 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),
@ -83,8 +83,8 @@ m_beacon(false)
m_streamId[0U] = 0x00U;
m_streamId[1U] = 0x00U;
m_jitterBuffers[1U] = new CJitterBuffer(60U, DMR_SLOT_TIME, jitter, 256U, true);
m_jitterBuffers[2U] = new CJitterBuffer(60U, DMR_SLOT_TIME, jitter, 256U, true);
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_id[0U] = id >> 24;
m_id[1U] = id >> 16;
@ -148,35 +148,6 @@ bool CDMRNetwork::read(CDMRData& data)
if (m_status != RUNNING)
return false;
if (!m_rxData.isEmpty()) {
unsigned char length = 0U;
m_rxData.getData(&length, 1U);
m_rxData.getData(m_buffer, length);
// Is this a data packet?
if (::memcmp(m_buffer, "DMRD", 4U) == 0) {
unsigned int slotNo = (m_buffer[15U] & 0x80U) == 0x80U ? 2U : 1U;
bool wanted = true;
// DMO mode slot disabling
if (slotNo == 1U && !m_duplex)
wanted = false;
// Individual slot disabling
if (slotNo == 1U && !m_slot1)
wanted = false;
if (slotNo == 2U && !m_slot2)
wanted = false;
if (wanted) {
unsigned char seqNo = m_buffer[4U];
m_jitterBuffers[slotNo]->addData(m_buffer, length, seqNo);
}
}
}
for (unsigned int slotNo = 1U; slotNo <= 2U; slotNo++) {
unsigned int length = 0U;
JB_STATUS status = m_jitterBuffers[slotNo]->getData(m_buffer, length);
@ -403,10 +374,7 @@ void CDMRNetwork::clock(unsigned int ms)
if (m_enabled) {
if (m_debug)
CUtils::dump(1U, "Network Received", m_buffer, length);
unsigned char len = length;
m_rxData.addData(&len, 1U);
m_rxData.addData(m_buffer, len);
receiveData(m_buffer, length);
}
} else if (::memcmp(m_buffer, "MSTNAK", 6U) == 0) {
if (m_status == RUNNING) {
@ -514,6 +482,27 @@ void CDMRNetwork::reset(unsigned int slotNo)
m_jitterBuffers[slotNo]->reset();
}
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;
unsigned char seqNo = data[4U];
m_jitterBuffers[slotNo]->addData(data, length, seqNo);
}
bool CDMRNetwork::writeLogin()
{
unsigned char buffer[8U];

View file

@ -22,7 +22,6 @@
#include "JitterBuffer.h"
#include "UDPSocket.h"
#include "Timer.h"
#include "RingBuffer.h"
#include "DMRData.h"
#include "Defines.h"
@ -90,8 +89,6 @@ private:
unsigned char* m_salt;
uint32_t* m_streamId;
CRingBuffer<unsigned char> m_rxData;
std::string m_options;
std::string m_callsign;
@ -115,6 +112,8 @@ private:
bool writePing();
bool write(const unsigned char* data, unsigned int length);
void receiveData(const unsigned char* data, unsigned int length);
};
#endif

View file

@ -93,6 +93,7 @@ m_interval(),
m_rfFrames(0U),
m_netFrames(0U),
m_netLost(0U),
m_netMissed(0U),
m_fec(),
m_rfBits(1U),
m_netBits(1U),
@ -974,17 +975,20 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
unsigned char data[DMR_FRAME_LENGTH_BYTES + 2U];
dmrData.getData(data + 2U);
if (dmrData.isMissing()) {
bool missing = dmrData.isMissing();
unsigned char dataType;
if (missing) {
m_netN = (m_netN + 1U) % 6U;
m_netLost++;
repeatFrame(data + 2U);
dataType = repeatFrame(data + 2U);
} else {
dataType = dmrData.getDataType();
m_netN = dmrData.getN();
m_networkWatchdog.start();
m_netMissed = 0U;
}
unsigned char dataType = dmrData.getDataType();
if (dataType == DT_VOICE_LC_HEADER) {
if (m_netState == RS_NET_AUDIO)
return;
@ -1320,10 +1324,6 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
// Convert the Audio Sync to be from the BS or MS as needed
CSync::addDMRAudioSync(data + 2U, m_duplex);
// Initialise the lost packet data
if (m_netFrames == 0U)
m_netLost = 0U;
if (!m_netTimeout)
writeQueueNet(data);
@ -1332,6 +1332,9 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
m_netEmbeddedData[m_netEmbeddedWriteN].reset();
if (missing)
m_netLost++;
m_netFrames++;
#if defined(DUMP_DMR)
@ -1460,13 +1463,12 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
data[0U] = TAG_DATA;
data[1U] = 0x00U;
// Initialise the lost packet data
if (m_netFrames == 0U)
m_netLost = 0U;
if (!m_netTimeout)
writeQueueNet(data);
if (missing)
m_netLost++;
m_netFrames++;
#if defined(DUMP_DMR)
@ -1588,38 +1590,37 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData)
}
}
void CDMRSlot::logGPSPosition(const unsigned char* data)
{
unsigned int errorI = (data[2U] & 0x0E) >> 1U;
char errorS[30];
switch (errorI) {
const char* error;
switch (errorI) {
case 0U:
::strcpy(errorS, "< 2m");
error = "< 2m";
break;
case 1U:
::strcpy(errorS, "< 20m");
error = "< 20m";
break;
case 2U:
::strcpy(errorS, "< 200m");
error = "< 200m";
break;
case 3U:
::strcpy(errorS, "< 2km");
error = "< 2km";
break;
case 4U:
::strcpy(errorS, "< 20km");
error = "< 20km";
break;
case 5U:
::strcpy(errorS, "< 200km");
error = "< 200km";
break;
case 6U:
::strcpy(errorS, "> 200km");
error = "> 200km";
break;
default:
::strcpy(errorS, "not known");
error = "not known";
break;
}
}
int32_t longitudeI = ((data[2U] & 0x01U) << 31) | (data[3U] << 23) | (data[4U] << 15) | (data[5U] << 7);
longitudeI >>= 7;
@ -1628,12 +1629,12 @@ void CDMRSlot::logGPSPosition(const unsigned char* data)
latitudeI >>= 8;
float longitude = 360.0F / 33554432.0F; // 360/2^25 steps
float latitude = 180.0F / 16777216.0F; // 180/2^24 steps
float latitude = 180.0F / 16777216.0F; // 180/2^24 steps
longitude *= float(longitudeI);
latitude *= float(latitudeI);
latitude *= float(latitudeI);
LogMessage("GPS position [%f,%f] (Position error %s)", latitude, longitude, errorS);
LogMessage("GPS position [%f,%f] (Position error %s)", latitude, longitude, error);
}
void CDMRSlot::clock()
@ -1915,10 +1916,23 @@ void CDMRSlot::closeFile()
}
}
void CDMRSlot::repeatFrame(unsigned char* data)
unsigned char CDMRSlot::repeatFrame(unsigned char* data)
{
// Repeat the last audio for 60ms then silence after that
if (m_netMissed == 0U) {
::memcpy(data, data + 24U, 9U); // Copy the last audio block to the first
::memcpy(data + 9U, data + 24U, 5U); // Copy the last audio block to the middle (1/2)
::memcpy(data + 19U, data + 24U, 5U); // Copy the last audio block to the middle (2/2)
} else {
::memcpy(data, DMR_SILENCE_DATA + 2U, DMR_FRAME_LENGTH_BYTES);
}
if (m_netN == 0U) {
CSync::addDMRAudioSync(data, m_duplex);
m_netMissed++;
return DT_VOICE_SYNC;
} else {
m_netEmbeddedLC.getData(data, 0U);
@ -1926,5 +1940,9 @@ void CDMRSlot::repeatFrame(unsigned char* data)
emb.setColorCode(m_colorCode);
emb.setLCSS(0U);
emb.getData(data);
m_netMissed++;
return DT_VOICE;
}
}

View file

@ -87,6 +87,7 @@ private:
unsigned int m_rfFrames;
unsigned int m_netFrames;
unsigned int m_netLost;
unsigned int m_netMissed;
CAMBEFEC m_fec;
unsigned int m_rfBits;
unsigned int m_netBits;
@ -138,7 +139,7 @@ private:
bool writeFile(const unsigned char* data);
void closeFile();
void repeatFrame(unsigned char* data);
unsigned char repeatFrame(unsigned char* data);
static void setShortLC(unsigned int slotNo, unsigned int id, FLCO flco = FLCO_GROUP, ACTIVITY_TYPE type = ACTIVITY_NONE);
};

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 by Jonathan Naylor G4KLX
* Copyright (C) 2017,2018 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -24,7 +24,8 @@
#include <cassert>
#include <cstring>
CJitterBuffer::CJitterBuffer(unsigned int blockSize, unsigned int blockTime, unsigned int jitterTime, unsigned int topSequenceNumber, bool debug) :
CJitterBuffer::CJitterBuffer(const std::string& name, unsigned int blockSize, unsigned int blockTime, unsigned int jitterTime, unsigned int topSequenceNumber, bool debug) :
m_name(name),
m_blockSize(blockSize),
m_blockTime(blockTime),
m_topSequenceNumber(topSequenceNumber),
@ -32,18 +33,18 @@ m_debug(debug),
m_blockCount(0U),
m_timer(1000U, 0U, jitterTime),
m_stopWatch(),
m_running(false),
m_buffer(NULL),
m_headSequenceNumber(0U),
m_lastData(NULL),
m_lastDataLength(0U),
m_running(false)
m_lastDataLength(0U)
{
assert(blockSize > 0U);
assert(blockTime > 0U);
assert(jitterTime > 0U);
assert(topSequenceNumber > 0U);
m_blockCount = (jitterTime / blockTime) * 2U + 1U;
m_blockCount = topSequenceNumber / 2U;
m_buffer = new JitterEntry[m_blockCount];
@ -76,14 +77,12 @@ bool CJitterBuffer::addData(const unsigned char* data, unsigned int length, unsi
// Is the data out of sequence?
if (headSequenceNumber < tailSequenceNumber) {
if (sequenceNumber < headSequenceNumber || sequenceNumber >= tailSequenceNumber) {
if (m_debug)
LogDebug("JitterBuffer: rejecting frame with seqNo=%u, raw=%u, head=%u, tail=%u", sequenceNumber, m_headSequenceNumber, headSequenceNumber, tailSequenceNumber);
LogDebug("%s, JitterBuffer: rejecting frame with seqNo=%u, raw=%u, head=%u, tail=%u", m_name.c_str(), sequenceNumber, m_headSequenceNumber, headSequenceNumber, tailSequenceNumber);
return false;
}
} else {
if (sequenceNumber >= tailSequenceNumber && sequenceNumber < headSequenceNumber) {
if (m_debug)
LogDebug("JitterBuffer: rejecting frame with seqNo=%u, raw=%u, head=%u, tail=%u", sequenceNumber, m_headSequenceNumber, headSequenceNumber, tailSequenceNumber);
LogDebug("%s, JitterBuffer: rejecting frame with seqNo=%u, raw=%u, head=%u, tail=%u", m_name.c_str(), sequenceNumber, m_headSequenceNumber, headSequenceNumber, tailSequenceNumber);
return false;
}
}
@ -98,16 +97,20 @@ bool CJitterBuffer::addData(const unsigned char* data, unsigned int length, unsi
// Do we already have the data?
if (m_buffer[index].m_length > 0U) {
if (m_debug)
LogDebug("JitterBuffer: rejecting duplicate frame with seqNo=%u, raw=%u, head=%u, tail=%u", sequenceNumber, m_headSequenceNumber, headSequenceNumber, tailSequenceNumber);
LogDebug("%s, JitterBuffer: rejecting duplicate frame with seqNo=%u, pos=%u, raw=%u, head=%u, tail=%u", m_name.c_str(), sequenceNumber, index, m_headSequenceNumber, headSequenceNumber, tailSequenceNumber);
return false;
}
if (m_debug)
LogDebug("%s, JitterBuffer: adding frame with seqNo=%u, pos=%u, raw=%u, head=%u, tail=%u", m_name.c_str(), sequenceNumber, index, m_headSequenceNumber, headSequenceNumber, tailSequenceNumber);
::memcpy(m_buffer[index].m_data, data, length);
m_buffer[index].m_length = length;
if (!m_timer.isRunning())
if (!m_timer.isRunning()) {
LogDebug("%s, JitterBuffer: starting the timer", m_name.c_str());
m_timer.start();
}
return true;
}
@ -119,7 +122,7 @@ JB_STATUS CJitterBuffer::getData(unsigned char* data, unsigned int& length)
if (!m_running)
return JBS_NO_DATA;
unsigned int sequenceNumber = m_stopWatch.elapsed() / m_blockTime;
unsigned int sequenceNumber = m_stopWatch.elapsed() / m_blockTime + 2U;
if (m_headSequenceNumber > sequenceNumber)
return JBS_NO_DATA;
@ -128,6 +131,9 @@ JB_STATUS CJitterBuffer::getData(unsigned char* data, unsigned int& length)
m_headSequenceNumber++;
if (m_buffer[head].m_length > 0U) {
if (m_debug)
LogDebug("%s, JitterBuffer: returning data, elapsed=%ums, raw=%u, head=%u", m_name.c_str(), m_stopWatch.elapsed(), m_headSequenceNumber - 1U, head);
::memcpy(data, m_buffer[head].m_data, m_buffer[head].m_length);
length = m_buffer[head].m_length;
@ -140,11 +146,13 @@ JB_STATUS CJitterBuffer::getData(unsigned char* data, unsigned int& length)
return JBS_DATA;
}
if (m_debug)
LogDebug("JitterBuffer: no data available, elapsed=%ums, raw=%u, head=%u", m_stopWatch.elapsed(), m_headSequenceNumber - 1U, head);
m_buffer[head].m_length = 0U;
LogDebug("%s, JitterBuffer: no data available, elapsed=%ums, raw=%u, head=%u", m_name.c_str(), m_stopWatch.elapsed(), m_headSequenceNumber - 1U, head);
// Return the last data frame if we have it
if (m_lastDataLength > 0U) {
LogDebug("%s, JitterBuffer: returning the last received frame", m_name.c_str());
::memcpy(data, m_lastData, m_lastDataLength);
length = m_lastDataLength;

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 by Jonathan Naylor G4KLX
* Copyright (C) 2017,2018 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -22,6 +22,8 @@
#include "StopWatch.h"
#include "Timer.h"
#include <string>
enum JB_STATUS {
JBS_NO_DATA,
JBS_DATA,
@ -30,7 +32,7 @@ enum JB_STATUS {
class CJitterBuffer {
public:
CJitterBuffer(unsigned int blockSize, unsigned int blockTime, unsigned int jitterTime, unsigned int topSequenceNumber, bool debug);
CJitterBuffer(const std::string& name, unsigned int blockSize, unsigned int blockTime, unsigned int jitterTime, unsigned int topSequenceNumber, bool debug);
~CJitterBuffer();
bool addData(const unsigned char* data, unsigned int length, unsigned int sequenceNumber);
@ -42,6 +44,7 @@ public:
void clock(unsigned int ms);
private:
std::string m_name;
unsigned int m_blockSize;
unsigned int m_blockTime;
unsigned int m_topSequenceNumber;

View file

@ -116,7 +116,7 @@ Debug=0
Enable=1
Address=44.131.4.1
Port=62031
Jitter=300
Jitter=500
# Local=62032
Password=PASSWORD
# Options=