[PATCH] stream-restore: Add properties to suppress save/restore of volume

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This allows clients to set stream.save_volume and stream.restore_volume
to control whether a stream's volume should be saved/restored
respectively. We make save_volume a property instead of a flag since the
application might not know at stream creation time whether it wants the
volume to be saved or not. To keep things conistent, restore_volume is a
property as well (even though it is only meaningful to set at stream
creation time).
---
 src/modules/module-stream-restore.c |   32 +++++++++++++++++++++++++++++---
 src/pulse/proplist.h                |    6 ++++++
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index f8fecd8..1cf8ef3 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -1124,6 +1124,32 @@ static pa_bool_t entries_equal(const struct entry *a, const struct entry *b) {
     return TRUE;
 }
 
+static pa_bool_t should_save_volume (pa_sink_input *si) {
+    const char *value;
+
+    if (!si->save_volume)
+        return FALSE;
+
+    value = pa_proplist_gets(si->proplist, PA_PROP_STREAM_SAVE_VOLUME);
+    if (value && pa_streq(value, "0"))
+        return FALSE;
+
+    return TRUE;
+}
+
+static pa_bool_t should_restore_volume (struct userdata *u, pa_proplist *plist) {
+    const char *value;
+
+    if (!u->restore_volume)
+        return FALSE;
+
+    value = pa_proplist_gets(plist, PA_PROP_STREAM_RESTORE_VOLUME);
+    if (value && pa_streq (value, "0"))
+        return FALSE;
+
+    return TRUE;
+}
+
 static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
     struct userdata *u = userdata;
     struct entry entry, *old = NULL;
@@ -1167,7 +1193,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
             created_new_entry = FALSE;
         }
 
-        if (sink_input->save_volume) {
+        if (should_save_volume (sink_input)) {
             entry.channel_map = sink_input->channel_map;
             pa_sink_input_get_volume(sink_input, &entry.volume, FALSE);
             entry.volume_valid = TRUE;
@@ -1326,7 +1352,7 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *c, pa_sink_inpu
 
     if ((e = read_entry(u, name))) {
 
-        if (u->restore_volume && e->volume_valid) {
+        if (should_restore_volume (u, new_data->proplist) && e->volume_valid) {
 
             if (!new_data->volume_is_set) {
                 pa_cvolume v;
@@ -1615,7 +1641,7 @@ static void apply_entry(struct userdata *u, const char *name, struct entry *e) {
         }
         pa_xfree(n);
 
-        if (u->restore_volume && e->volume_valid) {
+        if (should_restore_volume(u, si->proplist) && e->volume_valid) {
             pa_cvolume v;
 
             v = e->volume;
diff --git a/src/pulse/proplist.h b/src/pulse/proplist.h
index 5db3ada..feaa319 100644
--- a/src/pulse/proplist.h
+++ b/src/pulse/proplist.h
@@ -168,6 +168,12 @@ PA_C_DECL_BEGIN
 /** For clients/streams: an id for the login session the application runs in. On Unix the value of $XDG_SESSION_COOKIE. e.g. "543679e7b01393ed3e3e650047d78f6e-1235159798.76193-190367717" */
 #define PA_PROP_APPLICATION_PROCESS_SESSION_ID "application.process.session_id"
 
+/** For streams: specify whether the volume of this stream should be saved when the stream is disconnected if support for this is available. Can be either "0" (don't save) or "1" (do save, this is the default behaviour). */
+#define PA_PROP_STREAM_SAVE_VOLUME              "stream.save_volume"
+
+/** For streams: specify whether the volume of this stream should be restored when the stream is created if support for this is available. Can be either "0" (don't restore) or "1" (do restore, this is the default behaviour). */
+#define PA_PROP_STREAM_RESTORE_VOLUME           "stream.restore_volume"
+
 /** For devices: device string in the underlying audio layer's format. e.g. "surround51:0" */
 #define PA_PROP_DEVICE_STRING                  "device.string"
 
-- 
1.7.4.rc3




[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux