From a72c0dfd8fb82c40ad4a864b0bb5208491c3f180 Mon Sep 17 00:00:00 2001
From: Yun Liu <yun@yun.(none)>
Date: Tue, 28 Oct 2008 14:17:27 -0400
Subject: [PATCH] Fix bug tickets: 104 and 105

---
 src/audio/alsalayer.cpp | 29 ++++++++++++++++++++++++++---
 src/iaxvoiplink.cpp     | 11 ++++++-----
 src/managerimpl.cpp     |  1 -
 3 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp
index 91a8a5a999..9d4c70ca02 100644
--- a/src/audio/alsalayer.cpp
+++ b/src/audio/alsalayer.cpp
@@ -134,7 +134,29 @@ void AlsaLayer::AlsaCallBack( snd_async_handler_t* pcm_callback )
     void 
 AlsaLayer::fillHWBuffer( void)
 {
-    
+
+  unsigned char* data;
+  int pcmreturn, l1, l2;
+  short s1, s2;
+  int periodSize = 128 ;
+  int frames = periodSize >> 2 ;
+  _debug("frames  = %d\n", frames);
+
+  data = (unsigned char*)malloc(periodSize);
+  for(l1 = 0; l1 < 100; l1++) {
+    for(l2 = 0; l2 < frames; l2++) {
+      s1 = 0;
+      s2 = 0;
+      data[4*l2] = (unsigned char)s1;
+      data[4*l2+1] = s1 >> 8;
+      data[4*l2+2] = (unsigned char)s2;
+      data[4*l2+3] = s2 >> 8;
+    }
+    while ((pcmreturn = snd_pcm_writei(_PlaybackHandle, data, frames)) < 0) {
+      snd_pcm_prepare(_PlaybackHandle);
+      //_debugAlsa("< Buffer Underrun >\n");
+    }
+  }
 }
 
     bool
@@ -273,6 +295,7 @@ bool AlsaLayer::alsa_set_params( snd_pcm_t *pcm_handle, int type, int rate ){
     /* Allocate the snd_pcm_hw_params_t struct */
     snd_pcm_hw_params_malloc( &hwparams );
 
+    _periodSize = 940;
     /* Full configuration space */
     if( (err = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) { 
         _debugAlsa(" Cannot initialize hardware parameter structure (%s)\n", snd_strerror(err));
@@ -290,7 +313,7 @@ bool AlsaLayer::alsa_set_params( snd_pcm_t *pcm_handle, int type, int rate ){
         _debugAlsa(" Cannot set sample format (%s)\n", snd_strerror(err));
         return false;
     }
-
+    
     /* Set sample rate. If we can't set to the desired exact value, we set to the nearest acceptable */
     dir=0;
     rate = getSampleRate();
@@ -319,7 +342,7 @@ bool AlsaLayer::alsa_set_params( snd_pcm_t *pcm_handle, int type, int rate ){
     if(dir!=0) {
         _debugAlsa("(%i) The choosen period size %d bytes is not supported by your hardware.\nUsing %d instead.\n ", type, (int)periodsize, (int)exact_lvalue);
     }
-    periodsize=exact_lvalue;
+    periodsize = exact_lvalue;
     /* Set the number of fragments */
     exact_ivalue = periods;
     dir=0;
diff --git a/src/iaxvoiplink.cpp b/src/iaxvoiplink.cpp
index 1bbdd62889..ff235d41b0 100644
--- a/src/iaxvoiplink.cpp
+++ b/src/iaxvoiplink.cpp
@@ -438,6 +438,7 @@ IAXVoIPLink::hangup(const CallID& id)
   call->setSession(NULL);
   if (Manager::instance().isCurrentCall(id)) {
     // stop audio
+    audiolayer->stopStream();
   }
   removeCall(id);
   return true;	
@@ -592,11 +593,11 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
 
   switch(event->etype) {
     case IAX_EVENT_HANGUP:
-      Manager::instance().peerHungupCall(id); 
       if (Manager::instance().isCurrentCall(id)) {
-	audiolayer->stopStream();
 	// stop audio
+	audiolayer->stopStream();
       }
+      Manager::instance().peerHungupCall(id); 
       removeCall(id);
       break;
 
@@ -631,7 +632,7 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
 
 	Manager::instance().peerAnsweredCall(id);
 	//audiolayer->flushMic();
-	//audiolayer->startStream();
+	audiolayer->startStream();
 	// start audio here?
       } else {
 	// deja connecté ?
@@ -647,8 +648,8 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
 
     case IAX_EVENT_VOICE:
       //_debug("Should have a decent value!!!!!! = %i\n" , call -> getAudioCodec());
-      //if( !audiolayer -> isCaptureActive())
-	//audiolayer->startStream();
+      if( !audiolayer -> isCaptureActive())
+	audiolayer->startStream();
       iaxHandleVoiceEvent(event, call);
       break;
 
diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp
index dcb15e44c4..313079e355 100644
--- a/src/managerimpl.cpp
+++ b/src/managerimpl.cpp
@@ -2258,7 +2258,6 @@ ManagerImpl::loadAccountMap()
 
   TokenList::iterator iter = sections.begin();
   while(iter != sections.end()) {
-    _debug("***************** In Load account: into while\n");
     // Check if it starts with "Account:" (SIP and IAX pour le moment)
     if ((int)(iter->find("Account:")) == -1) {
       iter++;
-- 
GitLab