From d346a1c7a6363def01b0159d655f53c28613b22b Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Wed, 2 Apr 2008 15:33:28 -0400
Subject: [PATCH] Correct the dtmf sound when dialing with ALSA plugin plughw

---
 sflphone-gtk/src/actions.c |  5 ++++-
 src/audio/audiolayer.cpp   | 32 ++++++++++++++------------------
 2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/sflphone-gtk/src/actions.c b/sflphone-gtk/src/actions.c
index 7963b56cc8..e265c98d9c 100644
--- a/sflphone-gtk/src/actions.c
+++ b/sflphone-gtk/src/actions.c
@@ -357,7 +357,10 @@ sflphone_incoming_call (call_t * c)
 void process_dialing(call_t * c, guint keyval, gchar * key)
 {
 	// We stop the tone
-	dbus_start_tone( FALSE , 0 );
+	if(strlen(c->to) == 0){
+	  dbus_start_tone( FALSE , 0 );
+	  dbus_play_dtmf( key );
+	}
 	switch (keyval)
 	{
 		case 65293: /* ENTER */
diff --git a/src/audio/audiolayer.cpp b/src/audio/audiolayer.cpp
index 746cadf752..0b35738200 100644
--- a/src/audio/audiolayer.cpp
+++ b/src/audio/audiolayer.cpp
@@ -36,13 +36,13 @@
 #endif
 
   AudioLayer::AudioLayer(ManagerImpl* manager)
-:   _defaultVolume(100)
+  :   _defaultVolume(100)
   , _errorMessage(-1)
   , _manager(manager)
   , _PlaybackHandle( NULL )
   , _CaptureHandle( NULL )
   , deviceClosed( true )
-    , _urgentBuffer( SIZEBUF )
+      , _urgentBuffer( SIZEBUF )
 {
 
   _inChannel  = 1; // don't put in stereo
@@ -68,13 +68,9 @@ AudioLayer::openDevice (int indexIn, int indexOut, int sampleRate, int frameSize
   if(deviceClosed == false)
   {
     if( stream == SFL_PCM_CAPTURE )
-    {
       closeCaptureStream();
-    }
     else if( stream == SFL_PCM_PLAYBACK)
-    {
       closePlaybackStream();
-    }
     else
     {
       closeCaptureStream();
@@ -118,6 +114,7 @@ AudioLayer::startStream(void)
 AudioLayer::stopStream(void) 
 {
   //ost::MutexLock lock( _mutex );
+  _debugAlsa(" Stop Stream\n ");
   _talk = false;
   snd_pcm_drop( _CaptureHandle );
   snd_pcm_prepare( _CaptureHandle );
@@ -386,7 +383,7 @@ AudioLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
     _debug("Min available = %d\n" ,val);
     //if( err = snd_pcm_sw_params_set_silence_threshold( _PlaybackHandle, swparams, period_size_out) < 0) _debugAlsa(" Cannot set silence threshold (%s)\n" , snd_strerror(err)); 
     //snd_pcm_sw_params_get_silence_threshold( swparams , &val);
-      //  _debug("Silence threshold = %d\n" ,val);
+    //  _debug("Silence threshold = %d\n" ,val);
     if( err = snd_pcm_sw_params( _PlaybackHandle, swparams ) < 0 ) _debugAlsa(" Cannot set sw parameters (%s)\n", snd_strerror(err)); 
     snd_pcm_sw_params_free( swparams );
 
@@ -404,7 +401,7 @@ AudioLayer::open_device(std::string pcm_p, std::string pcm_c, int flag)
 AudioLayer::write(void* buffer, int length)
 {
   //if(snd_pcm_state( _PlaybackHandle ) == SND_PCM_STATE_XRUN)
-    //handle_xrun_playback();  
+  //handle_xrun_playback();  
   //_debugAlsa("avail = %d - toWrite = %d\n" , snd_pcm_avail_update( _PlaybackHandle ) , length / 2);
 
   snd_pcm_uframes_t frames = snd_pcm_bytes_to_frames( _PlaybackHandle, length);
@@ -427,10 +424,10 @@ AudioLayer::write(void* buffer, int length)
       _debugAlsa(" (%s)\n", snd_strerror( err ));
       break;
   }
-  
+
   if( err >=0 && err < frames )
     _debugAlsa("Short write : %d out of %d\n", err , frames);
-  
+
   return ( err > 0 )? err : 0 ;
 }
 
@@ -584,9 +581,9 @@ AudioLayer::getSoundCardsInfo( int stream )
 AudioLayer::closeCaptureStream( void)
 {
   if(_CaptureHandle){
-    snd_pcm_drop( _CaptureHandle );
-    snd_pcm_close( _CaptureHandle );
-    _CaptureHandle = 0;
+      snd_pcm_drop( _CaptureHandle );
+      snd_pcm_close( _CaptureHandle );
+      _CaptureHandle = 0;
   }
 }
 
@@ -594,13 +591,12 @@ AudioLayer::closeCaptureStream( void)
 AudioLayer::closePlaybackStream( void)
 {
   if(_PlaybackHandle){
-    snd_pcm_drop( _PlaybackHandle );
-    snd_pcm_close( _PlaybackHandle );
-    _PlaybackHandle = 0;
+      snd_pcm_drop( _PlaybackHandle );
+      snd_pcm_close( _PlaybackHandle );
+      _PlaybackHandle = 0;
   }
 }
 
-
   bool
 AudioLayer::soundCardIndexExist( int card , int stream )
 {
@@ -612,7 +608,7 @@ AudioLayer::soundCardIndexExist( int card , int stream )
   ss << card ;
   name.append(ss.str());
   if(snd_ctl_open( &handle, name.c_str(), 0) == 0 ){
-   snd_pcm_info_set_stream( pcminfo , ( stream == SFL_PCM_PLAYBACK )? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE );
+    snd_pcm_info_set_stream( pcminfo , ( stream == SFL_PCM_PLAYBACK )? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE );
     if( snd_ctl_pcm_info( handle , pcminfo ) < 0) return false;
     else
       return true;
-- 
GitLab