Commit f62a68a8 authored by alexandresavard's avatar alexandresavard
Browse files

Audio recording working in AudioRTP: receiveSessionForSpeaker

parent e0527b19
......@@ -79,6 +79,7 @@ AudioRtp::createNewSession (SIPCall *ca) {
void
AudioRtp::closeRtpSession () {
//ost::MutexLock m(_threadMutex);
// This will make RTP threads finish.
// _debug("Stopping AudioRTP\n");
......@@ -88,6 +89,8 @@ AudioRtp::closeRtpSession () {
_debugException("! ARTP Exception: when stopping audiortp\n");
throw;
}
AudioLayer* audiolayer = Manager::instance().getAudioDriver();
audiolayer->stopStream();
}
......@@ -225,6 +228,13 @@ AudioRtpRTX::initAudioRtpSession (void)
}
}
}
_debug("Opening the wave file\n");
FILE_TYPE ft = FILE_WAV;
SOUND_FORMAT sf = INT16;
recAudio.setSndSamplingRate(44100);
recAudio.openFile("SFLWavFile.wav",ft,sf);
} catch(...) {
_debugException("! ARTP Failure: initialisation failed");
throw;
......@@ -321,6 +331,7 @@ AudioRtpRTX::receiveSessionForSpkr (int& countTime)
}
if (_audiocodec != NULL) {
int expandedSize = _audiocodec->codecDecode( spkrDataDecoded , spkrData , size );
//buffer _receiveDataDecoded ----> short int or int16, coded on 2 bytes
......@@ -339,7 +350,11 @@ AudioRtpRTX::receiveSessionForSpkr (int& countTime)
#else
#endif
// Record before sending to audio
recAudio.recData(spkrDataConverted,nbSample);
audiolayer->playSamples( spkrDataConverted, nbSample * sizeof(SFLDataFormat), true);
// Notify (with a beep) an incoming call when there is already a call
countTime += time->getSecond();
......@@ -420,15 +435,25 @@ AudioRtpRTX::run () {
Thread::sleep(TimerPort::getTimer());
TimerPort::incTimer(_layerFrameSize); // 'frameSize' ms
}
_debug("Close wave file\n");
recAudio.closeFile();
//_debug("stop stream for audiortp loop\n");
audiolayer->stopStream();
} catch(std::exception &e) {
_start.post();
_debug("! ARTP: Stop %s\n", e.what());
_debug("! Close wave file\n");
recAudio.closeFile();
throw;
} catch(...) {
_start.post();
_debugException("* ARTP Action: Stop");
_debug("* Close wave file\n");
recAudio.closeFile();
throw;
}
}
......
......@@ -29,6 +29,7 @@
#include <cc++/numbers.h>
#include "../global.h"
#include "plug-in/audiorecorder/audiorecord.h"
#include "../samplerateconverter.h"
#define UP_SAMPLING 0
......@@ -39,6 +40,8 @@
* @brief Manage the real-time data transport in a SIP call
*/
typedef unsigned char* samplePtr;
class SIPCall;
///////////////////////////////////////////////////////////////////////////////
......@@ -64,6 +67,11 @@ class AudioRtpRTX : public ost::Thread, public ost::TimerPort {
/** Thread associated method */
virtual void run ();
/**
* Audio recording object
*/
AudioRecord recAudio;
private:
// copy constructor
......@@ -146,7 +154,12 @@ class AudioRtpRTX : public ost::Thread, public ost::TimerPort {
int reSampleData(int sampleRate_codec, int nbSamples, int status);
/** The audio codec used during the session */
AudioCodec* _audiocodec;
AudioCodec* _audiocodec;
/**
* Audio recording object
*/
// AudioRecord recAudio;
};
///////////////////////////////////////////////////////////////////////////////
......
......@@ -153,23 +153,29 @@ void AudioRecord::recData(SFLDataFormat* buffer, int nSamples) {
return;
}
// int size = nSamples * (sizeof(SFLDataFormat));
// int size = sizeof(buffer);
// int count = sizeof(buffer) / sizeof(SFLDataFormat);
// printf("AudioRecord : sizeof(buffer) : %d \n",size);
// printf("AudioRecord : sizeof(buffer) / sizeof(SFLDataFormat) : %d \n",count);
// printf("AudioRecord : nSamples : %d \n",nSamples);
// printf("AudioRecord : buffer: %x : ", buffer);
if ( sndFormat_ == INT16 ) { // TODO change INT16 to SINT16
if (nSamples <= 1){
if ( fwrite(buffer, 2, 1, fp) != 1)
_debug("AudioRecord: Could not record data!\n");
}
else {
for ( int k=0; k<nSamples; k++ ) {
if ( fwrite(&buffer[k], 2, 1, fp) != 1 )
_debug("AudioRecord: Could not record data!\n");
}
if ( fwrite(buffer, nSamples*sizeof(SFLDataFormat), 1, fp) != 1)
_debug("AudioRecord: Could not record data!\n");
else {
// printf("Buffer : %x \n",*buffer);
fflush(fp);
// _debug("Flushing!\n");
}
}
byteCounter_ += (unsigned long)(sizeof(buffer) / sizeof(SINT16));
byteCounter_ += (unsigned long)(nSamples*sizeof(SFLDataFormat));
return;
}
......
Supports Markdown
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