mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-09 13:29:59 -05:00
module-tunnel: Improve latency calculation
The timestamp used for updating the smoother was taken at the wrong time. It may take some time until an async message is executed (measured up to 2ms), therefore the timestamp used to update the smoother must be taken before the message is executed and not inside the message. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/705>
This commit is contained in:
parent
363a384143
commit
5bba8ee621
1 changed files with 12 additions and 4 deletions
|
|
@ -290,6 +290,7 @@ struct userdata {
|
||||||
pa_iochannel *io;
|
pa_iochannel *io;
|
||||||
|
|
||||||
pa_usec_t reconnect_interval_us;
|
pa_usec_t reconnect_interval_us;
|
||||||
|
pa_usec_t snapshot_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct module_restart_data {
|
struct module_restart_data {
|
||||||
|
|
@ -646,7 +647,8 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
|
||||||
else
|
else
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
|
|
||||||
pa_smoother_2_put(u->smoother, pa_rtclock_now(), bytes);
|
/* We may use u->snapshot time because the main thread is waiting */
|
||||||
|
pa_smoother_2_put(u->smoother, u->snapshot_time, bytes);
|
||||||
#else
|
#else
|
||||||
pa_usec_t y;
|
pa_usec_t y;
|
||||||
|
|
||||||
|
|
@ -657,7 +659,8 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
|
||||||
else
|
else
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|
||||||
pa_smoother_put(u->smoother, pa_rtclock_now(), y);
|
/* We may use u->snapshot time because the main thread is waiting */
|
||||||
|
pa_smoother_put(u->smoother, u->snapshot_time, y);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* We can access this freely here, since the main thread is waiting for us */
|
/* We can access this freely here, since the main thread is waiting for us */
|
||||||
|
|
@ -790,14 +793,16 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
|
||||||
|
|
||||||
bytes += u->counter;
|
bytes += u->counter;
|
||||||
|
|
||||||
pa_smoother_2_put(u->smoother, pa_rtclock_now(), bytes);
|
/* We may use u->snapshot time because the main thread is waiting */
|
||||||
|
pa_smoother_2_put(u->smoother, u->snapshot_time, bytes);
|
||||||
#else
|
#else
|
||||||
pa_usec_t y;
|
pa_usec_t y;
|
||||||
|
|
||||||
y = pa_bytes_to_usec((uint64_t) u->counter, &u->source->sample_spec);
|
y = pa_bytes_to_usec((uint64_t) u->counter, &u->source->sample_spec);
|
||||||
y += offset;
|
y += offset;
|
||||||
|
|
||||||
pa_smoother_put(u->smoother, pa_rtclock_now(), y);
|
/* We may use u->snapshot time because the main thread is waiting */
|
||||||
|
pa_smoother_put(u->smoother, u->snapshot_time, y);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* We can access this freely here, since the main thread is waiting for us */
|
/* We can access this freely here, since the main thread is waiting for us */
|
||||||
|
|
@ -1011,6 +1016,9 @@ static void stream_get_latency_callback(pa_pdispatch *pd, uint32_t command, uint
|
||||||
delay += (int64_t) pa_bytes_to_usec(send_counter - u->receive_snapshot, ss);
|
delay += (int64_t) pa_bytes_to_usec(send_counter - u->receive_snapshot, ss);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* It may take some time before the async message is executed, so we take a timestamp here */
|
||||||
|
u->snapshot_time = pa_rtclock_now();
|
||||||
|
|
||||||
#ifdef TUNNEL_SINK
|
#ifdef TUNNEL_SINK
|
||||||
pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UPDATE_LATENCY, 0, delay, NULL);
|
pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UPDATE_LATENCY, 0, delay, NULL);
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue