Commit 90edabd1 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Merge branch 'recording'

Conflicts:

	src/audio/audiortp.cpp
	src/sipvoiplink.cpp
parents e19dbdb1 b4784ab7
......@@ -22,6 +22,7 @@
#include <cstdio>
#include <speex/speex.h>
class Speex : public AudioCodec{
public:
Speex(int payload=0)
......
......@@ -173,6 +173,12 @@ Call::setRecording()
recAudio.setRecording();
}
void
Call::stopRecording()
{
recAudio.stopRecording();
}
bool
Call::isRecording()
{
......
......@@ -224,6 +224,11 @@ class Call{
* SetRecording
*/
void setRecording();
/**
* stopRecording, make sure the recording is stopped (whe transfering call)
*/
void stopRecording();
/**
* Return Recording state
......
......@@ -163,6 +163,17 @@ IAXVoIPLink::terminateIAXCall()
_callMap.clear();
}
void IAXVoIPLink::terminateOneCall(const CallID& id)
{
IAXCall* call = getIAXCall(id);
if(call){
_debug("IAXVoIPLink::terminateOneCall()::the call is deleted, should close recording file \n");
delete call; call = 0;
}
}
void
IAXVoIPLink::getEvent()
{
......@@ -207,6 +218,8 @@ IAXVoIPLink::getEvent()
if (_nextRefreshStamp && _nextRefreshStamp - 2 < time(NULL)) {
sendRegister("");
}
if(call)
call->recAudio.recData(spkrDataConverted,micData,nbSample_,nbSample_);
// thread wait 3 millisecond
_evThread->sleep(3);
......@@ -216,7 +229,7 @@ IAXVoIPLink::getEvent()
void
IAXVoIPLink::sendAudioFromMic(void)
{
int maxBytesToGet, availBytesFromMic, bytesAvail, nbSample, compSize;
int maxBytesToGet, availBytesFromMic, bytesAvail, compSize;
AudioCodec *ac;
// We have to update the audio layer type in case we switched
......@@ -273,19 +286,19 @@ IAXVoIPLink::sendAudioFromMic(void)
//_debug("available = %d, maxBytesToGet = %d\n", availBytesFromMic, maxBytesToGet);
// Get bytes from micRingBuffer to data_from_mic
nbSample = audiolayer->getMic( micData, bytesAvail ) / sizeof(SFLDataFormat);
nbSample_ = audiolayer->getMic( micData, bytesAvail ) / sizeof(SFLDataFormat);
// resample
nbSample = converter->downsampleData( micData , micDataConverted , (int)ac ->getClockRate() , (int)audiolayer->getSampleRate() , nbSample );
nbSample_ = converter->downsampleData( micData , micDataConverted , (int)ac ->getClockRate() , (int)audiolayer->getSampleRate() , nbSample_ );
// for the mono: range = 0 to IAX_FRAME2SEND * sizeof(int16)
compSize = ac->codecEncode( micDataEncoded, micDataConverted , nbSample*sizeof(int16));
compSize = ac->codecEncode( micDataEncoded, micDataConverted , nbSample_*sizeof(int16));
// Send it out!
_mutexIAX.enterMutex();
// Make sure the session and the call still exists.
if (currentCall->getSession()) {
if (iax_send_voice(currentCall->getSession(), currentCall->getFormat(), micDataEncoded, compSize, nbSample) == -1) {
if (iax_send_voice(currentCall->getSession(), currentCall->getFormat(), micDataEncoded, compSize, nbSample_) == -1) {
_debug("IAX: Error sending voice data.\n");
}
}
......@@ -421,11 +434,12 @@ IAXVoIPLink::answer(const CallID& id)
bool
IAXVoIPLink::hangup(const CallID& id)
{
_debug("IAXVoIPLink::hangup() : function called once hangup \n");
IAXCall* call = getIAXCall(id);
std::string reason = "Dumped Call";
CHK_VALID_CALL;
_mutexIAX.enterMutex();
iax_hangup(call->getSession(), (char*) reason.c_str());
_mutexIAX.leaveMutex();
call->setSession(NULL);
......@@ -433,10 +447,34 @@ IAXVoIPLink::hangup(const CallID& id)
// stop audio
audiolayer->stopStream();
}
terminateOneCall(id);
removeCall(id);
return true;
}
bool
IAXVoIPLink::peerHungup(const CallID& id)
{
_debug("IAXVoIPLink::peerHangup() : function called once hangup \n");
IAXCall* call = getIAXCall(id);
std::string reason = "Dumped Call";
CHK_VALID_CALL;
_mutexIAX.enterMutex();
_mutexIAX.leaveMutex();
call->setSession(NULL);
if (Manager::instance().isCurrentCall(id)) {
// stop audio
audiolayer->stopStream();
}
terminateOneCall(id);
removeCall(id);
return true;
}
bool
IAXVoIPLink::onhold(const CallID& id)
{
......@@ -502,6 +540,8 @@ IAXVoIPLink::refuse(const CallID& id)
iax_reject(call->getSession(), (char*) reason.c_str());
_mutexIAX.leaveMutex();
// terminateOneCall(id);
removeCall(id);
return true;
......@@ -511,13 +551,21 @@ IAXVoIPLink::refuse(const CallID& id)
void
IAXVoIPLink::setRecording(const CallID& id)
{
_debug("IAXVoIPLink::setRecording!");
_debug("IAXVoIPLink::setRecording()!");
IAXCall* call = getIAXCall(id);
call->setRecording();
}
bool
IAXVoIPLink::isRecording(const CallID& id)
{
_debug("IAXVoIPLink::setRecording!");
_debug("IAXVoIPLink::setRecording()!");
IAXCall* call = getIAXCall(id);
return call->isRecording();
}
......@@ -604,7 +652,17 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
// stop audio
audiolayer->stopStream();
}
Manager::instance().peerHungupCall(id);
Manager::instance().peerHungupCall(id);
/*
_debug("IAXVoIPLink::iaxHandleCallEvent, peer hangup have been called");
std::string reason = "Dumped Call";
_mutexIAX.enterMutex();
iax_hangup(call->getSession(), (char*)reason.c_str());
_mutexIAX.leaveMutex();
call->setSession(NULL);
audiolayer->stopStream();
terminateOneCall(id);
*/
removeCall(id);
break;
......@@ -617,6 +675,7 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
call->setConnectionState(Call::Connected);
call->setState(Call::Error);
Manager::instance().callFailure(id);
// terminateOneCall(id);
removeCall(id);
break;
......@@ -650,6 +709,7 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
call->setConnectionState(Call::Connected);
call->setState(Call::Busy);
Manager::instance().callBusy(id);
// terminateOneCall(id);
removeCall(id);
break;
......@@ -698,7 +758,7 @@ IAXVoIPLink::iaxHandleVoiceEvent(iax_event* event, IAXCall* call)
unsigned char *data;
unsigned int size, max, nbInt16;
int expandedSize, nbSample;
int expandedSize, nbSample_;
AudioCodec *ac;
// If we receive datalen == 0, some things of the jitter buffer in libiax2/iax.c
......@@ -738,9 +798,9 @@ IAXVoIPLink::iaxHandleVoiceEvent(iax_event* event, IAXCall* call)
nbInt16 = max;
}
nbSample = nbInt16;
nbSample_ = nbInt16;
// resample
nbInt16 = converter->upsampleData( spkrDataDecoded , spkrDataConverted , ac->getClockRate() , audiolayer->getSampleRate() , nbSample);
nbInt16 = converter->upsampleData( spkrDataDecoded , spkrDataConverted , ac->getClockRate() , audiolayer->getSampleRate() , nbSample_);
//audiolayer->playSamples( spkrDataConverted , nbInt16 * sizeof(SFLDataFormat), true);
audiolayer->putMain (spkrDataConverted , nbInt16 * sizeof(SFLDataFormat));
......@@ -897,8 +957,9 @@ IAXVoIPLink::iaxHandlePrecallEvent(iax_event* event)
// Remote peer hung up
call = iaxFindCallBySession(event->session);
id = call->getCallId();
_debug("IAXVoIPLink::hungup::iaxHandlePrecallEvent");
Manager::instance().peerHungupCall(id);
// terminateOneCall(id);
removeCall(id);
break;
......
......@@ -72,6 +72,11 @@ class IAXVoIPLink : public VoIPLink
*/
void terminate (void);
/**
* Terminate on call
*/
void terminateOneCall(const CallID& id);
/**
* Send out registration
* @return bool The new registration state (are we registered ?)
......@@ -111,6 +116,14 @@ class IAXVoIPLink : public VoIPLink
*/
bool hangup(const CallID& id);
/**
* Peer Hungup a call
* @param id The ID of the call
* @return bool true on success
* false otherwise
*/
bool peerHungup(const CallID& id);
/**
* Cancel a call
* @param id The ID of the call
......@@ -280,7 +293,9 @@ class IAXVoIPLink : public VoIPLink
/** Sample rate converter object */
SamplerateConverter* converter;
/** number of sample */
int nbSample_;
};
#endif
......@@ -668,7 +668,7 @@ ManagerImpl::peerHungupCall(const CallID& id)
switchCall("");
}
returnValue = getAccountLink(accountid)->hangup(id);
returnValue = getAccountLink(accountid)->peerHungup(id);
removeWaitingCall(id);
removeCallAccount(id);
......
......@@ -152,6 +152,13 @@ bool AudioRecord::setRecording() {
}
void AudioRecord::stopRecording() {
_debug("AudioRecording::stopRecording() \n");
if(recordingEnabled_)
recordingEnabled_ = false;
}
bool AudioRecord::setRawFile() {
......@@ -369,7 +376,7 @@ void AudioRecord::recData(SFLDataFormat* buffer_1, SFLDataFormat* buffer_2, int
}
}
byteCounter_ += (unsigned long)(nSamples_1*sizeof(SFLDataFormat));
byteCounter_ += (unsigned long)(nSamples_1*sizeof(SFLDataFormat));
printf("AudioRecord::recData():: byteCounter_ : %i \n",(int)byteCounter_ );
......
......@@ -23,7 +23,7 @@
#include <sndfile.h>
#include "global.h"
#include "plug-in/plugin.h"
using namespace std;
......@@ -57,7 +57,7 @@ public:
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)
......@@ -90,6 +90,11 @@ public:
*/
bool setRecording();
/**
* Stop recording flag
*/
void stopRecording();
/**
* Record a chunk of data in an openend file
* @param buffer The data chunk to be recorded
......
......@@ -33,7 +33,7 @@ PluginManager::instance()
return _instance;
}
PluginManager::PluginManager()
PluginManager::PluginManager()
:_loadedPlugins()
{
_instance = this;
......
......@@ -236,9 +236,7 @@ SIPVoIPLink::terminateOneCall(const CallID& id)
{
_debug("SIPVoIPLink::terminateOneCall(): function called \n");
SIPCall *call;
call = getSIPCall(id);
SIPCall *call = getSIPCall(id);
if (call) {
// terminate the sip call
_debug("SIPVoIPLink::terminateOneCall()::the call is deleted, should close recording file \n");
......@@ -503,6 +501,44 @@ SIPVoIPLink::hangup(const CallID& id)
call->getInvSession()->mod_data[getModId()] = NULL;
// Release RTP thread
if (Manager::instance().isCurrentCall(id)) {
_debug("* SIP Info: Stopping AudioRTP for hangup\n");
_audiortp->closeRtpSession();
}
terminateOneCall(id);
removeCall(id);
return true;
}
bool
SIPVoIPLink::peerHungup(const CallID& id)
{
pj_status_t status;
pjsip_tx_data *tdata = NULL;
SIPCall* call;
call = getSIPCall(id);
if (call==0) { _debug("! SIP Error: Call doesn't exist\n"); return false; }
// User hangup current call. Notify peer
status = pjsip_inv_end_session(call->getInvSession(), 404, NULL, &tdata);
if(status != PJ_SUCCESS)
return false;
if(tdata == NULL)
return true;
status = pjsip_inv_send_msg(call->getInvSession(), tdata);
if(status != PJ_SUCCESS)
return false;
call->getInvSession()->mod_data[getModId()] = NULL;
// Release RTP thread
if (Manager::instance().isCurrentCall(id)) {
_debug("* SIP Info: Stopping AudioRTP for hangup\n");
......@@ -644,6 +680,7 @@ SIPVoIPLink::transfer(const CallID& id, const std::string& to)
call = getSIPCall(id);
call->stopRecording();
account_id = Manager::instance().getAccountFromCall(id);
account = dynamic_cast<SIPAccount *>(Manager::instance().getAccount(account_id));
......@@ -743,19 +780,17 @@ SIPVoIPLink::refuse (const CallID& id)
void
SIPVoIPLink::setRecording(const CallID& id)
{
//SIPCall *call;
//call = getSIPCall(id);
SIPCall* call = getSIPCall(id);
//call->setRecording();
call->setRecording();
_audiortp->setRecording();
// _audiortp->setRecording();
}
bool
SIPVoIPLink::isRecording(const CallID& id)
{
SIPCall *call;
call = getSIPCall(id);
SIPCall* call = getSIPCall(id);
return call->isRecording();
}
......@@ -1007,6 +1042,7 @@ SIPVoIPLink::SIPCallReleased(SIPCall *call)
removeCall(id);
}
void
SIPVoIPLink::SIPCallAnswered(SIPCall *call, pjsip_rx_data *rdata)
{
......
......@@ -124,6 +124,13 @@ class SIPVoIPLink : public VoIPLink
*/
bool hangup(const CallID& id);
/**
* Hang up the call
* @param id The call identifier
* @return bool True on success
*/
bool peerHungup(const CallID& id);
/**
* Cancel the call
* @param id The call identifier
......
......@@ -110,6 +110,13 @@ class VoIPLink {
*/
virtual bool hangup(const CallID& id) = 0;
/**
* Peer Hung up a call
* @param id The call identifier
* @return bool True on success
*/
virtual bool peerHungup(const CallID& id) = 0;
/**
* Cancel the call dialing
* @param id The call identifier
......
......@@ -47,6 +47,7 @@ configurationTester_LDADD = \
@DBUSCPP_LIBS@ \
@SAMPLERATE_LIBS@ \
$(PJSIP_LIBS) \
-luuid \
$(OBJECT_FILES)
pluginmanagerTester_LDADD = \
......@@ -61,6 +62,7 @@ pluginmanagerTester_LDADD = \
@DBUSCPP_LIBS@ \
@SAMPLERATE_LIBS@ \
$(PJSIP_LIBS) \
-luuid \
$(OBJECT_FILES)
audiorecorderTester_LDADD = \
......@@ -75,5 +77,6 @@ audiorecorderTester_LDADD = \
@DBUSCPP_LIBS@ \
@SAMPLERATE_LIBS@ \
$(PJSIP_LIBS) \
-luuid \
$(OBJECT_FILES)
......@@ -32,6 +32,7 @@ void AudioRecorderTest::setUp(){
void AudioRecorderTest::testRecordData(){
/*
FILE_TYPE ft = FILE_WAV;
SOUND_FORMAT sf = INT16;
_ar->setSndSamplingRate(44100);
......@@ -47,6 +48,7 @@ void AudioRecorderTest::testRecordData(){
}
_ar->closeFile();
*/
}
void AudioRecorderTest::tearDown(){
......
/*
x/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
*
......
......@@ -40,7 +40,7 @@
class PluginManagerTest : public CppUnit::TestCase {
/*
/**
* Use cppunit library macros to add unit test the factory
*/
CPPUNIT_TEST_SUITE( PluginManagerTest );
......
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