[pulseaudio-discuss] [PATCH 1/2] sink-input, source-output: add sink/source_requested_by_application flag

Tanu Kaskinen tanuk at iki.fi
Tue Nov 28 17:50:01 UTC 2017


When a stream is created, and the stream creator specifies which device
should be used, that can affect automatic routing policies.
Specifically, module-device-manager shouldn't apply its priority list
routing when a stream has been routed by the application that created
the stream.

A stream that was initially routed by the application may be moved for
some valid reason (e.g. user requesting a move, or the original device
disappearing). When the stream is moved away from its initial device,
the "device requested by application" flag isn't relevant any more, so
it's set to false and never reset to true again.

The change in module-device-manager's routing logic will be done in the
following patch.
---
 src/modules/echo-cancel/module-echo-cancel.c |  4 ++--
 src/modules/module-allow-passthrough.c       |  4 ++--
 src/modules/module-combine-sink.c            |  2 +-
 src/modules/module-device-manager.c          |  4 ++--
 src/modules/module-equalizer-sink.c          |  2 +-
 src/modules/module-intended-roles.c          |  8 ++++----
 src/modules/module-ladspa-sink.c             |  2 +-
 src/modules/module-loopback.c                |  4 ++--
 src/modules/module-remap-sink.c              |  2 +-
 src/modules/module-remap-source.c            |  2 +-
 src/modules/module-sine.c                    |  2 +-
 src/modules/module-stream-restore.c          |  4 ++--
 src/modules/module-virtual-sink.c            |  2 +-
 src/modules/module-virtual-source.c          |  2 +-
 src/modules/module-virtual-surround-sink.c   |  2 +-
 src/modules/rtp/module-rtp-recv.c            |  2 +-
 src/modules/rtp/module-rtp-send.c            |  2 +-
 src/pulsecore/play-memblockq.c               |  2 +-
 src/pulsecore/protocol-esound.c              |  4 ++--
 src/pulsecore/protocol-http.c                |  2 +-
 src/pulsecore/protocol-native.c              |  4 ++--
 src/pulsecore/protocol-simple.c              |  4 ++--
 src/pulsecore/sink-input.c                   | 10 +++++++---
 src/pulsecore/sink-input.h                   | 11 ++++++++++-
 src/pulsecore/sound-file-stream.c            |  2 +-
 src/pulsecore/source-output.c                | 12 +++++++++---
 src/pulsecore/source-output.h                | 13 ++++++++++++-
 27 files changed, 72 insertions(+), 42 deletions(-)

diff --git a/src/modules/echo-cancel/module-echo-cancel.c b/src/modules/echo-cancel/module-echo-cancel.c
index b28d60a60..3814884b6 100644
--- a/src/modules/echo-cancel/module-echo-cancel.c
+++ b/src/modules/echo-cancel/module-echo-cancel.c
@@ -1928,7 +1928,7 @@ int pa__init(pa_module*m) {
     pa_source_output_new_data_init(&source_output_data);
     source_output_data.driver = __FILE__;
     source_output_data.module = m;
-    pa_source_output_new_data_set_source(&source_output_data, source_master, false);
+    pa_source_output_new_data_set_source(&source_output_data, source_master, false, true);
     source_output_data.destination_source = u->source;
 
     pa_proplist_sets(source_output_data.proplist, PA_PROP_MEDIA_NAME, "Echo-Cancel Source Stream");
@@ -1967,7 +1967,7 @@ int pa__init(pa_module*m) {
     pa_sink_input_new_data_init(&sink_input_data);
     sink_input_data.driver = __FILE__;
     sink_input_data.module = m;
-    pa_sink_input_new_data_set_sink(&sink_input_data, sink_master, false);
+    pa_sink_input_new_data_set_sink(&sink_input_data, sink_master, false, true);
     sink_input_data.origin_sink = u->sink;
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "Echo-Cancel Sink Stream");
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter");
diff --git a/src/modules/module-allow-passthrough.c b/src/modules/module-allow-passthrough.c
index 63b621fb5..aea81cb52 100644
--- a/src/modules/module-allow-passthrough.c
+++ b/src/modules/module-allow-passthrough.c
@@ -180,7 +180,7 @@ static pa_hook_result_t sink_input_new_cb(pa_core *core, pa_sink_input_new_data
     if (!new_data->sink) {
         pa_sink *sink = pa_namereg_get(core, NULL, PA_NAMEREG_SINK);
         pa_return_val_if_fail(sink, -PA_ERR_NOENTITY);
-        pa_sink_input_new_data_set_sink(new_data, sink, false);
+        pa_sink_input_new_data_set_sink(new_data, sink, false, false);
     }
 
     if (!new_data->format && new_data->nego_formats && !pa_idxset_isempty(new_data->nego_formats))
@@ -193,7 +193,7 @@ static pa_hook_result_t sink_input_new_cb(pa_core *core, pa_sink_input_new_data
 
     if (null_sink) {
         pa_log_info("Already playing a passthrough stream; re-routing new stream to the null sink");
-        pa_sink_input_new_data_set_sink(new_data, null_sink, false);
+        pa_sink_input_new_data_set_sink(new_data, null_sink, false, false);
     }
 
     return PA_HOOK_OK;
diff --git a/src/modules/module-combine-sink.c b/src/modules/module-combine-sink.c
index 4aa7de921..ce6eb7766 100644
--- a/src/modules/module-combine-sink.c
+++ b/src/modules/module-combine-sink.c
@@ -974,7 +974,7 @@ static int output_create_sink_input(struct output *o) {
     u = o->userdata;
 
     pa_sink_input_new_data_init(&data);
-    pa_sink_input_new_data_set_sink(&data, o->sink, false);
+    pa_sink_input_new_data_set_sink(&data, o->sink, false, true);
     data.driver = __FILE__;
     pa_proplist_setf(data.proplist, PA_PROP_MEDIA_NAME, "Simultaneous output on %s", pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
     pa_proplist_sets(data.proplist, PA_PROP_MEDIA_ROLE, "filter");
diff --git a/src/modules/module-device-manager.c b/src/modules/module-device-manager.c
index 2a0a67f04..5d04bb667 100644
--- a/src/modules/module-device-manager.c
+++ b/src/modules/module-device-manager.c
@@ -996,7 +996,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
                 pa_sink *sink;
 
                 if ((sink = pa_idxset_get_by_index(u->core->sinks, device_index))) {
-                    if (!pa_sink_input_new_data_set_sink(new_data, sink, false))
+                    if (!pa_sink_input_new_data_set_sink(new_data, sink, false, false))
                         pa_log_debug("Not restoring device for stream because no supported format was found");
                 }
             }
@@ -1036,7 +1036,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
                 pa_source *source;
 
                 if ((source = pa_idxset_get_by_index(u->core->sources, device_index)))
-                    if (!pa_source_output_new_data_set_source(new_data, source, false))
+                    if (!pa_source_output_new_data_set_source(new_data, source, false, false))
                         pa_log_debug("Not restoring device for stream because no supported format was found");
             }
         }
diff --git a/src/modules/module-equalizer-sink.c b/src/modules/module-equalizer-sink.c
index 489062fc0..737453ca9 100644
--- a/src/modules/module-equalizer-sink.c
+++ b/src/modules/module-equalizer-sink.c
@@ -1254,7 +1254,7 @@ int pa__init(pa_module*m) {
     pa_sink_input_new_data_init(&sink_input_data);
     sink_input_data.driver = __FILE__;
     sink_input_data.module = m;
-    pa_sink_input_new_data_set_sink(&sink_input_data, master, false);
+    pa_sink_input_new_data_set_sink(&sink_input_data, master, false, true);
     sink_input_data.origin_sink = u->sink;
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "Equalized Stream");
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter");
diff --git a/src/modules/module-intended-roles.c b/src/modules/module-intended-roles.c
index f906b8800..733568cde 100644
--- a/src/modules/module-intended-roles.c
+++ b/src/modules/module-intended-roles.c
@@ -93,7 +93,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
 
     /* Prefer the default sink over any other sink, just in case... */
     if (c->default_sink)
-        if (role_match(c->default_sink->proplist, role) && pa_sink_input_new_data_set_sink(new_data, c->default_sink, false))
+        if (role_match(c->default_sink->proplist, role) && pa_sink_input_new_data_set_sink(new_data, c->default_sink, false, false))
             return PA_HOOK_OK;
 
     /* @todo: favour the highest priority device, not the first one we find? */
@@ -104,7 +104,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
         if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)))
             continue;
 
-        if (role_match(s->proplist, role) && pa_sink_input_new_data_set_sink(new_data, s, false))
+        if (role_match(s->proplist, role) && pa_sink_input_new_data_set_sink(new_data, s, false, false))
             return PA_HOOK_OK;
     }
 
@@ -138,7 +138,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
     /* Prefer the default source over any other source, just in case... */
     if (c->default_source)
         if (role_match(c->default_source->proplist, role)) {
-            pa_source_output_new_data_set_source(new_data, c->default_source, false);
+            pa_source_output_new_data_set_source(new_data, c->default_source, false, false);
             return PA_HOOK_OK;
         }
 
@@ -154,7 +154,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
 
         /* @todo: favour the highest priority device, not the first one we find? */
         if (role_match(s->proplist, role)) {
-            pa_source_output_new_data_set_source(new_data, s, false);
+            pa_source_output_new_data_set_source(new_data, s, false, false);
             return PA_HOOK_OK;
         }
     }
diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c
index 38be12b95..0493da894 100644
--- a/src/modules/module-ladspa-sink.c
+++ b/src/modules/module-ladspa-sink.c
@@ -1308,7 +1308,7 @@ int pa__init(pa_module*m) {
     pa_sink_input_new_data_init(&sink_input_data);
     sink_input_data.driver = __FILE__;
     sink_input_data.module = m;
-    pa_sink_input_new_data_set_sink(&sink_input_data, master, false);
+    pa_sink_input_new_data_set_sink(&sink_input_data, master, false, true);
     sink_input_data.origin_sink = u->sink;
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "LADSPA Stream");
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter");
diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index bb8024b4d..9d9b4ba3a 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -1370,7 +1370,7 @@ int pa__init(pa_module *m) {
     sink_input_data.module = m;
 
     if (sink)
-        pa_sink_input_new_data_set_sink(&sink_input_data, sink, false);
+        pa_sink_input_new_data_set_sink(&sink_input_data, sink, false, true);
 
     if (pa_modargs_get_proplist(ma, "sink_input_properties", sink_input_data.proplist, PA_UPDATE_REPLACE) < 0) {
         pa_log("Failed to parse the sink_input_properties value.");
@@ -1437,7 +1437,7 @@ int pa__init(pa_module *m) {
     source_output_data.driver = __FILE__;
     source_output_data.module = m;
     if (source)
-        pa_source_output_new_data_set_source(&source_output_data, source, false);
+        pa_source_output_new_data_set_source(&source_output_data, source, false, true);
 
     if (pa_modargs_get_proplist(ma, "source_output_properties", source_output_data.proplist, PA_UPDATE_REPLACE) < 0) {
         pa_log("Failed to parse the source_output_properties value.");
diff --git a/src/modules/module-remap-sink.c b/src/modules/module-remap-sink.c
index a2a8e3194..44372d0c0 100644
--- a/src/modules/module-remap-sink.c
+++ b/src/modules/module-remap-sink.c
@@ -423,7 +423,7 @@ int pa__init(pa_module*m) {
     pa_sink_input_new_data_init(&sink_input_data);
     sink_input_data.driver = __FILE__;
     sink_input_data.module = m;
-    pa_sink_input_new_data_set_sink(&sink_input_data, master, false);
+    pa_sink_input_new_data_set_sink(&sink_input_data, master, false, true);
     sink_input_data.origin_sink = u->sink;
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "Remapped Stream");
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter");
diff --git a/src/modules/module-remap-source.c b/src/modules/module-remap-source.c
index 980f2554a..4f27aedbd 100644
--- a/src/modules/module-remap-source.c
+++ b/src/modules/module-remap-source.c
@@ -380,7 +380,7 @@ int pa__init(pa_module*m) {
     pa_source_output_new_data_init(&source_output_data);
     source_output_data.driver = __FILE__;
     source_output_data.module = m;
-    pa_source_output_new_data_set_source(&source_output_data, master, false);
+    pa_source_output_new_data_set_source(&source_output_data, master, false, true);
     source_output_data.destination_source = u->source;
 
     pa_proplist_sets(source_output_data.proplist, PA_PROP_MEDIA_NAME, "Remapped Stream");
diff --git a/src/modules/module-sine.c b/src/modules/module-sine.c
index 459207176..e03eb9687 100644
--- a/src/modules/module-sine.c
+++ b/src/modules/module-sine.c
@@ -160,7 +160,7 @@ int pa__init(pa_module*m) {
     pa_sink_input_new_data_init(&data);
     data.driver = __FILE__;
     data.module = m;
-    pa_sink_input_new_data_set_sink(&data, sink, false);
+    pa_sink_input_new_data_set_sink(&data, sink, false, true);
     pa_proplist_setf(data.proplist, PA_PROP_MEDIA_NAME, "%u Hz Sine", frequency);
     pa_proplist_sets(data.proplist, PA_PROP_MEDIA_ROLE, "abstract");
     pa_proplist_setf(data.proplist, "sine.hz", "%u", frequency);
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index eb758330c..d99bb5814 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -1451,7 +1451,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
            same time, in which case we want to make sure we don't
            interfere with that */
         if (s && PA_SINK_IS_LINKED(pa_sink_get_state(s)))
-            if (pa_sink_input_new_data_set_sink(new_data, s, true))
+            if (pa_sink_input_new_data_set_sink(new_data, s, true, false))
                 pa_log_info("Restoring device for stream %s.", name);
 
         entry_free(e);
@@ -1555,7 +1555,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
            interfere with that */
         if (s && PA_SOURCE_IS_LINKED(pa_source_get_state(s))) {
             pa_log_info("Restoring device for stream %s.", name);
-            pa_source_output_new_data_set_source(new_data, s, true);
+            pa_source_output_new_data_set_source(new_data, s, true, false);
         }
 
         entry_free(e);
diff --git a/src/modules/module-virtual-sink.c b/src/modules/module-virtual-sink.c
index faa552433..14aa13fc4 100644
--- a/src/modules/module-virtual-sink.c
+++ b/src/modules/module-virtual-sink.c
@@ -576,7 +576,7 @@ int pa__init(pa_module*m) {
     pa_sink_input_new_data_init(&sink_input_data);
     sink_input_data.driver = __FILE__;
     sink_input_data.module = m;
-    pa_sink_input_new_data_set_sink(&sink_input_data, master, false);
+    pa_sink_input_new_data_set_sink(&sink_input_data, master, false, true);
     sink_input_data.origin_sink = u->sink;
     pa_proplist_setf(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "Virtual Sink Stream from %s", pa_proplist_gets(u->sink->proplist, PA_PROP_DEVICE_DESCRIPTION));
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter");
diff --git a/src/modules/module-virtual-source.c b/src/modules/module-virtual-source.c
index 8ec4525a7..8d8b20ae0 100644
--- a/src/modules/module-virtual-source.c
+++ b/src/modules/module-virtual-source.c
@@ -599,7 +599,7 @@ int pa__init(pa_module*m) {
     pa_source_output_new_data_init(&source_output_data);
     source_output_data.driver = __FILE__;
     source_output_data.module = m;
-    pa_source_output_new_data_set_source(&source_output_data, master, false);
+    pa_source_output_new_data_set_source(&source_output_data, master, false, true);
     source_output_data.destination_source = u->source;
 
     pa_proplist_setf(source_output_data.proplist, PA_PROP_MEDIA_NAME, "Virtual Source Stream of %s", pa_proplist_gets(u->source->proplist, PA_PROP_DEVICE_DESCRIPTION));
diff --git a/src/modules/module-virtual-surround-sink.c b/src/modules/module-virtual-surround-sink.c
index 09c5e6dd4..fa304c1fa 100644
--- a/src/modules/module-virtual-surround-sink.c
+++ b/src/modules/module-virtual-surround-sink.c
@@ -750,7 +750,7 @@ int pa__init(pa_module*m) {
     pa_sink_input_new_data_init(&sink_input_data);
     sink_input_data.driver = __FILE__;
     sink_input_data.module = m;
-    pa_sink_input_new_data_set_sink(&sink_input_data, master, false);
+    pa_sink_input_new_data_set_sink(&sink_input_data, master, false, true);
     sink_input_data.origin_sink = u->sink;
     pa_proplist_setf(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "Virtual Surround Sink Stream from %s", pa_proplist_gets(u->sink->proplist, PA_PROP_DEVICE_DESCRIPTION));
     pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter");
diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index f512a8a1e..8224163bd 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -527,7 +527,7 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in
         goto fail;
 
     pa_sink_input_new_data_init(&data);
-    pa_sink_input_new_data_set_sink(&data, sink, false);
+    pa_sink_input_new_data_set_sink(&data, sink, false, true);
     data.driver = __FILE__;
     pa_proplist_sets(data.proplist, PA_PROP_MEDIA_ROLE, "stream");
     pa_proplist_setf(data.proplist, PA_PROP_MEDIA_NAME,
diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c
index 15a7436cb..ab594ac07 100644
--- a/src/modules/rtp/module-rtp-send.c
+++ b/src/modules/rtp/module-rtp-send.c
@@ -430,7 +430,7 @@ int pa__init(pa_module*m) {
     pa_proplist_setf(data.proplist, "rtp.ttl", "%lu", (unsigned long) ttl);
     data.driver = __FILE__;
     data.module = m;
-    pa_source_output_new_data_set_source(&data, s, false);
+    pa_source_output_new_data_set_source(&data, s, false, true);
     pa_source_output_new_data_set_sample_spec(&data, &ss);
     pa_source_output_new_data_set_channel_map(&data, &cm);
     data.flags |= get_dont_inhibit_auto_suspend_flag(s, inhibit_auto_suspend);
diff --git a/src/pulsecore/play-memblockq.c b/src/pulsecore/play-memblockq.c
index c86bd15f3..da586a82b 100644
--- a/src/pulsecore/play-memblockq.c
+++ b/src/pulsecore/play-memblockq.c
@@ -197,7 +197,7 @@ pa_sink_input* pa_memblockq_sink_input_new(
     u->memblockq = NULL;
 
     pa_sink_input_new_data_init(&data);
-    pa_sink_input_new_data_set_sink(&data, sink, false);
+    pa_sink_input_new_data_set_sink(&data, sink, false, true);
     data.driver = __FILE__;
     pa_sink_input_new_data_set_sample_spec(&data, ss);
     pa_sink_input_new_data_set_channel_map(&data, map);
diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c
index a0aca9758..708fa16b0 100644
--- a/src/pulsecore/protocol-esound.c
+++ b/src/pulsecore/protocol-esound.c
@@ -423,7 +423,7 @@ static int esd_proto_stream_play(connection *c, esd_proto_t request, const void
     sdata.module = c->options->module;
     sdata.client = c->client;
     if (sink)
-        pa_sink_input_new_data_set_sink(&sdata, sink, false);
+        pa_sink_input_new_data_set_sink(&sdata, sink, false, true);
     pa_sink_input_new_data_set_sample_spec(&sdata, &ss);
 
     pa_sink_input_new(&c->sink_input, c->protocol->core, &sdata);
@@ -523,7 +523,7 @@ static int esd_proto_stream_record(connection *c, esd_proto_t request, const voi
     sdata.module = c->options->module;
     sdata.client = c->client;
     if (source)
-        pa_source_output_new_data_set_source(&sdata, source, false);
+        pa_source_output_new_data_set_source(&sdata, source, false, true);
     pa_source_output_new_data_set_sample_spec(&sdata, &ss);
 
     pa_source_output_new(&c->source_output, c->protocol->core, &sdata);
diff --git a/src/pulsecore/protocol-http.c b/src/pulsecore/protocol-http.c
index 25a2cd008..e8d22ed37 100644
--- a/src/pulsecore/protocol-http.c
+++ b/src/pulsecore/protocol-http.c
@@ -559,7 +559,7 @@ static void handle_listen_prefix(struct connection *c, const char *source_name)
     data.driver = __FILE__;
     data.module = c->module;
     data.client = c->client;
-    pa_source_output_new_data_set_source(&data, source, false);
+    pa_source_output_new_data_set_source(&data, source, false, true);
     pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist);
     pa_source_output_new_data_set_sample_spec(&data, &ss);
     pa_source_output_new_data_set_channel_map(&data, &cm);
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 6ff5ed40e..2d45a4cb6 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -533,7 +533,7 @@ static record_stream* record_stream_new(
     data.module = c->options->module;
     data.client = c->client;
     if (source)
-        pa_source_output_new_data_set_source(&data, source, false);
+        pa_source_output_new_data_set_source(&data, source, false, true);
     if (pa_sample_spec_valid(ss))
         pa_source_output_new_data_set_sample_spec(&data, ss);
     if (pa_channel_map_valid(map))
@@ -1006,7 +1006,7 @@ static playback_stream* playback_stream_new(
     data.module = c->options->module;
     data.client = c->client;
     if (sink)
-        pa_sink_input_new_data_set_sink(&data, sink, false);
+        pa_sink_input_new_data_set_sink(&data, sink, false, true);
     if (pa_sample_spec_valid(ss))
         pa_sink_input_new_data_set_sample_spec(&data, ss);
     if (pa_channel_map_valid(map))
diff --git a/src/pulsecore/protocol-simple.c b/src/pulsecore/protocol-simple.c
index 5e2d6c8f8..77d05398c 100644
--- a/src/pulsecore/protocol-simple.c
+++ b/src/pulsecore/protocol-simple.c
@@ -533,7 +533,7 @@ void pa_simple_protocol_connect(pa_simple_protocol *p, pa_iochannel *io, pa_simp
         data.driver = __FILE__;
         data.module = o->module;
         data.client = c->client;
-        pa_sink_input_new_data_set_sink(&data, sink, false);
+        pa_sink_input_new_data_set_sink(&data, sink, false, true);
         pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist);
         pa_sink_input_new_data_set_sample_spec(&data, &o->sample_spec);
 
@@ -589,7 +589,7 @@ void pa_simple_protocol_connect(pa_simple_protocol *p, pa_iochannel *io, pa_simp
         data.driver = __FILE__;
         data.module = o->module;
         data.client = c->client;
-        pa_source_output_new_data_set_source(&data, source, false);
+        pa_source_output_new_data_set_source(&data, source, false, true);
         pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist);
         pa_source_output_new_data_set_sample_spec(&data, &o->sample_spec);
 
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index f993322e9..5a55e93a5 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -180,7 +180,7 @@ void pa_sink_input_new_data_set_muted(pa_sink_input_new_data *data, bool mute) {
     data->muted = mute;
 }
 
-bool pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink *s, bool save) {
+bool pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink *s, bool save, bool requested_by_application) {
     bool ret = true;
     pa_idxset *formats = NULL;
 
@@ -191,6 +191,7 @@ bool pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink *s, b
         /* We're not working with the extended API */
         data->sink = s;
         data->save_sink = save;
+        data->sink_requested_by_application = requested_by_application;
     } else {
         /* Extended API: let's see if this sink supports the formats the client can provide */
         formats = pa_sink_check_formats(s, data->req_formats);
@@ -199,6 +200,7 @@ bool pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink *s, b
             /* Sink supports at least one of the requested formats */
             data->sink = s;
             data->save_sink = save;
+            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);
             data->nego_formats = formats;
@@ -224,7 +226,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);
+        return pa_sink_input_new_data_set_sink(data, data->sink, data->save_sink, data->sink_requested_by_application);
     }
 
     return true;
@@ -329,7 +331,7 @@ int pa_sink_input_new(
     if (!data->sink) {
         pa_sink *sink = pa_namereg_get(core, NULL, PA_NAMEREG_SINK);
         pa_return_val_if_fail(sink, -PA_ERR_NOENTITY);
-        pa_sink_input_new_data_set_sink(data, sink, false);
+        pa_sink_input_new_data_set_sink(data, sink, false, false);
     }
 
     /* If something didn't pick a format for us, pick the top-most format since
@@ -479,6 +481,7 @@ int pa_sink_input_new(
     i->driver = pa_xstrdup(pa_path_get_filename(data->driver));
     i->module = data->module;
     i->sink = data->sink;
+    i->sink_requested_by_application = data->sink_requested_by_application;
     i->origin_sink = data->origin_sink;
     i->client = data->client;
 
@@ -1741,6 +1744,7 @@ int pa_sink_input_start_move(pa_sink_input *i) {
     pa_cvolume_remap(&i->volume_factor_sink, &i->sink->channel_map, &i->channel_map);
 
     i->sink = NULL;
+    i->sink_requested_by_application = false;
 
     pa_sink_input_unref(i);
 
diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h
index f957a0e1f..b16f60fe5 100644
--- a/src/pulsecore/sink-input.h
+++ b/src/pulsecore/sink-input.h
@@ -80,6 +80,14 @@ struct pa_sink_input {
     pa_client *client;                  /* may be NULL */
 
     pa_sink *sink;                      /* NULL while we are being moved */
+
+    /* This is set to true when creating the sink input if the sink was
+     * requested by the application that created the sink input. This is
+     * sometimes useful for determining whether the sink input should be
+     * moved by some automatic policy. If the sink input is moved away from the
+     * sink that the application requested, this flag is reset to false. */
+    bool sink_requested_by_application;
+
     pa_sink *origin_sink;               /* only set by filter sinks */
 
     /* A sink input may be connected to multiple source outputs
@@ -284,6 +292,7 @@ typedef struct pa_sink_input_new_data {
     pa_client *client;
 
     pa_sink *sink;
+    bool sink_requested_by_application;
     pa_sink *origin_sink;
 
     pa_resample_method_t resample_method;
@@ -321,7 +330,7 @@ void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cv
 void pa_sink_input_new_data_add_volume_factor(pa_sink_input_new_data *data, const char *key, const pa_cvolume *volume_factor);
 void pa_sink_input_new_data_add_volume_factor_sink(pa_sink_input_new_data *data, const char *key, const pa_cvolume *volume_factor);
 void pa_sink_input_new_data_set_muted(pa_sink_input_new_data *data, bool mute);
-bool pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink *s, bool save);
+bool pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink *s, bool save, bool requested_by_application);
 bool pa_sink_input_new_data_set_formats(pa_sink_input_new_data *data, pa_idxset *formats);
 void pa_sink_input_new_data_done(pa_sink_input_new_data *data);
 
diff --git a/src/pulsecore/sound-file-stream.c b/src/pulsecore/sound-file-stream.c
index aeaa60854..147aa2288 100644
--- a/src/pulsecore/sound-file-stream.c
+++ b/src/pulsecore/sound-file-stream.c
@@ -296,7 +296,7 @@ int pa_play_file(
     u->readf_function = pa_sndfile_readf_function(&ss);
 
     pa_sink_input_new_data_init(&data);
-    pa_sink_input_new_data_set_sink(&data, sink, false);
+    pa_sink_input_new_data_set_sink(&data, sink, false, true);
     data.driver = __FILE__;
     pa_sink_input_new_data_set_sample_spec(&data, &ss);
     pa_sink_input_new_data_set_channel_map(&data, &cm);
diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index f8f4e0ef0..bcef51fdb 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -123,7 +123,8 @@ void pa_source_output_new_data_set_muted(pa_source_output_new_data *data, bool m
     data->muted = mute;
 }
 
-bool pa_source_output_new_data_set_source(pa_source_output_new_data *data, pa_source *s, bool save) {
+bool pa_source_output_new_data_set_source(pa_source_output_new_data *data, pa_source *s, bool save,
+                                          bool requested_by_application) {
     bool ret = true;
     pa_idxset *formats = NULL;
 
@@ -134,6 +135,7 @@ bool pa_source_output_new_data_set_source(pa_source_output_new_data *data, pa_so
         /* We're not working with the extended API */
         data->source = s;
         data->save_source = save;
+        data->source_requested_by_application = requested_by_application;
     } else {
         /* Extended API: let's see if this source supports the formats the client would like */
         formats = pa_source_check_formats(s, data->req_formats);
@@ -142,6 +144,7 @@ bool pa_source_output_new_data_set_source(pa_source_output_new_data *data, pa_so
             /* Source supports at least one of the requested formats */
             data->source = s;
             data->save_source = save;
+            data->source_requested_by_application = requested_by_application;
             if (data->nego_formats)
                 pa_idxset_free(data->nego_formats, (pa_free_cb_t) pa_format_info_free);
             data->nego_formats = formats;
@@ -167,7 +170,8 @@ bool pa_source_output_new_data_set_formats(pa_source_output_new_data *data, pa_i
 
     if (data->source) {
         /* Trigger format negotiation */
-        return pa_source_output_new_data_set_source(data, data->source, data->save_source);
+        return pa_source_output_new_data_set_source(data, data->source, data->save_source,
+                                                    data->source_requested_by_application);
     }
 
     return true;
@@ -271,7 +275,7 @@ int pa_source_output_new(
             pa_return_val_if_fail(source, -PA_ERR_NOENTITY);
         }
 
-        pa_source_output_new_data_set_source(data, source, false);
+        pa_source_output_new_data_set_source(data, source, false, false);
     }
 
     /* If something didn't pick a format for us, pick the top-most format since
@@ -424,6 +428,7 @@ int pa_source_output_new(
     o->driver = pa_xstrdup(pa_path_get_filename(data->driver));
     o->module = data->module;
     o->source = data->source;
+    o->source_requested_by_application = data->source_requested_by_application;
     o->destination_source = data->destination_source;
     o->client = data->client;
 
@@ -1365,6 +1370,7 @@ int pa_source_output_start_move(pa_source_output *o) {
     pa_cvolume_remap(&o->volume_factor_source, &o->source->channel_map, &o->channel_map);
 
     o->source = NULL;
+    o->source_requested_by_application = false;
 
     pa_source_output_unref(o);
 
diff --git a/src/pulsecore/source-output.h b/src/pulsecore/source-output.h
index 40e4e3a73..2f06f7d16 100644
--- a/src/pulsecore/source-output.h
+++ b/src/pulsecore/source-output.h
@@ -75,6 +75,15 @@ struct pa_source_output {
     pa_client *client;                    /* may be NULL */
 
     pa_source *source;                    /* NULL while being moved */
+
+    /* This is set to true when creating the source output if the source was
+     * requested by the application that created the source output. This is
+     * sometimes useful for determining whether the source output should be
+     * moved by some automatic policy. If the source output is moved away from
+     * the source that the application requested, this flag is reset to
+     * false. */
+    bool source_requested_by_application;
+
     pa_source *destination_source;        /* only set by filter sources */
 
     /* A source output can monitor just a single input of a sink, in which case we find it here */
@@ -243,6 +252,7 @@ typedef struct pa_source_output_new_data {
     pa_client *client;
 
     pa_source *source;
+    bool source_requested_by_application;
     pa_source *destination_source;
 
     pa_resample_method_t resample_method;
@@ -277,7 +287,8 @@ void pa_source_output_new_data_set_volume(pa_source_output_new_data *data, const
 void pa_source_output_new_data_apply_volume_factor(pa_source_output_new_data *data, const pa_cvolume *volume_factor);
 void pa_source_output_new_data_apply_volume_factor_source(pa_source_output_new_data *data, const pa_cvolume *volume_factor);
 void pa_source_output_new_data_set_muted(pa_source_output_new_data *data, bool mute);
-bool pa_source_output_new_data_set_source(pa_source_output_new_data *data, pa_source *s, bool save);
+bool pa_source_output_new_data_set_source(pa_source_output_new_data *data, pa_source *s, bool save,
+                                          bool requested_by_application);
 bool pa_source_output_new_data_set_formats(pa_source_output_new_data *data, pa_idxset *formats);
 void pa_source_output_new_data_done(pa_source_output_new_data *data);
 
-- 
2.14.2



More information about the pulseaudio-discuss mailing list