Ticket #7496: pulse-latency-001.patch

File pulse-latency-001.patch, 3.1 KB (added by Alan Calvert <cal@…>, 10 years ago)

trunk @ 22716

  • libs/libmyth/audiooutputpulse.cpp

    old new  
    552552    else
    553553        pa_cvolume_reset(&volume_control, audio_channels);
    554554
    555     // set myth sizes and pa buffer metrics
    556     fragment_size = (float)sample_rate * 0.020f * // 20msec
    557         (float)(audio_bits / 8 * audio_channels);
    558     soundcard_buffer_size = 16 * fragment_size;
    559     buffer_settings.maxlength = soundcard_buffer_size;
    560     buffer_settings.tlength = fragment_size * 4;
    561     buffer_settings.prebuf = (uint32_t)-1;
    562     buffer_settings.minreq = (uint32_t)-1;
    563     VERBOSE(VB_AUDIO, LOC + fn_log_tag +
    564             QString("fragment size %1, soundcard buffer size %2")
    565             .arg(fragment_size).arg(soundcard_buffer_size));
    566 
    567555    int flags = PA_STREAM_INTERPOLATE_TIMING
    568556        | PA_STREAM_AUTO_TIMING_UPDATE
    569557        | PA_STREAM_NO_REMAP_CHANNELS
    570         | PA_STREAM_NO_REMIX_CHANNELS;
     558        | PA_STREAM_NO_REMIX_CHANNELS
     559        | PA_STREAM_ADJUST_LATENCY;
     560
     561    // request pa buffer metrics
     562    pa_buffer_attr buffer_settings;
     563    buffer_settings.tlength = pa_usec_to_bytes(80000, &sample_spec);
     564                              // request 80msec total buffer
     565    buffer_settings.prebuf = buffer_settings.tlength / 4;
     566                             // limit size of pre-buffer before play starts
     567    buffer_settings.maxlength = (uint32_t)-1;
     568    buffer_settings.minreq = (uint32_t)-1;
     569    VERBOSE(VB_AUDIO+VB_EXTRA, LOC +
     570        QString("PulseAudio buffer settings requested: maxlength %1, tlength %2,"
     571                " prebuf %3, minreq %4").arg(buffer_settings.maxlength)
     572                .arg(buffer_settings.tlength).arg(buffer_settings.prebuf)
     573                .arg(buffer_settings.minreq));
     574
    571575    pa_stream_connect_playback(pstream, NULL, &buffer_settings,
    572576                               (pa_stream_flags_t)flags, &volume_control, NULL);
    573577    pa_context_state_t cstate;
     
    605609                }
    606610        }
    607611    }
    608     return (connected && !failed);
     612    if (connected && !failed)
     613    {
     614        const pa_buffer_attr *buffer_metrics = pa_stream_get_buffer_attr(pstream);
     615        VERBOSE(VB_AUDIO+VB_EXTRA, LOC +
     616            QString("PulseAudio buffer metrics - maxlength %1, tlength %2, prebuf %3, minreq %4")
     617            .arg(buffer_metrics->maxlength).arg(buffer_metrics->tlength)
     618            .arg(buffer_metrics->prebuf).arg(buffer_metrics->minreq));
     619
     620        // set myth sizes
     621        fragment_size = buffer_metrics->minreq;
     622        soundcard_buffer_size = buffer_metrics->tlength;
     623        VERBOSE(VB_AUDIO, LOC + fn_log_tag +
     624            QString("Myth fragment size %1, soundcard buffer size %2")
     625            .arg(fragment_size).arg(soundcard_buffer_size));
     626        return true;
     627    }
     628    return false;
    609629}
    610630
    611631void AudioOutputPulseAudio::FlushStream(const char *caller)
  • libs/libmyth/audiooutputpulse.h

    old new  
    6767    pa_sample_spec          sample_spec;
    6868    pa_channel_map          channel_map;
    6969    pa_cvolume              volume_control;
    70     pa_buffer_attr          buffer_settings;
     70
    7171};
     72
    7273#endif
    7374
    7475/* vim: set expandtab tabstop=4 shiftwidth=4: */