]> code.delx.au - pulseaudio/blobdiff - src/modules/module-volume-restore.c
move flat volume logic into the core. while doing so add n_volume_steps field to...
[pulseaudio] / src / modules / module-volume-restore.c
index 192a2a7864a286ba362dc868210ed6d780ceedbc..e32552c3c5590e968bcde32d293f6a85c32d7727 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -102,10 +100,10 @@ static pa_cvolume* parse_volume(const char *s, pa_cvolume *v) {
         return NULL;
 
     k = strtol(s, &p, 0);
-    if (k <= 0 || k > PA_CHANNELS_MAX)
+    if (k <= 0 || k > (long) PA_CHANNELS_MAX)
         return NULL;
 
-    v->channels = (unsigned) k;
+    v->channels = (uint8_t) k;
 
     for (i = 0; i < v->channels; i++) {
         p += strspn(p, WHITESPACE);
@@ -115,7 +113,7 @@ static pa_cvolume* parse_volume(const char *s, pa_cvolume *v) {
 
         k = strtol(p, &p, 0);
 
-        if (k < PA_VOLUME_MUTED)
+        if (k < (long) PA_VOLUME_MUTED)
             return NULL;
 
         v->values[i] = (pa_volume_t) k;
@@ -134,16 +132,12 @@ static int load_rules(struct userdata *u) {
     char buf_name[256], buf_volume[256], buf_sink[256], buf_source[256];
     char *ln = buf_name;
 
-    f = u->table_file ?
-        fopen(u->table_file, "r") :
-        pa_open_config_file(NULL, DEFAULT_VOLUME_TABLE_FILE, NULL, &u->table_file, "r");
-
-    if (!f) {
+    if (!(f = fopen(u->table_file, "r"))) {
         if (errno == ENOENT) {
-            pa_log_info("starting with empty ruleset.");
+            pa_log_info("Starting with empty ruleset.");
             ret = 0;
         } else
-            pa_log("failed to open file '%s': %s", u->table_file, pa_cstrerror(errno));
+            pa_log("Failed to open file '%s': %s", u->table_file, pa_cstrerror(errno));
 
         goto finish;
     }
@@ -236,11 +230,7 @@ static int save_rules(struct userdata *u) {
 
     pa_log_info("Saving rules...");
 
-    f = u->table_file ?
-        fopen(u->table_file, "w") :
-        pa_open_config_file(NULL, DEFAULT_VOLUME_TABLE_FILE, NULL, &u->table_file, "w");
-
-    if (!f) {
+    if (!(f = fopen(u->table_file, "w"))) {
         pa_log("Failed to open file '%s': %s", u->table_file, pa_cstrerror(errno));
         goto finish;
     }
@@ -280,10 +270,10 @@ finish:
 static char* client_name(pa_client *c) {
     char *t, *e;
 
-    if (!c->name || !c->driver)
+    if (!pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME) || !c->driver)
         return NULL;
 
-    t = pa_sprintf_malloc("%s$%s", c->driver, c->name);
+    t = pa_sprintf_malloc("%s$%s", c->driver, pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME));
     t[strcspn(t, "\n\r#")] = 0;
 
     if (!*t) {
@@ -427,7 +417,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
 
     if ((r = pa_hashmap_get(u->hashmap, name))) {
         if (!data->sink && r->sink) {
-            if ((data->sink = pa_namereg_get(c, r->sink, PA_NAMEREG_SINK, 1)))
+            if ((data->sink = pa_namereg_get(c, r->sink, PA_NAMEREG_SINK)))
                 pa_log_info("Restoring sink for <%s>", r->name);
         }
     }
@@ -453,7 +443,7 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *c, pa_sink_inpu
 
         if (r->volume_is_set && data->sample_spec.channels == r->volume.channels) {
             pa_log_info("Restoring volume for <%s>", r->name);
-            pa_sink_input_new_data_set_volume(data, &r->volume);
+            pa_sink_input_new_data_set_virtual_volume(data, &r->volume);
         }
     }
 
@@ -473,7 +463,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
 
     if ((r = pa_hashmap_get(u->hashmap, name))) {
         if (!data->source && r->source) {
-            if ((data->source = pa_namereg_get(c, r->source, PA_NAMEREG_SOURCE, 1)))
+            if ((data->source = pa_namereg_get(c, r->source, PA_NAMEREG_SOURCE)))
                 pa_log_info("Restoring source for <%s>", r->name);
         }
     }
@@ -496,7 +486,6 @@ int pa__init(pa_module*m) {
     u = pa_xnew(struct userdata, 1);
     u->core = m->core;
     u->hashmap = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    u->table_file = pa_xstrdup(pa_modargs_get_value(ma, "table", NULL));
     u->modified = FALSE;
     u->subscription = NULL;
     u->sink_input_new_hook_slot = u->sink_input_fixate_hook_slot = u->source_output_new_hook_slot = NULL;
@@ -504,6 +493,9 @@ int pa__init(pa_module*m) {
 
     m->userdata = u;
 
+    if (!(u->table_file = pa_state_path(pa_modargs_get_value(ma, "table", DEFAULT_VOLUME_TABLE_FILE), TRUE)))
+        goto fail;
+
     if (pa_modargs_get_value_boolean(ma, "restore_device", &restore_device) < 0 ||
         pa_modargs_get_value_boolean(ma, "restore_volume", &restore_volume) < 0) {
         pa_log("restore_volume= and restore_device= expect boolean arguments");
@@ -521,12 +513,12 @@ int pa__init(pa_module*m) {
     u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u);
 
     if (restore_device) {
-        u->sink_input_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], (pa_hook_cb_t) sink_input_new_hook_callback, u);
-        u->source_output_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], (pa_hook_cb_t) source_output_new_hook_callback, u);
+        u->sink_input_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_new_hook_callback, u);
+        u->source_output_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_new_hook_callback, u);
     }
 
     if (restore_volume)
-        u->sink_input_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], (pa_hook_cb_t) sink_input_fixate_hook_callback, u);
+        u->sink_input_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_fixate_hook_callback, u);
 
     pa_modargs_free(ma);
     return 0;