diff --git a/sflphone-common/src/audio/alsa/alsalayer.cpp b/sflphone-common/src/audio/alsa/alsalayer.cpp index c13d56450e42fe44aebe23dc3eea51688d58e0ec..4261eb4896e793f6e50b215e233b7eb5b846af78 100644 --- a/sflphone-common/src/audio/alsa/alsalayer.cpp +++ b/sflphone-common/src/audio/alsa/alsalayer.cpp @@ -1038,7 +1038,7 @@ void AlsaLayer::audioCallback (void) _audiofilter->processAudio (rsmpl_out, nbSample*sizeof (SFLDataFormat)); - getMainBuffer()->putData (rsmpl_out, nbSample * sizeof (SFLDataFormat), 100); + getMainBuffer()->putData (rsmpl_out, nbSample * sizeof (SFLDataFormat)); free (rsmpl_out); } else { @@ -1047,7 +1047,7 @@ void AlsaLayer::audioCallback (void) if (filter_out) { _audiofilter->processAudio (in, filter_out, toPut); // captureFile->write ( (const char *) filter_out, toPut); - getMainBuffer()->putData (filter_out, toPut, 100); + getMainBuffer()->putData (filter_out, toPut); free (filter_out); } } diff --git a/sflphone-common/src/audio/audiolayer.cpp b/sflphone-common/src/audio/audiolayer.cpp index f7eb216a8ff1485d78871658afde44db444b8524..1615d97c71317f10ba23ef9eac06cedcbbe9baf0 100644 --- a/sflphone-common/src/audio/audiolayer.cpp +++ b/sflphone-common/src/audio/audiolayer.cpp @@ -56,9 +56,9 @@ int AudioLayer::putUrgent (void* buffer, int toCopy) a = _urgentRingBuffer.AvailForPut(); if (a >= toCopy) { - return _urgentRingBuffer.Put (buffer, toCopy, _defaultVolume); + return _urgentRingBuffer.Put (buffer, toCopy); } else { - return _urgentRingBuffer.Put (buffer, a, _defaultVolume); + return _urgentRingBuffer.Put (buffer, a); } return 0; @@ -72,10 +72,10 @@ int AudioLayer::putMain (void *buffer, int toCopy, std::string call_id) a = getMainBuffer()->availForPut (call_id); if (a >= toCopy) { - return getMainBuffer()->putData (buffer, toCopy, _defaultVolume, call_id); + return getMainBuffer()->putData (buffer, toCopy, call_id); } else { _debug ("Chopping sound, Ouch! RingBuffer full ?"); - return getMainBuffer()->putData (buffer, a, _defaultVolume, call_id); + return getMainBuffer()->putData (buffer, a, call_id); } return 0; diff --git a/sflphone-common/src/audio/audiolayer.h b/sflphone-common/src/audio/audiolayer.h index 77e72610565cd7eac72b36cd69eb730c70aaf702..89ea65bb9be66a8e6d4c37d9278e0b66afc068b3 100644 --- a/sflphone-common/src/audio/audiolayer.h +++ b/sflphone-common/src/audio/audiolayer.h @@ -70,8 +70,7 @@ class AudioLayer * @param manager An instance of managerimpl */ AudioLayer (ManagerImpl* manager , int type) - : _defaultVolume (100) - , _layerType (type) + : _layerType (type) , _isStarted(false) , _manager (manager) , _urgentRingBuffer (SIZEBUF, default_id) @@ -245,12 +244,6 @@ class AudioLayer _mainBuffer = mainbuffer; } - /** - * Default volume for incoming RTP and Urgent sounds. - */ - unsigned short _defaultVolume; // 100 - - /** * Set the audio recorder */ diff --git a/sflphone-common/src/audio/audiortp/AudioRtpRecordHandler.cpp b/sflphone-common/src/audio/audiortp/AudioRtpRecordHandler.cpp index 822b10492036b4ec3e344a6d36cf5638f9e83d2d..6cc6862971f6d76f30d811ffcafa9304fc16c578 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpRecordHandler.cpp +++ b/sflphone-common/src/audio/audiortp/AudioRtpRecordHandler.cpp @@ -260,7 +260,6 @@ int AudioRtpRecordHandler::processDataEncode (void) { SFLDataFormat *micData = _audioRtpRecord._micData; unsigned char *micDataEncoded = _audioRtpRecord._micDataEncoded; - //SFLDataFormat *micDataEchoCancelled = _audioRtpRecord._micDataEchoCancelled; SFLDataFormat *micDataConverted = _audioRtpRecord._micDataConverted; int codecFrameSize = getCodecFrameSize(); @@ -303,11 +302,9 @@ int AudioRtpRecordHandler::processDataEncode (void) _audioRtpRecord.audioProcessMutex.enter(); if (Manager::instance().audioPreference.getNoiseReduce()) { - // _audioRtpRecord._audioProcess->processAudio (micDataEchoCancelled, nbSample * sizeof (SFLDataFormat)); _audioRtpRecord._audioProcess->processAudio (micDataConverted, nbSample * sizeof (SFLDataFormat)); } - // echoCanceller.process(micDataConverted, micDataEchoCancelled, nbSample * sizeof(SFLDataFormat)); if(Manager::instance().getEchoCancelState() == "enabled") { echoCanceller.getData(micData); } @@ -317,7 +314,6 @@ int AudioRtpRecordHandler::processDataEncode (void) _audioRtpRecord.audioCodecMutex.enter(); compSize = _audioRtpRecord._audioCodec->encode (micDataEncoded, micData, nbSample * sizeof (SFLDataFormat)); - // compSize = _audioRtpRecord._audioCodec->encode (micDataEncoded, micDataConverted, nbSample * sizeof (SFLDataFormat)); _audioRtpRecord.audioCodecMutex.leave(); @@ -327,11 +323,8 @@ int AudioRtpRecordHandler::processDataEncode (void) if (Manager::instance().audioPreference.getNoiseReduce()) { _audioRtpRecord._audioProcess->processAudio (micData, nbSample * sizeof (SFLDataFormat)); - // _audioRtpRecord._audioProcess->processAudio (micDataEchoCancelled, nbSample * sizeof (SFLDataFormat)); } - // echoCanceller.process(micData, micDataEchoCancelled, nbSample * sizeof(SFLDataFormat)); - // echoCanceller.process(micData, micDataEchoCancelled, nbSample * sizeof(SFLDataFormat)); if(Manager::instance().getEchoCancelState() == "enabled") { echoCanceller.getData(micData); } @@ -346,7 +339,6 @@ int AudioRtpRecordHandler::processDataEncode (void) _audioRtpRecord.audioCodecMutex.enter(); // no resampling required - // compSize = _audioRtpRecord._audioCodec->encode (micDataEncoded, micData, nbSample * sizeof (SFLDataFormat)); compSize = _audioRtpRecord._audioCodec->encode (micDataEncoded, micData, nbSample * sizeof (SFLDataFormat)); _audioRtpRecord.audioCodecMutex.leave(); @@ -383,17 +375,15 @@ void AudioRtpRecordHandler::processDataDecode (unsigned char *spkrData, unsigned // test if resampling is required if (codecSampleRate != mainBufferSampleRate) { - // Do sample rate conversion - int nbSampleDown = nbSample; - nbSample = _audioRtpRecord._converter->upsampleData (spkrDataDecoded, spkrDataConverted, codecSampleRate, mainBufferSampleRate, nbSampleDown); + nbSample = _audioRtpRecord._converter->upsampleData (spkrDataDecoded, spkrDataConverted, codecSampleRate, mainBufferSampleRate, nbSample); if(Manager::instance().getEchoCancelState() == "enabled") { echoCanceller.putData(spkrDataConverted, nbSample * sizeof(SFLDataFormat)); } // put data in audio layer, size in byte - Manager::instance().getMainBuffer()->putData (spkrDataConverted, nbSample * sizeof (SFLDataFormat), 100, id_); + Manager::instance().getMainBuffer()->putData (spkrDataConverted, nbSample * sizeof (SFLDataFormat), id_); } else { @@ -401,28 +391,22 @@ void AudioRtpRecordHandler::processDataDecode (unsigned char *spkrData, unsigned echoCanceller.putData(spkrDataDecoded, expandedSize); } // put data in audio layer, size in byte - Manager::instance().getMainBuffer()->putData (spkrDataDecoded, expandedSize, 100, id_); + Manager::instance().getMainBuffer()->putData (spkrDataDecoded, expandedSize, id_); } } bool AudioRtpRecordHandler::fadeIn (SFLDataFormat *audio, int size, SFLDataFormat *factor) { - // if factor reach 0, this function should no be called anymore if (*factor <= 0) return true; - // apply amplitude factor; - while (size) { - size--; - audio[size] /= *factor; - } + while (size) + audio[--size] /= *factor; - // decrease factor *factor /= FADEIN_STEP_SIZE; - return false; - + return *factor <= 0; } } diff --git a/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp index 7a19a6df813c1abb9771b187a63a7b3f2d981a17..9bd49b20b1ceb3515eef8ab77075030e0a5b5b3d 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp @@ -181,7 +181,6 @@ void AudioRtpSession::sendDtmfEvent (sfl::DtmfEvent *dtmf) dtmf->payload.duration++; - // next packet is going to be the last one if ( (dtmf->length - increment) < increment) dtmf->payload.ebit = true; @@ -195,26 +194,16 @@ void AudioRtpSession::sendDtmfEvent (sfl::DtmfEvent *dtmf) void AudioRtpSession::receiveSpeakerData () { - const ost::AppDataUnit* adu = NULL; - - int packetTimestamp = _queue->getFirstTimestamp(); - - adu = _queue->getData (packetTimestamp); - - if (!adu) { + const ost::AppDataUnit* adu = _queue->getData (_queue->getFirstTimestamp()); + if (!adu) return; - } - - unsigned char* spkrDataIn = NULL; - unsigned int size = 0; - spkrDataIn = (unsigned char*) adu->getData(); // data in char - size = adu->getSize(); // size in char + unsigned char* spkrDataIn = (unsigned char*) adu->getData(); // data in char + unsigned int size = adu->getSize(); // size in char // DTMF over RTP, size must be over 4 in order to process it as voice data - if (size > 4) { + if (size > 4) processDataDecode (spkrDataIn, size); - } delete adu; } @@ -327,7 +316,6 @@ void AudioRtpSession::stopRtpThread () bool AudioRtpSession::onRTPPacketRecv (ost::IncomingRTPPkt&) { receiveSpeakerData(); - return true; } diff --git a/sflphone-common/src/audio/mainbuffer.cpp b/sflphone-common/src/audio/mainbuffer.cpp index 0232fbad4c0d6dfb6cb3b9cf3489e9cebda93e1b..5514c28ffa3a49553880f36cfafe89ee83b49861 100644 --- a/sflphone-common/src/audio/mainbuffer.cpp +++ b/sflphone-common/src/audio/mainbuffer.cpp @@ -35,81 +35,49 @@ MainBuffer::MainBuffer() : _internalSamplingRate (8000) { - mixBuffer = new SFLDataFormat[STATIC_BUFSIZE]; } MainBuffer::~MainBuffer() { - - delete [] mixBuffer; - mixBuffer = NULL; } void MainBuffer::setInternalSamplingRate (int sr) { - _debug("MainBuffer: Set internal sampling rate"); - if (sr > _internalSamplingRate) { - - _debug ("MainBuffer: Internal sampling rate changed %d", sr); - - // This call takes the mutex flushAllBuffers(); - - // ost::MutexLock guard (_mutex); - _internalSamplingRate = sr; - - // Manager::instance().audioSamplingRateChanged(sr); - } } CallIDSet* MainBuffer::getCallIDSet (std::string call_id) { - CallIDMap::iterator iter = _callIDMap.find (call_id); - - if (iter != _callIDMap.end()) - return iter->second; - else - return NULL; - + return (iter != _callIDMap.end()) ? iter->second : NULL; } -bool MainBuffer::createCallIDSet (std::string set_id) +void MainBuffer::createCallIDSet (std::string set_id) { - - CallIDSet* newCallIDSet = new CallIDSet; - - _callIDMap.insert (std::pair<std::string, CallIDSet*> (set_id, newCallIDSet)); - - return true; - + _callIDMap.insert (std::pair<std::string, CallIDSet*> (set_id, new CallIDSet)); } bool MainBuffer::removeCallIDSet (std::string set_id) { - - CallIDSet* callid_set = getCallIDSet (set_id); - if (callid_set != NULL) { - if (_callIDMap.erase (set_id) != 0) { - delete callid_set; - callid_set = NULL; - return true; - } else { - _debug ("removeCallIDSet error while removing callid set %s!", set_id.c_str()); - return false; - } - } else { + if (!callid_set) { _debug ("removeCallIDSet error callid set %s does not exist!", set_id.c_str()); return false; } + if (_callIDMap.erase (set_id) == 0) { + _debug ("removeCallIDSet error while removing callid set %s!", set_id.c_str()); + return false; + } + delete callid_set; + callid_set = NULL; + return true; } void MainBuffer::addCallIDtoSet (std::string set_id, std::string call_id) @@ -148,9 +116,7 @@ RingBuffer* MainBuffer::getRingBuffer (std::string call_id) RingBuffer* MainBuffer::createRingBuffer (std::string call_id) { RingBuffer* newRingBuffer = new RingBuffer (SIZEBUF, call_id); - _ringBufferMap.insert (std::pair<std::string, RingBuffer*> (call_id, newRingBuffer)); - return newRingBuffer; } @@ -332,7 +298,7 @@ void MainBuffer::unBindAllHalfDuplexOut (std::string process_id) } -int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, std::string call_id) +int MainBuffer::putData (void *buffer, int toCopy, std::string call_id) { ost::MutexLock guard (_mutex); @@ -348,11 +314,11 @@ int MainBuffer::putData (void *buffer, int toCopy, unsigned short volume, std::s if (a >= toCopy) { - return ring_buffer->Put (buffer, toCopy, volume); + return ring_buffer->Put (buffer, toCopy); } else { - return ring_buffer->Put (buffer, a, volume); + return ring_buffer->Put (buffer, a); } } @@ -378,12 +344,7 @@ int MainBuffer::getData (void *buffer, int toCopy, unsigned short volume, std::s CallIDSet* callid_set = getCallIDSet (call_id); - int nbSmplToCopy = toCopy / sizeof (SFLDataFormat); - - if (callid_set == NULL) - return 0; - - if (callid_set->empty()) { + if (!callid_set || callid_set->empty()) { return 0; } @@ -396,18 +357,17 @@ int MainBuffer::getData (void *buffer, int toCopy, unsigned short volume, std::s } else return 0; } else { - - memset (buffer, 0, nbSmplToCopy*sizeof (SFLDataFormat)); + memset (buffer, 0, toCopy); int size = 0; CallIDSet::iterator iter_id = callid_set->begin(); while (iter_id != callid_set->end()) { - + int nbSmplToCopy = toCopy / sizeof (SFLDataFormat); + SFLDataFormat mixBuffer[nbSmplToCopy]; memset (mixBuffer, 0, toCopy); - - size = getDataByID (mixBuffer, toCopy, volume, (std::string) (*iter_id), call_id); + size = getDataByID (mixBuffer, toCopy, volume, *iter_id, call_id); if (size > 0) { for (int k = 0; k < nbSmplToCopy; k++) { diff --git a/sflphone-common/src/audio/mainbuffer.h b/sflphone-common/src/audio/mainbuffer.h index 973039fc2b51e1398191b858c02351cfefeaca6c..8d74dc3deb532cbf1ec122d46b727f1b958bcc86 100644 --- a/sflphone-common/src/audio/mainbuffer.h +++ b/sflphone-common/src/audio/mainbuffer.h @@ -89,7 +89,7 @@ class MainBuffer void unBindAllHalfDuplexOut (std::string process_id); - int putData (void *buffer, int toCopy, unsigned short volume = 100, std::string call_id = default_id); + int putData (void *buffer, int toCopy, std::string call_id = default_id); int getData (void *buffer, int toCopy, unsigned short volume = 100, std::string call_id = default_id); @@ -113,7 +113,7 @@ class MainBuffer CallIDSet* getCallIDSet (std::string call_id); - bool createCallIDSet (std::string set_id); + void createCallIDSet (std::string set_id); bool removeCallIDSet (std::string set_id); @@ -145,8 +145,6 @@ class MainBuffer CallIDMap _callIDMap; - SFLDataFormat* mixBuffer; - ost::Mutex _mutex; int _internalSamplingRate; diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp index 08c2e6db9803242da2530bb7a8e27071ee485bfc..03e3049d401b7ee886a3d653504a263908446f81 100644 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp @@ -889,7 +889,7 @@ void PulseLayer::readFromMic (void) // remove dc offset _audiofilter->processAudio (rsmpl_out, nbSample*sizeof (SFLDataFormat)); - getMainBuffer()->putData (rsmpl_out, nbSample*sizeof (SFLDataFormat), 100); + getMainBuffer()->putData (rsmpl_out, nbSample*sizeof (SFLDataFormat)); pa_xfree (rsmpl_out); @@ -902,7 +902,7 @@ void PulseLayer::readFromMic (void) // remove dc offset _audiofilter->processAudio ( (SFLDataFormat *) data, filter_out, r); - getMainBuffer()->putData (filter_out, r, 100); + getMainBuffer()->putData (filter_out, r); pa_xfree (filter_out); } diff --git a/sflphone-common/src/audio/ringbuffer.cpp b/sflphone-common/src/audio/ringbuffer.cpp index 2a1d5fdea84be7577ab91c81af5418c2e22c5e0a..2b15ef80b36f55a5b189e1f215f3ea17cd414348 100644 --- a/sflphone-common/src/audio/ringbuffer.cpp +++ b/sflphone-common/src/audio/ringbuffer.cpp @@ -227,9 +227,8 @@ RingBuffer::AvailForPut() } // This one puts some data inside the ring buffer. -// Change the volume if it's not 100 int -RingBuffer::Put (void* buffer, int toCopy, unsigned short volume) +RingBuffer::Put (void* buffer, int toCopy) { samplePtr src; int block; @@ -258,18 +257,6 @@ RingBuffer::Put (void* buffer, int toCopy, unsigned short volume) block = mBufferSize - pos; } - // Gain adjustment (when Mic vol. is changed) - if (volume != 100) { - SFLDataFormat* start = (SFLDataFormat*) src; - int nbSample = block / sizeof (SFLDataFormat); - - for (int i=0; i<nbSample; i++) { - start[i] = start[i] * volume / 100; - } - } - - // bcopy(src, dest, len) - //fprintf(stderr, "has %d put %d\t", len, block); bcopy (src, mBuffer + pos, block); src += block; diff --git a/sflphone-common/src/audio/ringbuffer.h b/sflphone-common/src/audio/ringbuffer.h index d931470eaa634418f18b0f3f43fb201632b4f1c6..8b84e94418212005a45c590095956f05c9927bac 100644 --- a/sflphone-common/src/audio/ringbuffer.h +++ b/sflphone-common/src/audio/ringbuffer.h @@ -107,10 +107,9 @@ class RingBuffer * Write data in the ring buffer * @param buffer Data to copied * @param toCopy Number of bytes to copy - * @param volume The volume * @return int Number of bytes copied */ - int Put (void* buffer, int toCopy, unsigned short volume = 100); + int Put (void* buffer, int toCopy); /** * To get how much space is available in the buffer to read in diff --git a/sflphone-common/src/global.h b/sflphone-common/src/global.h index d244ece14fff906ff1b7111b5f1de6b4a459c871..504713b89ca223616f3b0189973c11a268fdd91d 100644 --- a/sflphone-common/src/global.h +++ b/sflphone-common/src/global.h @@ -83,7 +83,6 @@ static const SOUND_FORMAT INT32 = 0x8; #define CODECDIR "codecs" /** Codecs directory */ #define SIZEBUF 400000 /** About 12 sec of buffering at 8000 Hz*/ -#define STATIC_BUFSIZE 5000 #define ALSA_DFT_CARD_ID 0 /** Index of the default soundcard */ diff --git a/sflphone-common/src/iax/iaxvoiplink.cpp b/sflphone-common/src/iax/iaxvoiplink.cpp index 4e38d0ce35f0d279a623477b7380a91a7cfa1c6b..5a23dfdd35df029dc3f9e370e2973f299e9147d9 100644 --- a/sflphone-common/src/iax/iaxvoiplink.cpp +++ b/sflphone-common/src/iax/iaxvoiplink.cpp @@ -95,46 +95,18 @@ IAXVoIPLink::IAXVoIPLink (const std::string& accountID) : VoIPLink () IAXVoIPLink::~IAXVoIPLink() { - if (_evThread) { - delete _evThread; - _evThread = NULL; - } + delete _evThread; + _evThread = NULL; _regSession = NULL; // shall not delete it terminate(); - audiolayer = NULL; - - if (converter) { - delete converter; - converter = NULL; - } - - if (micData) { - delete [] micData; - micData = NULL; - } - - if (micDataConverted) { - delete [] micDataConverted; - micDataConverted = NULL; - } - - if (micDataEncoded) { - delete [] micDataEncoded; - micDataEncoded = NULL; - } - - if (spkrDataDecoded) { - delete [] spkrDataDecoded; - spkrDataDecoded = NULL; - } - - if (spkrDataConverted) { - delete [] spkrDataConverted; - spkrDataConverted = NULL; - } - + delete converter; + delete [] micData; + delete [] micDataConverted; + delete [] micDataEncoded; + delete [] spkrDataDecoded; + delete [] spkrDataConverted; } bool @@ -211,21 +183,17 @@ IAXVoIPLink::terminate() void IAXVoIPLink::terminateIAXCall() { - std::string reason = "Dumped Call"; ost::MutexLock m (_callMapMutex); CallMap::iterator iter = _callMap.begin(); - IAXCall *call; while (iter != _callMap.end()) { - call = dynamic_cast<IAXCall*> (iter->second); - + IAXCall *call = dynamic_cast<IAXCall*> (iter->second); if (call) { _mutexIAX.enterMutex(); - iax_hangup (call->getSession(), (char*) reason.c_str()); + iax_hangup (call->getSession(), (char*) "Dumped Call"); _mutexIAX.leaveMutex(); call->setSession (NULL); delete call; - call = NULL; } iter++; @@ -307,11 +275,6 @@ IAXVoIPLink::getEvent() void IAXVoIPLink::sendAudioFromMic (void) { - - int maxBytesToGet, availBytesFromMic, bytesAvail, compSize; - sfl::AudioCodec *audioCodec = NULL; - IAXCall *currentCall; - // We have to update the audio layer type in case we switched // TODO Find out a better way to do it updateAudiolayer(); @@ -322,89 +285,53 @@ IAXVoIPLink::sendAudioFromMic (void) CallMap::iterator iter_call = _callMap.begin(); while (iter_call != _callMap.end()) { - - currentCall = (IAXCall*) iter_call->second; - + IAXCall *currentCall = (IAXCall*) iter_call->second; iter_call++; - if (currentCall) { - - // bool sessionIsConnected = (currentCall->getConnectionState() == Call::Connected); - bool callIsActive = (currentCall->getState() == Call::Active); - - // if (sessionIsConnected || callIsActive) { - - if (callIsActive) { + if (!currentCall || currentCall->getState() != Call::Active) + continue; AudioCodecType codecType = currentCall->getAudioCodec(); - audioCodec = static_cast<sfl::AudioCodec *>(currentCall->getAudioCodecFactory().getCodec (codecType)); - - // Send sound here - - if (audioCodec && audiolayer) { - - // _debug("Send sound"); - // audiolayer->getMainBuffer()->flush(currentCall->getCallId()); - - Manager::instance().getMainBuffer()->setInternalSamplingRate (audioCodec->getClockRate()); - - int _mainBufferSampleRate = audiolayer->getMainBuffer()->getInternalSamplingRate(); - - // we have to get 20ms of data from the mic *20/1000 = /50 - // rate/50 shall be lower than IAX__20S_48KHZ_MAX - maxBytesToGet = _mainBufferSampleRate * audiolayer->getFrameSize() / 1000 * sizeof (SFLDataFormat); - - // available bytes inside ringbuffer - availBytesFromMic = audiolayer->getMainBuffer()->availForGet (currentCall->getCallId()); - // We need packets full! - - if (availBytesFromMic > maxBytesToGet) { + sfl::AudioCodec *audioCodec = static_cast<sfl::AudioCodec *>(currentCall->getAudioCodecFactory().getCodec (codecType)); - // take the lowest - bytesAvail = (availBytesFromMic < maxBytesToGet) ? availBytesFromMic : maxBytesToGet; + // Send sound here - // Get bytes from micRingBuffer to data_from_mic - nbSample_ = audiolayer->getMainBuffer()->getData (micData, bytesAvail, 100, currentCall->getCallId()) / sizeof (SFLDataFormat); + if (!audioCodec || !audiolayer) + continue; + Manager::instance().getMainBuffer()->setInternalSamplingRate (audioCodec->getClockRate()); - // Store the number of samples for recording - nbSampleForRec_ = nbSample_; + int _mainBufferSampleRate = audiolayer->getMainBuffer()->getInternalSamplingRate(); + // we have to get 20ms of data from the mic *20/1000 = /50 + // rate/50 shall be lower than IAX__20S_48KHZ_MAX + int needed = _mainBufferSampleRate * audiolayer->getFrameSize() / 1000 * sizeof (SFLDataFormat); + if (audiolayer->getMainBuffer()->availForGet (currentCall->getCallId()) < needed) + continue; - if (audioCodec->getClockRate() && ((int) audioCodec->getClockRate() != _mainBufferSampleRate)) { + // Get bytes from micRingBuffer to data_from_mic + int bytes = audiolayer->getMainBuffer()->getData (micData, needed, 100, currentCall->getCallId()) / sizeof (SFLDataFormat); - // resample - nbSample_ = converter->downsampleData (micData , micDataConverted , (int) audioCodec->getClockRate(), _mainBufferSampleRate, nbSample_); + int compSize; + if (audioCodec->getClockRate() && ((int) audioCodec->getClockRate() != _mainBufferSampleRate)) { + // resample + bytes = converter->downsampleData (micData , micDataConverted , (int) audioCodec->getClockRate(), _mainBufferSampleRate, bytes); + compSize = audioCodec->encode (micDataEncoded, micDataConverted , bytes); + } else { + compSize = audioCodec->encode (micDataEncoded, micData, bytes); + } - // for the mono: range = 0 to IAX_FRAME2SEND * sizeof(int16) - compSize = audioCodec->encode (micDataEncoded, micDataConverted , nbSample_*sizeof (int16)); + // Send it out! + _mutexIAX.enterMutex(); - } else { - - // for the mono: range = 0 to IAX_FRAME2SEND * sizeof(int16) - compSize = audioCodec->encode (micDataEncoded, micData, nbSample_*sizeof (int16)); - - } - - // Send it out! - _mutexIAX.enterMutex(); - - // Make sure the session and the call still exists. - if (currentCall->getSession() && (micDataEncoded != NULL) && (nbSample_ > 0)) { - if (iax_send_voice (currentCall->getSession(), currentCall->getFormat(), micDataEncoded, compSize, nbSample_) == -1) { - _debug ("IAX: Error sending voice data."); - } - } - - _mutexIAX.leaveMutex(); - - } - } - - } - - } + // Make sure the session and the call still exists. + if (currentCall->getSession() && (micDataEncoded != NULL) && (bytes > 0)) { + if (iax_send_voice (currentCall->getSession(), currentCall->getFormat(), micDataEncoded, compSize, bytes) == -1) { + _debug ("IAX: Error sending voice data."); + } + } + _mutexIAX.leaveMutex(); } } @@ -1049,12 +976,12 @@ IAXVoIPLink::iaxHandleVoiceEvent (iax_event* event, IAXCall* call) nbInt16 = converter->upsampleData (spkrDataDecoded, spkrDataConverted, audioCodec->getClockRate(), _mainBufferSampleRate, nbSample_); /* Write the data to the mic ring buffer */ - audiolayer->getMainBuffer()->putData (spkrDataConverted, nbInt16 * sizeof (SFLDataFormat), 100, call->getCallId()); + audiolayer->getMainBuffer()->putData (spkrDataConverted, nbInt16 * sizeof (SFLDataFormat), call->getCallId()); } else { /* Write the data to the mic ring buffer */ - audiolayer->getMainBuffer()->putData (spkrDataDecoded, nbInt16 * sizeof (SFLDataFormat), 100, call->getCallId()); + audiolayer->getMainBuffer()->putData (spkrDataDecoded, nbInt16 * sizeof (SFLDataFormat), call->getCallId()); } diff --git a/sflphone-common/src/iax/iaxvoiplink.h b/sflphone-common/src/iax/iaxvoiplink.h index 7ac602372e70520e7cc671d3b80b20fe26b218b4..88da9088d337fe3a74b9d03d42f2e63d0c0639ef 100644 --- a/sflphone-common/src/iax/iaxvoiplink.h +++ b/sflphone-common/src/iax/iaxvoiplink.h @@ -320,12 +320,6 @@ class IAXVoIPLink : public VoIPLink int converterSamplingRate; - /** number of sample */ - int nbSample_; - - /** number of sample before conversion (recording) */ - int nbSampleForRec_; - /* URL hook */ UrlHook *urlhook; diff --git a/sflphone-common/src/sip/sipcall.h b/sflphone-common/src/sip/sipcall.h index d0bb4f76a241972cfa49b35b579b80eebe0fcd8e..1d9366f95bcfd49287dbee06e283983e2d8eaa23 100644 --- a/sflphone-common/src/sip/sipcall.h +++ b/sflphone-common/src/sip/sipcall.h @@ -99,13 +99,6 @@ class SIPCall : public Call return _local_sdp; } - /** - * Set the local SDP session - */ - void setLocalSDP (Sdp *local_sdp) { - _local_sdp = local_sdp; - } - /** * Returns a pointer to the AudioRtp object */ diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 5e5d05ba509d113c93cec02afb2018a8176ab048..8001baf75dcf64d7c11aeca025fdbd00e71b3182 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -3674,13 +3674,9 @@ void registration_cb (struct pjsip_regc_cbparam *param) const pj_str_t * description = pjsip_get_status_text (param->code); if (param->code && description) { - - //std::string descriptionprint(description->ptr, description->slen); - //_debug("Received client registration callback wiht code: %i, %s\n", param->code, descriptionprint.c_str()); - DBusManager::instance().getCallManager()->registrationStateChanged (account->getAccountID(), std::string (description->ptr, description->slen), param->code); - std::pair<int, std::string> details (param->code, std::string (description->ptr, description->slen)); - - + std::string state(description->ptr, description->slen); + DBusManager::instance().getCallManager()->registrationStateChanged (account->getAccountID(), state, param->code); + std::pair<int, std::string> details (param->code, state); // TODO: there id a race condition for this ressource when closing the application account->setRegistrationStateDetailed (details); } diff --git a/sflphone-common/test/mainbuffertest.cpp b/sflphone-common/test/mainbuffertest.cpp index a55f843fb4dae4d6405066ab9ba3ebb330defe16..68c4d087de9d9e40e63c77f89dd9f81cd6bcf2fe 100644 --- a/sflphone-common/test/mainbuffertest.cpp +++ b/sflphone-common/test/mainbuffertest.cpp @@ -177,7 +177,7 @@ void MainBufferTest::testCallIDSet() CPPUNIT_ASSERT (iter_map ==_mainbuffer._callIDMap.end()); // test callidset creation - CPPUNIT_ASSERT (_mainbuffer.createCallIDSet (test_id) == true); + _mainbuffer.createCallIDSet (test_id); CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 1); iter_map = _mainbuffer._callIDMap.find (test_id); CPPUNIT_ASSERT (iter_map->first == test_id); @@ -929,14 +929,14 @@ void MainBufferTest::testGetPutDataByID() // pu by test_id get by test_id CPPUNIT_ASSERT (_mainbuffer.availForPut (test_id) == avail_for_put_defaultid); - CPPUNIT_ASSERT (_mainbuffer.putData (&test_input2, sizeof (int), 100, test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input2, sizeof (int), test_id) == sizeof (int)); CPPUNIT_ASSERT (_mainbuffer.availForGetByID (test_id, default_id) == sizeof (int)); CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_output, sizeof (int), 100, test_id, default_id) == sizeof (int)); CPPUNIT_ASSERT (_mainbuffer.availForGetByID (test_id, default_id) == 0); CPPUNIT_ASSERT (test_input2 == test_output); // put/get by false id - CPPUNIT_ASSERT (_mainbuffer.putData (&test_input2, sizeof (int), 100, false_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input2, sizeof (int), false_id) == 0); CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_input2, sizeof (int), 100, false_id, false_id) == 0); CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_input2, sizeof (int), 100, default_id, false_id) == 0); CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_input2, sizeof (int), 100, false_id, default_id) == 0); @@ -969,7 +969,7 @@ void MainBufferTest::testGetPutData() // put by default_id, get by test_id CPPUNIT_ASSERT (_mainbuffer.availForPut() == avail_for_put_defaultid); - CPPUNIT_ASSERT (_mainbuffer.putData (&test_input1, sizeof (int), 100) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input1, sizeof (int)) == sizeof (int)); CPPUNIT_ASSERT (_mainbuffer.availForPut() == (avail_for_put_defaultid - (int) sizeof (int))); CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id) == sizeof (int)); CPPUNIT_ASSERT (_mainbuffer.getData (&test_output, sizeof (int), 100, test_id) == sizeof (int)); @@ -983,7 +983,7 @@ void MainBufferTest::testGetPutData() // put by test_id, get by default_id CPPUNIT_ASSERT (_mainbuffer.availForPut (test_id) == avail_for_put_testid); - CPPUNIT_ASSERT (_mainbuffer.putData (&test_input2, sizeof (int), 100, test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input2, sizeof (int), test_id) == sizeof (int)); CPPUNIT_ASSERT (_mainbuffer.availForPut (test_id) == (avail_for_put_testid - (int) sizeof (int))); CPPUNIT_ASSERT (_mainbuffer.availForGet() == sizeof (int)); CPPUNIT_ASSERT (_mainbuffer.getData (&test_output, sizeof (int), 100) == sizeof (int)); @@ -1007,7 +1007,7 @@ void MainBufferTest::testDiscardFlush() // int test_output_size; // int init_size; - CPPUNIT_ASSERT (_mainbuffer.putData (&test_input1, sizeof (int), 100, test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input1, sizeof (int), test_id) == sizeof (int)); CPPUNIT_ASSERT (_mainbuffer.availForGet() == sizeof (int)); _mainbuffer.discard (sizeof (int)); CPPUNIT_ASSERT (_mainbuffer.availForGet() == 0); @@ -1341,7 +1341,7 @@ void MainBufferTest::testConference() CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == 0); // put data test ring buffers - CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int)) == sizeof (int)); test_ring_buffer = _mainbuffer.getRingBuffer (default_id); CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int)));