From 5d1184b35a0e469d66bd6406b50855fd2ffc389f Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 12 Jan 2022 16:23:36 -0500 Subject: [PATCH] sink, source: Drop redundant restore argument to reconfigure The sample spec's NULLness is sufficient to determine whether we are restoring or not. --- src/pulsecore/sink-input.c | 11 +++++------ src/pulsecore/sink.c | 16 +++++----------- src/pulsecore/sink.h | 2 +- src/pulsecore/source-output.c | 10 +++++----- src/pulsecore/source.c | 16 +++++----------- src/pulsecore/source.h | 2 +- 6 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c index 958bf76bb..03518845b 100644 --- a/src/pulsecore/sink-input.c +++ b/src/pulsecore/sink-input.c @@ -493,8 +493,7 @@ int pa_sink_input_new( module-suspend-on-idle can resume a sink */ pa_log_info("Trying to change sample spec"); - pa_sink_reconfigure(data->sink, &data->sample_spec, &data->channel_map, pa_sink_input_new_data_is_passthrough(data), - false); + pa_sink_reconfigure(data->sink, &data->sample_spec, &data->channel_map, pa_sink_input_new_data_is_passthrough(data)); } if (pa_sink_input_new_data_is_passthrough(data) && @@ -710,7 +709,7 @@ static void sink_input_set_state(pa_sink_input *i, pa_sink_input_state_t state) !pa_sample_spec_equal(&i->sample_spec, &i->sink->sample_spec)) { /* We were uncorked and the sink was not playing anything -- let's try * to update the sample format and rate to avoid resampling */ - pa_sink_reconfigure(i->sink, &i->sample_spec, &i->channel_map, pa_sink_input_is_passthrough(i), false); + pa_sink_reconfigure(i->sink, &i->sample_spec, &i->channel_map, pa_sink_input_is_passthrough(i)); } pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL) == 0); @@ -815,7 +814,7 @@ void pa_sink_input_unlink(pa_sink_input *i) { if (pa_sink_input_is_passthrough(i)) { pa_log_debug("Leaving passthrough, trying to restore previous configuration"); - pa_sink_reconfigure(i->sink, NULL, NULL, false, true); + pa_sink_reconfigure(i->sink, NULL, NULL, false); } } @@ -1901,7 +1900,7 @@ int pa_sink_input_start_move(pa_sink_input *i) { if (pa_sink_input_is_passthrough(i)) { pa_log_debug("Leaving passthrough, trying to restore previous configuration"); - pa_sink_reconfigure(i->sink, NULL, NULL, false, true); + pa_sink_reconfigure(i->sink, NULL, NULL, false); } PA_HASHMAP_FOREACH(v, i->volume_factor_sink_items, state) @@ -2179,7 +2178,7 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, bool save) { SINK_INPUT_MOVE_FINISH hook */ pa_log_info("Trying to change sample spec"); - pa_sink_reconfigure(dest, &i->sample_spec, &i->channel_map, pa_sink_input_is_passthrough(i), false); + pa_sink_reconfigure(dest, &i->sample_spec, &i->channel_map, pa_sink_input_is_passthrough(i)); } if (i->moving) diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index e6236fb91..cb62d7c81 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -1494,7 +1494,7 @@ void pa_sink_render_full(pa_sink *s, size_t length, pa_memchunk *result) { } /* Called from main thread */ -int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough, bool restore) { +int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough) { int ret = -1; pa_sample_spec desired_spec; pa_sample_format_t default_format = s->default_sample_spec.format; @@ -1508,9 +1508,9 @@ int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, b bool avoid_resampling = s->avoid_resampling; bool avoid_processing = s->avoid_processing; pa_channel_map old_map, *new_map; + bool restore = spec == NULL; - pa_assert(restore || (spec != NULL)); - pa_assert(!restore || (spec == NULL && map == NULL && pa_sample_spec_valid(&s->saved_spec))); + pa_assert(spec != NULL || (map == NULL && pa_sample_spec_valid(&s->saved_spec))); if (!restore && pa_sample_spec_equal(spec, &s->sample_spec)) return 0; @@ -1614,15 +1614,9 @@ int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, b if (restore) { /* Restore the previous channel map as well */ new_map = &s->saved_map; - } else if (map) { + } else { /* Set the requested channel map */ new_map = map; - } else if (desired_spec.channels == s->sample_spec.channels) { - /* No requested channel map, but channel count is unchanged so don't change */ - new_map = &s->channel_map; - } else { - /* No requested channel map, let the device decide */ - new_map = NULL; } if (s->reconfigure(s, &desired_spec, new_map, passthrough) >= 0) { @@ -1630,7 +1624,7 @@ int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, b /* update monitor source as well */ if (s->monitor_source && !passthrough) - pa_source_reconfigure(s->monitor_source, &desired_spec, new_map, false, false); + pa_source_reconfigure(s->monitor_source, &desired_spec, new_map, false); pa_log_info("Reconfigured successfully to: %s", pa_sample_spec_snprint(spec_str, sizeof(spec_str), &desired_spec)); diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h index eab41b7c3..0bd6203fc 100644 --- a/src/pulsecore/sink.h +++ b/src/pulsecore/sink.h @@ -456,7 +456,7 @@ unsigned pa_device_init_priority(pa_proplist *p); /**** May be called by everyone, from main context */ -int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough, bool restore); +int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough); void pa_sink_set_port_latency_offset(pa_sink *s, int64_t offset); /* The returned value is supposed to be in the time domain of the sound card! */ diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c index 136c0518c..679475379 100644 --- a/src/pulsecore/source-output.c +++ b/src/pulsecore/source-output.c @@ -381,7 +381,7 @@ int pa_source_output_new( pa_log_info("Trying to change sample spec"); pa_source_reconfigure(data->source, &data->sample_spec, &data->channel_map, - pa_source_output_new_data_is_passthrough(data), false); + pa_source_output_new_data_is_passthrough(data)); } if (pa_source_output_new_data_is_passthrough(data) && @@ -560,7 +560,7 @@ static void source_output_set_state(pa_source_output *o, pa_source_output_state_ !pa_sample_spec_equal(&o->sample_spec, &o->source->sample_spec)) { /* We were uncorked and the source was not playing anything -- let's try * to update the sample format and rate to avoid resampling */ - pa_source_reconfigure(o->source, &o->sample_spec, &o->channel_map, pa_source_output_is_passthrough(o), false); + pa_source_reconfigure(o->source, &o->sample_spec, &o->channel_map, pa_source_output_is_passthrough(o)); } pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL) == 0); @@ -631,7 +631,7 @@ void pa_source_output_unlink(pa_source_output*o) { if (pa_source_output_is_passthrough(o)) { pa_log_debug("Leaving passthrough, trying to restore previous configuration"); - pa_source_reconfigure(o->source, NULL, NULL, false, true); + pa_source_reconfigure(o->source, NULL, NULL, false); } } @@ -1412,7 +1412,7 @@ int pa_source_output_start_move(pa_source_output *o) { if (pa_source_output_is_passthrough(o)) { pa_log_debug("Leaving passthrough, trying to restore previous configuration"); - pa_source_reconfigure(o->source, NULL, NULL, false, true); + pa_source_reconfigure(o->source, NULL, NULL, false); } pa_cvolume_remap(&o->volume_factor_source, &o->source->channel_map, &o->channel_map); @@ -1608,7 +1608,7 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, bool save SOURCE_OUTPUT_MOVE_FINISH hook */ pa_log_info("Trying to change sample spec"); - pa_source_reconfigure(dest, &o->sample_spec, &o->channel_map, pa_source_output_is_passthrough(o), false); + pa_source_reconfigure(dest, &o->sample_spec, &o->channel_map, pa_source_output_is_passthrough(o)); } if (o->moving) diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 77a4fe626..e4d351581 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -1059,7 +1059,7 @@ void pa_source_post_direct(pa_source*s, pa_source_output *o, const pa_memchunk * } /* Called from main thread */ -int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough, bool restore) { +int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough) { int ret; pa_sample_spec desired_spec; pa_sample_format_t default_format = s->default_sample_spec.format; @@ -1071,9 +1071,9 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *ma bool avoid_resampling = s->avoid_resampling; bool avoid_processing = s->avoid_processing; pa_channel_map old_map, *new_map; + bool restore = spec == NULL; - pa_assert(restore || (spec != NULL)); - pa_assert(!restore || (spec == NULL && map == NULL && pa_sample_spec_valid(&s->saved_spec))); + pa_assert(spec != NULL || (map == NULL && pa_sample_spec_valid(&s->saved_spec))); if (!restore && pa_sample_spec_equal(spec, &s->sample_spec)) return 0; @@ -1178,15 +1178,9 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *ma if (restore) { /* Restore the previous channel map as well */ new_map = &s->saved_map; - } else if (map) { + } else { /* Set the requested channel map */ new_map = map; - } else if (desired_spec.channels == s->sample_spec.channels) { - /* No requested channel map, but channel count is unchanged so don't change */ - new_map = &s->channel_map; - } else { - /* No requested channel map, let the device decide */ - new_map = NULL; } if (s->reconfigure) @@ -1200,7 +1194,7 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *ma if (!passthrough) { pa_sample_spec old_spec = s->sample_spec; s->sample_spec = desired_spec; - ret = pa_sink_reconfigure(s->monitor_of, &desired_spec, new_map, false, false); + ret = pa_sink_reconfigure(s->monitor_of, &desired_spec, new_map, false); if (ret < 0) { /* Changing the sink rate failed, roll back the old rate for diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h index 2a24264a7..6decf96d2 100644 --- a/src/pulsecore/source.h +++ b/src/pulsecore/source.h @@ -422,7 +422,7 @@ bool pa_source_update_proplist(pa_source *s, pa_update_mode_t mode, pa_proplist int pa_source_set_port(pa_source *s, const char *name, bool save); -int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough, bool restore); +int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *map, bool passthrough); unsigned pa_source_linked_by(pa_source *s); /* Number of connected streams */ unsigned pa_source_used_by(pa_source *s); /* Number of connected streams that are not corked */