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

[#1143] Fix dynamic thread sleep time calculation

parent 8cbd116b
Branches
Tags
No related merge requests found
...@@ -186,6 +186,7 @@ AudioRtpRTX::initBuffers() ...@@ -186,6 +186,7 @@ AudioRtpRTX::initBuffers()
void void
AudioRtpRTX::initAudioRtpSession (void) AudioRtpRTX::initAudioRtpSession (void)
{ {
_debug("************* initAudioRtpSession *******************\n");
try { try {
if (_ca == 0) { return; } if (_ca == 0) { return; }
...@@ -193,8 +194,12 @@ AudioRtpRTX::initAudioRtpSession (void) ...@@ -193,8 +194,12 @@ AudioRtpRTX::initAudioRtpSession (void)
if (_audiocodec == NULL) { return; } if (_audiocodec == NULL) { return; }
_debug("************* get codec info *******************\n");
_codecSampleRate = _audiocodec->getClockRate(); _codecSampleRate = _audiocodec->getClockRate();
_codecFrameSize = _audiocodec->getFrameSize(); _codecFrameSize = _audiocodec->getFrameSize();
_debug("_codecFrameSize: %i\n", _codecFrameSize);
_debug("_codecSampleRate: %i\n", _codecSampleRate);
ost::InetHostAddress remote_ip(_ca->getLocalSDP()->get_remote_ip().c_str()); ost::InetHostAddress remote_ip(_ca->getLocalSDP()->get_remote_ip().c_str());
_debug("Init audio RTP session %s\n", _ca->getLocalSDP()->get_remote_ip().data()); _debug("Init audio RTP session %s\n", _ca->getLocalSDP()->get_remote_ip().data());
...@@ -553,11 +558,10 @@ AudioRtpRTX::run () { ...@@ -553,11 +558,10 @@ AudioRtpRTX::run () {
AudioLayer *audiolayer = Manager::instance().getAudioDriver(); AudioLayer *audiolayer = Manager::instance().getAudioDriver();
_layerFrameSize = audiolayer->getFrameSize(); // en ms _layerFrameSize = audiolayer->getFrameSize(); // en ms
_layerSampleRate = audiolayer->getSampleRate(); _layerSampleRate = audiolayer->getSampleRate();
initBuffers(); initBuffers();
int step; int step;
int sessionWaiting; int sessionWaiting;
//try { //try {
...@@ -565,8 +569,6 @@ AudioRtpRTX::run () { ...@@ -565,8 +569,6 @@ AudioRtpRTX::run () {
// Init the session // Init the session
initAudioRtpSession(); initAudioRtpSession();
// frame length in ms
int threadSleep = (_codecFrameSize * 1000) / _codecSampleRate;
// step = (int) (_layerFrameSize * _codecSampleRate / 1000); // step = (int) (_layerFrameSize * _codecSampleRate / 1000);
step = _codecFrameSize; step = _codecFrameSize;
...@@ -581,8 +583,15 @@ AudioRtpRTX::run () { ...@@ -581,8 +583,15 @@ AudioRtpRTX::run () {
} }
int timestamp = 0; // for mic int timestamp = 0; // for mic
// step = (int) (_layerFrameSize * _codecSampleRate / 1000);
step = _codecFrameSize;
int countTime = 0; // for receive int countTime = 0; // for receive
// TimerPort::setTimer(_layerFrameSize); // TimerPort::setTimer(20);
_debug("****************************************************** \n");
_debug("_codecFrameSize: %i\n", _codecFrameSize);
_debug("_codecSampleRate: %i\n", _codecSampleRate);
int threadSleep = (_codecFrameSize * 1000) / _codecSampleRate;
TimerPort::setTimer(threadSleep); TimerPort::setTimer(threadSleep);
audiolayer->startStream(); audiolayer->startStream();
...@@ -590,7 +599,8 @@ AudioRtpRTX::run () { ...@@ -590,7 +599,8 @@ AudioRtpRTX::run () {
_debug("- ARTP Action: Start call %s\n",_ca->getCallId().c_str()); _debug("- ARTP Action: Start call %s\n",_ca->getCallId().c_str());
while (!testCancel()) { while (!testCancel()) {
printf(" --------- >Step: %i ", step); printf(" --------- >Step: %i \n", step);
_debug("_codecFrameSize: %i \n", _codecFrameSize);
// printf("AudioRtpRTX::run() _session->getFirstTimestamp() %i \n",_session->getFirstTimestamp()); // printf("AudioRtpRTX::run() _session->getFirstTimestamp() %i \n",_session->getFirstTimestamp());
// printf("AudioRtpRTX::run() _session->isWaiting() %i \n",_session->isWaiting()); // printf("AudioRtpRTX::run() _session->isWaiting() %i \n",_session->isWaiting());
...@@ -622,7 +632,7 @@ AudioRtpRTX::run () { ...@@ -622,7 +632,7 @@ AudioRtpRTX::run () {
} }
Thread::sleep(TimerPort::getTimer()); Thread::sleep(TimerPort::getTimer());
// TimerPort::incTimer(_layerFrameSize); // 'frameSize' ms // TimerPort::incTimer(20); // 'frameSize' ms
TimerPort::incTimer(threadSleep); TimerPort::incTimer(threadSleep);
} }
......
...@@ -11,13 +11,13 @@ protected: ...@@ -11,13 +11,13 @@ protected:
std::string _codecName; // what we put inside sdp std::string _codecName; // what we put inside sdp
/** Clock rate or sample rate of the codec, in Hz */ /** Clock rate or sample rate of the codec, in Hz */
unsigned int _clockRate; int _clockRate;
/** Number of channel 1 = mono, 2 = stereo */ /** Number of channel 1 = mono, 2 = stereo */
unsigned int _channel; int _channel;
/** codec frame size in samples*/ /** codec frame size in samples*/
unsigned int _frameSize; int _frameSize;
/** Bitrate */ /** Bitrate */
double _bitrate; double _bitrate;
...@@ -61,9 +61,9 @@ public: ...@@ -61,9 +61,9 @@ public:
std::string getCodecName( void ) { return _codecName; } std::string getCodecName( void ) { return _codecName; }
int getPayload( void ) { return _payload; } int getPayload( void ) { return _payload; }
bool hasDynamicPayload( void ) { return _hasDynamicPayload; } bool hasDynamicPayload( void ) { return _hasDynamicPayload; }
unsigned int getClockRate( void ) { return _clockRate; } int getClockRate( void ) { return _clockRate; }
unsigned int getFrameSize( void ) { return _frameSize; } int getFrameSize( void ) { return _frameSize; }
unsigned int getChannel( void ) { return _channel; } int getChannel( void ) { return _channel; }
bool getState( void ) { return _state; } bool getState( void ) { return _state; }
void setState(bool b) { _state = b; } void setState(bool b) { _state = b; }
double getBitRate( void ) { return _bitrate; } double getBitRate( void ) { return _bitrate; }
......
...@@ -36,7 +36,7 @@ class Speex : public AudioCodec{ ...@@ -36,7 +36,7 @@ class Speex : public AudioCodec{
_preprocess_state() _preprocess_state()
{ {
_clockRate = 8000; _clockRate = 8000;
_frameSize = 320; // samples, 20 ms at 8kHz _frameSize = 160; // samples, 20 ms at 8kHz
_channel = 1; _channel = 1;
_bitrate = 0; _bitrate = 0;
_bandwidth = 0; _bandwidth = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment