[spice-gtk PATCH v4 6/6] agent: sync guest audio with client values

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

 



Functions to sync volume and mute value when necessary. In this patch,
only one sync is allowed per connection.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1012868
---
 gtk/channel-main.c       | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/spice-session-priv.h |  2 +-
 2 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index 82169aa..4e97603 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -30,6 +30,7 @@
 #include "spice-util-priv.h"
 #include "spice-channel-priv.h"
 #include "spice-session-priv.h"
+#include "spice-audio-priv.h"
 
 /**
  * SECTION:channel-main
@@ -77,6 +78,8 @@ struct _SpiceMainChannelPrivate  {
     enum SpiceMouseMode         mouse_mode;
     bool                        agent_connected;
     bool                        agent_caps_received;
+    bool                        agent_volume_playback_sync;
+    bool                        agent_volume_record_sync;
 
     gboolean                    agent_display_config_sent;
     guint8                      display_color_depth;
@@ -187,6 +190,7 @@ static const char *agent_msg_types[] = {
     [ VD_AGENT_CLIPBOARD_GRAB          ] = "clipboard grab",
     [ VD_AGENT_CLIPBOARD_REQUEST       ] = "clipboard request",
     [ VD_AGENT_CLIPBOARD_RELEASE       ] = "clipboard release",
+    [ VD_AGENT_AUDIO_VOLUME_SYNC       ] = "volume-sync",
 };
 
 static const char *agent_caps[] = {
@@ -201,6 +205,7 @@ static const char *agent_caps[] = {
     [ VD_AGENT_CAP_GUEST_LINEEND_LF    ] = "line-end lf",
     [ VD_AGENT_CAP_GUEST_LINEEND_CRLF  ] = "line-end crlf",
     [ VD_AGENT_CAP_MAX_CLIPBOARD       ] = "max-clipboard",
+    [ VD_AGENT_CAP_AUDIO_VOLUME_SYNC   ] = "volume-sync",
 };
 #define NAME(_a, _i) ((_i) < SPICE_N_ELEMENTS(_a) ? (_a[(_i)] ?: "?") : "?")
 
@@ -1092,6 +1097,80 @@ gboolean spice_main_send_monitor_config(SpiceMainChannel *channel)
     return TRUE;
 }
 
+static gboolean agent_sync_audio_playback(gpointer user_data)
+{
+    VDAgentAudioVolumeSync *avs;
+    SpiceMainChannel *main_channel = user_data;
+    SpiceSession *session = spice_channel_get_session(SPICE_CHANNEL(main_channel));
+    SpiceAudio *audio = spice_audio_get(session, NULL);
+    SpiceMainChannelPrivate *c = main_channel->priv;
+    guint16 *volume;
+    guint8 nchannels;
+    gboolean mute;
+    gsize array_size;
+
+    mute = SPICE_AUDIO_GET_CLASS(audio)->get_playback_mute(audio);
+    volume = SPICE_AUDIO_GET_CLASS(audio)->get_playback_volume(audio, &nchannels);
+    if (volume == NULL || nchannels == 0) {
+        SPICE_DEBUG ("Failed to get playback sync data");
+        return G_SOURCE_CONTINUE;
+    }
+
+    /* only one per connection */
+    c->agent_volume_playback_sync = true;
+
+    array_size = sizeof(uint16_t) * nchannels;
+    avs = g_malloc0(sizeof(VDAgentAudioVolumeSync) + array_size);
+    avs->is_playback = TRUE;
+    avs->mute = mute;
+    avs->nchannels = nchannels;
+    memcpy(avs->volume, volume, array_size);
+
+    SPICE_DEBUG ("%s mute=%s nchannels=%u volume[0]=%u",
+                 __func__, spice_yes_no(mute), nchannels, volume[0]);
+    g_clear_pointer (&volume, g_free);
+    agent_msg_queue(main_channel, VD_AGENT_AUDIO_VOLUME_SYNC,
+                    sizeof(VDAgentAudioVolumeSync) + array_size, avs);
+    return G_SOURCE_REMOVE;
+}
+
+static gboolean agent_sync_audio_record(gpointer user_data)
+{
+    VDAgentAudioVolumeSync *avs;
+    SpiceMainChannel *main_channel = user_data;
+    SpiceSession *session = spice_channel_get_session(SPICE_CHANNEL(main_channel));
+    SpiceAudio *audio = spice_audio_get(session, NULL);
+    SpiceMainChannelPrivate *c = main_channel->priv;
+    guint16 *volume;
+    guint8 nchannels;
+    gboolean mute;
+    gsize array_size;
+
+    mute = SPICE_AUDIO_GET_CLASS(audio)->get_record_mute(audio);
+    volume = SPICE_AUDIO_GET_CLASS(audio)->get_record_volume(audio, &nchannels);
+    if (volume == NULL || nchannels == 0) {
+        SPICE_DEBUG ("Failed to get record sync data");
+        return G_SOURCE_CONTINUE;
+    }
+
+    /* only one per connection */
+    c->agent_volume_record_sync = true;
+
+    array_size = sizeof(uint16_t) * nchannels;
+    avs = g_malloc0(sizeof(VDAgentAudioVolumeSync) + array_size);
+    avs->is_playback = FALSE;
+    avs->mute = mute;
+    avs->nchannels = nchannels;
+    memcpy(avs->volume, volume, array_size);
+
+    SPICE_DEBUG ("%s mute=%s nchannels=%u volume[0]=%u",
+                 __func__, spice_yes_no(mute), nchannels, volume[0]);
+    g_clear_pointer (&volume, g_free);
+    agent_msg_queue(main_channel, VD_AGENT_AUDIO_VOLUME_SYNC,
+                    sizeof(VDAgentAudioVolumeSync) + array_size, avs);
+    return G_SOURCE_REMOVE;
+}
+
 /* any context: the message is not flushed immediately,
    you can wakeup() the channel coroutine or send_msg_queue() */
 static void agent_display_config(SpiceMainChannel *channel)
@@ -1345,6 +1424,8 @@ static void agent_start(SpiceMainChannel *channel)
     };
     SpiceMsgOut *out;
 
+    c->agent_volume_playback_sync = false;
+    c->agent_volume_record_sync = false;
     c->agent_caps_received = false;
     set_agent_connected(channel, TRUE);
 
@@ -1801,6 +1882,16 @@ static void main_agent_handle_msg(SpiceChannel *channel,
             c->agent_display_config_sent = true;
         }
 
+        if (!test_agent_cap(self, VD_AGENT_CAP_AUDIO_VOLUME_SYNC) ||
+            c->agent_volume_playback_sync == true) {
+            g_idle_add (agent_sync_audio_playback, self);
+        }
+
+        if (!test_agent_cap(self, VD_AGENT_CAP_AUDIO_VOLUME_SYNC) ||
+            c->agent_volume_record_sync == true) {
+            g_idle_add (agent_sync_audio_record, self);
+        }
+
         agent_max_clipboard(self);
 
         agent_send_msg_queue(self);
diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index 46938ff..049973a 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -98,7 +98,7 @@ PhodavServer* channel_webdav_server_new(SpiceSession *session);
 guint spice_session_get_n_display_channels(SpiceSession *session);
 void spice_session_set_main_channel(SpiceSession *session, SpiceChannel *channel);
 gboolean spice_session_set_migration_session(SpiceSession *session, SpiceSession *mig_session);
-
+SpiceAudio *spice_audio_get(SpiceSession *session, GMainContext *context);
 G_END_DECLS
 
 #endif /* __SPICE_CLIENT_SESSION_PRIV_H__ */
-- 
2.1.0

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]