summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2010-09-27 14:27:43 +0200
committerGerd Hoffmann <kraxel@redhat.com>2010-09-27 14:27:43 +0200
commite63dbb458242d73a86776acdaf1102e65624ae14 (patch)
treeba717549d3c6b9eee78404d49fcc37d30d578a49
parentec92ad9d3a921f57ef421600c6aedde219465f34 (diff)
g-objectify playback channel
-rw-r--r--gtk/Makefile.am2
-rw-r--r--gtk/channel-playback.c120
-rw-r--r--gtk/spice-channel-priv.h10
-rw-r--r--gtk/spice-channel.c36
-rw-r--r--gtk/spice-channel.h6
-rw-r--r--gtk/spice-client.h1
-rw-r--r--gtk/spice-pulse.c11
7 files changed, 115 insertions, 71 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 5d788a8..aedd38d 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -110,8 +110,10 @@ libspice_client_glib_la_SOURCES = \
channel-main.c \
channel-display.c \
channel-display-mjpeg.c \
+ channel-cursor.h \
channel-cursor.c \
channel-inputs.c \
+ channel-playback.h \
channel-playback.c \
\
decode.h \
diff --git a/gtk/channel-playback.c b/gtk/channel-playback.c
index 0071e0a..70b9845 100644
--- a/gtk/channel-playback.c
+++ b/gtk/channel-playback.c
@@ -2,10 +2,99 @@
#include "spice-client.h"
#include "spice-channel-priv.h"
+#include "spice-marshal.h"
+
+#define SPICE_PLAYBACK_CHANNEL_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_PLAYBACK_CHANNEL, spice_playback_channel))
+
+struct spice_playback_channel {
+ int mode;
+};
+
+G_DEFINE_TYPE(SpicePlaybackChannel, spice_playback_channel, SPICE_TYPE_CHANNEL)
+
+enum {
+ SPICE_PLAYBACK_START,
+ SPICE_PLAYBACK_DATA,
+ SPICE_PLAYBACK_STOP,
+
+ SPICE_PLAYBACK_LAST_SIGNAL,
+};
+
+static guint signals[SPICE_PLAYBACK_LAST_SIGNAL];
+
+static void spice_playback_handle_msg(SpiceChannel *channel, spice_msg_in *msg);
+
+/* ------------------------------------------------------------------ */
+
+static void spice_playback_channel_init(SpicePlaybackChannel *channel)
+{
+ spice_playback_channel *c;
+
+ fprintf(stderr, "%s\n", __FUNCTION__);
+
+ c = channel->priv = SPICE_PLAYBACK_CHANNEL_GET_PRIVATE(channel);
+ memset(c, 0, sizeof(*c));
+}
+
+static void spice_playback_channel_finalize(GObject *obj)
+{
+ fprintf(stderr, "%s\n", __FUNCTION__);
+
+ if (G_OBJECT_CLASS(spice_playback_channel_parent_class)->finalize)
+ G_OBJECT_CLASS(spice_playback_channel_parent_class)->finalize(obj);
+}
+
+static void spice_playback_channel_class_init(SpicePlaybackChannelClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ SpiceChannelClass *channel_class = SPICE_CHANNEL_CLASS(klass);
+
+ fprintf(stderr, "%s\n", __FUNCTION__);
+
+ gobject_class->finalize = spice_playback_channel_finalize;
+ channel_class->handle_msg = spice_playback_handle_msg;
+
+ signals[SPICE_PLAYBACK_START] =
+ g_signal_new("spice-playback-start",
+ G_OBJECT_CLASS_TYPE(gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET(SpicePlaybackChannelClass, spice_playback_start),
+ NULL, NULL,
+ g_cclosure_user_marshal_VOID__INT_INT_INT,
+ G_TYPE_NONE,
+ 3,
+ G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
+
+ signals[SPICE_PLAYBACK_DATA] =
+ g_signal_new("spice-playback-data",
+ G_OBJECT_CLASS_TYPE(gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET(SpicePlaybackChannelClass, spice_playback_data),
+ NULL, NULL,
+ g_cclosure_user_marshal_VOID__POINTER_INT,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_POINTER, G_TYPE_INT);
+
+ signals[SPICE_PLAYBACK_STOP] =
+ g_signal_new("spice-playback-stop",
+ G_OBJECT_CLASS_TYPE(gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET(SpicePlaybackChannelClass, spice_playback_stop),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ g_type_class_add_private(klass, sizeof(spice_playback_channel));
+}
+
+/* ------------------------------------------------------------------ */
static void playback_handle_data(SpiceChannel *channel, spice_msg_in *in)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
+ spice_playback_channel *c = SPICE_PLAYBACK_CHANNEL(channel)->priv;
SpiceMsgPlaybackPacket *data = spice_msg_in_parsed(in);
#if 0
@@ -13,9 +102,9 @@ static void playback_handle_data(SpiceChannel *channel, spice_msg_in *in)
data->time, data->data, data->data_size);
#endif
- switch (c->playback.mode) {
+ switch (c->mode) {
case SPICE_AUDIO_DATA_MODE_RAW:
- g_signal_emit(channel, channel_signals[SPICE_PLAYBACK_DATA], 0,
+ g_signal_emit(channel, signals[SPICE_PLAYBACK_DATA], 0,
data->data, data->data_size);
break;
default:
@@ -26,7 +115,7 @@ static void playback_handle_data(SpiceChannel *channel, spice_msg_in *in)
static void playback_handle_mode(SpiceChannel *channel, spice_msg_in *in)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
+ spice_playback_channel *c = SPICE_PLAYBACK_CHANNEL(channel)->priv;
SpiceMsgPlaybackMode *mode = spice_msg_in_parsed(in);
#if 0
@@ -34,8 +123,8 @@ static void playback_handle_mode(SpiceChannel *channel, spice_msg_in *in)
mode->time, mode->mode, mode->data, mode->data_size);
#endif
- c->playback.mode = mode->mode;
- switch (c->playback.mode) {
+ c->mode = mode->mode;
+ switch (c->mode) {
case SPICE_AUDIO_DATA_MODE_RAW:
break;
default:
@@ -46,7 +135,7 @@ static void playback_handle_mode(SpiceChannel *channel, spice_msg_in *in)
static void playback_handle_start(SpiceChannel *channel, spice_msg_in *in)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
+ spice_playback_channel *c = SPICE_PLAYBACK_CHANNEL(channel)->priv;
SpiceMsgPlaybackStart *start = spice_msg_in_parsed(in);
#if 0
@@ -54,9 +143,9 @@ static void playback_handle_start(SpiceChannel *channel, spice_msg_in *in)
start->format, start->channels, start->frequency, start->time);
#endif
- switch (c->playback.mode) {
+ switch (c->mode) {
case SPICE_AUDIO_DATA_MODE_RAW:
- g_signal_emit(channel, channel_signals[SPICE_PLAYBACK_START], 0,
+ g_signal_emit(channel, signals[SPICE_PLAYBACK_START], 0,
start->format, start->channels, start->frequency);
break;
default:
@@ -67,7 +156,7 @@ static void playback_handle_start(SpiceChannel *channel, spice_msg_in *in)
static void playback_handle_stop(SpiceChannel *channel, spice_msg_in *in)
{
- g_signal_emit(channel, channel_signals[SPICE_PLAYBACK_STOP], 0);
+ g_signal_emit(channel, signals[SPICE_PLAYBACK_STOP], 0);
}
static spice_msg_handler playback_handlers[] = {
@@ -81,8 +170,9 @@ static spice_msg_handler playback_handlers[] = {
[ SPICE_MSG_PLAYBACK_STOP ] = playback_handle_stop,
};
-spice_channel_info playback_channel_info = {
- .name = "playback",
- .handlers = playback_handlers,
- .nhandlers = SPICE_N_ELEMENTS(playback_handlers),
-};
+static void spice_playback_handle_msg(SpiceChannel *channel, spice_msg_in *msg)
+{
+ assert(msg->header.type < SPICE_N_ELEMENTS(playback_handlers));
+ assert(playback_handlers[msg->header.type] != NULL);
+ playback_handlers[msg->header.type](channel, msg);
+}
diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index 3d569ea..7ad4354 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -134,10 +134,6 @@ struct inputs_channel {
int motion_count;
};
-struct playback_channel {
- int mode;
-};
-
struct spice_channel {
SpiceSession *session;
char name[16];
@@ -170,7 +166,6 @@ struct spice_channel {
struct main_channel main;
struct display_channel display;
struct inputs_channel inputs;
- struct playback_channel playback;
};
};
@@ -184,10 +179,6 @@ enum {
SPICE_DISPLAY_PRIMARY_DESTROY,
SPICE_DISPLAY_INVALIDATE,
- SPICE_PLAYBACK_START,
- SPICE_PLAYBACK_DATA,
- SPICE_PLAYBACK_STOP,
-
SPICE_CHANNEL_LAST_SIGNAL,
};
@@ -214,6 +205,5 @@ struct spice_channel_info {
extern spice_channel_info main_channel_info;
extern spice_channel_info display_channel_info;
extern spice_channel_info inputs_channel_info;
-extern spice_channel_info playback_channel_info;
#endif /* __SPICE_CLIENT_CHANNEL_PRIV_H__ */
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index 92ccde5..d5ac728 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -20,7 +20,6 @@ static spice_channel_info *type2info[] = {
[ SPICE_CHANNEL_MAIN ] = &main_channel_info,
[ SPICE_CHANNEL_DISPLAY ] = &display_channel_info,
[ SPICE_CHANNEL_INPUTS ] = &inputs_channel_info,
- [ SPICE_CHANNEL_PLAYBACK ] = &playback_channel_info,
};
/* ------------------------------------------------------------------ */
@@ -279,38 +278,6 @@ static void spice_channel_class_init(SpiceChannelClass *klass)
4,
G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
- channel_signals[SPICE_PLAYBACK_START] =
- g_signal_new("spice-playback-start",
- G_OBJECT_CLASS_TYPE(gobject_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET(SpiceChannelClass, spice_playback_start),
- NULL, NULL,
- g_cclosure_user_marshal_VOID__INT_INT_INT,
- G_TYPE_NONE,
- 3,
- G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
-
- channel_signals[SPICE_PLAYBACK_DATA] =
- g_signal_new("spice-playback-data",
- G_OBJECT_CLASS_TYPE(gobject_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET(SpiceChannelClass, spice_playback_data),
- NULL, NULL,
- g_cclosure_user_marshal_VOID__POINTER_INT,
- G_TYPE_NONE,
- 2,
- G_TYPE_POINTER, G_TYPE_INT);
-
- channel_signals[SPICE_PLAYBACK_STOP] =
- g_signal_new("spice-playback-stop",
- G_OBJECT_CLASS_TYPE(gobject_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET(SpiceChannelClass, spice_playback_stop),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
g_type_class_add_private(klass, sizeof(spice_channel));
sw_canvas_init();
@@ -835,6 +802,9 @@ SpiceChannel *spice_channel_new(SpiceSession *s, int type, int id)
case SPICE_CHANNEL_CURSOR:
gtype = SPICE_TYPE_CURSOR_CHANNEL;
break;
+ case SPICE_CHANNEL_PLAYBACK:
+ gtype = SPICE_TYPE_PLAYBACK_CHANNEL;
+ break;
default:
gtype = SPICE_TYPE_CHANNEL;
break;
diff --git a/gtk/spice-channel.h b/gtk/spice-channel.h
index b12b698..e3a96aa 100644
--- a/gtk/spice-channel.h
+++ b/gtk/spice-channel.h
@@ -56,12 +56,6 @@ struct _SpiceChannelClass
void (*spice_display_invalidate)(SpiceChannel *channel,
gint x, gint y, gint w, gint h);
- /* playback signals */
- void (*spice_playback_start)(SpiceChannel *channel,
- gint format, gint channels, gint freq);
- void (*spice_playback_data)(SpiceChannel *channel, gpointer *data, gint size);
- void (*spice_playback_stop)(SpiceChannel *channel);
-
#if 0
/*
* If adding fields to this struct, remove corresponding
diff --git a/gtk/spice-client.h b/gtk/spice-client.h
index bc7492d..113eb07 100644
--- a/gtk/spice-client.h
+++ b/gtk/spice-client.h
@@ -34,6 +34,7 @@
#include "spice-channel.h"
#include "channel-cursor.h"
+#include "channel-playback.h"
/* debug bits */
#define PANIC(fmt, ...) \
diff --git a/gtk/spice-pulse.c b/gtk/spice-pulse.c
index e158254..f58fd68 100644
--- a/gtk/spice-pulse.c
+++ b/gtk/spice-pulse.c
@@ -132,7 +132,7 @@ static void playback_data(SpiceChannel *channel, gpointer *audio, gint size,
static void playback_stop(SpiceChannel *channel, gpointer data)
{
SpicePulse *pulse = data;
- spice_pulse *p = SPICE_PULSE_GET_PRIVATE(pulse);
+ spice_pulse *p = pulse->priv;
if (!p->playback.stream)
return;
@@ -143,10 +143,10 @@ static void playback_stop(SpiceChannel *channel, gpointer data)
static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer data)
{
SpicePulse *pulse = data;
- int type = spice_channel_type(channel);
+ spice_pulse *p = pulse->priv;
- switch (type) {
- case SPICE_CHANNEL_PLAYBACK:
+ if (SPICE_IS_PLAYBACK_CHANNEL(channel)) {
+ p->pchannel = channel;
g_signal_connect(channel, "spice-playback-start",
G_CALLBACK(playback_start), pulse);
g_signal_connect(channel, "spice-playback-data",
@@ -154,9 +154,6 @@ static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer data)
g_signal_connect(channel, "spice-playback-stop",
G_CALLBACK(playback_stop), pulse);
spice_channel_connect(channel);
- break;
- default:
- return;
}
}