]> code.delx.au - pulseaudio/commitdiff
device-restore: Various fixes for the protocol extension.
authorColin Guthrie <colin@mageia.org>
Mon, 8 Aug 2011 21:29:47 +0000 (23:29 +0200)
committerColin Guthrie <colin@mageia.org>
Tue, 9 Aug 2011 09:01:01 +0000 (11:01 +0200)
 * Fix extension API function export list.
 * Ensure we trigger a subscription event when things change.
 * Send the index with our subscription events.
 * Clear out any existing formats when saving.
 * Call the correct extension command for subscriptions.

src/map-file
src/modules/module-device-restore.c
src/pulse/context.c
src/pulse/ext-device-restore.c
src/pulse/ext-device-restore.h

index aacd52412861ce1df6560d5acd72e5e71678c2b6..dd2e7d9c95a178277887109cd1ab0c18cb56fd08 100644 (file)
@@ -154,6 +154,7 @@ pa_ext_device_manager_test;
 pa_ext_device_restore_read_sink_formats;
 pa_ext_device_restore_read_sink_formats_all;
 pa_ext_device_restore_save_sink_formats;
+pa_ext_device_restore_set_subscribe_cb;
 pa_ext_device_restore_subscribe;
 pa_ext_device_restore_test;
 pa_ext_stream_restore_delete;
index 7d94ffa4bb4b882fb1aa18ea6c0d592335838883..75b1e40e12944f7958b9a881a2cd3116e70160d2 100644 (file)
@@ -133,7 +133,26 @@ static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct
     pa_log_info("Synced.");
 }
 
-static void trigger_save(struct userdata *u) {
+static void trigger_save(struct userdata *u, uint32_t sink_idx) {
+    pa_native_connection *c;
+    uint32_t idx;
+
+    if (sink_idx != PA_INVALID_INDEX) {
+        for (c = pa_idxset_first(u->subscribed, &idx); c; c = pa_idxset_next(u->subscribed, &idx)) {
+            pa_tagstruct *t;
+
+            t = pa_tagstruct_new(NULL, 0);
+            pa_tagstruct_putu32(t, PA_COMMAND_EXTENSION);
+            pa_tagstruct_putu32(t, 0);
+            pa_tagstruct_putu32(t, u->module->index);
+            pa_tagstruct_puts(t, u->module->name);
+            pa_tagstruct_putu32(t, SUBCOMMAND_EVENT);
+            pa_tagstruct_putu32(t, sink_idx);
+
+            pa_pstream_send_tagstruct(pa_native_connection_get_pstream(c), t);
+        }
+    }
+
     if (u->save_time_event)
         return;
 
@@ -337,7 +356,7 @@ fail:
     if ((e = legacy_entry_read(u, &data))) {
         pa_log_debug("Success. Saving new format for key: %s", name);
         if (entry_write(u, name, e))
-            trigger_save(u);
+            trigger_save(u, PA_INVALID_INDEX);
         pa_datum_free(&data);
         return e;
     } else
@@ -488,7 +507,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
     pa_log_info("Storing volume/mute/port for device %s.", name);
 
     if (entry_write(u, name, entry))
-        trigger_save(u);
+        trigger_save(u, idx);
 
     entry_free(entry);
     pa_xfree(name);
@@ -786,6 +805,11 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
             name = pa_sprintf_malloc("sink:%s", sink->name);
             if (!(e = entry_read(u, name)))
                 e = entry_new(FALSE);
+            else {
+                /* Clean out any saved formats */
+                pa_idxset_free(e->formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
+                e->formats = pa_idxset_new(NULL, NULL);
+            }
 
             /* Read all the formats from our tagstruct */
             for (i = 0; i < n_formats; ++i) {
@@ -805,7 +829,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
             }
 
             if (entry_write(u, name, e))
-                trigger_save(u);
+                trigger_save(u, sink_index);
             else
                 pa_log_warn("Could not save format info for sink %s", sink->name);
 
index e8f303287e04fe219d15aedf151a4c97d599900c..dbb5d42b726f9d3d26422b365a7fc78856053b40 100644 (file)
@@ -1424,7 +1424,7 @@ void pa_command_extension(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_t
     if (pa_streq(name, "module-device-manager"))
         pa_ext_device_manager_command(c, tag, t);
     else if (pa_streq(name, "module-device-restore"))
-        pa_ext_device_manager_command(c, tag, t);
+        pa_ext_device_restore_command(c, tag, t);
     else if (pa_streq(name, "module-stream-restore"))
         pa_ext_stream_restore_command(c, tag, t);
     else
index 938d4664a3b09c49e8f2b72253f18f1b4c4cfa92..3cbbe1a6fc21bc0e4ec4ed064a3991e46f9df53d 100644 (file)
@@ -324,12 +324,14 @@ pa_operation *pa_ext_device_restore_save_sink_formats(
 /* Command function defined in internal.h */
 void pa_ext_device_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t) {
     uint32_t subcommand;
+    uint32_t idx;
 
     pa_assert(c);
     pa_assert(PA_REFCNT_VALUE(c) >= 1);
     pa_assert(t);
 
     if (pa_tagstruct_getu32(t, &subcommand) < 0 ||
+        pa_tagstruct_getu32(t, &idx) < 0 ||
         !pa_tagstruct_eof(t)) {
 
         pa_context_fail(c, PA_ERR_PROTOCOL);
@@ -341,6 +343,11 @@ void pa_ext_device_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t)
         return;
     }
 
+    if (idx == PA_INVALID_INDEX) {
+        pa_context_fail(c, PA_ERR_PROTOCOL);
+        return;
+    }
+
     if (c->ext_device_restore.callback)
-        c->ext_device_restore.callback(c, c->ext_device_restore.userdata);
+        c->ext_device_restore.callback(c, idx, c->ext_device_restore.userdata);
 }
index eb0619cdb05a9429a4ecde95c1a221c1adcf3d53..f43946b4f35ba47987aa7d3d34960cfb9c7dd0b0 100644 (file)
@@ -63,6 +63,7 @@ pa_operation *pa_ext_device_restore_subscribe(
 /** Callback prototype for pa_ext_device_restore_set_subscribe_cb(). \since 1.0 */
 typedef void (*pa_ext_device_restore_subscribe_cb_t)(
         pa_context *c,
+        uint32_t idx,
         void *userdata);
 
 /** Set the subscription callback that is called when