Commit 6726d18c authored by yanmorin's avatar yanmorin

Hold/unhold : quelch/unquelch and pointer error fix

parent 6b7a705e
2006-08-02 Yan Morin
* Add IAX quelch/unquelch
* Add SAMPLERATE for incoming voice data
2006-07-27 Yan Morin
* Add IAX registration and outgoing call
......
......@@ -25,6 +25,14 @@ IAXSOURCES =
IAXHEADERS =
endif
if USE_SAMPLERATE
SAMPLERATE_FLAG=-DUSE_SAMPLERATE
SAMPLERATE_LIB =-lsamplerate
else
SAMPLERATE_FLAG=
SAMPLERATE_LIB=
endif
SUBDIRS = audio config gui $(ZEROCONFDIR)
sflphoned_SOURCES = eventthread.cpp main.cpp voIPLink.cpp \
......@@ -37,7 +45,7 @@ sflphoned_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone
#sflphoned_LDFLAGS = -static
sflphoned_LDADD = ./libsflphone.la $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) $(IAX_LIBS) $(EXOSIP_LIBS)
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $(libccgnu2_CFLAGS) $(IAX_CFLAGS) $(USER_INCLUDES)
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libs $(libccext2_CFLAGS) $(libccgnu2_CFLAGS) $(IAX_CFLAGS) $(USER_INCLUDES) $(SAMPLERATE_FLAG)
#libsflphone_la_LDFLAGS= -version-info 0:1:0
libsflphone_la_LIBADD = \
......@@ -46,7 +54,7 @@ libsflphone_la_LIBADD = \
./audio/libaudio.la \
./gui/libguiframework.la \
./config/libconfig.la \
$(IAX_LIBS)
$(IAX_LIBS) $(SAMPLERATE_LIB)
libsflphone_la_SOURCES =
......
......@@ -350,32 +350,8 @@ AudioRtpRTX::receiveSessionForSpkr (int16* data_for_speakers_stereo, int16* data
src_data.output_frames = _nbFrames;
src_data.src_ratio = factord;
src_short_to_float_array(data_for_speakers_recv, _floatBufferIn, nbInt16);
#if 0
for(int i=0; i<20; i++) {
printf("%3d ", data_for_speakers_recv[i]);
}
printf("\n");
for(int i=0; i<20; i++) {
printf("%7.6f ", _floatBufferIn[i]);
}
printf("\n");
#endif
src_simple (&src_data, SRC_SINC_MEDIUM_QUALITY, fromChannel);
src_float_to_short_array(_floatBufferOut, data_for_speakers_recv, src_data.output_frames_gen*fromChannel);
#if 0
for(int i=0; i<100; i++) {
printf("%7.6f ", _floatBufferOut[i]);
}
printf("\n");
for(int i=0; i<100; i++) {
printf("%3d ", data_for_speakers_recv[i]);
}
printf("\n");
printf("receive get %d and convert to %d\n", nbInt16, src_data.output_frames_gen);
#endif
nbInt16 = src_data.output_frames_gen*fromChannel;
}
#endif
......
......@@ -25,6 +25,10 @@
#include "audio/audiocodec.h"
#include "audio/audiolayer.h"
#ifdef USE_SAMPLERATE
#include <samplerate.h>
#endif
#define IAX_SUCCESS 0
#define IAX_FAILURE -1
......@@ -67,9 +71,14 @@ IAXVoIPLink::IAXVoIPLink(const AccountID& accountID)
audiocodec = 0;
audiolayer = 0;
_nbFrames = 160;
_nbFrames = 160;
data_for_speakers_recv = new int16[_nbFrames*2];
data_for_speakers_output = new int16[_nbFrames*2];
#ifdef USE_SAMPLERATE
_floatBufferIn = new float[_nbFrames*2];
_floatBufferOut = new float[_nbFrames*2];
#endif
}
......@@ -83,6 +92,11 @@ IAXVoIPLink::~IAXVoIPLink()
audiolayer = 0;
delete [] data_for_speakers_recv; data_for_speakers_recv = 0;
delete [] data_for_speakers_output; data_for_speakers_output = 0;
#ifdef USE_SAMPLERATE
delete [] _floatBufferIn;
delete [] _floatBufferOut;
#endif
}
bool
......@@ -130,9 +144,30 @@ IAXVoIPLink::terminate()
{
// iaxc_shutdown();
// hangup all call
terminateIAXCall();
// iax_hangup(calls[callNo].session,"Dumped Call");
}
void
IAXVoIPLink::terminateIAXCall()
{
ost::MutexLock m(_callMapMutex);
CallMap::iterator iter = _callMap.begin();
IAXCall *call;
while( iter != _callMap.end() ) {
call = dynamic_cast<IAXCall*>(iter->second);
if (call) {
_mutexIAX.enterMutex();
iax_hangup(call->getSession(),"Dumped Call");
_mutexIAX.leaveMutex();
call->setSession(0);
delete call; call = 0;
}
iter++;
}
_callMap.clear();
}
void
IAXVoIPLink::getEvent()
{
......@@ -273,6 +308,33 @@ IAXVoIPLink::hangup(const CallID& id)
removeCall(id);
return true;
}
bool
IAXVoIPLink::onhold(const CallID& id)
{
IAXCall* call = getIAXCall(id);
if (call==0) { _debug("Call doesn't exists\n"); return false; }
//if (call->getState() == Call::Hold) { _debug("Call is already on hold\n"); return false; }
_mutexIAX.enterMutex();
iax_quelch(call->getSession());
_mutexIAX.leaveMutex();
call->setState(Call::Hold);
return true;
}
bool
IAXVoIPLink::offhold(const CallID& id)
{
IAXCall* call = getIAXCall(id);
if (call==0) { _debug("Call doesn't exists\n"); return false; }
//if (call->getState() == Call::Active) { _debug("Call is already active\n"); return false; }
_mutexIAX.enterMutex();
iax_unquelch(call->getSession());
_mutexIAX.leaveMutex();
call->setState(Call::Active);
return true;
}
bool
IAXVoIPLink::iaxOutgoingInvite(IAXCall* call)
{
......@@ -337,11 +399,13 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
// note activity?
//
CallID id = call->getCallId();
int16* output = 0; // for audio output
switch(event->etype) {
case IAX_EVENT_HANGUP:
Manager::instance().peerHungupCall(id);
if (Manager::instance().isCurrentCall(id)) {
audiolayer->stopStream();
audiolayer->stopStream();
// stop audio
}
removeCall(id);
......@@ -351,7 +415,7 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
Manager::instance().peerHungupCall(id);
if (Manager::instance().isCurrentCall(id)) {
// stop audio
audiolayer->stopStream();
audiolayer->stopStream();
}
removeCall(id);
break;
......@@ -387,28 +451,48 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
break;
case IAX_EVENT_VOICE:
output = data_for_speakers_output; // don't use data directly, use a pointer instead!!!
// since convert return doesn't copy anything if it doesn't have to.
if (audiocodec != 0 && audiolayer!=0) {
_debug("Receive: len=%d, format=%d, data_for_speakers_recv=%p\n", event->datalen, call->getFormat(), data_for_speakers_recv);
unsigned char* data = (unsigned char*)event->data;
unsigned int size = event->datalen;
//_debug("Receive: len=%d, format=%d, data_for_speakers_recv=%p\n", event->datalen, call->getFormat(), data_for_speakers_recv);
unsigned char* data = (unsigned char*)event->data;
unsigned int size = event->datalen;
int expandedSize = audiocodec->codecDecode(data_for_speakers_recv, data, size);
int nbInt16 = expandedSize/sizeof(int16);
int toChannel = 1;
int fromChannel = 1;
int toPut;
toPut = audiolayer->convert(data_for_speakers_recv, fromChannel, nbInt16, &data_for_speakers_output, toChannel);
audiolayer->putMain(data_for_speakers_output, toPut * sizeof(int16));
_debug("sending %d int16 to speakers..\n", toPut);
int nbInt16 = expandedSize/sizeof(int16);
int toChannel = 1;
int fromChannel = 1;
int toPut;
#ifdef USE_SAMPLERATE
if ( audiolayer->getSampleRate() != audiocodec->getClockRate() ) {
// convert here
double factord = (double)audiolayer->getSampleRate()/ audiocodec->getClockRate();
SRC_DATA src_data;
src_data.data_in = _floatBufferIn;
src_data.data_out = _floatBufferOut;
src_data.input_frames = nbInt16/fromChannel;
src_data.output_frames = _nbFrames;
src_data.src_ratio = factord;
src_short_to_float_array(data_for_speakers_recv, _floatBufferIn, nbInt16);
src_simple (&src_data, SRC_SINC_MEDIUM_QUALITY, fromChannel);
src_float_to_short_array(_floatBufferOut, data_for_speakers_recv, src_data.output_frames_gen*fromChannel);
nbInt16 = src_data.output_frames_gen*fromChannel;
}
#endif
toPut = audiolayer->convert(data_for_speakers_recv, fromChannel, nbInt16, &output, toChannel);
audiolayer->putMain(output, toPut * sizeof(int16));
//_debug("sending %d int16 to speakers..\n", toPut);
}
break;
case IAX_EVENT_TEXT:
break;
case IAX_EVENT_RINGA:
break;
case IAX_EVENT_PONG:
break;
......
......@@ -55,8 +55,8 @@ public:
bool hangup(const CallID& id);
bool cancel(const CallID& id) { return false; }
bool onhold(const CallID& id) { return false; }
bool offhold(const CallID& id) { return false; }
bool onhold(const CallID& id);
bool offhold(const CallID& id);
bool transfer(const CallID& id, const std::string& to) { return false; }
bool refuse (const CallID& id) { return false; }
bool carryingDTMFdigits(const CallID& id, char code) { return false; }
......@@ -75,7 +75,12 @@ private:
*/
IAXCall* getIAXCall(const CallID& id);
/*
/**
* Delete every call
*/
void terminateIAXCall();
/**
* Find a iaxcall by iax session number
* @param session an iax_session valid pointer
* @return iaxcall or 0 if not found
......@@ -119,6 +124,10 @@ private:
int16* data_for_speakers_recv;
int16* data_for_speakers_output;
int _nbFrames;
#ifdef USE_SAMPLERATE
float *_floatBufferIn;
float *_floatBufferOut;
#endif
};
#endif
......@@ -1718,8 +1718,10 @@ ManagerImpl::loadAccountMap()
void
ManagerImpl::unloadAccountMap()
{
_debug("Unloading account map...\n");
AccountMap::iterator iter = _accountMap.begin();
while ( iter != _accountMap.end() ) {
_debug("-> Deleting account %s\n", iter->first.c_str());
delete iter->second; iter->second = 0;
iter++;
}
......
......@@ -735,6 +735,7 @@ SIPVoIPLink::offhold(const CallID& id)
// Enable audio
_debug("SIP: Starting AudioRTP when offhold\n");
call->setState(Call::Active);
// it's sure that this is the current call id...
if (_audiortp.createNewSession(call) < 0) {
_debug("SIP Failure: Unable to start sound (%s:%d)\n", __FILE__, __LINE__);
......
......@@ -57,7 +57,7 @@ prepare()
fi
}
#prepare $SFL_FILE_CCPP2 ''
prepare $SFL_FILE_CCPP2 ''
prepare $SFL_FILE_CCRTP ''
#prepare $SFL_FILE_LIBOSIP2 ''
#prepare $SFL_FILE_LIBEXOSIP2 ''
......
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