[Spice-devel] [spice-gtk PATCH 1/5] audio: set volume/mute in record/playback channels
Victor Toso
victortoso at redhat.com
Wed Mar 18 10:17:13 PDT 2015
In order to allow backend audio to update channel's volume/mute values
when necessary.
---
gtk/channel-playback.c | 30 ++++++++++++++++++++++++------
gtk/channel-record.c | 30 ++++++++++++++++++++++++------
2 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/gtk/channel-playback.c b/gtk/channel-playback.c
index ae8a75d..7fa4386 100644
--- a/gtk/channel-playback.c
+++ b/gtk/channel-playback.c
@@ -84,6 +84,8 @@ enum {
static guint signals[SPICE_PLAYBACK_LAST_SIGNAL];
static void channel_set_handlers(SpiceChannelClass *klass);
+static void playback_set_prop_volume(SpicePlaybackChannel *channel,
+ guint8 nchannels, const guint16 *volume);
/* ------------------------------------------------------------------ */
@@ -153,11 +155,18 @@ static void spice_playback_channel_set_property(GObject *gobject,
const GValue *value,
GParamSpec *pspec)
{
+ SpicePlaybackChannel *channel = SPICE_PLAYBACK_CHANNEL(gobject);
+ SpicePlaybackChannelPrivate *c = channel->priv;
+
switch (prop_id) {
- case PROP_VOLUME:
+ case PROP_VOLUME: {
+ const guint16 *volume = g_value_get_pointer(value);
+ playback_set_prop_volume (channel, c->nchannels, volume);
/* TODO: request guest volume change */
break;
+ }
case PROP_MUTE:
+ c->mute = g_value_get_boolean(value);
/* TODO: request guest mute change */
break;
default:
@@ -396,7 +405,6 @@ static void playback_handle_stop(SpiceChannel *channel, SpiceMsgIn *in)
/* coroutine context */
static void playback_handle_set_volume(SpiceChannel *channel, SpiceMsgIn *in)
{
- SpicePlaybackChannelPrivate *c = SPICE_PLAYBACK_CHANNEL(channel)->priv;
SpiceMsgAudioVolume *vol = spice_msg_in_parsed(in);
if (vol->nchannels == 0) {
@@ -404,10 +412,8 @@ static void playback_handle_set_volume(SpiceChannel *channel, SpiceMsgIn *in)
return;
}
- g_free(c->volume);
- c->nchannels = vol->nchannels;
- c->volume = g_new(guint16, c->nchannels);
- memcpy(c->volume, vol->volume, sizeof(guint16) * c->nchannels);
+ playback_set_prop_volume (SPICE_PLAYBACK_CHANNEL(channel),
+ vol->nchannels, vol->volume);
g_coroutine_object_notify(G_OBJECT(channel), "volume");
}
@@ -486,3 +492,15 @@ void spice_playback_channel_sync_latency(SpicePlaybackChannel *channel)
SPICE_DEBUG("%s: notify latency update %u", __FUNCTION__, channel->priv->min_latency);
g_coroutine_object_notify(G_OBJECT(SPICE_CHANNEL(channel)), "min-latency");
}
+
+static void
+playback_set_prop_volume(SpicePlaybackChannel *channel, guint8 nchannels, const guint16 *volume)
+{
+ SpicePlaybackChannelPrivate *c = channel->priv;
+ if (c->nchannels != nchannels) {
+ g_free(c->volume);
+ c->nchannels = nchannels;
+ c->volume = g_new(guint16, nchannels);
+ }
+ memcpy(c->volume, volume, sizeof(guint16) * nchannels);
+}
diff --git a/gtk/channel-record.c b/gtk/channel-record.c
index ac71999..99d9946 100644
--- a/gtk/channel-record.c
+++ b/gtk/channel-record.c
@@ -84,6 +84,8 @@ static guint signals[SPICE_RECORD_LAST_SIGNAL];
static void channel_set_handlers(SpiceChannelClass *klass);
+static void record_set_prop_volume(SpiceRecordChannel *channel, guint8 nchannels, const guint16 *volume);
+
/* ------------------------------------------------------------------ */
static void spice_record_channel_reset_capabilities(SpiceChannel *channel)
@@ -149,11 +151,18 @@ static void spice_record_channel_set_property(GObject *gobject,
const GValue *value,
GParamSpec *pspec)
{
+ SpiceRecordChannel *channel = SPICE_RECORD_CHANNEL(gobject);
+ SpiceRecordChannelPrivate *c = channel->priv;
+
switch (prop_id) {
- case PROP_VOLUME:
+ case PROP_VOLUME: {
+ const guint16 *volume = g_value_get_pointer(value);
+ record_set_prop_volume(channel, c->nchannels, volume);
/* TODO: request guest volume change */
break;
+ }
case PROP_MUTE:
+ c->mute = g_value_get_boolean(value);
/* TODO: request guest mute change */
break;
default:
@@ -437,7 +446,6 @@ static void record_handle_stop(SpiceChannel *channel, SpiceMsgIn *in)
/* coroutine context */
static void record_handle_set_volume(SpiceChannel *channel, SpiceMsgIn *in)
{
- SpiceRecordChannelPrivate *c = SPICE_RECORD_CHANNEL(channel)->priv;
SpiceMsgAudioVolume *vol = spice_msg_in_parsed(in);
if (vol->nchannels == 0) {
@@ -445,10 +453,8 @@ static void record_handle_set_volume(SpiceChannel *channel, SpiceMsgIn *in)
return;
}
- g_free(c->volume);
- c->nchannels = vol->nchannels;
- c->volume = g_new(guint16, c->nchannels);
- memcpy(c->volume, vol->volume, sizeof(guint16) * c->nchannels);
+ record_set_prop_volume(SPICE_RECORD_CHANNEL(channel),
+ vol->nchannels, vol->volume);
g_coroutine_object_notify(G_OBJECT(channel), "volume");
}
@@ -473,3 +479,15 @@ static void channel_set_handlers(SpiceChannelClass *klass)
spice_channel_set_handlers(klass, handlers, G_N_ELEMENTS(handlers));
}
+
+static void
+record_set_prop_volume(SpiceRecordChannel *channel, guint8 nchannels, const guint16 *volume)
+{
+ SpiceRecordChannelPrivate *c = channel->priv;
+ if (c->nchannels != nchannels) {
+ g_free(c->volume);
+ c->nchannels = nchannels;
+ c->volume = g_new(guint16, nchannels);
+ }
+ memcpy(c->volume, volume, sizeof(guint16) * nchannels);
+}
--
2.1.0
More information about the Spice-devel
mailing list