[PATCH v8 06/11] sound: Reuse code for snd_set_{playback, record}_peer

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

 



Almost identical beside the type.

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

diff --git a/server/sound.c b/server/sound.c
index 745cac7..88171cc 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1084,9 +1084,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;
@@ -1106,7 +1106,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,
@@ -1123,6 +1123,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;
@@ -1340,39 +1349,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)
-- 
git-series 0.9.1
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://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]