[Spice-devel] [PATCH spice-server 18/18] sound: Reuse code for snd_set_{playback, record}_peer

Frediano Ziglio fziglio at redhat.com
Wed Nov 23 18:07:32 UTC 2016


Almost identical beside the type.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/sound.c | 53 ++++++++++++++++-------------------------------------
 1 file changed, 16 insertions(+), 37 deletions(-)

diff --git a/server/sound.c b/server/sound.c
index 464e6bc..91b4c77 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1066,9 +1066,9 @@ playback_channel_client_constructed(GObject *object)
     snd_send(SND_CHANNEL_CLIENT(playback_client));
 }
 
-static void snd_set_playback_peer(RedChannel *red_channel, RedClient *client, RedsStream *stream,
-                                  int migration, int num_common_caps, uint32_t *common_caps,
-                                  int num_caps, uint32_t *caps)
+static void snd_set_peer(RedChannel *red_channel, RedClient *client, RedsStream *stream,
+                         int migration, int num_common_caps, uint32_t *common_caps,
+                         int num_caps, uint32_t *caps, GType type)
 {
     SndChannel *channel = SND_CHANNEL(red_channel);
     GArray *common_caps_array = NULL, *caps_array = NULL;
@@ -1088,7 +1088,7 @@ static void snd_set_playback_peer(RedChannel *red_channel, RedClient *client, Re
         g_array_append_vals(caps_array, caps, num_caps);
     }
 
-    g_initable_new(TYPE_PLAYBACK_CHANNEL_CLIENT,
+    g_initable_new(type,
                    NULL, NULL,
                    "channel", channel,
                    "client", client,
@@ -1105,6 +1105,15 @@ static void snd_set_playback_peer(RedChannel *red_channel, RedClient *client, Re
     }
 }
 
+static void snd_set_playback_peer(RedChannel *red_channel, RedClient *client, RedsStream *stream,
+                                  int migration, int num_common_caps, uint32_t *common_caps,
+                                  int num_caps, uint32_t *caps)
+{
+    snd_set_peer(red_channel, client, stream, migration,
+                 num_common_caps, common_caps, num_caps, caps,
+                 TYPE_PLAYBACK_CHANNEL_CLIENT);
+}
+
 static void snd_record_migrate_channel_client(RedChannelClient *rcc)
 {
     SndChannel *channel;
@@ -1323,39 +1332,9 @@ static void snd_set_record_peer(RedChannel *red_channel, RedClient *client, Reds
                                 int migration, int num_common_caps, uint32_t *common_caps,
                                 int num_caps, uint32_t *caps)
 {
-    SndChannel *channel = SND_CHANNEL(red_channel);
-    GArray *common_caps_array = NULL, *caps_array = NULL;
-
-    if (channel->connection) {
-        red_channel_client_disconnect(RED_CHANNEL_CLIENT(channel->connection));
-        channel->connection = NULL;
-    }
-
-    if (common_caps) {
-        common_caps_array = g_array_sized_new(FALSE, FALSE, sizeof (*common_caps),
-                                              num_common_caps);
-        g_array_append_vals(common_caps_array, common_caps, num_common_caps);
-    }
-    if (caps) {
-        caps_array = g_array_sized_new(FALSE, FALSE, sizeof (*caps), num_caps);
-        g_array_append_vals(caps_array, caps, num_caps);
-    }
-
-    g_initable_new(TYPE_RECORD_CHANNEL_CLIENT,
-                   NULL, NULL,
-                   "channel", channel,
-                   "client", client,
-                   "stream", stream,
-                   "caps", caps_array,
-                   "common-caps", common_caps_array,
-                   NULL);
-
-    if (caps_array) {
-        g_array_unref(caps_array);
-    }
-    if (common_caps_array) {
-        g_array_unref(common_caps_array);
-    }
+    snd_set_peer(red_channel, client, stream, migration,
+                 num_common_caps, common_caps, num_caps, caps,
+                 TYPE_RECORD_CHANNEL_CLIENT);
 }
 
 static void snd_playback_migrate_channel_client(RedChannelClient *rcc)
-- 
2.7.4



More information about the Spice-devel mailing list