Commit 971b66f3 authored by Alexandre Savard's avatar Alexandre Savard

[#2209] Reinit converterSamplingRate in RTP sessions

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