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

[#2209] Reinit converterSamplingRate in RTP sessions

parent 7c64f324
Branches
Tags
No related merge requests found
...@@ -81,8 +81,8 @@ namespace sfl { ...@@ -81,8 +81,8 @@ namespace sfl {
inline float computeCodecFrameSize (int codecSamplePerFrame, int codecClockRate) { inline float computeCodecFrameSize (int codecSamplePerFrame, int codecClockRate) {
return ( (float) codecSamplePerFrame * 1000.0) / (float) codecClockRate; return ( (float) codecSamplePerFrame * 1000.0) / (float) codecClockRate;
} }
inline int computeNbByteAudioLayer (float codecFrameSize) { int computeNbByteAudioLayer (float codecFrameSize) {
return (int) ( (float) converterSamplingRate * codecFrameSize * (float) sizeof (SFLDataFormat) / 1000.0); return (int) ( ((float) converterSamplingRate * codecFrameSize * sizeof(SFLDataFormat))/ 1000.0);
} }
void sendMicData(int timestamp); void sendMicData(int timestamp);
...@@ -225,9 +225,9 @@ namespace sfl { ...@@ -225,9 +225,9 @@ namespace sfl {
// initialize SampleRate converter using AudioLayer's sampling rate // initialize SampleRate converter using AudioLayer's sampling rate
// (internal buffers initialized with maximal sampling rate and frame size) // (internal buffers initialized with maximal sampling rate and frame size)
_converter = new SamplerateConverter (_layerSampleRate, _layerFrameSize); _converter = new SamplerateConverter(_layerSampleRate, _layerFrameSize);
int nbSamplesMax = (int) (_codecSampleRate * _layerFrameSize /1000)*2; int nbSamplesMax = (int)(_codecSampleRate * _layerFrameSize /1000)*2;
_micData = new SFLDataFormat[nbSamplesMax]; _micData = new SFLDataFormat[nbSamplesMax];
_micDataConverted = new SFLDataFormat[nbSamplesMax]; _micDataConverted = new SFLDataFormat[nbSamplesMax];
_micDataEncoded = new unsigned char[nbSamplesMax]; _micDataEncoded = new unsigned char[nbSamplesMax];
...@@ -309,19 +309,31 @@ namespace sfl { ...@@ -309,19 +309,31 @@ namespace sfl {
{ {
assert(_audiocodec); assert(_audiocodec);
assert(_audiolayer); assert(_audiolayer);
_debug("AudioRtpSession::processDataEncode %s\n", _ca->getCallId().c_str());
int _mainBufferSampleRate = _audiolayer->getMainBuffer()->getInternalSamplingRate(); int _mainBufferSampleRate = _audiolayer->getMainBuffer()->getInternalSamplingRate();
_debug(" _mainBufferSampleRate %i\n", _mainBufferSampleRate);
_debug(" converterSamplingRate %i\n", converterSamplingRate);
_debug(" _audiocodec->getFrameSize() %i, _audiocodec->getClockRate() %i\n", _audiocodec->getFrameSize(), _audiocodec->getClockRate());
// compute codec framesize in ms // compute codec framesize in ms
float fixed_codec_framesize = computeCodecFrameSize (_audiocodec->getFrameSize(), _audiocodec->getClockRate()); float fixed_codec_framesize = computeCodecFrameSize (_audiocodec->getFrameSize(), _audiocodec->getClockRate());
_debug(" fixed_codec_framesize %f\n", fixed_codec_framesize);
// compute nb of byte to get coresponding to 20 ms at audio layer frame size (44.1 khz) // compute nb of byte to get coresponding to 20 ms at audio layer frame size (44.1 khz)
int maxBytesToGet = computeNbByteAudioLayer (fixed_codec_framesize); int maxBytesToGet = computeNbByteAudioLayer (fixed_codec_framesize);
_debug(" maxBytesToGet %i\n", maxBytesToGet);
// available bytes inside ringbuffer // available bytes inside ringbuffer
int availBytesFromMic = _audiolayer->getMainBuffer()->availForGet(_ca->getCallId()); int availBytesFromMic = _audiolayer->getMainBuffer()->availForGet(_ca->getCallId());
_debug(" availBytesFromMic %i\n", availBytesFromMic);
// set available byte to maxByteToGet // set available byte to maxByteToGet
int bytesAvail = (availBytesFromMic < maxBytesToGet) ? availBytesFromMic : maxBytesToGet; int bytesAvail = (availBytesFromMic < maxBytesToGet) ? availBytesFromMic : maxBytesToGet;
...@@ -331,6 +343,8 @@ namespace sfl { ...@@ -331,6 +343,8 @@ namespace sfl {
// Get bytes from micRingBuffer to data_from_mic // Get bytes from micRingBuffer to data_from_mic
int nbSample = _audiolayer->getMainBuffer()->getData(_micData , bytesAvail, 100, _ca->getCallId()) / sizeof (SFLDataFormat); int nbSample = _audiolayer->getMainBuffer()->getData(_micData , bytesAvail, 100, _ca->getCallId()) / sizeof (SFLDataFormat);
_debug(" nbSample %i\n", nbSample);
// nb bytes to be sent over RTP // nb bytes to be sent over RTP
int compSize = 0; int compSize = 0;
...@@ -342,6 +356,8 @@ namespace sfl { ...@@ -342,6 +356,8 @@ namespace sfl {
compSize = _audiocodec->codecEncode (_micDataEncoded, _micDataConverted, nbSample*sizeof (int16)); compSize = _audiocodec->codecEncode (_micDataEncoded, _micDataConverted, nbSample*sizeof (int16));
_debug(" nbSample(in resampling block) %i\n", nbSample);
} else { } else {
// no resampling required // no resampling required
compSize = _audiocodec->codecEncode (_micDataEncoded, _micData, nbSample*sizeof (int16)); compSize = _audiocodec->codecEncode (_micDataEncoded, _micData, nbSample*sizeof (int16));
...@@ -354,8 +370,11 @@ namespace sfl { ...@@ -354,8 +370,11 @@ namespace sfl {
void AudioRtpSession<D>::processDataDecode(unsigned char * spkrData, unsigned int size, int& countTime) void AudioRtpSession<D>::processDataDecode(unsigned char * spkrData, unsigned int size, int& countTime)
{ {
_debug("AudioRtpSession::processDataDecode %s\n", _ca->getCallId().c_str());
if (_audiocodec != NULL) { if (_audiocodec != NULL) {
int _mainBufferSampleRate = _audiolayer->getMainBuffer()->getInternalSamplingRate(); int _mainBufferSampleRate = _audiolayer->getMainBuffer()->getInternalSamplingRate();
// Return the size of data in bytes // Return the size of data in bytes
...@@ -364,6 +383,10 @@ namespace sfl { ...@@ -364,6 +383,10 @@ namespace sfl {
// buffer _receiveDataDecoded ----> short int or int16, coded on 2 bytes // buffer _receiveDataDecoded ----> short int or int16, coded on 2 bytes
int nbSample = expandedSize / sizeof (SFLDataFormat); int nbSample = expandedSize / sizeof (SFLDataFormat);
_debug(" nbSample %i\n", nbSample);
_debug(" _mainBufferSampleRate %i\n", _mainBufferSampleRate);
// test if resampling is required // test if resampling is required
if (_audiocodec->getClockRate() != _mainBufferSampleRate) { if (_audiocodec->getClockRate() != _mainBufferSampleRate) {
...@@ -375,6 +398,8 @@ namespace sfl { ...@@ -375,6 +398,8 @@ namespace sfl {
// Store the number of samples for recording // Store the number of samples for recording
_nSamplesSpkr = nbSample; _nSamplesSpkr = nbSample;
_debug(" nbSample (in resampling block) %i\n", nbSample);
// put data in audio layer, size in byte // put data in audio layer, size in byte
_audiolayer->getMainBuffer()->putData (_spkrDataConverted, nbSample * sizeof (SFLDataFormat), 100, _ca->getCallId()); _audiolayer->getMainBuffer()->putData (_spkrDataConverted, nbSample * sizeof (SFLDataFormat), 100, _ca->getCallId());
...@@ -383,6 +408,7 @@ namespace sfl { ...@@ -383,6 +408,7 @@ namespace sfl {
// Store the number of samples for recording // Store the number of samples for recording
_nSamplesSpkr = nbSample; _nSamplesSpkr = nbSample;
// put data in audio layer, size in byte // put data in audio layer, size in byte
_audiolayer->getMainBuffer()->putData (_spkrDataDecoded, expandedSize, 100, _ca->getCallId()); _audiolayer->getMainBuffer()->putData (_spkrDataDecoded, expandedSize, 100, _ca->getCallId());
} }
...@@ -503,6 +529,8 @@ namespace sfl { ...@@ -503,6 +529,8 @@ namespace sfl {
while (!testCancel()) { while (!testCancel()) {
converterSamplingRate = _audiolayer->getMainBuffer()->getInternalSamplingRate();
// Send session // Send session
sessionWaiting = static_cast<D*>(this)->isWaiting(); sessionWaiting = static_cast<D*>(this)->isWaiting();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment