<div dir="ltr">Thanks Tanu,<div><br></div><div>I am still interested in this and will fix my mistakes, thanks for finding them!</div><div><br></div><div>I'll get to this sometime in the next week.</div><div><br>Regards,</div><div><br></div><div>Chris</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 6, 2016 at 4:21 AM, Tanu Kaskinen <span dir="ltr"><<a href="mailto:tanuk@iki.fi" target="_blank">tanuk@iki.fi</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sat, 2016-01-23 at 12:31 +1100, Chris Billington wrote:<br>
<br>
> Some sinks and sources do not have ports associated with them, such as a null<br>
> sink. Nonetheless sources and sinks with no ports can be used for sound<br>
> input/output with an associated latency, for example by capturing output from<br>
> a null sink and directing over a network, which is how some implementations of<br>
> network audio streaming protocols interact with PulseAudio.<br>
><br>
> To keep graphics in sync with audio in these cases, the application/plugin must<br>
> be able to report the latency due to network transport/buffering to PulseAudio<br>
> and have it included in the total latency for that source or sink.<br>
><br>
> Previously, only the latency offset of a whole port could be set.<br>
> You could call pa_sink_set_latency_offset(), but the value you passed in would<br>
> be overwritten on change to a new port - that value was really just a cached<br>
> value of the port's latency offset. So those variables and functions have since<br>
> (in the previous commit) been renamed pa_sink_set_port_latency_offset() etc, to<br>
> distinguish them from the ones introduced in this commit.<br>
><br>
> This patch adds set_sink_latency_offset() and set_source_latency offset(),<br>
> and the corresponding members of the sink and source structs.<br>
><br>
> It also adds corresponding hooks PA_CORE_HOOK_SINK_LATENCY_OFFSET_CHANGED<br>
> and PA_CORE_HOOK_SOURCE_LATENCY_OFFSET_CHANGED.<br>
><br>
> The total latency reported by a source or sink now includes both the port<br>
> latency offset (if any) as well as the source or sink's own latency offset.<br>
<br>
</span>Thanks, looks mostly good. I'll point out a few small issues below.<br>
<br>
Since it's been already many months since you submitted these patches,<br>
please let me know if during that time you have lost interest to finish<br>
off this work (it would be understandable).<br>
<span class=""><br>
> @@ -125,6 +125,8 @@ typedef enum pa_core_hook {<br>
>      PA_CORE_HOOK_CARD_PROFILE_AVAILABLE_CHANGED,<br>
>      PA_CORE_HOOK_PORT_AVAILABLE_CHANGED,<br>
>      PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED,<br>
> +    PA_CORE_HOOK_SINK_LATENCY_OFFSET_CHANGED,<br>
> +    PA_CORE_HOOK_SOURCE_LATENCY_OFFSET_CHANGED,<br>
<br>
</span>A cosmetic note about the hook list ordering: I prefer different<br>
grouping - e.g. all sink hooks should be together.<br>
<span class=""><br>
> @@ -314,6 +319,11 @@ pa_sink* pa_sink_new(<br>
>      else<br>
>          s->port_latency_offset = 0;<br>
>  <br>
> +    if (data->latency_offset)<br>
> +        s->latency_offset = data->latency_offset;<br>
> +    else<br>
> +        s->latency_offset = 0;<br>
<br>
</span>This can be replaced with just<br>
<span class=""><br>
    s->latency_offset = data->latency_offset;<br>
<br>
</span>without any changes in behaviour. The same applies to the code in<br>
source.c.<br>
<span class=""><br>
> @@ -1512,6 +1525,12 @@ pa_usec_t pa_sink_get_latency(pa_sink *s) {<br>
>      else<br>
>          usec = 0;<br>
>  <br>
> +    /* Similarly checking for underflow */<br>
> +    if (-s->latency_offset <= (int64_t) usec)<br>
> +        usec += s->latency_offset;<br>
> +    else<br>
> +        usec = 0;<br>
<br>
</span>The two offsets should be summed together and then added to usec,<br>
rather than adding them to usec one by one. The code in the patch<br>
doesn't work correctly if, for example, the initial usec is 1000, the<br>
port latency offset -2000 and the sink latency offset is 2000. The<br>
final usec should be unchanged (1000), because the two offsets undo<br>
each other, but this code results in the final usec being 2000.<br>
<br>
This applies also to pa_sink_get_latency_within_thread() and the<br>
corresponding functions in source.c.<br>
<span class=""><br>
> @@ -1096,6 +1107,8 @@ pa_usec_t pa_source_get_latency(pa_source *s) {<br>
>  <br>
>      pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0);<br>
>  <br>
> +    /* Total latency offset is the sum of the port latency offset and the sink latency offset */<br>
<br>
</span>Copy-paste mistake: s/sink/source/<br>
<span class=""><br>
> @@ -1130,6 +1149,8 @@ pa_usec_t pa_source_get_latency_within_thread(pa_source *s) {<br>
>      if (o->process_msg(o, PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0)<br>
>          return -1;<br>
>  <br>
> +    /* Total latency offset is the sum of the port latency offset and the sink latency offset */<br>
<br>
</span>The same copy-paste error here too.<br>
<span class="HOEnZb"><font color="#888888"><br>
-- <br>
Tanu<br>
</font></span></blockquote></div><br></div>