From: "poljar (Damir Jeli?)" <poljarinho@xxxxxxxxx> A maximum volume variable was added to the sink struct. Also a function was added to update the maximum volume and enforce it if it's needed. The maximum volume is automatically populated with the volume from the currently active port. --- src/pulsecore/device-port.c | 13 +++++++++++++ src/pulsecore/sink.c | 24 ++++++++++++++++++++++-- src/pulsecore/sink.h | 4 +++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c index c467a09..efe1d56 100644 --- a/src/pulsecore/device-port.c +++ b/src/pulsecore/device-port.c @@ -150,10 +150,23 @@ void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) { } void pa_device_port_set_max_volume(pa_device_port *p, pa_volume_t max) { + uint32_t state; + pa_core *core; + pa_assert(p); if (max == PA_VOLUME_MUTED) p->max_volume = PA_VOLUME_INVALID; else p->max_volume = max; + + if (p->is_output) { + pa_sink *sink; + + PA_IDXSET_FOREACH(sink, p->core->sinks, state) + if (sink->active_port == p) { + pa_sink_set_max_volume(sink, p->max_volume); + break; + } + } } diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 3d72f55..e474821 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -309,10 +309,14 @@ pa_sink* pa_sink_new( s->active_port = p; } - if (s->active_port) + if (s->active_port) { s->latency_offset = s->active_port->latency_offset; - else + s->max_volume = s->active_port->max_volume; + + } else { s->latency_offset = 0; + s->max_volume = PA_VOLUME_INVALID; + } s->save_volume = data->save_volume; s->save_muted = data->save_muted; @@ -1967,6 +1971,13 @@ void pa_sink_set_volume( pa_cvolume_scale(&new_reference_volume, pa_cvolume_max(volume)); } + /* If we have a max_volume set enforce it if needed */ + + if (PA_VOLUME_IS_VALID(s->max_volume)) + for (unsigned i = 0; i < new_reference_volume.channels; i++) + if (new_reference_volume.values[i] > s->max_volume) + new_reference_volume.values[i] = s->max_volume; + pa_cvolume_remap(&new_reference_volume, &s->channel_map, &root_sink->channel_map); if (update_reference_volume(root_sink, &new_reference_volume, &root_sink->channel_map, save)) { @@ -3261,6 +3272,15 @@ void pa_sink_set_latency_offset(pa_sink *s, int64_t offset) { } /* Called from main context */ +void pa_sink_set_max_volume(pa_sink *s, pa_volume_t max) { + pa_sink_assert_ref(s); + + s->max_volume = max; + + pa_sink_set_volume(s, &s->reference_volume, TRUE, s->save_volume); +} + +/* Called from main context */ size_t pa_sink_get_max_rewind(pa_sink *s) { size_t r; pa_assert_ctl_context(); diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h index 2c52348..6efeb46 100644 --- a/src/pulsecore/sink.h +++ b/src/pulsecore/sink.h @@ -113,8 +113,9 @@ struct pa_sink { pa_device_port *active_port; pa_atomic_t mixer_dirty; - /* The latency offset is inherited from the currently active port */ + /* The latency offset and the maximum volume are inherited from the currently active port */ int64_t latency_offset; + pa_volume_t max_volume; unsigned priority; @@ -411,6 +412,7 @@ unsigned pa_device_init_priority(pa_proplist *p); pa_bool_t pa_sink_update_rate(pa_sink *s, uint32_t rate, pa_bool_t passthrough); void pa_sink_set_latency_offset(pa_sink *s, int64_t offset); +void pa_sink_set_max_volume(pa_sink *s, pa_volume_t max); /* The returned value is supposed to be in the time domain of the sound card! */ pa_usec_t pa_sink_get_latency(pa_sink *s); -- 1.7.11.4