Ticket #31: portaudio_dmix_default.patch

File portaudio_dmix_default.patch, 3.7 KB (added by rossb, 2 years ago)
  • src/hostapi/alsa/pa_linux_alsa.c

     
    467467 */ 
    468468static int IgnorePlugin( const char *pluginId ) 
    469469{ 
    470     /* XXX: dmix and default ignored because after opening and closing, they seem to keep hogging resources. 
    471      */ 
    472470    static const char *ignoredPlugins[] = {"hw", "plughw", "plug", "dsnoop", "tee", 
    473         "file", "null", "shm", "cards", "dmix", "default", NULL}; 
     471        "file", "null", "shm", "cards", NULL}; 
    474472    int i = 0; 
    475473    while( ignoredPlugins[i] ) 
    476474    { 
     
    484482    return 0; 
    485483} 
    486484 
     485static int snd_pcm_open_with_retry(snd_pcm_t **pcmp, const char *name, snd_pcm_stream_t stream, int mode) 
     486{ 
     487        int ret = snd_pcm_open(pcmp, name, stream, mode); 
     488        if (ret==EBUSY) { 
     489                sleep(1); 
     490                int ret = snd_pcm_open(pcmp, name, stream, mode); 
     491        } 
     492        return ret; 
     493} 
     494                                                                           
    487495/* Build PaDeviceInfo list, ignore devices for which we cannot determine capabilities (possibly busy, sigh) */ 
    488496static PaError BuildDeviceList( PaAlsaHostApiRepresentation *alsaApi ) 
    489497{ 
     
    681689 
    682690        /* Query capture */ 
    683691        if( deviceNames[i].hasCapture && 
    684                 snd_pcm_open( &pcm, deviceNames[i].alsaName, SND_PCM_STREAM_CAPTURE, blocking ) >= 0 ) 
     692                snd_pcm_open_with_retry( &pcm, deviceNames[i].alsaName, SND_PCM_STREAM_CAPTURE, blocking ) >= 0 ) 
    685693        { 
    686694            if( GropeDevice( pcm, deviceNames[i].isPlug, StreamDirection_In, blocking, deviceInfo, 
    687695                        &canMmap ) != paNoError ) 
     
    694702 
    695703        /* Query playback */ 
    696704        if( deviceNames[i].hasPlayback && 
    697                 snd_pcm_open( &pcm, deviceNames[i].alsaName, SND_PCM_STREAM_PLAYBACK, blocking ) >= 0 ) 
     705                snd_pcm_open_with_retry( &pcm, deviceNames[i].alsaName, SND_PCM_STREAM_PLAYBACK, blocking ) >= 0 ) 
    698706        { 
    699707            if( GropeDevice( pcm, deviceNames[i].isPlug, StreamDirection_Out, blocking, deviceInfo, 
    700708                        &canMmap ) != paNoError ) 
     
    726734                baseApi->info.defaultInputDevice = devIdx; 
    727735            if(  baseApi->info.defaultOutputDevice == paNoDevice && baseDeviceInfo->maxOutputChannels > 0 ) 
    728736                baseApi->info.defaultOutputDevice = devIdx; 
     737            if( strcmp(deviceNames[i].alsaName, "default")==0 ) 
     738                baseApi->info.defaultOutputDevice = devIdx; 
    729739            PA_DEBUG(("%s: Adding device %s\n", __FUNCTION__, deviceNames[i].name)); 
    730740            baseApi->deviceInfos[devIdx++] = (PaDeviceInfo *) deviceInfo; 
    731741        } 
     
    869879        deviceName = streamInfo->deviceString; 
    870880 
    871881    PA_DEBUG(( "%s: Opening device %s\n", __FUNCTION__, deviceName )); 
    872     if( (ret = snd_pcm_open( pcm, deviceName, streamDir == StreamDirection_In ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK, 
     882    if( (ret = snd_pcm_open_with_retry( pcm, deviceName, streamDir == StreamDirection_In ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK, 
    873883                    SND_PCM_NONBLOCK )) < 0 ) 
    874884    { 
    875885        /* Not to be closed */ 
     
    19811991        if( stream->playback.pcm ) 
    19821992        { 
    19831993            ENSURE_( snd_pcm_nonblock( stream->playback.pcm, 0 ), paUnanticipatedHostError ); 
    1984             if( snd_pcm_drain( stream->playback.pcm ) < 0 ) 
     1994            /* draining causes deadlock when we are using dmix */ 
     1995            /* if( snd_pcm_drain( stream->playback.pcm ) < 0 ) */ 
     1996            if( snd_pcm_drop( stream->playback.pcm ) < 0 ) 
    19851997            { 
    19861998                PA_DEBUG(( "%s: Draining playback handle failed!\n", __FUNCTION__ )); 
    19871999            }