>
> Artur, could you please submit this patch to the portaudio mailing list,
> and put the wengophone-devel mailing list in the cc field? If portaudio
> maintainers can't integrate it soon enough, then it might be better to
> modify our own import of portaudio.

I'm unable to register to portaudio mailing list ( the mailing list website is 
not working at the time). I'll try to do it later.
I've send the patch few days ago as not registered user but I think that it 
didn't show up on the mailing list.

Also I would like to say that this patch is only really useful with latest 
pa_linux_alsa.c from portaudio. The one in wengphone has problems with plugin 
devices.

So the way to test it would be first upgrade pa_linux_alsa.c to the version 
from portaudio V19 cvs ( or you can use included 
"alsa-cvs-120306-update .patch" ). And later apply "alsa-devbuild.patch".

This is the version of wengophone I'm successfully using at home ( with 
disabled video - as there is some bug in h264 video codec and when I was 
trying to connect ( audio only ) with friends using windows version, 
wengophone was using only this codec ).

Regards, Artur
Index: libs/portaudio/pa_linux_alsa/pa_linux_alsa.c
===================================================================
--- libs/portaudio/pa_linux_alsa/pa_linux_alsa.c	(wersja 4513)
+++ libs/portaudio/pa_linux_alsa/pa_linux_alsa.c	(kopia robocza)
@@ -1,11 +1,11 @@
 /*
- * $Id: pa_linux_alsa.c,v 1.1.2.81 2005/11/09 19:11:13 aknudsen Exp $
+ * $Id: pa_linux_alsa.c,v 1.1.2.89 2006/03/05 13:22:54 aknudsen Exp $
  * PortAudio Portable Real-Time Audio Library
  * Latest Version at: http://www.portaudio.com
  * ALSA implementation by Joshua Haberman and Arve Knudsen
  *
  * Copyright (c) 2002 Joshua Haberman <[EMAIL PROTECTED]>
- * Copyright (c) 2005 Arve Knudsen <[EMAIL PROTECTED]>
+ * Copyright (c) 2005-2006 Arve Knudsen <[EMAIL PROTECTED]>
  *
  * Based on the Open Source API proposed by Ross Bencina
  * Copyright (c) 1999-2002 Ross Bencina, Phil Burk
@@ -182,7 +182,7 @@
 
 typedef struct PaAlsaHostApiRepresentation
 {
-    PaUtilHostApiRepresentation commonHostApiRep;
+    PaUtilHostApiRepresentation baseHostApiRep;
     PaUtilStreamInterface callbackStreamInterface;
     PaUtilStreamInterface blockingStreamInterface;
 
@@ -194,7 +194,7 @@
 
 typedef struct PaAlsaDeviceInfo
 {
-    PaDeviceInfo commonDeviceInfo;
+    PaDeviceInfo baseDeviceInfo;
     char *alsaName;
     int isPlug;
     int minInputChannels;
@@ -645,7 +645,7 @@
     snd_config_update_free_global();
 }
 
-/*! Determine max channels and default latencies.
+/** Determine max channels and default latencies.
  *
  * This function provides functionality to grope an opened (might be opened for capture or playback) pcm device for 
  * traits like max channels, suitable default latencies and default sample rate. Upon error, max channels is set to zero,
@@ -785,13 +785,12 @@
  */
 static int IgnorePlugin( const char *pluginId )
 {
-    static const char *ignoredPlugins[] = {"hw", "plughw", "plug", 
-						     // "default",
-						     "dsnoop", "dmix", "tee",
-        "file", "null", "shm", 0};
+#define numIgnored 10
+    static const char *ignoredPlugins[numIgnored] = {"hw", "plughw", "plug", "default", "dsnoop", "dmix", "tee",
+        "file", "null", "shm"};
     int i;
 
-    for( i = 0; ignoredPlugins[i]; ++i )
+    for( i = 0; i < numIgnored; ++i )
     {
         if( !strcmp( pluginId, ignoredPlugins[i] ) )
         {
@@ -805,7 +804,7 @@
 /* Build PaDeviceInfo list, ignore devices for which we cannot determine capabilities (possibly busy, sigh) */
 static PaError BuildDeviceList( PaAlsaHostApiRepresentation *alsaApi )
 {
-    PaUtilHostApiRepresentation *commonApi = &alsaApi->commonHostApiRep;
+    PaUtilHostApiRepresentation *baseApi = &alsaApi->baseHostApiRep;
     PaAlsaDeviceInfo *deviceInfoArray;
     int cardIdx = -1, devIdx = 0;
     snd_ctl_card_info_t *cardInfo;
@@ -821,8 +820,8 @@
         blocking = 0;
 
     /* These two will be set to the first working input and output device, respectively */
-    commonApi->info.defaultInputDevice = paNoDevice;
-    commonApi->info.defaultOutputDevice = paNoDevice;
+    baseApi->info.defaultInputDevice = paNoDevice;
+    baseApi->info.defaultOutputDevice = paNoDevice;
 
     /* count the devices by enumerating all the card numbers */
 
@@ -846,7 +845,10 @@
 
         /* Acquire name of card */
         if( snd_ctl_open( &ctl, alsaCardName, 0 ) < 0 )
-            continue;   /* Unable to open card :( */
+        {
+            /* Unable to open card :( */
+            continue;
+        }
         snd_ctl_card_info( ctl, cardInfo );
 
         PA_ENSURE( PaAlsa_StrDup( alsaApi, &cardName, snd_ctl_card_info_get_name( cardInfo )) );
@@ -863,11 +865,15 @@
             snd_pcm_info_set_subdevice( pcmInfo, 0 );
             snd_pcm_info_set_stream( pcmInfo, SND_PCM_STREAM_CAPTURE );
             if( snd_ctl_pcm_info( ctl, pcmInfo ) >= 0 )
+            {
                 hasCapture = 1;
+            }
             
             snd_pcm_info_set_stream( pcmInfo, SND_PCM_STREAM_PLAYBACK );
             if( snd_ctl_pcm_info( ctl, pcmInfo ) >= 0 )
+            {
                 hasPlayback = 1;
+            }
 
             if( !hasPlayback && !hasCapture )
             {
@@ -958,7 +964,7 @@
         PA_DEBUG(( "%s: Iterating over ALSA plugins failed: %s\n", __FUNCTION__, snd_strerror( res ) ));
 
     /* allocate deviceInfo memory based on the number of devices */
-    PA_UNLESS( commonApi->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory(
+    PA_UNLESS( baseApi->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory(
             alsaApi->allocations, sizeof(PaDeviceInfo*) * (numDeviceNames) ), paInsufficientMemory );
 
     /* allocate all device info structs in a contiguous block */
@@ -973,10 +979,10 @@
     {
         snd_pcm_t *pcm;
         PaAlsaDeviceInfo *deviceInfo = &deviceInfoArray[devIdx];
-        PaDeviceInfo *commonDeviceInfo = &deviceInfo->commonDeviceInfo;
+        PaDeviceInfo *baseDeviceInfo = &deviceInfo->baseDeviceInfo;
 
         /* Zero fields */
-        InitializeDeviceInfo( commonDeviceInfo );
+        InitializeDeviceInfo( baseDeviceInfo );
 
         /* to determine device capabilities, we must open the device and query the
          * hardware parameter configuration space */
@@ -985,9 +991,9 @@
         if( deviceNames[i].hasCapture &&
                 snd_pcm_open( &pcm, deviceNames[i].alsaName, SND_PCM_STREAM_CAPTURE, blocking ) >= 0 )
         {
-            if( GropeDevice( pcm, &deviceInfo->minInputChannels, &commonDeviceInfo->maxInputChannels,
-                        &commonDeviceInfo->defaultLowInputLatency, &commonDeviceInfo->defaultHighInputLatency,
-                        &commonDeviceInfo->defaultSampleRate, deviceNames[i].isPlug ) != paNoError )
+            if( GropeDevice( pcm, &deviceInfo->minInputChannels, &baseDeviceInfo->maxInputChannels,
+                        &baseDeviceInfo->defaultLowInputLatency, &baseDeviceInfo->defaultHighInputLatency,
+                        &baseDeviceInfo->defaultSampleRate, deviceNames[i].isPlug ) != paNoError )
                 continue;   /* Error */
         }
 
@@ -995,34 +1001,34 @@
         if( deviceNames[i].hasPlayback &&
                 snd_pcm_open( &pcm, deviceNames[i].alsaName, SND_PCM_STREAM_PLAYBACK, blocking ) >= 0 )
         {
-            if( GropeDevice( pcm, &deviceInfo->minOutputChannels, &commonDeviceInfo->maxOutputChannels,
-                        &commonDeviceInfo->defaultLowOutputLatency, &commonDeviceInfo->defaultHighOutputLatency,
-                        &commonDeviceInfo->defaultSampleRate, deviceNames[i].isPlug ) != paNoError )
+            if( GropeDevice( pcm, &deviceInfo->minOutputChannels, &baseDeviceInfo->maxOutputChannels,
+                        &baseDeviceInfo->defaultLowOutputLatency, &baseDeviceInfo->defaultHighOutputLatency,
+                        &baseDeviceInfo->defaultSampleRate, deviceNames[i].isPlug ) != paNoError )
                 continue;   /* Error */
         }
 
-        commonDeviceInfo->structVersion = 2;
-        commonDeviceInfo->hostApi = alsaApi->hostApiIndex;
-        commonDeviceInfo->name = deviceNames[i].name;
+        baseDeviceInfo->structVersion = 2;
+        baseDeviceInfo->hostApi = alsaApi->hostApiIndex;
+        baseDeviceInfo->name = deviceNames[i].name;
         deviceInfo->alsaName = deviceNames[i].alsaName;
         deviceInfo->isPlug = deviceNames[i].isPlug;
 
         /* A: Storing pointer to PaAlsaDeviceInfo object as pointer to PaDeviceInfo object.
          * Should now be safe to add device info, unless the device supports neither capture nor playback
          */
-        if( commonDeviceInfo->maxInputChannels > 0 || commonDeviceInfo->maxOutputChannels > 0 )
+        if( baseDeviceInfo->maxInputChannels > 0 || baseDeviceInfo->maxOutputChannels > 0 )
         {
-            if( commonApi->info.defaultInputDevice == paNoDevice && commonDeviceInfo->maxInputChannels > 0 )
-                commonApi->info.defaultInputDevice = devIdx;
-            if(  commonApi->info.defaultOutputDevice == paNoDevice && commonDeviceInfo->maxOutputChannels > 0 )
-                commonApi->info.defaultOutputDevice = devIdx;
+            if( baseApi->info.defaultInputDevice == paNoDevice && baseDeviceInfo->maxInputChannels > 0 )
+                baseApi->info.defaultInputDevice = devIdx;
+            if(  baseApi->info.defaultOutputDevice == paNoDevice && baseDeviceInfo->maxOutputChannels > 0 )
+                baseApi->info.defaultOutputDevice = devIdx;
 
-            commonApi->deviceInfos[devIdx++] = (PaDeviceInfo *) deviceInfo;
+            baseApi->deviceInfos[devIdx++] = (PaDeviceInfo *) deviceInfo;
         }
     }
     free( deviceNames );
 
-    commonApi->info.deviceCount = devIdx;   /* Number of successfully queried devices */
+    baseApi->info.deviceCount = devIdx;   /* Number of successfully queried devices */
 
 end:
     return result;
@@ -1032,7 +1038,6 @@
     goto end;
 }
 
-
 /* Check against known device capabilities */
 static PaError ValidateParameters( const PaStreamParameters *parameters, PaUtilHostApiRepresentation *hostApi, StreamDirection mode )
 {
@@ -1062,8 +1067,8 @@
 
     assert( deviceInfo );
     assert( parameters->hostApiSpecificStreamInfo == NULL );
-    maxChans = (StreamDirection_In == mode ? deviceInfo->commonDeviceInfo.maxInputChannels :
-        deviceInfo->commonDeviceInfo.maxOutputChannels);
+    maxChans = (StreamDirection_In == mode ? deviceInfo->baseDeviceInfo.maxInputChannels :
+        deviceInfo->baseDeviceInfo.maxOutputChannels);
     PA_UNLESS( parameters->channelCount <= maxChans, paInvalidChannelCount );
 
 error:
@@ -1162,7 +1167,8 @@
     if( (ret = snd_pcm_open( pcm, deviceName, streamDir == StreamDirection_In ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
                     SND_PCM_NONBLOCK )) < 0 )
     {
-        *pcm = NULL;     /* Not to be closed */
+        /* Not to be closed */
+        *pcm = NULL;
         ENSURE_( ret, ret == -EBUSY ? paDeviceUnavailable : paBadIODeviceCombination );
     }
     ENSURE_( snd_pcm_nonblock( *pcm, 0 ), paUnanticipatedHostError );
@@ -1216,11 +1222,20 @@
     PA_ENSURE( hostFormat = PaUtil_SelectClosestAvailableFormat( availableFormats, parameters->sampleFormat ) );
     ENSURE_( snd_pcm_hw_params_set_format( pcm, hwParams, Pa2AlsaFormat( hostFormat ) ), paUnanticipatedHostError );
 
-    ENSURE_( snd_pcm_hw_params( pcm, hwParams ), paUnanticipatedHostError );
+    {
+        /* It happens that this call fails because the device is busy */
+        int ret = 0;
+        if( (ret = snd_pcm_hw_params( pcm, hwParams )) < 0)
+        {
+            ENSURE_( ret, ret == -EBUSY ? paDeviceUnavailable : paUnanticipatedHostError );
+        }
+    }
 
 end:
     if( pcm )
+    {
         snd_pcm_close( pcm );
+    }
     return result;
 
 error:
@@ -1283,7 +1298,7 @@
 
     if( NULL == params->hostApiSpecificStreamInfo )
     {
-        const PaAlsaDeviceInfo *devInfo = GetDeviceInfo( &alsaApi->commonHostApiRep, params->device );
+        const PaAlsaDeviceInfo *devInfo = GetDeviceInfo( &alsaApi->baseHostApiRep, params->device );
         self->numHostChannels = PA_MAX( params->channelCount, StreamDirection_In == streamDir ? devInfo->minInputChannels
                 : devInfo->minOutputChannels );
     }
@@ -1293,7 +1308,7 @@
         self->numHostChannels = params->channelCount;
     }
 
-    PA_ENSURE( AlsaOpen( &alsaApi->commonHostApiRep, params, streamDir, &self->pcm ) );
+    PA_ENSURE( AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm ) );
     self->nfds = snd_pcm_poll_descriptors_count( self->pcm );
     hostSampleFormat = PaUtil_SelectClosestAvailableFormat( GetAvailableFormats( self->pcm ), userSampleFormat );
 
@@ -1354,7 +1369,6 @@
     ENSURE_( snd_pcm_hw_params_any( pcm, hwParams ), paUnanticipatedHostError );
 
     ENSURE_( snd_pcm_hw_params_set_periods_integer( pcm, hwParams ), paUnanticipatedHostError );
-    ENSURE_( snd_pcm_hw_params_set_period_size_integer( pcm, hwParams ), paUnanticipatedHostError );
     /* I think there should be at least 2 periods (even though ALSA doesn't appear to enforce this) */
     dir = 0;
     ENSURE_( snd_pcm_hw_params_set_periods_min( pcm, hwParams, &minPeriods, &dir ), paUnanticipatedHostError );
@@ -1400,13 +1414,18 @@
     goto end;
 }
 
+/** Finish the configuration of the component's ALSA device.
+ *
+ * As part of this method, the component's bufferSize attribute will be set.
+ * @param latency: The latency for this component.
+ */
 static PaError PaAlsaStreamComponent_FinishConfigure( PaAlsaStreamComponent *self, snd_pcm_hw_params_t* hwParams,
-        const PaStreamParameters *params, int primeBuffers, double sampleRate, PaTime* returnedLatency )
+        const PaStreamParameters *params, int primeBuffers, double sampleRate, PaTime* latency )
 {
     PaError result = paNoError;
     snd_pcm_sw_params_t* swParams;
     snd_pcm_uframes_t bufSz = 0;
-    *returnedLatency = -1.;
+    *latency = -1.;
 
     snd_pcm_sw_params_alloca( &swParams );
 
@@ -1417,7 +1436,7 @@
     ENSURE_( snd_pcm_hw_params( self->pcm, hwParams ), paUnanticipatedHostError );
     ENSURE_( snd_pcm_hw_params_get_buffer_size( hwParams, &self->bufferSize ), paUnanticipatedHostError );
     /* Latency in seconds, one period is not counted as latency */
-    *returnedLatency = (self->bufferSize - self->framesPerBuffer) / sampleRate;
+    *latency = (self->bufferSize - self->framesPerBuffer) / sampleRate;
 
     /* Now software parameters... */
     ENSURE_( snd_pcm_sw_params_current( self->pcm, swParams ), paUnanticipatedHostError );
@@ -1534,13 +1553,29 @@
     return (int)ceil( 1000 * frames / stream->streamRepresentation.streamInfo.sampleRate );
 }
 
+/** Determine size per host buffer.
+ *
+ * During this method call, the component's framesPerBuffer attribute gets computed, and the corresponding period size
+ * gets configured for the device.
+ * @param accurate: If the configured period size is non-integer, this will be set to 0.
+ */
 static PaError PaAlsaStreamComponent_DetermineFramesPerBuffer( PaAlsaStreamComponent* self, const PaStreamParameters* params,
-        unsigned long framesPerUserBuffer, double sampleRate, snd_pcm_hw_params_t* hwParams )
+        unsigned long framesPerUserBuffer, double sampleRate, snd_pcm_hw_params_t* hwParams, int* accurate )
 {
     PaError result = paNoError;
     unsigned long bufferSize = params->suggestedLatency * sampleRate, framesPerHostBuffer;
     int dir = 0;
+    
+    {
+        snd_pcm_uframes_t tmp;
+        snd_pcm_hw_params_get_buffer_size_min( hwParams, &tmp );
+        bufferSize = PA_MAX( bufferSize, tmp );
+        snd_pcm_hw_params_get_buffer_size_max( hwParams, &tmp );
+        bufferSize = PA_MIN( bufferSize, tmp );
+    }
 
+    assert( bufferSize > 0 );
+
     if( framesPerUserBuffer != paFramesPerBufferUnspecified )
     {
         /* Preferably the host buffer size should be a multiple of the user buffer size */
@@ -1646,8 +1681,34 @@
     }
 
     assert( framesPerHostBuffer > 0 );
-    dir = 0;
-    ENSURE_( snd_pcm_hw_params_set_period_size_near( self->pcm, hwParams, &framesPerHostBuffer, &dir ), paUnanticipatedHostError );
+    {
+        snd_pcm_uframes_t min = 0, max = 0;
+        ENSURE_( snd_pcm_hw_params_get_period_size_min( hwParams, &min, NULL ), paUnanticipatedHostError );
+        ENSURE_( snd_pcm_hw_params_get_period_size_max( hwParams, &max, NULL ), paUnanticipatedHostError );
+
+        if( framesPerHostBuffer < min )
+        {
+            framesPerHostBuffer = min;
+            PA_DEBUG(( "%s: The determined period size (%lu) is less than minimum (%lu)\n", __FUNCTION__,
+                        framesPerHostBuffer, min ));
+        }
+        else if( framesPerHostBuffer > max )
+        {
+            framesPerHostBuffer = max;
+            PA_DEBUG(( "%s: The determined period size (%lu) is greater than maximum (%lu)\n", __FUNCTION__,
+                        framesPerHostBuffer, max ));
+        }
+
+        assert( framesPerHostBuffer >= min && framesPerHostBuffer <= max );
+        dir = 0;
+        ENSURE_( snd_pcm_hw_params_set_period_size_near( self->pcm, hwParams, &framesPerHostBuffer, &dir ),
+                paUnanticipatedHostError );
+        if( dir != 0 )
+        {
+            PA_DEBUG(( "%s: The configured period size is non-integer.\n", __FUNCTION__, dir ));
+            *accurate = 0;
+        }
+    }
     self->framesPerBuffer = framesPerHostBuffer;
 
 error:
@@ -1685,6 +1746,8 @@
  * to find a number of frames per buffer acceptable to both devices
  * TODO: Implement an algorithm to find the value closest to acceptance
  * by both devices, to minimize difference between period sizes?
+ *
+ * @param determinedFramesPerHostBuffer: The determined host buffer size.
  */
 static PaError PaAlsaStream_DetermineFramesPerBuffer( PaAlsaStream* self, double sampleRate, const PaStreamParameters* inputParameters,
         const PaStreamParameters* outputParameters, unsigned long framesPerUserBuffer, snd_pcm_hw_params_t* hwParamsCapture,
@@ -1693,6 +1756,7 @@
     PaError result = paNoError;
     unsigned long framesPerHostBuffer = 0;
     int dir = 0;
+    int accurate = 1;
 
     if( self->capture.pcm && self->playback.pcm )
     {
@@ -1802,12 +1866,12 @@
             PaAlsaStreamComponent* first = &self->capture, * second = &self->playback;
             const PaStreamParameters* firstStreamParams = inputParameters;
             snd_pcm_hw_params_t* firstHwParams = hwParamsCapture, * secondHwParams = hwParamsPlayback;
-            
+
             dir = 0;
             ENSURE_( snd_pcm_hw_params_get_periods_max( hwParamsPlayback, &maxPeriods, &dir ), paUnanticipatedHostError );
             if( maxPeriods < 4 )
             {
-                /* The playback component is tricker to get right, try that first */
+                /* The playback component is trickier to get right, try that first */
                 first = &self->playback;
                 second = &self->capture;
                 firstStreamParams = outputParameters;
@@ -1816,8 +1880,8 @@
             }
 
             PA_ENSURE( PaAlsaStreamComponent_DetermineFramesPerBuffer( first, firstStreamParams, framesPerUserBuffer,
-                        sampleRate, firstHwParams ) );
-            
+                        sampleRate, firstHwParams, &accurate ) );
+
             second->framesPerBuffer = first->framesPerBuffer;
             dir = 0;
             ENSURE_( snd_pcm_hw_params_set_period_size_near( second->pcm, secondHwParams, &second->framesPerBuffer, &dir ),
@@ -1838,14 +1902,14 @@
         if( self->capture.pcm )
         {
             PA_ENSURE( PaAlsaStreamComponent_DetermineFramesPerBuffer( &self->capture, inputParameters, framesPerUserBuffer,
-                        sampleRate, hwParamsCapture) );
+                        sampleRate, hwParamsCapture, &accurate) );
             framesPerHostBuffer = self->capture.framesPerBuffer;
         }
         else
         {
             assert( self->playback.pcm );
             PA_ENSURE( PaAlsaStreamComponent_DetermineFramesPerBuffer( &self->playback, outputParameters, framesPerUserBuffer,
-                        sampleRate, hwParamsPlayback ) );
+                        sampleRate, hwParamsPlayback, &accurate ) );
             framesPerHostBuffer = self->playback.framesPerBuffer;
         }
     }
@@ -1853,6 +1917,14 @@
     PA_UNLESS( framesPerHostBuffer != 0, paInternalError );
     self->maxFramesPerHostBuffer = framesPerHostBuffer;
 
+    if( !accurate )
+    {
+        /* Don't know the exact size per host buffer */
+        *hostBufferSizeMode = paUtilBoundedHostBufferSize;
+        /* Raise upper bound */
+        ++self->maxFramesPerHostBuffer;
+    }
+
 error:
     return result;
 }
@@ -1963,6 +2035,8 @@
     PaSampleFormat inputSampleFormat = 0, outputSampleFormat = 0;
     int numInputChannels = 0, numOutputChannels = 0;
     PaTime inputLatency, outputLatency;
+    /* Operate with fixed host buffer size by default, since other modes will invariably lead to block adaption */
+    /* XXX: Use Bounded by default? Output tends to get stuttery with Fixed ... */
     PaUtilHostBufferSizeMode hostBufferSizeMode = paUtilFixedHostBufferSize;
 
     if( (streamFlags & paPlatformSpecificFlags) != 0 )
@@ -1996,31 +2070,6 @@
 
     PA_ENSURE( PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer,
                 &inputLatency, &outputLatency, &hostBufferSizeMode ) );
-    if( stream->capture.pcm && stream->playback.pcm )
-    {
-        /* In full-duplex mode, host buffers should be of a fixed size unless we were unable to match the period
-         * sizes of the two handles */
-        if( hostBufferSizeMode == paUtilFixedHostBufferSize )
-        {
-            PA_UNLESS( stream->capture.framesPerBuffer == stream->playback.framesPerBuffer, paInternalError );
-        }
-        else
-        {
-            assert( hostBufferSizeMode == paUtilBoundedHostBufferSize );
-            PA_UNLESS( stream->capture.framesPerBuffer != stream->playback.framesPerBuffer, paInternalError );
-        }
-    }
-    else
-    {
-        if( stream->capture.pcm )
-        {
-            PA_UNLESS( stream->maxFramesPerHostBuffer == stream->capture.framesPerBuffer, paInternalError );
-        }
-        else
-        {
-            PA_UNLESS( stream->maxFramesPerHostBuffer == stream->playback.framesPerBuffer, paInternalError );
-        }
-    }
     hostInputSampleFormat = stream->capture.hostSampleFormat;
     hostOutputSampleFormat = stream->playback.hostSampleFormat;
 
@@ -2045,7 +2094,7 @@
 error:
     if( stream )
     {
-        PA_DEBUG(( "\nStream in error, terminating\n\n" ));
+        PA_DEBUG(( "%s: Stream in error, terminating\n", __FUNCTION__ ));
         PaAlsaStream_Terminate( stream );
     }
 
@@ -2342,7 +2391,7 @@
     PaAlsaStream *stream = (PaAlsaStream*)s;
 
     snd_timestamp_t timestamp;
-    snd_pcm_status_t *status;
+    snd_pcm_status_t* status;
     snd_pcm_status_alloca( &status );
 
     /* TODO: what if we have both?  does it really matter? */
@@ -2361,7 +2410,7 @@
     }
 
     snd_pcm_status_get_tstamp( status, &timestamp );
-    return timestamp.tv_sec + (PaTime)timestamp.tv_usec / 1000000.0;
+    return timestamp.tv_sec + (PaTime)timestamp.tv_usec / 1e6;
 }
 
 static double GetStreamCpuLoad( PaStream* s )
@@ -2910,7 +2959,9 @@
         if( poll( self->pfds, totalFds, pollTimeout ) < 0 )
         {
             /*  XXX: Depend on preprocessor condition? */
-            if( errno == EINTR ) {  /* gdb */
+            if( errno == EINTR )
+            {
+                /* gdb */
                 continue;
             }
 
@@ -3006,8 +3057,8 @@
  * 
  * @param numFrames On entrance the number of requested frames, on exit the number of contiguously accessible frames.
  */
-static PaError PaAlsaStreamComponent_RegisterChannels( PaAlsaStreamComponent *self, PaUtilBufferProcessor *bp,
-        unsigned long *numFrames, int *xrun )
+static PaError PaAlsaStreamComponent_RegisterChannels( PaAlsaStreamComponent* self, PaUtilBufferProcessor* bp,
+        unsigned long* numFrames, int* xrun )
 {
     PaError result = paNoError;
     const snd_pcm_channel_area_t *areas, *area;
@@ -3067,7 +3118,7 @@
  * @param numFrames On entrance the number of available frames, on exit the number of received frames
  * @param xrunOccurred Return whether an xrun has occurred
  */
-static PaError PaAlsaStream_SetUpBuffers( PaAlsaStream *self, unsigned long *numFrames, int *xrunOccurred )
+static PaError PaAlsaStream_SetUpBuffers( PaAlsaStream* self, unsigned long* numFrames, int* xrunOccurred )
 {
     PaError result = paNoError;
     unsigned long captureFrames = ULONG_MAX, playbackFrames = ULONG_MAX, commonFrames = 0;
@@ -3217,7 +3268,8 @@
     else
     {
         PA_ENSURE( LockMutex( &stream->startMtx ) );
-        PA_ENSURE( AlsaStart( stream, 0 ) );    /* Buffer will be zeroed */
+        /* Buffer will be zeroed */
+        PA_ENSURE( AlsaStart( stream, 0 ) );
         ENSURE_SYSTEM_( pthread_cond_signal( &stream->startCond ), 0 );
         PA_ENSURE( UnlockMutex( &stream->startMtx ) );
 
@@ -3313,9 +3365,7 @@
             PaUtil_BeginCpuLoadMeasurement( &stream->cpuLoadMeasurer );
 
             framesGot = framesAvail;
-            PA_ENSURE( PaAlsaStream_SetUpBuffers( stream, &framesGot, &xrun ) );
-            /* Check the host buffer size against the buffer processor configuration */
-            if( stream->bufferProcessor.hostBufferSizeMode == paUtilFixedHostBufferSize )
+            if( paUtilFixedHostBufferSize == stream->bufferProcessor.hostBufferSizeMode )
             {
                 /* We've committed to a fixed host buffer size, stick to that */
                 framesGot = framesGot >= stream->maxFramesPerHostBuffer ? stream->maxFramesPerHostBuffer : 0;
@@ -3323,9 +3373,11 @@
             else
             {
                 /* We've committed to an upper bound on the size of host buffers */
-                assert( stream->bufferProcessor.hostBufferSizeMode == paUtilBoundedHostBufferSize );
+                assert( paUtilBoundedHostBufferSize == stream->bufferProcessor.hostBufferSizeMode );
                 framesGot = PA_MIN( framesGot, stream->maxFramesPerHostBuffer );
             }
+            PA_ENSURE( PaAlsaStream_SetUpBuffers( stream, &framesGot, &xrun ) );
+            /* Check the host buffer size against the buffer processor configuration */
             framesAvail -= framesGot;
 
             if( framesGot > 0 )
@@ -3336,14 +3388,8 @@
             }
             PaUtil_EndCpuLoadMeasurement( &stream->cpuLoadMeasurer, framesGot );
 
-            if( framesGot == 0 )
+            if( 0 == framesGot )
             {
-                if( !xrun )
-                {
-                    PA_DEBUG(( "%s: Received less frames than reported from ALSA, framesAvail: %lu\n", __FUNCTION__,
-                                framesAvail ));
-                }
-
                 /* Go back to polling for more frames */
                 break;
 
@@ -3393,7 +3439,9 @@
     }
 
     if( stream->capture.userInterleaved )
+    {
         userBuffer = buffer;
+    }
     else
     {
         /* Copy channels into local array */
--- libs/portaudio/pa_linux_alsa/pa_linux_alsa.c	2006-03-05 14:22:54.000000000 +0100
+++ libs/portaudio/pa_linux_alsa/pa_linux_alsa.c	2006-03-11 12:15:47.000000000 +0100
@@ -786,8 +786,8 @@
 static int IgnorePlugin( const char *pluginId )
 {
 #define numIgnored 10
-    static const char *ignoredPlugins[numIgnored] = {"hw", "plughw", "plug", "default", "dsnoop", "dmix", "tee",
-        "file", "null", "shm"};
+    static const char *ignoredPlugins[numIgnored] = {"hw", "plughw", "plug", "dsnoop", "dmix", "tee",
+        "file", "null", "shm", "cards"};
     int i;
 
     for( i = 0; i < numIgnored; ++i )
@@ -920,23 +920,20 @@
 
         snd_config_for_each( i, next, topNode )
         {
-            const char *tpStr = NULL, *idStr = NULL;
+            const char *idStr = NULL;
             char *alsaDeviceName, *deviceName;
-            snd_config_t *n = snd_config_iterator_entry( i ), *tp = NULL;
-            if( snd_config_get_type( n ) != SND_CONFIG_TYPE_COMPOUND )
-                continue;
+            snd_config_t *n = snd_config_iterator_entry( i );
 
-            ENSURE_( snd_config_search( n, "type", &tp ), paUnanticipatedHostError );
-            ENSURE_( snd_config_get_string( tp, &tpStr ), paUnanticipatedHostError );
+	    ENSURE_( snd_config_get_id( n, &idStr ), paUnanticipatedHostError );
+	    PA_DEBUG(( "%s: Plugin device '%s'\n", __FUNCTION__, idStr ));	    
 
-            ENSURE_( snd_config_get_id( n, &idStr ), paUnanticipatedHostError );
             if( IgnorePlugin( idStr ) )
             {
-                PA_DEBUG(( "%s: Ignoring ALSA plugin device %s of type %s\n", __FUNCTION__, idStr, tpStr ));
+                PA_DEBUG(( "%s: Ignoring ALSA plugin device %s\n", __FUNCTION__, idStr ));
                 continue;
             }
 
-            PA_DEBUG(( "%s: Found plugin %s of type %s\n", __FUNCTION__, idStr, tpStr ));
+            PA_DEBUG(( "%s: Found plugin device '%s'\n", __FUNCTION__, idStr ));
 
             PA_UNLESS( alsaDeviceName = (char*)PaUtil_GroupAllocateMemory( alsaApi->allocations,
                                                             strlen(idStr) + 6 ), paInsufficientMemory );
_______________________________________________
Wengophone-devel mailing list
[email protected]
http://dev.openwengo.com/mailman/listinfo/wengophone-devel

Reply via email to