[pulseaudio-discuss] [PATCH v6 02/25] loopback: Improve latency estimation in snapshots
Georg Chini
georg at chini.tk
Sun Jun 5 19:05:05 UTC 2016
The delay and render memblockq are using the source and sink sample specs,
so using pa_bytes_to_usec() will produce better estimates of the delays than
using pa_resmpler_result(). Because the delays are considered to be part of
the sink or source latency, they are added to them. source_output_buffer
becomes obsolete.
---
src/modules/module-loopback.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index 22615d3..aa559aa 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -89,7 +89,6 @@ struct userdata {
struct {
int64_t send_counter;
- size_t source_output_buffer;
pa_usec_t source_latency;
pa_usec_t source_timestamp;
@@ -181,9 +180,7 @@ static void adjust_rates(struct userdata *u) {
pa_asyncmsgq_send(u->source_output->source->asyncmsgq, PA_MSGOBJECT(u->source_output), SOURCE_OUTPUT_MESSAGE_LATENCY_SNAPSHOT, NULL, 0, NULL);
pa_asyncmsgq_send(u->sink_input->sink->asyncmsgq, PA_MSGOBJECT(u->sink_input), SINK_INPUT_MESSAGE_LATENCY_SNAPSHOT, NULL, 0, NULL);
- buffer =
- u->latency_snapshot.sink_input_buffer +
- u->latency_snapshot.source_output_buffer;
+ buffer = u->latency_snapshot.sink_input_buffer;
if (u->latency_snapshot.recv_counter <= u->latency_snapshot.send_counter)
buffer += (size_t) (u->latency_snapshot.send_counter - u->latency_snapshot.recv_counter);
@@ -316,8 +313,9 @@ static int source_output_process_msg_cb(pa_msgobject *obj, int code, void *data,
length = pa_memblockq_get_length(u->source_output->thread_info.delay_memblockq);
u->latency_snapshot.send_counter = u->send_counter;
- u->latency_snapshot.source_output_buffer = u->source_output->thread_info.resampler ? pa_resampler_result(u->source_output->thread_info.resampler, length) : length;
- u->latency_snapshot.source_latency = pa_source_get_latency_within_thread(u->source_output->source);
+ /* Add content of delay memblockq to the source latency */
+ u->latency_snapshot.source_latency = pa_source_get_latency_within_thread(u->source_output->source) +
+ pa_bytes_to_usec(length, &u->source_output->source->sample_spec);
u->latency_snapshot.source_timestamp = pa_rtclock_now();
return 0;
@@ -561,10 +559,10 @@ static int sink_input_process_msg_cb(pa_msgobject *obj, int code, void *data, in
length = pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq);
u->latency_snapshot.recv_counter = u->recv_counter;
- u->latency_snapshot.sink_input_buffer =
- pa_memblockq_get_length(u->memblockq) +
- (u->sink_input->thread_info.resampler ? pa_resampler_request(u->sink_input->thread_info.resampler, length) : length);
- u->latency_snapshot.sink_latency = pa_sink_get_latency_within_thread(u->sink_input->sink);
+ u->latency_snapshot.sink_input_buffer = pa_memblockq_get_length(u->memblockq);
+ /* Add content of render memblockq to sink latency */
+ u->latency_snapshot.sink_latency = pa_sink_get_latency_within_thread(u->sink_input->sink) +
+ pa_bytes_to_usec(length, &u->sink_input->sink->sample_spec);
u->latency_snapshot.sink_timestamp = pa_rtclock_now();
u->latency_snapshot.max_request = pa_sink_input_get_max_request(u->sink_input);
--
2.8.1
More information about the pulseaudio-discuss
mailing list