loopback: Improve latency estimation in snapshots

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.
This commit is contained in:
Georg Chini 2016-06-05 21:05:05 +02:00 committed by Tanu Kaskinen
parent 86e54c8c13
commit 2d7a5cda43

View file

@ -89,7 +89,6 @@ struct userdata {
struct { struct {
int64_t send_counter; int64_t send_counter;
size_t source_output_buffer;
pa_usec_t source_latency; pa_usec_t source_latency;
pa_usec_t source_timestamp; 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->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); pa_asyncmsgq_send(u->sink_input->sink->asyncmsgq, PA_MSGOBJECT(u->sink_input), SINK_INPUT_MESSAGE_LATENCY_SNAPSHOT, NULL, 0, NULL);
buffer = buffer = u->latency_snapshot.sink_input_buffer;
u->latency_snapshot.sink_input_buffer +
u->latency_snapshot.source_output_buffer;
if (u->latency_snapshot.recv_counter <= u->latency_snapshot.send_counter) if (u->latency_snapshot.recv_counter <= u->latency_snapshot.send_counter)
buffer += (size_t) (u->latency_snapshot.send_counter - u->latency_snapshot.recv_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); length = pa_memblockq_get_length(u->source_output->thread_info.delay_memblockq);
u->latency_snapshot.send_counter = u->send_counter; 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; /* Add content of delay memblockq to the source latency */
u->latency_snapshot.source_latency = pa_source_get_latency_within_thread(u->source_output->source); 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(); u->latency_snapshot.source_timestamp = pa_rtclock_now();
return 0; 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); length = pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq);
u->latency_snapshot.recv_counter = u->recv_counter; u->latency_snapshot.recv_counter = u->recv_counter;
u->latency_snapshot.sink_input_buffer = u->latency_snapshot.sink_input_buffer = pa_memblockq_get_length(u->memblockq);
pa_memblockq_get_length(u->memblockq) + /* Add content of render memblockq to sink latency */
(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_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.sink_timestamp = pa_rtclock_now();
u->latency_snapshot.max_request = pa_sink_input_get_max_request(u->sink_input); u->latency_snapshot.max_request = pa_sink_input_get_max_request(u->sink_input);