diff options
author | Georg Chini <georg@chini.tk> | 2022-05-24 20:33:24 +0200 |
---|---|---|
committer | PulseAudio Marge Bot <pulseaudio-maintainers@lists.freedesktop.org> | 2022-05-25 07:04:09 +0000 |
commit | 5bba8ee621340bde1808ad42e4b61f45821ac886 (patch) | |
tree | 2222d41a44f019bbbef85fb33bc7e2c6eed7a8a8 | |
parent | 363a384143f81aeb455d7bae60591a7ef242cad7 (diff) | |
download | pulseaudio-5bba8ee621340bde1808ad42e4b61f45821ac886.tar.gz |
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>
-rw-r--r-- | src/modules/module-tunnel.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c index 5ecc521a6..33cff1e82 100644 --- a/src/modules/module-tunnel.c +++ b/src/modules/module-tunnel.c @@ -290,6 +290,7 @@ struct userdata { pa_iochannel *io; pa_usec_t reconnect_interval_us; + pa_usec_t snapshot_time; }; struct module_restart_data { @@ -646,7 +647,8 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse else 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 pa_usec_t y; @@ -657,7 +659,8 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse else 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 /* 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; - 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 pa_usec_t y; y = pa_bytes_to_usec((uint64_t) u->counter, &u->source->sample_spec); 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 /* 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); #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 pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_UPDATE_LATENCY, 0, delay, NULL); #else |