sink-input: change bool save_sink to char *preferred_sink

The finial objective is to store the preferred sink name in the
sink-input struct, and use module-stream-restore to save and restore
it.

This patch just replaces the save_sink with preferred_sink, and tries
to keep the original logic.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
This commit is contained in:
Hui Wang 2019-01-15 12:12:52 +08:00
parent 26a66d103f
commit fbf8716685
6 changed files with 55 additions and 28 deletions

View file

@ -190,7 +190,10 @@ bool pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink *s, b
if (!data->req_formats) {
/* We're not working with the extended API */
data->sink = s;
data->save_sink = save;
if (save) {
pa_xfree(data->preferred_sink);
data->preferred_sink = pa_xstrdup(s->name);
}
data->sink_requested_by_application = requested_by_application;
} else {
/* Extended API: let's see if this sink supports the formats the client can provide */
@ -199,7 +202,10 @@ bool pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink *s, b
if (formats && !pa_idxset_isempty(formats)) {
/* Sink supports at least one of the requested formats */
data->sink = s;
data->save_sink = save;
if (save) {
pa_xfree(data->preferred_sink);
data->preferred_sink = pa_xstrdup(s->name);
}
data->sink_requested_by_application = requested_by_application;
if (data->nego_formats)
pa_idxset_free(data->nego_formats, (pa_free_cb_t) pa_format_info_free);
@ -226,7 +232,7 @@ bool pa_sink_input_new_data_set_formats(pa_sink_input_new_data *data, pa_idxset
if (data->sink) {
/* Trigger format negotiation */
return pa_sink_input_new_data_set_sink(data, data->sink, data->save_sink, data->sink_requested_by_application);
return pa_sink_input_new_data_set_sink(data, data->sink, (data->preferred_sink != NULL), data->sink_requested_by_application);
}
return true;
@ -250,6 +256,9 @@ void pa_sink_input_new_data_done(pa_sink_input_new_data *data) {
if (data->volume_factor_sink_items)
pa_hashmap_free(data->volume_factor_sink_items);
if (data->preferred_sink)
pa_xfree(data->preferred_sink);
pa_proplist_free(data->proplist);
}
@ -518,7 +527,7 @@ int pa_sink_input_new(
pa_cvolume_reset(&i->real_ratio, i->sample_spec.channels);
i->volume_writable = data->volume_writable;
i->save_volume = data->save_volume;
i->save_sink = data->save_sink;
i->preferred_sink = pa_xstrdup(data->preferred_sink);
i->save_muted = data->save_muted;
i->muted = data->muted;
@ -776,6 +785,9 @@ static void sink_input_free(pa_object *o) {
if (i->volume_factor_sink_items)
pa_hashmap_free(i->volume_factor_sink_items);
if (i->preferred_sink)
pa_xfree(i->preferred_sink);
pa_xfree(i->driver);
pa_xfree(i);
}
@ -1914,7 +1926,12 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, bool save) {
i->moving(i, dest);
i->sink = dest;
i->save_sink = save;
/* save == true, means user is calling the move_to() and want to
save the preferred_sink */
if (save) {
pa_xfree(i->preferred_sink);
i->preferred_sink = pa_xstrdup(dest->name);
}
pa_idxset_put(dest->inputs, pa_sink_input_ref(i), NULL);
PA_HASHMAP_FOREACH(v, i->volume_factor_sink_items, state)

View file

@ -119,11 +119,16 @@ struct pa_sink_input {
bool muted:1;
/* if true then the sink we are connected to and/or the volume
* set is worth remembering, i.e. was explicitly chosen by the
* user and not automatically. module-stream-restore looks for
/* if true then the volume and the mute state of this sink-input
* are worth remembering, module-stream-restore looks for
* this.*/
bool save_sink:1, save_volume:1, save_muted:1;
bool save_volume:1, save_muted:1;
/* if users move the sink-input to a sink, and the sink is not default_sink,
* the sink->name will be saved in preferred_sink. And later if sink-input
* is moved to other sinks for some reason, it still can be restored to the
* preferred_sink at an appropriate time */
char *preferred_sink;
pa_resample_method_t requested_resample_method, actual_resample_method;
@ -315,7 +320,9 @@ typedef struct pa_sink_input_new_data {
bool volume_writable:1;
bool save_sink:1, save_volume:1, save_muted:1;
bool save_volume:1, save_muted:1;
char *preferred_sink;
} pa_sink_input_new_data;
pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data);