[Spice-commits] 7 commits - server/red-channel-client-private.h server/red-channel-client.c server/red-channel-client.h server/sound.c
Frediano Ziglio
fziglio at kemper.freedesktop.org
Thu Feb 2 16:03:08 UTC 2017
server/red-channel-client-private.h | 11 +
server/red-channel-client.c | 12 +-
server/red-channel-client.h | 13 --
server/sound.c | 210 ++++++++++++------------------------
4 files changed, 90 insertions(+), 156 deletions(-)
New commits:
commit 3066ebe33b690f5163204a99b4c63e3512b62ad3
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu Nov 24 04:42:04 2016 +0000
sound: Make clear active and client_active are boolean
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/sound.c b/server/sound.c
index c0b332f..4548c25 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -91,8 +91,8 @@ GType snd_channel_client_get_type(void) G_GNUC_CONST;
struct SndChannelClient {
RedChannelClient parent;
- int active;
- int client_active;
+ gboolean active;
+ gboolean client_active;
uint32_t command;
@@ -174,7 +174,7 @@ struct SndChannel {
SndChannelClient *connection; /* Only one client is supported */
SndChannel *next; /* For the global SndChannel list */
- int active;
+ gboolean active;
SpiceVolumeState volume;
uint32_t frequency;
};
@@ -884,7 +884,7 @@ static void snd_playback_start(SndChannel *channel)
{
SndChannelClient *client = channel->connection;
- channel->active = 1;
+ channel->active = TRUE;
if (!client)
return;
spice_assert(!client->active);
@@ -907,7 +907,7 @@ SPICE_GNUC_VISIBLE void spice_server_playback_stop(SpicePlaybackInstance *sin)
{
SndChannelClient *client = sin->st->channel.connection;
- sin->st->channel.active = 0;
+ sin->st->channel.active = FALSE;
if (!client)
return;
PlaybackChannelClient *playback_client = PLAYBACK_CHANNEL_CLIENT(client);
@@ -1179,7 +1179,7 @@ static void snd_record_start(SndChannel *channel)
{
SndChannelClient *client = channel->connection;
- channel->active = 1;
+ channel->active = TRUE;
if (!client) {
return;
}
@@ -1205,7 +1205,7 @@ SPICE_GNUC_VISIBLE void spice_server_record_stop(SpiceRecordInstance *sin)
{
SndChannelClient *client = sin->st->channel.connection;
- sin->st->channel.active = 0;
+ sin->st->channel.active = FALSE;
if (!client)
return;
spice_assert(client->active);
commit 7cb27a209e432a5fbd7bc43fc936455a1b59407b
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Nov 23 23:32:51 2016 +0000
sound: Reuse code to set volume and mute
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/sound.c b/server/sound.c
index 068c337..c0b332f 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -837,12 +837,11 @@ static void snd_set_command(SndChannelClient *client, uint32_t command)
client->command |= command;
}
-SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *sin,
- uint8_t nchannels,
- uint16_t *volume)
+static void snd_channel_set_volume(SndChannel *channel,
+ uint8_t nchannels, uint16_t *volume)
{
- SpiceVolumeState *st = &sin->st->channel.volume;
- SndChannelClient *client = sin->st->channel.connection;
+ SpiceVolumeState *st = &channel->volume;
+ SndChannelClient *client = channel->connection;
st->volume_nchannels = nchannels;
free(st->volume);
@@ -855,10 +854,17 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *
snd_send(client);
}
-SPICE_GNUC_VISIBLE void spice_server_playback_set_mute(SpicePlaybackInstance *sin, uint8_t mute)
+SPICE_GNUC_VISIBLE void spice_server_playback_set_volume(SpicePlaybackInstance *sin,
+ uint8_t nchannels,
+ uint16_t *volume)
{
- SpiceVolumeState *st = &sin->st->channel.volume;
- SndChannelClient *client = sin->st->channel.connection;
+ snd_channel_set_volume(&sin->st->channel, nchannels, volume);
+}
+
+static void snd_channel_set_mute(SndChannel *channel, uint8_t mute)
+{
+ SpiceVolumeState *st = &channel->volume;
+ SndChannelClient *client = channel->connection;
st->mute = mute;
@@ -869,6 +875,11 @@ SPICE_GNUC_VISIBLE void spice_server_playback_set_mute(SpicePlaybackInstance *si
snd_send(client);
}
+SPICE_GNUC_VISIBLE void spice_server_playback_set_mute(SpicePlaybackInstance *sin, uint8_t mute)
+{
+ snd_channel_set_mute(&sin->st->channel, mute);
+}
+
static void snd_playback_start(SndChannel *channel)
{
SndChannelClient *client = channel->connection;
@@ -1156,32 +1167,12 @@ SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin,
uint8_t nchannels,
uint16_t *volume)
{
- SpiceVolumeState *st = &sin->st->channel.volume;
- SndChannelClient *client = sin->st->channel.connection;
-
- st->volume_nchannels = nchannels;
- free(st->volume);
- st->volume = spice_memdup(volume, sizeof(uint16_t) * nchannels);
-
- if (!client || nchannels == 0)
- return;
-
- snd_set_command(client, SND_VOLUME_MASK);
- snd_send(client);
+ snd_channel_set_volume(&sin->st->channel, nchannels, volume);
}
SPICE_GNUC_VISIBLE void spice_server_record_set_mute(SpiceRecordInstance *sin, uint8_t mute)
{
- SpiceVolumeState *st = &sin->st->channel.volume;
- SndChannelClient *client = sin->st->channel.connection;
-
- st->mute = mute;
-
- if (!client)
- return;
-
- snd_set_command(client, SND_MUTE_MASK);
- snd_send(client);
+ snd_channel_set_mute(&sin->st->channel, mute);
}
static void snd_record_start(SndChannel *channel)
commit 6128aae6d2d910524501d4eb9df013f10bb372ca
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Nov 23 23:32:00 2016 +0000
sound: Reuse code for migrating client channels
We support only a single client so don't waste code just
to check this.
The worst stuff can happen is that we'll migrate multiple
connections.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/sound.c b/server/sound.c
index ccaf8d5..068c337 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1146,19 +1146,10 @@ static void snd_set_playback_peer(RedChannel *red_channel, RedClient *client, Re
TYPE_PLAYBACK_CHANNEL_CLIENT);
}
-static void snd_record_migrate_channel_client(RedChannelClient *rcc)
+static void snd_migrate_channel_client(RedChannelClient *rcc)
{
- SndChannel *channel;
- RedChannel *red_channel = red_channel_client_get_channel(rcc);
-
- channel = SND_CHANNEL(red_channel);
- spice_assert(channel);
-
- if (channel->connection) {
- spice_assert(RED_CHANNEL_CLIENT(channel->connection) == rcc);
- snd_set_command(channel->connection, SND_MIGRATE_MASK);
- snd_send(channel->connection);
- }
+ snd_set_command(SND_CHANNEL_CLIENT(rcc), SND_MIGRATE_MASK);
+ snd_send(SND_CHANNEL_CLIENT(rcc));
}
SPICE_GNUC_VISIBLE void spice_server_record_set_volume(SpiceRecordInstance *sin,
@@ -1357,22 +1348,6 @@ static void snd_set_record_peer(RedChannel *red_channel, RedClient *client, Reds
TYPE_RECORD_CHANNEL_CLIENT);
}
-static void snd_playback_migrate_channel_client(RedChannelClient *rcc)
-{
- SndChannel *channel;
- RedChannel *red_channel = red_channel_client_get_channel(rcc);
-
- channel = SND_CHANNEL(red_channel);
- spice_assert(channel);
- spice_debug(NULL);
-
- if (channel->connection) {
- spice_assert(RED_CHANNEL_CLIENT(channel->connection) == rcc);
- snd_set_command(channel->connection, SND_MIGRATE_MASK);
- snd_send(channel->connection);
- }
-}
-
static void add_channel(SndChannel *channel)
{
channel->next = snd_channels;
@@ -1440,7 +1415,7 @@ playback_channel_constructed(GObject *object)
G_OBJECT_CLASS(playback_channel_parent_class)->constructed(object);
client_cbs.connect = snd_set_playback_peer;
- client_cbs.migrate = snd_playback_migrate_channel_client;
+ client_cbs.migrate = snd_migrate_channel_client;
red_channel_register_client_cbs(RED_CHANNEL(self), &client_cbs, self);
if (snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_CELT_0_5_1, SND_CODEC_ANY_FREQUENCY)) {
@@ -1490,7 +1465,7 @@ record_channel_constructed(GObject *object)
G_OBJECT_CLASS(record_channel_parent_class)->constructed(object);
client_cbs.connect = snd_set_record_peer;
- client_cbs.migrate = snd_record_migrate_channel_client;
+ client_cbs.migrate = snd_migrate_channel_client;
red_channel_register_client_cbs(RED_CHANNEL(self), &client_cbs, self);
if (snd_codec_is_capable(SPICE_AUDIO_DATA_MODE_CELT_0_5_1, SND_CODEC_ANY_FREQUENCY)) {
commit f6406bbaae683f457938f21c32cc9f59582247b6
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Nov 23 17:08:22 2016 +0000
sound: Reuse code for snd_set_{playback,record}_peer
Almost identical beside the type.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/sound.c b/server/sound.c
index bddf5ec..ccaf8d5 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1096,14 +1096,13 @@ 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,
- G_GNUC_UNUSED 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 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;
- PlaybackChannelClient *playback_client;
+ SndChannelClient *snd_client;
if (channel->connection) {
red_channel_client_disconnect(RED_CHANNEL_CLIENT(channel->connection));
@@ -1120,15 +1119,15 @@ static void snd_set_playback_peer(RedChannel *red_channel, RedClient *client, Re
g_array_append_vals(caps_array, caps, num_caps);
}
- playback_client = g_initable_new(TYPE_PLAYBACK_CHANNEL_CLIENT,
- NULL, NULL,
- "channel", channel,
- "client", client,
- "stream", stream,
- "caps", caps_array,
- "common-caps", common_caps_array,
- NULL);
- g_warn_if_fail(playback_client != NULL);
+ snd_client = g_initable_new(type,
+ NULL, NULL,
+ "channel", channel,
+ "client", client,
+ "stream", stream,
+ "caps", caps_array,
+ "common-caps", common_caps_array,
+ NULL);
+ g_warn_if_fail(snd_client != NULL);
if (caps_array) {
g_array_unref(caps_array);
@@ -1138,6 +1137,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,
+ G_GNUC_UNUSED int migration, int num_common_caps, uint32_t *common_caps,
+ int num_caps, uint32_t *caps)
+{
+ snd_set_peer(red_channel, client, stream,
+ num_common_caps, common_caps, num_caps, caps,
+ TYPE_PLAYBACK_CHANNEL_CLIENT);
+}
+
static void snd_record_migrate_channel_client(RedChannelClient *rcc)
{
SndChannel *channel;
@@ -1344,41 +1352,9 @@ static void snd_set_record_peer(RedChannel *red_channel, RedClient *client, Reds
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;
- RecordChannelClient *record_client;
-
- 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);
- }
-
- record_client = g_initable_new(TYPE_RECORD_CHANNEL_CLIENT,
- NULL, NULL,
- "channel", channel,
- "client", client,
- "stream", stream,
- "caps", caps_array,
- "common-caps", common_caps_array,
- NULL);
- g_warn_if_fail(record_client != 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,
+ num_common_caps, common_caps, num_caps, caps,
+ TYPE_RECORD_CHANNEL_CLIENT);
}
static void snd_playback_migrate_channel_client(RedChannelClient *rcc)
commit 46ed676eb5c2a393953d5dd59264be610d41eecb
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Nov 23 17:07:40 2016 +0000
sound: Use default disconnect for client channels
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/sound.c b/server/sound.c
index ba2ee79..bddf5ec 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -829,23 +829,6 @@ snd_channel_client_release_recv_buf(RedChannelClient *rcc, uint16_t type, uint32
}
}
-static void snd_disconnect_channel_client(RedChannelClient *rcc)
-{
- SndChannel *channel;
- RedChannel *red_channel = red_channel_client_get_channel(rcc);
- uint32_t type;
-
- channel = SND_CHANNEL(red_channel);
- spice_assert(channel);
- g_object_get(red_channel, "channel-type", &type, NULL);
-
- spice_debug("channel-type=%d", type);
- if (channel->connection) {
- spice_assert(RED_CHANNEL_CLIENT(channel->connection) == rcc);
- red_channel_client_disconnect(rcc);
- }
-}
-
static void snd_set_command(SndChannelClient *client, uint32_t command)
{
if (!client) {
@@ -1481,7 +1464,6 @@ playback_channel_constructed(GObject *object)
G_OBJECT_CLASS(playback_channel_parent_class)->constructed(object);
client_cbs.connect = snd_set_playback_peer;
- client_cbs.disconnect = snd_disconnect_channel_client;
client_cbs.migrate = snd_playback_migrate_channel_client;
red_channel_register_client_cbs(RED_CHANNEL(self), &client_cbs, self);
@@ -1532,7 +1514,6 @@ record_channel_constructed(GObject *object)
G_OBJECT_CLASS(record_channel_parent_class)->constructed(object);
client_cbs.connect = snd_set_record_peer;
- client_cbs.disconnect = snd_disconnect_channel_client;
client_cbs.migrate = snd_record_migrate_channel_client;
red_channel_register_client_cbs(RED_CHANNEL(self), &client_cbs, self);
commit 92c051a820357acb18fbab30f3bf1110ce39fb51
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Nov 23 10:52:24 2016 +0000
sound: free SndChannel data in finalize()
Move the freeing of SndChannel data members from snd_detach_common() to
the finalize function to encapsulate things a bit more cleanly. It
doesn't really change the behavior or order of destruction since
snd_detach_common() destroys the channel.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/sound.c b/server/sound.c
index 7095e2b..ba2ee79 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -1440,10 +1440,26 @@ snd_channel_init(SndChannel *self)
}
static void
+snd_channel_finalize(GObject *object)
+{
+ SndChannel *channel = SND_CHANNEL(object);
+
+ remove_channel(channel);
+
+ free(channel->volume.volume);
+ channel->volume.volume = NULL;
+
+ G_OBJECT_CLASS(snd_channel_parent_class)->finalize(object);
+}
+
+static void
snd_channel_class_init(SndChannelClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
RedChannelClass *channel_class = RED_CHANNEL_CLASS(klass);
+ object_class->finalize = snd_channel_finalize;
+
channel_class->config_socket = snd_channel_config_socket;
channel_class->alloc_recv_buf = snd_channel_client_alloc_recv_buf;
channel_class->release_recv_buf = snd_channel_client_release_recv_buf;
@@ -1559,10 +1575,7 @@ static void snd_detach_common(SndChannel *channel)
}
RedsState *reds = red_channel_get_server(RED_CHANNEL(channel));
- remove_channel(channel);
reds_unregister_channel(reds, RED_CHANNEL(channel));
- free(channel->volume.volume);
- channel->volume.volume = NULL;
red_channel_destroy(RED_CHANNEL(channel));
}
commit b7e4703140447b5a78640d0b1e611ad189b6e5f9
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Nov 23 01:55:42 2016 +0000
Make RedChannelClient::incoming private
Sound implementation used internal RedChannelClient data while now
it just uses the public interface not thouching RedChannelClient
internal state so now is possible to make this field private.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
diff --git a/server/red-channel-client-private.h b/server/red-channel-client-private.h
index 593fee5..d01cdbd 100644
--- a/server/red-channel-client-private.h
+++ b/server/red-channel-client-private.h
@@ -50,6 +50,16 @@ typedef struct OutgoingHandler {
int size;
} OutgoingHandler;
+typedef struct IncomingHandler {
+ IncomingHandlerInterface *cb;
+ void *opaque;
+ uint8_t header_buf[MAX_HEADER_SIZE];
+ SpiceDataHeaderOpaque header;
+ uint32_t header_pos;
+ uint8_t *msg; // data of the msg following the header. allocated by alloc_msg_buf.
+ uint32_t msg_pos;
+} IncomingHandler;
+
struct RedChannelClientPrivate
{
RedChannel *channel;
@@ -95,6 +105,7 @@ struct RedChannelClientPrivate
RedChannelClientLatencyMonitor latency_monitor;
RedChannelClientConnectivityMonitor connectivity_monitor;
+ IncomingHandler incoming;
OutgoingHandler outgoing;
};
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 8312d3e..0002951 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -268,8 +268,8 @@ static void red_channel_client_constructed(GObject *object)
{
RedChannelClient *self = RED_CHANNEL_CLIENT(object);
- self->incoming.opaque = self;
- self->incoming.cb = red_channel_get_incoming_handler(self->priv->channel);
+ self->priv->incoming.opaque = self;
+ self->priv->incoming.cb = red_channel_get_incoming_handler(self->priv->channel);
self->priv->outgoing.opaque = self;
self->priv->outgoing.cb = red_channel_get_outgoing_handler(self->priv->channel);
@@ -277,15 +277,15 @@ static void red_channel_client_constructed(GObject *object)
self->priv->outgoing.size = 0;
if (red_channel_client_test_remote_common_cap(self, SPICE_COMMON_CAP_MINI_HEADER)) {
- self->incoming.header = mini_header_wrapper;
+ self->priv->incoming.header = mini_header_wrapper;
self->priv->send_data.header = mini_header_wrapper;
self->priv->is_mini_header = TRUE;
} else {
- self->incoming.header = full_header_wrapper;
+ self->priv->incoming.header = full_header_wrapper;
self->priv->send_data.header = full_header_wrapper;
self->priv->is_mini_header = FALSE;
}
- self->incoming.header.data = self->incoming.header_buf;
+ self->priv->incoming.header.data = self->priv->incoming.header_buf;
}
static void red_channel_client_class_init(RedChannelClientClass *klass)
@@ -1178,7 +1178,7 @@ static void red_peer_handle_incoming(RedsStream *stream, IncomingHandler *handle
void red_channel_client_receive(RedChannelClient *rcc)
{
g_object_ref(rcc);
- red_peer_handle_incoming(rcc->priv->stream, &rcc->incoming);
+ red_peer_handle_incoming(rcc->priv->stream, &rcc->priv->incoming);
g_object_unref(rcc);
}
diff --git a/server/red-channel-client.h b/server/red-channel-client.h
index 0d404d1..fada609 100644
--- a/server/red-channel-client.h
+++ b/server/red-channel-client.h
@@ -190,23 +190,10 @@ gboolean red_channel_client_set_migration_seamless(RedChannelClient *rcc);
void red_channel_client_set_destroying(RedChannelClient *rcc);
gboolean red_channel_client_is_destroying(RedChannelClient *rcc);
-typedef struct IncomingHandler {
- IncomingHandlerInterface *cb;
- void *opaque;
- uint8_t header_buf[MAX_HEADER_SIZE];
- SpiceDataHeaderOpaque header;
- uint32_t header_pos;
- uint8_t *msg; // data of the msg following the header. allocated by alloc_msg_buf.
- uint32_t msg_pos;
-} IncomingHandler;
-
struct RedChannelClient
{
GObject parent;
- /* protected */
- IncomingHandler incoming;
-
RedChannelClientPrivate *priv;
};
More information about the Spice-commits
mailing list