From 8be6b010824ad0602ffbb78ed65f9eabd335e05d Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Sat, 14 Feb 2009 13:12:33 -0500
Subject: [PATCH] Fix the ASLSA capture problem one more time

---
 src/audio/alsalayer.cpp | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp
index 03869783fc..6bc9424bf4 100644
--- a/src/audio/alsalayer.cpp
+++ b/src/audio/alsalayer.cpp
@@ -134,21 +134,46 @@ AlsaLayer::stopStream(void)
 
     int
 AlsaLayer::canGetMic()
-{
+{   
+    int avail;
+
+    if (!_CaptureHandle)
+        return 0;
+
+    avail = snd_pcm_avail_update (_CaptureHandle);
+
+    if (avail == -EPIPE)
+    {
+        stop_capture ();
+        return 0;
+    }
+    else
+        return ((avail<0)?0:avail);
+
+    /*
     if(_CaptureHandle) 
+
         return _micRingBuffer.AvailForGet();
     else
-        return 0;
+        return 0;*/
 }
 
     int 
 AlsaLayer::getMic(void *buffer, int toCopy)
 {
+    /*
     if( _CaptureHandle ){
         return _micRingBuffer.Get(buffer, toCopy,100);
     } 
     else
-        return 0;
+        return 0;*/
+   int res = 0;
+   if( _CaptureHandle )
+   {
+       res = read( buffer, toCopy);
+       adjustVolume (buffer, toCopy, SFL_PCM_CAPTURE);
+   }
+   return res;
 }
 
 bool AlsaLayer::isCaptureActive(void) {
@@ -669,7 +694,7 @@ void AlsaLayer::audioCallback (void)
     
     // Additionally handle the mic's audio stream 
     //if(is_capture_running()){  
-    micAvailAlsa = snd_pcm_avail_update(_CaptureHandle);
+    /*micAvailAlsa = snd_pcm_avail_update(_CaptureHandle);
     if(micAvailAlsa > 0) {
         micAvailPut = _micRingBuffer.AvailForPut();
         toPut = (micAvailAlsa <= micAvailPut) ? micAvailAlsa : micAvailPut;
@@ -680,7 +705,7 @@ void AlsaLayer::audioCallback (void)
             _micRingBuffer.Put(in, toPut, 100);
         }
         free(in); in=0;
-    }
+    }*/
 }
 
 void* AlsaLayer::adjustVolume( void* buffer , int len, int stream )
-- 
GitLab