Commit e872d3e1 authored by alexandresavard's avatar alexandresavard
Browse files

setRecordingOption function implement in audiorecord

parent efe07d8c
......@@ -100,10 +100,9 @@ AudioRtp::closeRtpSession () {
void
AudioRtp::setRecording() {
_debug("AudioRtp::setRecording");
// _RTXThread->recAudio.setRecording();
_debug("AudioRtp::setRecording\n");
_RTXThread->_ca->setRecording();
}
......@@ -192,24 +191,6 @@ AudioRtpRTX::initAudioRtpSession (void)
return;
}
// Initialization
printf("AudioRTPX::initAudioRtpSession: CallID to be used: %s \n",_ca->getCallId().c_str());
printf("AudioRTPX::initAudioRtpSession: Account %s \n",Manager::instance().getAccountFromCall(_ca->getCallId()).c_str());
printf("AudioRTPX::initAudioSRtpSession: FileName from call class: %s \n", _ca->getFileName().c_str());
_debug("Opening the wave file\n");
FILE_TYPE ft = FILE_WAV;
SOUND_FORMAT sf = INT16;
recAudio.setSndSamplingRate(44100);
recAudio.openFile(_ca->getFileName(),ft,sf);
//_debug("Opening the wave file in call nstance\n");
//_ca->recAudio.setSndSamplingRate(44100);
//_ca->recAudio.openFile("testRecFromCall",ft,sf,_ca->getCallId());
if (!_sym) {
_sessionRecv->setSchedulingTimeout (10000);
......@@ -463,40 +444,23 @@ AudioRtpRTX::run () {
receiveSessionForSpkr(countTime);
// Let's wait for the next transmit cycle
recAudio.recData(spkrDataConverted,micData,_nSamplesSpkr,_nSamplesMic);
_ca->recAudio.recData(spkrDataConverted,micData,_nSamplesSpkr,_nSamplesMic);
Thread::sleep(TimerPort::getTimer());
TimerPort::incTimer(_layerFrameSize); // 'frameSize' ms
}
_debug("Close wave file\n");
recAudio.closeFile();
//_debug("Close wave file in call instance\n");
//_ca->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();
//_debug("Close wave file in call instance\n");
//_ca->recAudio.closeFile();
throw;
} catch(...) {
_start.post();
_debugException("* ARTP Action: Stop");
_debug("* Close wave file\n");
recAudio.closeFile();
//_debug("Close wave file in call instance\n");
//_ca->recAudio.closeFile();
throw;
}
......
......@@ -112,7 +112,7 @@ class AudioRtpRTX : public ost::Thread, public ost::TimerPort {
/** Variables to process audio stream: sample rate for playing sound (typically 44100HZ) */
int _layerSampleRate;
/** Sample rate of the codec we use to encode and decode (most of time 8000HZ) */
/** Sample rate of te codec we use to encode and decode (most of time 8000HZ) */
int _codecSampleRate;
/** Length of the sound frame we capture in ms(typically 20ms) */
......
......@@ -51,24 +51,31 @@ Call::Call(const CallID& id, Call::CallType type)
if (timeinfo->tm_mday < 10) // 01 02 03, not 1 2 3
out << 0;
out << timeinfo->tm_mday;
_filename = out.str();
printf("Call::constructor filename for tis call %s \n",_filename.c_str());
if (timeinfo->tm_hour < 10) // 01 02 03, not 1 2 3
out << 0;
out << timeinfo->tm_hour;
if (timeinfo->tm_min < 10) // 01 02 03, not 1 2 3
out << 0;
out << timeinfo->tm_min;
if (timeinfo->tm_sec < 10) // 01 02 03, not 1 2 3
out << 0;
out << timeinfo->tm_sec;
_filename = out.str();
printf("Call::constructor filename for this call %s \n",_filename.c_str());
FILE_TYPE fileType = FILE_WAV;
SOUND_FORMAT soundFormat = INT16;
recAudio.setRecordingOption(_filename.c_str(),fileType,soundFormat,44100);
FILE_TYPE ft = FILE_WAV;
SOUND_FORMAT sf = INT16;
_debug("CALL::Opening the wave file in call nstance\n");
recAudio.setSndSamplingRate(44100);
recAudio.openFile("testRecFromCall",ft,sf);
_debug("CALL::Constructor for this clss is called \n");
}
Call::~Call()
{
_debug("CALL::Close wave file in call instance\n");
_debug("CALL::Destructor for this clss is called \n");
recAudio.closeFile();
}
......
......@@ -216,7 +216,7 @@ class Call{
std::string getFileName() {return _filename;}
/**
* A recorder fro this call
* A recorder for this call
*/
AudioRecord recAudio;
......@@ -275,6 +275,7 @@ class Call{
private:
/** Unique ID of the call */
CallID _id;
......
......@@ -27,6 +27,7 @@ AudioRecord::AudioRecord(){
channels_ = 1;
byteCounter_ = 0;
recordingEnabled_ = false;
fp = 0;
}
......@@ -35,17 +36,16 @@ void AudioRecord::setSndSamplingRate(int smplRate){
sndSmplRate_ = smplRate;
}
void AudioRecord::setRecordingOption(std::string name, FILE_TYPE type, SOUND_FORMAT format, int sndSmplRate){
void AudioRecord::openFile(std::string name, FILE_TYPE type, SOUND_FORMAT format){
_debug("AudioRecord::openFile()\n");
bool result = false;
strncpy(fileName_, name.c_str(), 8192);
fileType_ = type;
strncpy(fileName_, name.c_str(), 8192);
fileType_ = type;
sndFormat_ = format;
channels_ = 1;
sndSmplRate_ = sndSmplRate;
if (fileType_ == FILE_RAW){
if (fileType_ == FILE_RAW){
if ( strstr(fileName_, ".raw") == NULL){
printf("AudioRecord::openFile::concatenate .raw file extension: name : %s \n", fileName_);
strcat(fileName_, ".raw");
......@@ -57,31 +57,34 @@ void AudioRecord::openFile(std::string name, FILE_TYPE type, SOUND_FORMAT format
strcat(fileName_, ".wav");
}
}
}
void AudioRecord::openFile(){
_debug("AudioRecord::openFile()\n");
bool result = false;
if(isFileExist()) {
_debug("AudioRecord::Filename does not exist, creating one \n");
channels_ = 1;
byteCounter_ = 0;
sndFormat_ = format;
_debug("AudioRecord::Filename does not exist, creating one \n");
byteCounter_ = 0;
if(fileType_ == FILE_RAW){
result = setRawFile();
}
else if (fileType_ == FILE_WAV){
result = setWavFile();
}
}
else {
fileType_ = type;
_debug("AudioRecord::Filename already exist opening it \n");
if(fileType_ == FILE_RAW){
result = openExistingRawFile();
}
else if (fileType_ == FILE_WAV){
result = openExistingWavFile();
}
}
if(fileType_ == FILE_RAW){
result = setRawFile();
}
else if (fileType_ == FILE_WAV){
result = setWavFile();
}
}
else {
_debug("AudioRecord::Filename already exist opening it \n");
if(fileType_ == FILE_RAW){
result = openExistingRawFile();
}
else if (fileType_ == FILE_WAV){
result = openExistingWavFile();
}
}
}
......@@ -99,10 +102,14 @@ void AudioRecord::closeFile() {
bool AudioRecord::isOpenFile() {
if(fp)
if(fp){
_debug("AudioRecord::isOpenFile(): file already openend\n");
return true;
else
}
else {
_debug("AudioRecord::isOpenFIle(): file not openend \n");
return false;
}
}
......@@ -118,12 +125,21 @@ bool AudioRecord::isFileExist() {
bool AudioRecord::setRecording() {
_debug("AudioRecord::setRecording()");
_debug("AudioRecord::setRecording()\n");
if(!recordingEnabled_)
recordingEnabled_ = true;
else
recordingEnabled_ = false;
if (isOpenFile()){
_debug("AuioRecord::setRecording()::file already opened\n");
if(!recordingEnabled_)
recordingEnabled_ = true;
else
recordingEnabled_ = false;
}
else {
_debug("AudioRecord::setRecording():Opening the wave file in call during call instantiation\n");
openFile();
recordingEnabled_ = true; // once opend file, start recording
}
}
......
......@@ -55,13 +55,15 @@ public:
void setSndSamplingRate(int smplRate);
void setRecordingOption(std::string name, FILE_TYPE type, SOUND_FORMAT format, int sndSmplRate);
/**
* Check if no otehr file is opened, then create a new one
* @param fileName A string containing teh file (with/without extension)
* @param type The sound file format (FILE_RAW, FILE_WAVE)
* @param format Internal sound format (INT16 / INT32)
*/
void openFile(std::string fileName, FILE_TYPE type, SOUND_FORMAT format);
void openFile();
/**
* Close the opend recording file. If wave: cout the number of byte
......
......@@ -39,10 +39,13 @@ SIPCall::SIPCall(const CallID& id, Call::CallType type) : Call(id, type)
, _xferSub(NULL)
, _invSession(NULL)
{
_debug("SIPCALL::Constructor for this clss is called \n");
}
SIPCall::~SIPCall()
{
_debug("SIPCALL::Destructor for this clss is called \n");
}
......
......@@ -88,6 +88,7 @@ SIPVoIPLink::terminateSIPCall()
call = dynamic_cast<SIPCall*>(iter->second);
if (call) {
//TODO terminate the sip call
_debug("SIPVOIP::the call is deleted, should close recording file \n");
delete call; call = 0;
}
iter++;
......@@ -348,9 +349,7 @@ SIPVoIPLink::refuse (const CallID& id)
void
SIPVoIPLink::setRecording(const CallID& id)
{
// _debug("SIPVoIPLink::setRecording!");
// printf("SIPVoIPLink:: CallID: %s", id);
_audiortp->setRecording();
}
......
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