[pulseaudio-discuss] Why does a VOIP sink input's current latency become "0" after moving to a new sink? I saw endless "rewind" in log

xing wang wangxingchao2011 at gmail.com
Thu Jun 2 03:10:21 PDT 2011


2011/6/2 Lin, Mengdong <mengdong.lin at intel.com>:
> I’m working on a module that can switch profile for a Bluetooth headset:
> A2DP for music playback and HSP for a phone.
>
> When this module detects a sink-input-put event of a “phone” like GTalk and
> Bluetooth is the default sink, it can change BT profile from A2DP to HSP if
> necessary. Then the A2DP sink is deleted, and the phone’s input stream will
> be routed to the new HSP Bluetooth sink.
>
>
>
> My problem is: I cannot hear good voice from the other side of GTalk, I get
> bursts of audio (about 2 seconds) followed by very long bursts of silence.
>
> By using pacmd, I found that Gtalk input stream is connected to the BT HSP
> sink, but GTalk input stream’s latency is “0”, very strange. Like this:
>
>
Mengdong, current latency of the sink-input is calculated by
pa_sink_input_get_latency(), you can check details there. For the "0"
result, there're two "if" conditions in
pa_sink_get_latency_within_thread(). If the sink's state is
"suspended"(from your log,it's running" or sink doesnot support
"PA_SINK_LATENCY", the current latency will be 0. otherwise, there's a
real calculation function in sink_get_latency() in alsa-sink.c.let's
further check the conditions.

>
>>>list-sinks
>
> index: 2
>
>          name: <bluez_sink.00_16_44_FD_36_33.2>
>
>          driver: <module-bluetooth-device.c>
>
>          flags: HARDWARE HW_VOLUME_CTRL LATENCY
>
>          state: RUNNING
>
>          …
>
>          current latency: 128.46 ms
>
>          sample spec: s16le 1ch 8000Hz
>
>          channel map: mono
>
>          …
>
>          fixed latency: 128.00 ms
>
>
>
>
>
>>>list-sink-inputs
>
> index: 3
>
>          driver: <protocol-native.c>
>
>          flags: START_CORKED
>
>          state: RUNNING
>
>          sink: 2 <bluez_sink.00_16_44_FD_36_33.2>
>
>          current latency: 0.00 ms     …  this is abnormal. How PA calculate
> this value?
>
>          requested latency: 128.00 ms
>
>          sample spec: s16le 1ch 8000Hz
>
>          channel map: mono
>
>          resample method: (null)
>
>          client: 7 <Empathy>   … This is the frontend application of GTalk
>
>
>
>
>
> And in PA log, I saw many “protocol-native.c: Requesting rewind due to
> rewrite”.  I think this means GTalk data flow is abnormal and data is lost.
> Could anyone give me some hint? How the latency is calculated for a sink
> input? And how can the application be affected?
>
>
The "rewrites" maybe caused by previous abnormal latency . You can see
the handle_seek() will trigger "rewrite rewind". That means the app
didnot write data fast enough, the read index pointer is faster then
write pointer, so has do rewind operations.

The latency maybe tunned in fix_playback_buffer_attr() when created
the new playback stream.

>
> I think the BT HSP sink is working well, because if I connect another 8KHZ
> mono music stream to this sink at the same time, I can hear the music. And
> that music input’s latency is non-zero:
>
> “current latency: 1982.00 ms, requested latency: 128.00 ms”.
>
>
>
>
>
> Greate thanks
>
> Amanda
>
> _______________________________________________
> pulseaudio-discuss mailing list
> pulseaudio-discuss at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
>
>


More information about the pulseaudio-discuss mailing list