Ticket #3598: mythtv_alsa_non_mmap_fallback.patch

File mythtv_alsa_non_mmap_fallback.patch, 3.1 KB (added by wberrier@…, 13 years ago)

Fall back to non-mmap if mmap isn't available

  • audiooutputalsa.h

     
    3737    virtual inline int getBufferedOnSoundcard(void);
    3838
    3939  private:
    40     inline int SetParameters(snd_pcm_t *handle, snd_pcm_access_t access,
     40    inline int SetParameters(snd_pcm_t *handle,
    4141                             snd_pcm_format_t format, unsigned int channels,
    4242                             unsigned int rate, unsigned int buffer_time,
    4343                             unsigned int period_time);
     
    5959    float        volume_range_multiplier;
    6060    long         playback_vol_min;
    6161    long         playback_vol_max;
     62    snd_pcm_sframes_t (*pcm_write_func)(snd_pcm_t*, const void*, snd_pcm_uframes_t);
    6263};
    6364
    6465#endif
  • audiooutputalsa.cpp

     
    113113        return false;
    114114    }
    115115
    116     err = SetParameters(pcm_handle, SND_PCM_ACCESS_MMAP_INTERLEAVED,
     116    err = SetParameters(pcm_handle,
    117117                        format, audio_channels, audio_samplerate, buffer_time,
    118118                        period_time);
    119119    if (err < 0)
     
    164164   
    165165    while (frames > 0)
    166166    {
    167         lw = snd_pcm_mmap_writei(pcm_handle, tmpbuf, frames);
     167        lw = pcm_write_func(pcm_handle, tmpbuf, frames);
    168168       
    169169        if (lw >= 0)
    170170        {
     
    221221        }
    222222        else
    223223        {
    224             VERBOSE(VB_IMPORTANT, QString("snd_pcm_mmap_writei: %1 (%2)")
     224            VERBOSE(VB_IMPORTANT, QString("pcm_write_func: %1 (%2)")
    225225                    .arg(snd_strerror(lw)).arg(lw));
    226226            VERBOSE(VB_IMPORTANT, QString("WriteAudio: snd_pcm_state == %1")
    227227                    .arg(snd_pcm_state(pcm_handle)));
     
    292292}
    293293
    294294
    295 int AudioOutputALSA::SetParameters(snd_pcm_t *handle, snd_pcm_access_t access,
     295int AudioOutputALSA::SetParameters(snd_pcm_t *handle,
    296296                                   snd_pcm_format_t format, unsigned int channels,
    297297                                   unsigned int rate, unsigned int buffer_time,
    298298                                   unsigned int period_time)
     
    324324        return err;
    325325    }
    326326
    327     /* set the interleaved read/write format */
    328     if ((err = snd_pcm_hw_params_set_access(handle, params, access)) < 0)
     327    /* set the interleaved read/write format, use mmap if available */
     328    pcm_write_func = &snd_pcm_mmap_writei;
     329    if ((err = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0)
    329330    {
    330         Error(QString("Access type not available: %1")
    331               .arg(snd_strerror(err)));
    332         return err;
     331        VERBOSE(VB_GENERAL, QString("ALSA mmap not available"));
     332        pcm_write_func = &snd_pcm_writei;
     333        if ((err = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
     334        {
     335            Error(QString("Access type not available: %1")
     336                  .arg(snd_strerror(err)));
     337            return err;
     338        }
    333339    }
    334340
    335341    /* set the sample format */