Skip to content
Snippets Groups Projects
Commit 4b951b37 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#3443] Fix G722 codec timestamp incrementation

parent a38ea129
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
#include <ccrtp/rtp.h> #include <ccrtp/rtp.h>
#include <cc++/numbers.h> // ost::Time #include <cc++/numbers.h> // ost::Time
// Frequency (in packet number)
#define RTP_TIMESTAMP_RESET_FREQ 100
namespace sfl { namespace sfl {
static const int schedulingTimeout = 100000; static const int schedulingTimeout = 100000;
...@@ -206,6 +209,17 @@ namespace sfl { ...@@ -206,6 +209,17 @@ namespace sfl {
*/ */
int _timestamp; int _timestamp;
/**
* Timestamp incrementation value based on codec period length (framesize)
* except for G722 which require a 8 kHz incrementation.
*/
int _timestampIncrement;
/**
* Timestamp reset freqeuncy specified in number of packet sent
*/
short _timestampCount;
/** /**
* Time counter used to trigger incoming call notification * Time counter used to trigger incoming call notification
*/ */
...@@ -238,6 +252,8 @@ namespace sfl { ...@@ -238,6 +252,8 @@ namespace sfl {
_manager(manager), _manager(manager),
_converterSamplingRate(0), _converterSamplingRate(0),
_timestamp(0), _timestamp(0),
_timestampIncrement(0),
_timestampCount(0),
_countNotificationTime(0), _countNotificationTime(0),
_ca (sipcall) _ca (sipcall)
{ {
...@@ -329,18 +345,26 @@ namespace sfl { ...@@ -329,18 +345,26 @@ namespace sfl {
_codecSampleRate = _audiocodec->getClockRate(); _codecSampleRate = _audiocodec->getClockRate();
_codecFrameSize = _audiocodec->getFrameSize(); _codecFrameSize = _audiocodec->getFrameSize();
// G722 requires timestamp to be incremented at 8 kHz
if (_audiocodec->getPayload() == 9)
_timestampIncrement = 160;
else
_timestampIncrement = _codecFrameSize;
_debug("RTP: Codec sampling rate: %d", _codecSampleRate); _debug("RTP: Codec sampling rate: %d", _codecSampleRate);
_debug("RTP: Codec frame size: %d", _codecFrameSize); _debug("RTP: Codec frame size: %d", _codecFrameSize);
_debug("RTP: RTP timestamp increment: %d", _timestampIncrement);
//TODO: figure out why this is necessary. // Even if specified as a 16 kHz codec, G722 requires rtp sending rate to be 8 kHz
if (_audiocodec->getPayload() == 9) { if (_audiocodec->getPayload() == 9) {
_debug ("RTP: Setting payload format to G722"); _debug ("RTP: Setting G722 payload format");
static_cast<D*>(this)->setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) _audiocodec->getPayload(), _audiocodec->getClockRate())); static_cast<D*>(this)->setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) _audiocodec->getPayload(), _audiocodec->getClockRate()));
} else if (_audiocodec->hasDynamicPayload()) { } else if (_audiocodec->hasDynamicPayload()) {
_debug ("RTP: Setting a dynamic payload format"); _debug ("RTP: Setting dynamic payload format");
static_cast<D*>(this)->setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) _audiocodec->getPayload(), _audiocodec->getClockRate())); static_cast<D*>(this)->setPayloadFormat (ost::DynamicPayloadFormat ( (ost::PayloadType) _audiocodec->getPayload(), _audiocodec->getClockRate()));
} else if (!_audiocodec->hasDynamicPayload() && _audiocodec->getPayload() != 9) { } else if (!_audiocodec->hasDynamicPayload() && _audiocodec->getPayload() != 9) {
_debug ("RTP: Setting a static payload format"); _debug ("RTP: Setting static payload format");
static_cast<D*>(this)->setPayloadFormat (ost::StaticPayloadFormat ( (ost::StaticPayloadType) _audiocodec->getPayload())); static_cast<D*>(this)->setPayloadFormat (ost::StaticPayloadFormat ( (ost::StaticPayloadType) _audiocodec->getPayload()));
} }
} }
...@@ -567,7 +591,7 @@ namespace sfl { ...@@ -567,7 +591,7 @@ namespace sfl {
// 4. send it // 4. send it
// Increment timestamp for outgoing packet // Increment timestamp for outgoing packet
_timestamp += _codecFrameSize; _timestamp += _timestampIncrement;
if (!_audiolayer) { if (!_audiolayer) {
_debug ("No audiolayer available for MIC"); _debug ("No audiolayer available for MIC");
...@@ -668,14 +692,19 @@ namespace sfl { ...@@ -668,14 +692,19 @@ namespace sfl {
while (!testCancel()) { while (!testCancel()) {
// ost::MutexLock lock(*(_manager->getAudioLayerMutex())); // Reset timestamp to make sure the timing information are up to date
if(_timestampCount > RTP_TIMESTAMP_RESET_FREQ) {
_timestamp = static_cast<D*>(this)->getCurrentTimestamp();
_timestampCount = 0;
}
_timestampCount++;
_manager->getAudioLayerMutex()->enter(); _manager->getAudioLayerMutex()->enter();
// converterSamplingRate = _audiolayer->getMainBuffer()->getInternalSamplingRate(); // converterSamplingRate = _audiolayer->getMainBuffer()->getInternalSamplingRate();
_converterSamplingRate = _manager->getAudioDriver()->getMainBuffer()->getInternalSamplingRate(); _converterSamplingRate = _manager->getAudioDriver()->getMainBuffer()->getInternalSamplingRate();
sessionWaiting = static_cast<D*>(this)->isWaiting(); sessionWaiting = static_cast<D*>(this)->isWaiting();
// Send session // Send session
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment