sink, source: Drop redundant restore argument to reconfigure

The sample spec's NULLness is sufficient to determine whether we are
restoring or not.
This commit is contained in:
Arun Raghavan 2022-01-12 16:23:36 -05:00
parent 6afdebb55f
commit 5d1184b35a
6 changed files with 22 additions and 35 deletions

View file

@ -493,8 +493,7 @@ int pa_sink_input_new(
module-suspend-on-idle can resume a sink */ module-suspend-on-idle can resume a sink */
pa_log_info("Trying to change sample spec"); 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), pa_sink_reconfigure(data->sink, &data->sample_spec, &data->channel_map, pa_sink_input_new_data_is_passthrough(data));
false);
} }
if (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)) { !pa_sample_spec_equal(&i->sample_spec, &i->sink->sample_spec)) {
/* We were uncorked and the sink was not playing anything -- let's try /* We were uncorked and the sink was not playing anything -- let's try
* to update the sample format and rate to avoid resampling */ * 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); 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)) { if (pa_sink_input_is_passthrough(i)) {
pa_log_debug("Leaving passthrough, trying to restore previous configuration"); 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)) { if (pa_sink_input_is_passthrough(i)) {
pa_log_debug("Leaving passthrough, trying to restore previous configuration"); 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) 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 */ SINK_INPUT_MOVE_FINISH hook */
pa_log_info("Trying to change sample spec"); 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) if (i->moving)

View file

@ -1494,7 +1494,7 @@ void pa_sink_render_full(pa_sink *s, size_t length, pa_memchunk *result) {
} }
/* Called from main thread */ /* 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; int ret = -1;
pa_sample_spec desired_spec; pa_sample_spec desired_spec;
pa_sample_format_t default_format = s->default_sample_spec.format; 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_resampling = s->avoid_resampling;
bool avoid_processing = s->avoid_processing; bool avoid_processing = s->avoid_processing;
pa_channel_map old_map, *new_map; pa_channel_map old_map, *new_map;
bool restore = spec == NULL;
pa_assert(restore || (spec != NULL)); pa_assert(spec != NULL || (map == NULL && pa_sample_spec_valid(&s->saved_spec)));
pa_assert(!restore || (spec == NULL && map == NULL && pa_sample_spec_valid(&s->saved_spec)));
if (!restore && pa_sample_spec_equal(spec, &s->sample_spec)) if (!restore && pa_sample_spec_equal(spec, &s->sample_spec))
return 0; return 0;
@ -1614,15 +1614,9 @@ int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, pa_channel_map *map, b
if (restore) { if (restore) {
/* Restore the previous channel map as well */ /* Restore the previous channel map as well */
new_map = &s->saved_map; new_map = &s->saved_map;
} else if (map) { } else {
/* Set the requested channel map */ /* Set the requested channel map */
new_map = 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) { 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 */ /* update monitor source as well */
if (s->monitor_source && !passthrough) 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_log_info("Reconfigured successfully to: %s",
pa_sample_spec_snprint(spec_str, sizeof(spec_str), &desired_spec)); pa_sample_spec_snprint(spec_str, sizeof(spec_str), &desired_spec));

View file

@ -456,7 +456,7 @@ unsigned pa_device_init_priority(pa_proplist *p);
/**** May be called by everyone, from main context */ /**** 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); 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! */ /* The returned value is supposed to be in the time domain of the sound card! */

View file

@ -381,7 +381,7 @@ int pa_source_output_new(
pa_log_info("Trying to change sample spec"); pa_log_info("Trying to change sample spec");
pa_source_reconfigure(data->source, &data->sample_spec, &data->channel_map, 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) && 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)) { !pa_sample_spec_equal(&o->sample_spec, &o->source->sample_spec)) {
/* We were uncorked and the source was not playing anything -- let's try /* We were uncorked and the source was not playing anything -- let's try
* to update the sample format and rate to avoid resampling */ * 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); 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)) { if (pa_source_output_is_passthrough(o)) {
pa_log_debug("Leaving passthrough, trying to restore previous configuration"); 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)) { if (pa_source_output_is_passthrough(o)) {
pa_log_debug("Leaving passthrough, trying to restore previous configuration"); 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); 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 */ SOURCE_OUTPUT_MOVE_FINISH hook */
pa_log_info("Trying to change sample spec"); 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) if (o->moving)

View file

@ -1059,7 +1059,7 @@ void pa_source_post_direct(pa_source*s, pa_source_output *o, const pa_memchunk *
} }
/* Called from main thread */ /* 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; int ret;
pa_sample_spec desired_spec; pa_sample_spec desired_spec;
pa_sample_format_t default_format = s->default_sample_spec.format; 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_resampling = s->avoid_resampling;
bool avoid_processing = s->avoid_processing; bool avoid_processing = s->avoid_processing;
pa_channel_map old_map, *new_map; pa_channel_map old_map, *new_map;
bool restore = spec == NULL;
pa_assert(restore || (spec != NULL)); pa_assert(spec != NULL || (map == NULL && pa_sample_spec_valid(&s->saved_spec)));
pa_assert(!restore || (spec == NULL && map == NULL && pa_sample_spec_valid(&s->saved_spec)));
if (!restore && pa_sample_spec_equal(spec, &s->sample_spec)) if (!restore && pa_sample_spec_equal(spec, &s->sample_spec))
return 0; return 0;
@ -1178,15 +1178,9 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *ma
if (restore) { if (restore) {
/* Restore the previous channel map as well */ /* Restore the previous channel map as well */
new_map = &s->saved_map; new_map = &s->saved_map;
} else if (map) { } else {
/* Set the requested channel map */ /* Set the requested channel map */
new_map = 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) if (s->reconfigure)
@ -1200,7 +1194,7 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, pa_channel_map *ma
if (!passthrough) { if (!passthrough) {
pa_sample_spec old_spec = s->sample_spec; pa_sample_spec old_spec = s->sample_spec;
s->sample_spec = desired_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) { if (ret < 0) {
/* Changing the sink rate failed, roll back the old rate for /* Changing the sink rate failed, roll back the old rate for

View file

@ -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_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_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 */ unsigned pa_source_used_by(pa_source *s); /* Number of connected streams that are not corked */