[Spice-devel] [PATCH 16/18] Remove use of global 'reds' from sound.c
Frediano Ziglio
fziglio at redhat.com
Mon Feb 15 16:01:17 UTC 2016
From: Jonathon Jongsma <jjongsma at redhat.com>
Pass RedsState variable to snd_attach_(playback|record) and get a
reference to this variable when needed by various functions.
---
server/reds.c | 4 ++--
server/sound.c | 20 ++++++++++++++++++--
server/sound.h | 4 ++--
3 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/server/reds.c b/server/reds.c
index dd6ffd9..711744b 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3243,7 +3243,7 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
spice_warning("unsupported playback interface");
return -1;
}
- snd_attach_playback(SPICE_CONTAINEROF(sin, SpicePlaybackInstance, base));
+ snd_attach_playback(reds, SPICE_CONTAINEROF(sin, SpicePlaybackInstance, base));
} else if (strcmp(interface->type, SPICE_INTERFACE_RECORD) == 0) {
spice_info("SPICE_INTERFACE_RECORD");
@@ -3252,7 +3252,7 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
spice_warning("unsupported record interface");
return -1;
}
- snd_attach_record(SPICE_CONTAINEROF(sin, SpiceRecordInstance, base));
+ snd_attach_record(reds, SPICE_CONTAINEROF(sin, SpiceRecordInstance, base));
} else if (strcmp(interface->type, SPICE_INTERFACE_CHAR_DEVICE) == 0) {
if (interface->major_version != SPICE_INTERFACE_CHAR_DEVICE_MAJOR ||
diff --git a/server/sound.c b/server/sound.c
index fd0b416..4e61986 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -199,14 +199,22 @@ static SndChannel *snd_channel_put(SndChannel *channel)
return channel;
}
+static RedsState* snd_channel_get_server(SndChannel *channel)
+{
+ g_return_val_if_fail(channel != NULL, NULL);
+ return red_channel_get_server(channel->worker->base_channel);
+}
+
static void snd_disconnect_channel(SndChannel *channel)
{
SndWorker *worker;
+ RedsState *reds;
if (!channel || !channel->stream) {
spice_debug("not connected");
return;
}
+ reds = snd_channel_get_server(channel);
spice_debug("SndChannel=%p rcc=%p type=%d",
channel, channel->channel_client, channel->channel_client->channel->type);
worker = channel->worker;
@@ -247,6 +255,7 @@ static void snd_record_on_message_done(SndChannel *channel)
static int snd_send_data(SndChannel *channel)
{
+ RedsState *reds = snd_channel_get_server(channel);
uint32_t n;
if (!channel) {
@@ -900,6 +909,7 @@ static SndChannel *__new_channel(SndWorker *worker, int size, uint32_t channel_i
#endif
int tos;
MainChannelClient *mcc = red_client_get_main(client);
+ RedsState *reds = red_channel_get_server(worker->base_channel);
spice_assert(stream);
if ((flags = fcntl(stream->socket, F_GETFL)) == -1) {
@@ -1037,6 +1047,7 @@ SPICE_GNUC_VISIBLE void spice_server_playback_start(SpicePlaybackInstance *sin)
{
SndChannel *channel = sin->st->worker.connection;
PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
+ RedsState *reds = snd_channel_get_server(channel);
sin->st->worker.active = 1;
if (!channel)
@@ -1056,6 +1067,7 @@ SPICE_GNUC_VISIBLE void spice_server_playback_stop(SpicePlaybackInstance *sin)
{
SndChannel *channel = sin->st->worker.connection;
PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
+ RedsState *reds = snd_channel_get_server(channel);
sin->st->worker.active = 0;
if (!channel)
@@ -1161,6 +1173,7 @@ static int snd_desired_audio_mode(int frequency, int client_can_celt, int client
static void on_new_playback_channel(SndWorker *worker)
{
+ RedsState *reds = red_channel_get_server(worker->base_channel);
PlaybackChannel *playback_channel =
SPICE_CONTAINEROF(worker->connection, PlaybackChannel, base);
SpicePlaybackState *st = SPICE_CONTAINEROF(worker, SpicePlaybackState, worker);
@@ -1181,6 +1194,7 @@ static void on_new_playback_channel(SndWorker *worker)
static void snd_playback_cleanup(SndChannel *channel)
{
+ RedsState *reds = snd_channel_get_server(channel);
PlaybackChannel *playback_channel = SPICE_CONTAINEROF(channel, PlaybackChannel, base);
if (playback_channel->base.active) {
@@ -1507,7 +1521,7 @@ static void remove_worker(SndWorker *worker)
spice_printerr("not found");
}
-void snd_attach_playback(SpicePlaybackInstance *sin)
+void snd_attach_playback(RedsState *reds, SpicePlaybackInstance *sin)
{
SndWorker *playback_worker;
RedChannel *channel;
@@ -1537,7 +1551,7 @@ void snd_attach_playback(SpicePlaybackInstance *sin)
reds_register_channel(reds, channel);
}
-void snd_attach_record(SpiceRecordInstance *sin)
+void snd_attach_record(RedsState *reds, SpiceRecordInstance *sin)
{
SndWorker *record_worker;
RedChannel *channel;
@@ -1570,6 +1584,8 @@ static void snd_detach_common(SndWorker *worker)
if (!worker) {
return;
}
+ RedsState *reds = red_channel_get_server(worker->base_channel);
+
remove_worker(worker);
snd_disconnect_channel(worker->connection);
reds_unregister_channel(reds, worker->base_channel);
diff --git a/server/sound.h b/server/sound.h
index 97f8410..25e59f0 100644
--- a/server/sound.h
+++ b/server/sound.h
@@ -20,10 +20,10 @@
#include "spice.h"
-void snd_attach_playback(SpicePlaybackInstance *sin);
+void snd_attach_playback(RedsState *reds, SpicePlaybackInstance *sin);
void snd_detach_playback(SpicePlaybackInstance *sin);
-void snd_attach_record(SpiceRecordInstance *sin);
+void snd_attach_record(RedsState *reds, SpiceRecordInstance *sin);
void snd_detach_record(SpiceRecordInstance *sin);
void snd_set_playback_compression(int on);
--
2.5.0
More information about the Spice-devel
mailing list