mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
source-output: Ensure no volumes are applied for passthrough streams
This forces passthrough source-outputs and their corresponding sources to 0dB gain so that the data is sent unaltered to the receiver.
This commit is contained in:
parent
0dea35a818
commit
f0be9c4004
3 changed files with 49 additions and 6 deletions
|
|
@ -298,10 +298,13 @@ int pa_source_output_new(
|
||||||
|
|
||||||
pa_return_val_if_fail(pa_channel_map_compatible(&data->channel_map, &data->sample_spec), -PA_ERR_INVALID);
|
pa_return_val_if_fail(pa_channel_map_compatible(&data->channel_map, &data->sample_spec), -PA_ERR_INVALID);
|
||||||
|
|
||||||
/* Don't restore (or save) stream volume for passthrough streams */
|
/* Don't restore (or save) stream volume for passthrough streams and
|
||||||
|
* prevent attenuation/gain */
|
||||||
if (pa_source_output_new_data_is_passthrough(data)) {
|
if (pa_source_output_new_data_is_passthrough(data)) {
|
||||||
data->volume_is_set = FALSE;
|
data->volume_is_set = TRUE;
|
||||||
data->volume_factor_is_set = FALSE;
|
pa_cvolume_reset(&data->volume, data->sample_spec.channels);
|
||||||
|
data->volume_is_absolute = TRUE;
|
||||||
|
data->save_volume = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data->volume_is_set) {
|
if (!data->volume_is_set) {
|
||||||
|
|
@ -544,6 +547,9 @@ void pa_source_output_unlink(pa_source_output*o) {
|
||||||
o->state = PA_SOURCE_OUTPUT_UNLINKED;
|
o->state = PA_SOURCE_OUTPUT_UNLINKED;
|
||||||
|
|
||||||
if (linked && o->source) {
|
if (linked && o->source) {
|
||||||
|
if (pa_source_output_is_passthrough(o))
|
||||||
|
pa_source_leave_passthrough(o->source);
|
||||||
|
|
||||||
/* We might need to update the source's volume if we are in flat volume mode. */
|
/* We might need to update the source's volume if we are in flat volume mode. */
|
||||||
if (pa_source_flat_volume_enabled(o->source))
|
if (pa_source_flat_volume_enabled(o->source))
|
||||||
pa_source_set_volume(o->source, NULL, FALSE, FALSE);
|
pa_source_set_volume(o->source, NULL, FALSE, FALSE);
|
||||||
|
|
@ -628,6 +634,9 @@ void pa_source_output_put(pa_source_output *o) {
|
||||||
set_real_ratio(o, &o->volume);
|
set_real_ratio(o, &o->volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pa_source_output_is_passthrough(o))
|
||||||
|
pa_source_enter_passthrough(o->source);
|
||||||
|
|
||||||
o->thread_info.soft_volume = o->soft_volume;
|
o->thread_info.soft_volume = o->soft_volume;
|
||||||
o->thread_info.muted = o->muted;
|
o->thread_info.muted = o->muted;
|
||||||
|
|
||||||
|
|
@ -1180,6 +1189,9 @@ int pa_source_output_start_move(pa_source_output *o) {
|
||||||
if (pa_source_output_get_state(o) == PA_SOURCE_OUTPUT_CORKED)
|
if (pa_source_output_get_state(o) == PA_SOURCE_OUTPUT_CORKED)
|
||||||
pa_assert_se(origin->n_corked-- >= 1);
|
pa_assert_se(origin->n_corked-- >= 1);
|
||||||
|
|
||||||
|
if (pa_source_output_is_passthrough(o))
|
||||||
|
pa_source_leave_passthrough(o->source);
|
||||||
|
|
||||||
if (pa_source_flat_volume_enabled(o->source))
|
if (pa_source_flat_volume_enabled(o->source))
|
||||||
/* We might need to update the source's volume if we are in flat
|
/* We might need to update the source's volume if we are in flat
|
||||||
* volume mode. */
|
* volume mode. */
|
||||||
|
|
@ -1434,6 +1446,9 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t
|
||||||
|
|
||||||
update_volume_due_to_moving(o, dest);
|
update_volume_due_to_moving(o, dest);
|
||||||
|
|
||||||
|
if (pa_source_output_is_passthrough(o))
|
||||||
|
pa_source_enter_passthrough(o->source);
|
||||||
|
|
||||||
pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_ADD_OUTPUT, o, 0, NULL) == 0);
|
pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_ADD_OUTPUT, o, 0, NULL) == 0);
|
||||||
|
|
||||||
pa_log_debug("Successfully moved source output %i to %s.", o->index, dest->name);
|
pa_log_debug("Successfully moved source output %i to %s.", o->index, dest->name);
|
||||||
|
|
|
||||||
|
|
@ -978,6 +978,27 @@ pa_bool_t pa_source_is_passthrough(pa_source *s) {
|
||||||
return (s->monitor_of && pa_sink_is_passthrough(s->monitor_of));
|
return (s->monitor_of && pa_sink_is_passthrough(s->monitor_of));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Called from main context */
|
||||||
|
void pa_source_enter_passthrough(pa_source *s) {
|
||||||
|
pa_cvolume volume;
|
||||||
|
|
||||||
|
/* set the volume to NORM */
|
||||||
|
s->saved_volume = *pa_source_get_volume(s, TRUE);
|
||||||
|
s->saved_save_volume = s->save_volume;
|
||||||
|
|
||||||
|
pa_cvolume_set(&volume, s->sample_spec.channels, PA_VOLUME_NORM);
|
||||||
|
pa_source_set_volume(s, &volume, TRUE, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Called from main context */
|
||||||
|
void pa_source_leave_passthrough(pa_source *s) {
|
||||||
|
/* Restore source volume to what it was before we entered passthrough mode */
|
||||||
|
pa_source_set_volume(s, &s->saved_volume, TRUE, s->saved_save_volume);
|
||||||
|
|
||||||
|
pa_cvolume_init(&s->saved_volume);
|
||||||
|
s->saved_save_volume = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Called from main context. */
|
/* Called from main context. */
|
||||||
static void compute_reference_ratio(pa_source_output *o) {
|
static void compute_reference_ratio(pa_source_output *o) {
|
||||||
unsigned c = 0;
|
unsigned c = 0;
|
||||||
|
|
@ -1368,9 +1389,9 @@ void pa_source_set_volume(
|
||||||
pa_assert(volume || pa_source_flat_volume_enabled(s));
|
pa_assert(volume || pa_source_flat_volume_enabled(s));
|
||||||
pa_assert(!volume || volume->channels == 1 || pa_cvolume_compatible(volume, &s->sample_spec));
|
pa_assert(!volume || volume->channels == 1 || pa_cvolume_compatible(volume, &s->sample_spec));
|
||||||
|
|
||||||
/* make sure we don't change the volume when a PASSTHROUGH output is connected */
|
/* make sure we don't change the volume in PASSTHROUGH mode ...
|
||||||
if (pa_source_is_passthrough(s)) {
|
* ... *except* if we're being invoked to reset the volume to ensure 0 dB gain */
|
||||||
/* FIXME: Need to notify client that volume control is disabled */
|
if (pa_source_is_passthrough(s) && (!volume || !pa_cvolume_is_norm(volume))) {
|
||||||
pa_log_warn("Cannot change volume, Source is monitor of a PASSTHROUGH sink");
|
pa_log_warn("Cannot change volume, Source is monitor of a PASSTHROUGH sink");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,10 @@ struct pa_source {
|
||||||
pa_bool_t save_volume:1;
|
pa_bool_t save_volume:1;
|
||||||
pa_bool_t save_muted:1;
|
pa_bool_t save_muted:1;
|
||||||
|
|
||||||
|
/* Saved volume state while we're in passthrough mode */
|
||||||
|
pa_cvolume saved_volume;
|
||||||
|
pa_bool_t saved_save_volume:1;
|
||||||
|
|
||||||
pa_asyncmsgq *asyncmsgq;
|
pa_asyncmsgq *asyncmsgq;
|
||||||
|
|
||||||
pa_memchunk silence;
|
pa_memchunk silence;
|
||||||
|
|
@ -338,6 +342,9 @@ pa_bool_t pa_source_flat_volume_enabled(pa_source *s);
|
||||||
/* Is the source in passthrough mode? (that is, is this a monitor source for a sink
|
/* Is the source in passthrough mode? (that is, is this a monitor source for a sink
|
||||||
* that has a passthrough sink input connected to it. */
|
* that has a passthrough sink input connected to it. */
|
||||||
pa_bool_t pa_source_is_passthrough(pa_source *s);
|
pa_bool_t pa_source_is_passthrough(pa_source *s);
|
||||||
|
/* These should be called when a source enters/leaves passthrough mode */
|
||||||
|
void pa_source_enter_passthrough(pa_source *s);
|
||||||
|
void pa_source_leave_passthrough(pa_source *s);
|
||||||
|
|
||||||
void pa_source_set_volume(pa_source *source, const pa_cvolume *volume, pa_bool_t sendmsg, pa_bool_t save);
|
void pa_source_set_volume(pa_source *source, const pa_cvolume *volume, pa_bool_t sendmsg, pa_bool_t save);
|
||||||
const pa_cvolume *pa_source_get_volume(pa_source *source, pa_bool_t force_refresh);
|
const pa_cvolume *pa_source_get_volume(pa_source *source, pa_bool_t force_refresh);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue