<div dir="ltr">Hi<br><div class="gmail_extra"><br></div><div class="gmail_extra">A few comments below.<br><br></div><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 16, 2015 at 4:42 PM, Victor Toso <span dir="ltr"><<a href="mailto:victortoso@redhat.com" target="_blank">victortoso@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">In case of volume-sync between client and guest, we request volume-info<br>
from the availables streams and if the stream is not available we rely<br>
on ext-stream-restore.<br>
<br>
By using ext-stream-restore we can get the last stream data of the<br>
application that is stored by PulseAudio.<br>
<br>
Related: <a href="https://bugzilla.redhat.com/show_bug.cgi?id=1012868" target="_blank">https://bugzilla.redhat.com/show_bug.cgi?id=1012868</a><br>
---<br>
 gtk/spice-pulse.c | 476 ++++++++++++++++++++++++++++++++++++++++++++++++++++--<br>
 1 file changed, 467 insertions(+), 9 deletions(-)<br>
<br>
diff --git a/gtk/spice-pulse.c b/gtk/spice-pulse.c<br>
index c583032..c2be1b3 100644<br>
--- a/gtk/spice-pulse.c<br>
+++ b/gtk/spice-pulse.c<br>
@@ -25,18 +25,34 @@<br>
<br>
 #include <pulse/glib-mainloop.h><br>
 #include <pulse/pulseaudio.h><br>
+#include <pulse/ext-stream-restore.h><br>
<br>
 #define SPICE_PULSE_GET_PRIVATE(obj)                                  \<br>
     (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_PULSE, SpicePulsePrivate))<br>
<br>
+struct async_task {<br>
+    SpicePulse                 *pulse;<br>
+    SpiceMainChannel           *main_channel;<br>
+    GSimpleAsyncResult         *res;<br>
+    GAsyncReadyCallback        callback;<br>
+    gpointer                   user_data;<br>
+    gboolean                   is_playback;<br>
+    pa_operation               *pa_op;<br>
+    gulong                     cancel_id;<br>
+    GCancellable               *cancellable;<br>
+};<br>
+<br>
 struct stream {<br>
-    pa_sample_spec          spec;<br>
-    pa_stream               *stream;<br>
-    int                     state;<br>
-    pa_operation            *uncork_op;<br>
-    pa_operation            *cork_op;<br>
-    gboolean                started;<br>
-    guint                   num_underflow;<br>
+    pa_sample_spec             spec;<br>
+    pa_stream                  *stream;<br>
+    int                        state;<br>
+    pa_operation               *uncork_op;<br>
+    pa_operation               *cork_op;<br>
+    gboolean                   started;<br>
+    guint                      num_underflow;<br>
+    gboolean                   info_updated;<br>
+    gchar                      *name;<br>
+    pa_ext_stream_restore_info info;<br>
 };<br>
<br>
 struct _SpicePulsePrivate {<br>
@@ -50,6 +66,8 @@ struct _SpicePulsePrivate {<br>
     struct stream           record;<br>
     guint                   last_delay;<br>
     guint                   target_delay;<br>
+    struct async_task       *pending_restore_task;<br>
+    GList                   *results;<br>
 };<br>
<br>
 G_DEFINE_TYPE(SpicePulse, spice_pulse, SPICE_TYPE_AUDIO)<br>
@@ -77,6 +95,18 @@ static const char *context_state_names[] = {<br>
 static void stream_stop(SpicePulse *pulse, struct stream *s);<br>
 static gboolean connect_channel(SpiceAudio *audio, SpiceChannel *channel);<br>
 static void channel_weak_notified(gpointer data, GObject *where_the_object_was);<br>
+static void spice_pulse_get_playback_volume_info_async(SpiceAudio *audio, GCancellable *cancellable,<br>
+        SpiceMainChannel *main_channel, GAsyncReadyCallback callback, gpointer user_data);<br>
+static gboolean spice_pulse_get_playback_volume_info_finish(SpiceAudio *audio, GAsyncResult *res,<br>
+        gboolean *mute, guint8 *nchannels, guint16 **volume, GError **error);<br>
+static void spice_pulse_get_record_volume_info_async(SpiceAudio *audio, GCancellable *cancellable,<br>
+        SpiceMainChannel *main_channel, GAsyncReadyCallback callback, gpointer user_data);<br>
+static gboolean spice_pulse_get_record_volume_info_finish(SpiceAudio *audio,GAsyncResult *res,<br>
+        gboolean *mute, guint8 *nchannels, guint16 **volume, GError **error);<br>
+static void stream_restore_read_cb(pa_context *context,<br>
+        const pa_ext_stream_restore_info *info, int eol, void *userdata);<br>
+static void spice_pulse_complete_async_task(struct async_task *task, const gchar *err_msg);<br>
+static void spice_pulse_complete_all_async_tasks(SpicePulse *pulse, const gchar *err_msg);<br>
<br>
 static void spice_pulse_finalize(GObject *obj)<br>
 {<br>
@@ -118,6 +148,12 @@ static void spice_pulse_dispose(GObject *obj)<br>
         pa_operation_unref(p->record.cork_op);<br>
     p->record.cork_op = NULL;<br>
<br>
+    if (p->results != NULL)<br>
+        spice_pulse_complete_all_async_tasks(pulse, "PulseAudio is being dispose");<br>
+<br>
+    g_free(p-><a href="http://playback.name" target="_blank">playback.name</a>);<br>
+    g_free(p-><a href="http://record.name" target="_blank">record.name</a>);<br>
+<br>
     if (p->pchannel)<br>
         g_object_weak_unref(G_OBJECT(p->pchannel), channel_weak_notified, pulse);<br>
     p->pchannel = NULL;<br>
@@ -140,6 +176,10 @@ static void spice_pulse_class_init(SpicePulseClass *klass)<br>
     SpiceAudioClass *audio_class = SPICE_AUDIO_CLASS(klass);<br>
<br>
     audio_class->connect_channel = connect_channel;<br>
+    audio_class->get_playback_volume_info_async = spice_pulse_get_playback_volume_info_async;<br>
+    audio_class->get_playback_volume_info_finish = spice_pulse_get_playback_volume_info_finish;<br>
+    audio_class->get_record_volume_info_async = spice_pulse_get_record_volume_info_async;<br>
+    audio_class->get_record_volume_info_finish = spice_pulse_get_record_volume_info_finish;<br>
<br>
     gobject_class->finalize = spice_pulse_finalize;<br>
     gobject_class->dispose = spice_pulse_dispose;<br>
@@ -812,18 +852,40 @@ static void context_state_callback(pa_context *c, void *userdata)<br>
<br>
         if (!p->playback.stream && p->playback.started)<br>
             create_playback(SPICE_PULSE(userdata));<br>
+<br>
+        if (p->pending_restore_task != NULL &&<br>
+                p->pending_restore_task->pa_op == NULL) {<br>
+            pa_operation *op = pa_ext_stream_restore_read(p->context,<br>
+                                                          stream_restore_read_cb,<br>
+                                                          pulse);<br>
+            if (!op) {<br>
+                spice_pulse_complete_all_async_tasks(pulse,<br>
+                        pa_strerror(pa_context_errno(p->context)));<br>
+            } else {<br>
+                p->pending_restore_task->pa_op = op;<br>
+            }<br>
+        }<br>
         break;<br>
     }<br>
<br>
     case PA_CONTEXT_FAILED:<br>
         g_warning("PulseAudio context failed %s",<br>
                   pa_strerror(pa_context_errno(p->context)));<br>
-        break;<br>
+        goto context_fail;<br>
<br>
     case PA_CONTEXT_TERMINATED:<br>
     default:<br>
         SPICE_DEBUG("PulseAudio context terminated");<br>
-        break;<br>
+        goto context_fail;<br>
+    }<br>
+<br>
+    return;<br>
+<br>
+context_fail:<br>
+    if (p->pending_restore_task != NULL) {<br>
+        const gchar *errmsg = pa_strerror(pa_context_errno(p->context));<br>
+        errmsg = (errmsg != NULL) ? errmsg : "PulseAudio context terminated";<br>
+        spice_pulse_complete_all_async_tasks(pulse, errmsg);<br>
     }<br>
 }<br>
<br>
@@ -849,9 +911,405 @@ SpicePulse *spice_pulse_new(SpiceSession *session, GMainContext *context,<br>
         goto error;<br>
     }<br>
<br>
+    p-><a href="http://playback.name" target="_blank">playback.name</a> = g_strconcat("sink-input-by-application-name:",<br>
+                                   g_get_application_name(), NULL);<br>
+    p-><a href="http://record.name" target="_blank">record.name</a> = g_strconcat("source-output-by-application-name:",<br>
+                                 g_get_application_name(), NULL);<br>
     return pulse;<br>
<br>
 error:<br>
     g_object_unref(pulse);<br>
     return  NULL;<br>
 }<br>
+<br>
+static gboolean free_async_task(gpointer user_data)<br>
+{<br>
+    struct async_task *task = user_data;<br>
+<br>
+    if (task == NULL)<br>
+        return G_SOURCE_REMOVE;<br>
+<br>
+    if (task->pulse)<br>
+        g_object_unref(task->pulse);<br>
+<br>
+    if (task->res)<br>
+        g_object_unref(task->res);<br>
+<br>
+    if (task->main_channel)<br>
+        g_object_unref(task->main_channel);<br>
+<br>
+    if (task->pa_op != NULL)<br>
+        pa_operation_unref(task->pa_op);<br>
+<br>
+    if (task->cancel_id != 0) {<br>
+        g_cancellable_disconnect(task->cancellable, task->cancel_id);<br>
+        g_clear_object(&task->cancellable);<br>
+    }<br>
+<br>
+    g_free(task);<br>
+    return G_SOURCE_REMOVE;<br>
+}<br>
+<br>
+static void cancel_task(GCancellable *cancellable, gpointer user_data)<br>
+{<br>
+    struct async_task *task = user_data;<br>
+<br>
+    if (task->pa_op != NULL) {<br>
+        pa_operation_cancel(task->pa_op);<br>
+        pa_operation_unref(task->pa_op);<br>
+        task->pa_op = NULL;<br>
+    }<br>
+<br>
+    if (task->pulse->priv->pending_restore_task == task) {<br>
+        task->pulse->priv->pending_restore_task = NULL;<br>
+    }<br></div></div></blockquote><div><br></div><div>better in free_async_task() imho, but perhaps you wanted to clear it before the idle(). In which case, move it close to the idle_add()<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">
+<br>
+#if GLIB_CHECK_VERSION(2,40,0)<br>
+    free_async_task(task);<br>
+#else<br>
+    /* FIXME: <a href="https://bugzilla.gnome.org/show_bug.cgi?id=705395" target="_blank">https://bugzilla.gnome.org/show_bug.cgi?id=705395</a><br>
+     * Free the memory in idle */<br>
+    g_idle_add(free_async_task, task);<br>
+#endif<br>
+}<br>
+<br>
+static void complete_task(SpicePulse *pulse, struct async_task *task, const gchar *err_msg)<br>
+{<br>
+    SpicePulsePrivate *p = pulse->priv;<br>
+<br>
+    /* If we do have any err_msg, we failed */<br>
+    if (err_msg != NULL) {<br>
+        g_simple_async_result_set_op_res_gboolean(task->res, FALSE);<br>
+        g_simple_async_result_set_error(task->res,<br>
+                                        SPICE_CLIENT_ERROR,<br>
+                                        SPICE_CLIENT_ERROR_FAILED,<br>
+                                        "restore-info failed due %s",<br>
+                                        err_msg);<br>
+    /* Volume-info does not change if stream is not found */<br>
+    } else if ((task->is_playback == TRUE && p->playback.info_updated == FALSE) ||<br>
+               (task->is_playback == FALSE && p->record.info_updated == FALSE)) {<br>
+        g_simple_async_result_set_op_res_gboolean(task->res, FALSE);<br>
+        g_simple_async_result_set_error(task->res,<br>
+                                        SPICE_CLIENT_ERROR,<br>
+                                        SPICE_CLIENT_ERROR_FAILED,<br>
+                                        "Stream not found by pulse");<br>
+    } else {<br>
+        g_simple_async_result_set_op_res_gboolean(task->res, TRUE);<br>
+    }<br>
+<br>
+    /* As all async calls to PulseAudio are done with glib mainloop, it is<br>
+     * safe to complete the operation synchronously here. */<br>
+    g_simple_async_result_complete(task->res);<br>
+}<br>
+<br>
+static void spice_pulse_complete_async_task(struct async_task *task, const gchar *err_msg)<br>
+{<br>
+    SpicePulsePrivate *p;<br>
+<br>
+    if (task == NULL)<br>
+        return;<br></div></div></blockquote><div><br></div><div>When is this condition normally reached? g_return_if_fail() instead?<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">
+<br>
+    p = task->pulse->priv;<br>
+    complete_task(task->pulse, task, err_msg);<br>
+    if (p->results != NULL) {<br>
+        p->results = g_list_remove(p->results, task);<br>
+        SPICE_DEBUG("Number of async task is %d", g_list_length(p->results));<br>
+    }<br>
+    free_async_task(task);<br>
+}<br>
+<br>
+static void spice_pulse_complete_all_async_tasks(SpicePulse *pulse, const gchar *err_msg)<br>
+{<br>
+    SpicePulsePrivate *p = pulse->priv;<br>
+    GList *it;<br>
+<br>
+    /* Complete all tasks in list */<br>
+    for(it = p->results; it != NULL; it = it->next) {<br>
+        struct async_task *task = it->data;<br>
+<br>
+        if (task->pa_op != NULL) {<br>
+            pa_operation_cancel(task->pa_op);<br>
+            pa_operation_unref(task->pa_op);<br>
+            task->pa_op = NULL;<br>
+        }<br>
+        complete_task(pulse, task, err_msg);<br>
+        free_async_task(task);<br>
+    }<br>
+    g_list_free(p->results);<br>
+    p->results = NULL;<br>
+    p->pending_restore_task = NULL;<br></div></div></blockquote><div><br></div><div>(to be removed once in  free_async_task)<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">
+    SPICE_DEBUG("All async tasks completed");<br>
+}<br>
+<br>
+static void stream_restore_read_cb(pa_context *context,<br>
+                                   const pa_ext_stream_restore_info *info,<br>
+                                   int eol,<br>
+                                   void *userdata)<br>
+{<br>
+    SpicePulsePrivate *p = SPICE_PULSE(userdata)->priv;<br>
+    struct stream *pstream = NULL;<br>
+<br>
+    if (eol ||<br>
+            (p->playback.info_updated == TRUE &&<br>
+             p->record.info_updated == TRUE)) {<br></div></div></blockquote><div><br></div><div>This might still overwrite values set by info_cb if one of the two is set, I would just skip the code below when it's already set. It's also easier to read.<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">
+        /* As we only have one pa_operation running the stream-restore-info<br>
+         * which retrieves volume-info from both Playback and Record channels,<br>
+         * We can complete all async tasks now that this operation ended.<br>
+         * (or we already have the volume-info we want)<br>
+         * Note: the following function cancel the current pa_operation */<br>
+        spice_pulse_complete_all_async_tasks(SPICE_PULSE(userdata), NULL);<br>
+        return;<br>
+    }<br>
+<br>
+    if (g_strcmp0(info->name, p-><a href="http://playback.name" target="_blank">playback.name</a>) == 0) {<br>
+        pstream = &p->playback;<br>
+    } else if (g_strcmp0(info->name, p-><a href="http://record.name" target="_blank">record.name</a>) == 0) {<br>
+        pstream = &p->record;<br>
+    } else {<br>
+        /* This is not the stream you are looking for. */<br>
+        return;<br>
+    }<br>
+<br>
+    if (info->channel_map.channels == 0) {<br>
+        SPICE_DEBUG("Number of channels stored is zero. Ignore. (%s)", info->name);<br>
+        return;<br>
+    }<br>
+<br>
+    pstream->info_updated = TRUE;<br>
+    pstream-><a href="http://info.name" target="_blank">info.name</a> = pstream->name;<br>
+    pstream->info.mute = info->mute;<br>
+    pstream->info.channel_map = info->channel_map;<br>
+    pstream->info.volume = info->volume;<br>
+}<br>
+<br>
+static void source_output_info_cb(pa_context *context,<br>
+                                  const pa_source_output_info *info,<br>
+                                  int eol,<br>
+                                  void *userdata)<br>
+{<br>
+    struct async_task *task = userdata;<br>
+    SpicePulsePrivate *p = task->pulse->priv;<br>
+    struct stream *pstream = &p->record;<br>
+<br>
+    if (eol) {<br>
+        spice_pulse_complete_async_task(task, NULL);<br>
+        return;<br>
+    }<br>
+<br>
+    pstream->info_updated = TRUE;<br>
+    pstream-><a href="http://info.name" target="_blank">info.name</a> = pstream->name;<br>
+    pstream->info.mute = info->mute;<br>
+    pstream->info.channel_map = info->channel_map;<br>
+    pstream->info.volume = info->volume;<br>
+}<br>
+<br>
+static void sink_input_info_cb(pa_context *context,<br>
+                               const pa_sink_input_info *info,<br>
+                               int eol,<br>
+                               void *userdata)<br>
+{<br>
+    struct async_task *task = userdata;<br>
+    SpicePulsePrivate *p = task->pulse->priv;<br>
+    struct stream *pstream = &p->playback;<br>
+<br>
+    if (eol) {<br>
+        spice_pulse_complete_async_task(task, NULL);<br>
+        return;<br>
+    }<br>
+<br>
+    pstream->info_updated = TRUE;<br>
+    pstream-><a href="http://info.name" target="_blank">info.name</a> = pstream->name;<br>
+    pstream->info.mute = info->mute;<br>
+    pstream->info.channel_map = info->channel_map;<br>
+    pstream->info.volume = info->volume;<br>
+}<br>
+<br>
+/* to avoid code duplication */<br>
+static void pulse_stream_restore_info_async(gboolean is_playback,<br>
+                                            SpiceAudio *audio,<br>
+                                            GCancellable *cancellable,<br>
+                                            SpiceMainChannel *main_channel,<br>
+                                            GAsyncReadyCallback callback,<br>
+                                            gpointer user_data)<br>
+{<br>
+    SpicePulsePrivate *p = SPICE_PULSE(audio)->priv;<br>
+    GSimpleAsyncResult *simple;<br>
+    struct async_task *task = g_malloc0(sizeof(struct async_task));<br>
+    pa_operation *op = NULL;<br>
+<br>
+    simple = g_simple_async_result_new(G_OBJECT(audio),<br>
+                                       callback,<br>
+                                       user_data,<br>
+                                       pulse_stream_restore_info_async);<br>
+    g_simple_async_result_set_check_cancellable (simple, cancellable);<br>
+<br>
+    task->res = simple;<br>
+    task->pulse = g_object_ref(audio);<br>
+    task->callback = callback;<br>
+    task->user_data = user_data;<br>
+    task->is_playback = is_playback;<br>
+    task->main_channel = g_object_ref(main_channel);<br>
+    task->pa_op = NULL;<br>
+<br>
+    if (cancellable) {<br>
+        task->cancellable = g_object_ref(cancellable);<br>
+        task->cancel_id = g_cancellable_connect(cancellable, G_CALLBACK(cancel_task), task, NULL);<br>
+    }<br>
+<br>
+    /* If Playback/Record stream is created we use pulse API to get volume-info<br>
+     * from those streams directly. If the stream is not created, retrieve last<br>
+     * volume/mute values from Pulse database using the application name; */<br>
+<br>
+    if (is_playback == TRUE &&<br>
+            p->playback.stream != NULL &&<br>
+            pa_stream_get_index(p->playback.stream) != PA_INVALID_INDEX) {<br>
+        SPICE_DEBUG("Playback stream is created - get-sink-input-info");<br>
+        p->playback.info_updated = FALSE;<br>
+        op = pa_context_get_sink_input_info(p->context,<br>
+                                            pa_stream_get_index(p->playback.stream),<br>
+                                            sink_input_info_cb,<br>
+                                            task);<br>
+        if (!op)<br>
+            goto fail;<br>
+        task->pa_op = op;<br>
+<br>
+    } else if (is_playback == FALSE &&<br>
+            p->record.stream != NULL &&<br>
+            pa_stream_get_index(p->record.stream) != PA_INVALID_INDEX) {<br>
+        SPICE_DEBUG("Record stream is created - get-source-output-info");<br>
+        p->record.info_updated = FALSE;<br>
+        op = pa_context_get_source_output_info(p->context,<br>
+                                               pa_stream_get_index(p->record.stream),<br>
+                                               source_output_info_cb,<br>
+                                               task);<br>
+        if (!op)<br>
+            goto fail;<br>
+        task->pa_op = op;<br>
+<br>
+    } else {<br>
+        if (p-><a href="http://playback.info.name" target="_blank">playback.info.name</a> != NULL ||<br>
+                p-><a href="http://record.info.name" target="_blank">record.info.name</a> != NULL) {<br>
+            /* If the pstream-><a href="http://info.name" target="_blank">info.name</a> is set then we already have updated<br>
+             * volume information. We can complete the request now */<br>
+            SPICE_DEBUG("Return the volume-information we already have");<br>
+            spice_pulse_complete_async_task(task, NULL);<br>
+            return;<br>
+        }<br>
+<br>
+        if (p->results == NULL) {<br>
+            SPICE_DEBUG("Streams are not created - ext-stream-restore");<br>
+            p->playback.info_updated = FALSE;<br>
+            p->record.info_updated = FALSE;<br>
+<br>
+            if (pa_context_get_state(p->context) == PA_CONTEXT_READY) {<br>
+                /* Restore value from pulse db */<br>
+                op = pa_ext_stream_restore_read(p->context, stream_restore_read_cb, audio);<br>
+                if (!op)<br>
+                    goto fail;<br>
+                task->pa_op = op;<br>
+            } else {<br>
+                /* It is possible that we want to get volume-info before the<br>
+                 * context is in READY state. In this case, we wait for the<br>
+                 * context state change to READY. */<br>
+                p->pending_restore_task = task;<br>
+            }<br>
+        }<br>
+    }<br>
+<br>
+    p->results = g_list_append(p->results, task);<br>
+    SPICE_DEBUG ("Number of async task is %d", g_list_length(p->results));<br>
+    return;<br>
+<br>
+fail:<br>
+    if (!op) {<br>
+        g_simple_async_report_error_in_idle(G_OBJECT(audio),<br>
+                                            callback,<br>
+                                            user_data,<br>
+                                            SPICE_CLIENT_ERROR,<br>
+                                            SPICE_CLIENT_ERROR_FAILED,<br>
+                                            "Volume-Info failed: %s",<br>
+                                            pa_strerror(pa_context_errno(p->context)));<br>
+        free_async_task(task);<br>
+    }<br>
+}<br>
+<br>
+/* to avoid code duplication */<br>
+static gboolean pulse_stream_restore_info_finish(gboolean is_playback,<br>
+                                                 SpiceAudio *audio,<br>
+                                                 GAsyncResult *res,<br>
+                                                 gboolean *mute,<br>
+                                                 guint8 *nchannels,<br>
+                                                 guint16 **volume,<br>
+                                                 GError **error)<br>
+{<br>
+    SpicePulsePrivate *p = SPICE_PULSE(audio)->priv;<br>
+    struct stream *pstream = (is_playback) ? &p->playback : &p->record;<br>
+    GSimpleAsyncResult *simple = (GSimpleAsyncResult *) res;<br>
+<br>
+    g_return_val_if_fail(g_simple_async_result_is_valid(res,<br>
+        G_OBJECT(audio), pulse_stream_restore_info_async), FALSE);<br>
+<br>
+    if (g_simple_async_result_propagate_error(simple, error)) {<br>
+        return FALSE;<br>
+    }<br>
+<br>
+    if (mute != NULL) {<br>
+        *mute = (pstream->info.mute) ? TRUE : FALSE;<br>
+    }<br>
+<br>
+    if (nchannels != NULL) {<br>
+        *nchannels = pstream->info.channel_map.channels;<br>
+    }<br>
+<br>
+    if (volume != NULL) {<br>
+        gint i;<br>
+        *volume = g_new(guint16, pstream->info.channel_map.channels);<br>
+        for (i = 0; i < pstream->info.channel_map.channels; i++) {<br>
+            (*volume)[i] = MIN(pstream->info.volume.values[i], G_MAXUINT16);<br>
+            SPICE_DEBUG("(%s) volume at channel %d is %u",<br>
+                        (is_playback) ? "playback" : "record", i, (*volume)[i]);<br>
+        }<br>
+    }<br>
+<br>
+    return g_simple_async_result_get_op_res_gboolean(simple);<br>
+}<br>
+<br>
+static void spice_pulse_get_playback_volume_info_async(SpiceAudio *audio,<br>
+                                                       GCancellable *cancellable,<br>
+                                                       SpiceMainChannel *main_channel,<br>
+                                                       GAsyncReadyCallback callback,<br>
+                                                       gpointer user_data)<br>
+{<br>
+    pulse_stream_restore_info_async(TRUE, audio, cancellable, main_channel, callback, user_data);<br>
+}<br>
+<br>
+static gboolean spice_pulse_get_playback_volume_info_finish(SpiceAudio *audio,<br>
+                                                            GAsyncResult *res,<br>
+                                                            gboolean *mute,<br>
+                                                            guint8 *nchannels,<br>
+                                                            guint16 **volume,<br>
+                                                            GError **error)<br>
+{<br>
+    return pulse_stream_restore_info_finish(TRUE, audio, res, mute,<br>
+                                            nchannels, volume, error);<br>
+}<br>
+<br>
+static void spice_pulse_get_record_volume_info_async(SpiceAudio *audio,<br>
+                                                     GCancellable *cancellable,<br>
+                                                     SpiceMainChannel *main_channel,<br>
+                                                     GAsyncReadyCallback callback,<br>
+                                                     gpointer user_data)<br>
+{<br>
+    pulse_stream_restore_info_async(FALSE, audio, cancellable, main_channel, callback, user_data);<br>
+}<br>
+<br>
+static gboolean spice_pulse_get_record_volume_info_finish(SpiceAudio *audio,<br>
+                                                          GAsyncResult *res,<br>
+                                                          gboolean *mute,<br>
+                                                          guint8 *nchannels,<br>
+                                                          guint16 **volume,<br>
+                                                          GError **error)<br>
+{<br>
+    return pulse_stream_restore_info_finish(FALSE, audio, res, mute,<br>
+                                            nchannels, volume, error);<br>
+}<br>
--<br>
2.1.0<br>
<br>
_______________________________________________<br>
Spice-devel mailing list<br>
<a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br>
</div></div></blockquote></div><br></div><div class="gmail_extra"><br><br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">Marc-André Lureau</div>
</div></div>