Commit 91bea584 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

perfect ringtones + dtmf

parent 2b5bc243
......@@ -427,6 +427,7 @@ call_t * sflphone_new_call()
void
sflphone_keypad( guint keyval, gchar * key)
{
dbus_play_dtmf(key);
call_t * c = call_get_selected();
if(c)
{
......@@ -434,6 +435,7 @@ sflphone_keypad( guint keyval, gchar * key)
switch(c->state)
{
case CALL_STATE_DIALING: // Currently dialing => edit number
//dbus_play_dtmf(key);
process_dialing(c, keyval, key);
break;
case CALL_STATE_CURRENT:
......
......@@ -177,10 +177,11 @@ AudioLayer::isStreamActive (void)
int
AudioLayer::playSamples(void* buffer, int toCopy)
AudioLayer::playSamples(void* buffer, int toCopy, bool isTalking)
{
//ost::MutexLock lock( _mutex );
_talk = true;
if( isTalking )
_talk = true;
if ( _PlaybackHandle ){
write( adjustVolume( buffer , toCopy , SFL_PCM_PLAYBACK ) , toCopy );
}
......@@ -254,7 +255,7 @@ AudioLayer::toggleEchoTesting() {
void
AudioLayer::playTones( void )
{
int frames = 1024 ;
int frames = _periodSize ;
int maxBytes = frames * sizeof(SFLDataFormat) ;
SFLDataFormat* out = (SFLDataFormat*)malloc(maxBytes * sizeof(SFLDataFormat));
if( _talk ) {}
......@@ -364,13 +365,10 @@ AudioLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
//if( err = snd_pcm_hw_params_set_buffer_size_near( _PlaybackHandle, hwParams, &buffer_size_out ) < 0) _debugAlsa(" Cannot set buffer size (%s)\n", snd_strerror(err));
if( err = snd_pcm_hw_params_set_buffer_time_near( _PlaybackHandle, hwParams, &buffer_time , &dir) < 0) _debugAlsa(" Cannot set buffer time (%s)\n", snd_strerror(err));
if( err = snd_pcm_hw_params_set_period_time_near( _PlaybackHandle, hwParams, &period_time , &dir) < 0) _debugAlsa(" Cannot set period time (%s)\n", snd_strerror(err));
if( err = snd_pcm_hw_params_get_period_size( hwParams, &period_size_out , &dir) < 0) _debugAlsa(" Cannot get period size (%s)\n", snd_strerror(err));
if( err = snd_pcm_hw_params_get_period_size( hwParams, &_periodSize , &dir) < 0) _debugAlsa(" Cannot get period size (%s)\n", snd_strerror(err));
if( err = snd_pcm_hw_params_get_buffer_size( hwParams, &buffer_size_out ) < 0) _debugAlsa(" Cannot get buffer size (%s)\n", snd_strerror(err));
if( err = snd_pcm_hw_params( _PlaybackHandle, hwParams ) < 0) _debugAlsa(" Cannot set hw parameters (%s)\n", snd_strerror(err));
unsigned int hz;
snd_pcm_hw_params_get_rate( hwParams , &hz , &dir );
_debugAlsa("Rate = %d\n" , hz);
snd_pcm_hw_params_free( hwParams );
......
......@@ -111,7 +111,7 @@ class AudioLayer {
* @params toCopy The number of samples, in bytes
* @return int The number of bytes played
*/
int playSamples(void* buffer, int toCopy);
int playSamples(void* buffer, int toCopy, bool isTalking);
/*
* Send a chunk of data to the hardware buffer to start the playback
......@@ -287,6 +287,7 @@ class AudioLayer {
*/
snd_pcm_t* _PlaybackHandle;
snd_pcm_t* _CaptureHandle;
snd_pcm_uframes_t _periodSize;
/*
* Handle on asynchronous event
......
......@@ -379,7 +379,7 @@ AudioRtpRTX::receiveSessionForSpkr (int& countTime)
#endif
audiolayer->playSamples(toAudioLayer, nbSample * sizeof(SFLDataFormat));
audiolayer->playSamples(toAudioLayer, nbSample * sizeof(SFLDataFormat), true);
// Notify (with a beep) an incoming call when there is already a call
countTime += time->getSecond();
if (Manager::instance().incomingCallWaiting() > 0) {
......
......@@ -823,7 +823,7 @@ IAXVoIPLink::iaxHandleVoiceEvent(iax_event* event, IAXCall* call)
toAudioLayer = _receiveDataDecoded; // int to int
#endif
}
audiolayer->playSamples(toAudioLayer, nbSample * sizeof(SFLDataFormat));
audiolayer->playSamples(toAudioLayer, nbSample * sizeof(SFLDataFormat), true);
} else {
_debug("IAX: incoming audio, but no sound card open");
}
......
......@@ -501,8 +501,8 @@ ManagerImpl::sendDtmf(const CallID& id, char code)
{
AccountID accountid = getAccountFromCall( id );
if (accountid == AccountNULL) {
_debug("Send DTMF: call doesn't exists\n");
//playDtmf(code);
//_debug("Send DTMF: call doesn't exists\n");
playDtmf(code, false);
return false;
}
......@@ -510,7 +510,7 @@ ManagerImpl::sendDtmf(const CallID& id, char code)
bool returnValue = false;
switch (sendType) {
case 0: // SIP INFO
playDtmf(code);
playDtmf(code , true);
returnValue = getAccountLink(accountid)->carryingDTMFdigits(id, code);
break;
......@@ -526,7 +526,7 @@ ManagerImpl::sendDtmf(const CallID& id, char code)
//THREAD=Main | VoIPLink
bool
ManagerImpl::playDtmf(char code)
ManagerImpl::playDtmf(char code, bool isTalking)
{
// HERE are the variable:
// - boolean variable to play or not (config)
......@@ -566,7 +566,7 @@ ManagerImpl::playDtmf(char code)
// Put buffer to urgentRingBuffer
// put the size in bytes...
// so size * 1 channel (mono) * sizeof (bytes for the data)
audiolayer->playSamples(_buf, size * sizeof(SFLDataFormat));
audiolayer->playSamples(_buf, size * sizeof(SFLDataFormat), isTalking);
//audiolayer->putUrgent(_buf, size * sizeof(SFLDataFormat));
// We activate the stream if it's not active yet.
......@@ -974,7 +974,7 @@ ManagerImpl::notificationIncomingCall(void) {
unsigned int nbSampling = tone.getSize();
SFLDataFormat buf[nbSampling];
tone.getNext(buf, tone.getSize());
audiolayer->playSamples(buf, sizeof(SFLDataFormat)*nbSampling);
audiolayer->playSamples(buf, sizeof(SFLDataFormat)*nbSampling, true);
}
}
......@@ -2164,11 +2164,11 @@ ManagerImpl::setSwitch(const std::string& switchName, std::string& message) {
}
message = _("Change with success");
playDtmf('9');
playDtmf('9', true);
//getAudioDriver()->sleep(300); // in milliseconds
playDtmf('1');
playDtmf('1', true);
//getAudioDriver()->sleep(300); // in milliseconds
playDtmf('1');
playDtmf('1', true);
return true;
}
} else if ( switchName == "echo" ) {
......
......@@ -174,7 +174,7 @@ public:
* @param code: pressed key.
*/
bool sendDtmf(const CallID& id, char code);
bool playDtmf(char code);
bool playDtmf(char code, bool isTalking);
bool playTone ();
void stopTone(bool stopAudio/*=true*/);
......
......@@ -1692,7 +1692,7 @@ SIPVoIPLink::handleDtmfRelay(eXosip_event_t* event) {
if (!signal.empty()) {
if (Manager::instance().isCurrentCall(call->getCallId())) {
Manager::instance().playDtmf(signal[0]);
Manager::instance().playDtmf(signal[0], true);
returnValue = true;
}
}
......
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