[Spice-devel] [PATCH v7 07/12] sound: Reuse code for snd_set_{playback, record}_peer
Frediano Ziglio
fziglio at redhat.com
Mon Dec 5 12:07:34 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 fed6062..a4313c4 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1083,9 +1083,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;
@@ -1105,7 +1105,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,
@@ -1122,6 +1122,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;
@@ -1339,39 +1348,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
More information about the Spice-devel
mailing list