From: poljar <poljarinho@xxxxxxxxx> A latency offset variable was added to the sink struct. This variable gets automatically populated with the latency from the currently active port. --- src/pulsecore/sink.c | 24 ++++++++++++++++++++++++ src/pulsecore/sink.h | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index e4c343d..a39d34d 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -308,6 +308,11 @@ pa_sink* pa_sink_new( s->active_port = p; } + if (s->active_port) + pa_sink_set_latency_offset(s, pa_device_port_get_latency_offset(s->active_port)); + else + pa_sink_set_latency_offset(s, 0); + s->save_volume = data->save_volume; s->save_muted = data->save_muted; @@ -338,6 +343,7 @@ pa_sink* pa_sink_new( pa_sw_cvolume_multiply(&s->thread_info.current_hw_volume, &s->soft_volume, &s->real_volume); s->thread_info.volume_change_safety_margin = core->deferred_volume_safety_margin_usec; s->thread_info.volume_change_extra_delay = core->deferred_volume_extra_delay_usec; + s->thread_info.latency_offset_copy = &s->latency_offset; /* FIXME: This should probably be moved to pa_sink_put() */ pa_assert_se(pa_idxset_put(core->sinks, s, &s->index) >= 0); @@ -1422,6 +1428,8 @@ pa_usec_t pa_sink_get_latency(pa_sink *s) { pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0); + usec += pa_sink_get_latency_offset(s); + return usec; } @@ -1449,6 +1457,8 @@ pa_usec_t pa_sink_get_latency_within_thread(pa_sink *s) { if (o->process_msg(o, PA_SINK_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0) return -1; + usec += pa_sink_get_latency_offset(s); + return usec; } @@ -3223,6 +3233,18 @@ void pa_sink_set_fixed_latency_within_thread(pa_sink *s, pa_usec_t latency) { pa_source_set_fixed_latency_within_thread(s->monitor_source, latency); } +void pa_sink_set_latency_offset(pa_sink *s, pa_usec_t latency) { + pa_sink_assert_ref(s); + + s->latency_offset = latency; +} + +pa_usec_t pa_sink_get_latency_offset(pa_sink *s) { + pa_sink_assert_ref(s); + + return s->latency_offset; +} + /* Called from main context */ size_t pa_sink_get_max_rewind(pa_sink *s) { size_t r; @@ -3293,6 +3315,8 @@ int pa_sink_set_port(pa_sink *s, const char *name, pa_bool_t save) { s->active_port = port; s->save_port = save; + pa_sink_set_latency_offset(s, pa_device_port_get_latency_offset(port)); + pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_PORT_CHANGED], s); return 0; diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h index 0b5048a..cea988e 100644 --- a/src/pulsecore/sink.h +++ b/src/pulsecore/sink.h @@ -109,8 +109,10 @@ struct pa_sink { pa_memchunk silence; + /* The latency offset is inherited from the currently active port */ pa_hashmap *ports; pa_device_port *active_port; + pa_usec_t latency_offset; pa_atomic_t mixer_dirty; unsigned priority; @@ -268,6 +270,9 @@ struct pa_sink { * in changing it */ pa_usec_t fixed_latency; /* for sinks with PA_SINK_DYNAMIC_LATENCY this is 0 */ + /* This points to sink->latency_offset */ + pa_usec_t *latency_offset_copy; + /* Delayed volume change events are queued here. The events * are stored in expiration order. The one expiring next is in * the head of the list. */ @@ -385,6 +390,7 @@ void pa_sink_set_max_rewind(pa_sink *s, size_t max_rewind); void pa_sink_set_max_request(pa_sink *s, size_t max_request); void pa_sink_set_latency_range(pa_sink *s, pa_usec_t min_latency, pa_usec_t max_latency); void pa_sink_set_fixed_latency(pa_sink *s, pa_usec_t latency); +void pa_sink_set_latency_offset(pa_sink *s, pa_usec_t latency); void pa_sink_detach(pa_sink *s); void pa_sink_attach(pa_sink *s); @@ -409,6 +415,7 @@ pa_usec_t pa_sink_get_latency(pa_sink *s); pa_usec_t pa_sink_get_requested_latency(pa_sink *s); void pa_sink_get_latency_range(pa_sink *s, pa_usec_t *min_latency, pa_usec_t *max_latency); pa_usec_t pa_sink_get_fixed_latency(pa_sink *s); +pa_usec_t pa_sink_get_latency_offset(pa_sink *s); size_t pa_sink_get_max_rewind(pa_sink *s); size_t pa_sink_get_max_request(pa_sink *s); -- 1.7.10.4