Gstaudio rely on sink/src elements to get the volume/mute. * In the case of pulsesink and pulsesrc, the values are updated. --- gtk/spice-gstaudio.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/gtk/spice-gstaudio.c b/gtk/spice-gstaudio.c index 892028c..fb6464e 100644 --- a/gtk/spice-gstaudio.c +++ b/gtk/spice-gstaudio.c @@ -50,6 +50,10 @@ struct _SpiceGstaudioPrivate { static gboolean connect_channel(SpiceAudio *audio, SpiceChannel *channel); static void channel_weak_notified(gpointer data, GObject *where_the_object_was); +static gboolean spice_gstaudio_get_playback_mute(SpiceAudio *audio); +static guint16* spice_gstaudio_get_playback_volume(SpiceAudio *audio, guint8 *nchannels); +static gboolean spice_gstaudio_get_record_mute(SpiceAudio *audio); +static guint16* spice_gstaudio_get_record_volume(SpiceAudio *audio, guint8 *nchannels); static void spice_gstaudio_finalize(GObject *obj) { @@ -108,6 +112,10 @@ static void spice_gstaudio_class_init(SpiceGstaudioClass *klass) SpiceAudioClass *audio_class = SPICE_AUDIO_CLASS(klass); audio_class->connect_channel = connect_channel; + audio_class->get_playback_mute = spice_gstaudio_get_playback_mute; + audio_class->get_playback_volume = spice_gstaudio_get_playback_volume; + audio_class->get_record_mute = spice_gstaudio_get_record_mute; + audio_class->get_record_volume = spice_gstaudio_get_record_volume; gobject_class->finalize = spice_gstaudio_finalize; gobject_class->dispose = spice_gstaudio_dispose; @@ -370,6 +378,7 @@ static void playback_volume_changed(GObject *object, GParamSpec *pspec, gpointer g_return_if_fail(nchannels > 0); vol = 1.0 * volume[0] / VOLUME_NORMAL; + SPICE_DEBUG("%s volume changed to %u (%0.2f)", __func__, volume[0], 100*vol); if (GST_IS_BIN(p->playback.sink)) e = gst_bin_get_by_interface(GST_BIN(p->playback.sink), GST_TYPE_STREAM_VOLUME); @@ -395,7 +404,7 @@ static void playback_mute_changed(GObject *object, GParamSpec *pspec, gpointer d return; g_object_get(object, "mute", &mute, NULL); - SPICE_DEBUG("playback mute changed %u", mute); + SPICE_DEBUG("%s mute changed to %u", __func__, mute); if (GST_IS_BIN(p->playback.sink)) e = gst_bin_get_by_interface(GST_BIN(p->playback.sink), GST_TYPE_STREAM_VOLUME); @@ -428,6 +437,7 @@ static void record_volume_changed(GObject *object, GParamSpec *pspec, gpointer d g_return_if_fail(nchannels > 0); vol = 1.0 * volume[0] / VOLUME_NORMAL; + SPICE_DEBUG("%s volume changed to %u (%0.2f)", __func__, volume[0], 100*vol); /* TODO directsoundsrc doesn't support IDirectSoundBuffer_SetVolume */ /* TODO pulsesrc doesn't support volume property, it's all coming! */ @@ -456,6 +466,7 @@ static void record_mute_changed(GObject *object, GParamSpec *pspec, gpointer dat return; g_object_get(object, "mute", &mute, NULL); + SPICE_DEBUG("%s mute changed to %u", __func__, mute); if (GST_IS_BIN(p->record.src)) e = gst_bin_get_by_interface(GST_BIN(p->record.src), GST_TYPE_STREAM_VOLUME); @@ -543,3 +554,150 @@ SpiceGstaudio *spice_gstaudio_new(SpiceSession *session, GMainContext *context, return gstaudio; } + +static gboolean spice_gstaudio_get_playback_mute(SpiceAudio *audio) +{ + SpiceGstaudioPrivate *p = SPICE_GSTAUDIO(audio)->priv; + GstElement *e; + gboolean mute; + gboolean fake_channel = FALSE; + + if (p->playback.sink == NULL) { + SPICE_DEBUG("%s PlaybackChannel not created yet, force start", __func__); + /* In order to get system mute, we start the pipeline */ + playback_start(NULL, SPICE_AUDIO_FMT_S16, 2, 48000, audio); + fake_channel = TRUE; + } + + if (GST_IS_BIN(p->playback.sink)) + e = gst_bin_get_by_interface(GST_BIN(p->playback.sink), GST_TYPE_STREAM_VOLUME); + else + e = g_object_ref(p->playback.sink); + + if (GST_IS_STREAM_VOLUME(e)) + mute = gst_stream_volume_get_mute(GST_STREAM_VOLUME(e)); + else + g_object_get(e, "mute", &mute, NULL); + + if (fake_channel) { + SPICE_DEBUG("%s Stop faked PlaybackChannel", __func__); + playback_stop(NULL, audio); + } + return mute; +} + +static guint16* spice_gstaudio_get_playback_volume(SpiceAudio *audio, guint8 *nchannels) +{ + SpiceGstaudioPrivate *p = SPICE_GSTAUDIO(audio)->priv; + GstElement *e; + gint i; + guint16 *volume; + gdouble vol; + gboolean fake_channel = FALSE; + + if (p->playback.sink == NULL || p->playback.channels == 0) { + SPICE_DEBUG("%s PlaybackChannel not created yet, force start", __func__); + /* In order to get system volume, we start the pipeline */ + playback_start(NULL, SPICE_AUDIO_FMT_S16, 2, 48000, audio); + fake_channel = TRUE; + } + + if (GST_IS_BIN(p->playback.sink)) + e = gst_bin_get_by_interface(GST_BIN(p->playback.sink), GST_TYPE_STREAM_VOLUME); + else + e = g_object_ref(p->playback.sink); + + if (GST_IS_STREAM_VOLUME(e)) + vol = gst_stream_volume_get_volume(GST_STREAM_VOLUME(e), GST_STREAM_VOLUME_FORMAT_CUBIC); + else + g_object_get(e, "volume", &vol, NULL); + + if (nchannels != NULL) + *nchannels = p->playback.channels; + + volume = g_new(guint16, p->playback.channels); + for (i = 0; i < p->playback.channels; i++) { + volume[i] = (guint16) (vol * VOLUME_NORMAL); + SPICE_DEBUG("%s (playback) volume[%d] = %d (%f)", __func__, i, volume[i], vol); + } + + if (fake_channel) { + SPICE_DEBUG("%s Stop faked PlaybackChannel", __func__); + playback_stop(NULL, audio); + } + + return volume; +} + +static gboolean spice_gstaudio_get_record_mute(SpiceAudio *audio) +{ + SpiceGstaudioPrivate *p = SPICE_GSTAUDIO(audio)->priv; + GstElement *e; + gboolean mute; + gboolean fake_channel = FALSE; + + if (p->record.src != NULL) { + SPICE_DEBUG("%s RecordChannel not created yet, force start", __func__); + /* In order to get system mute, we start the pipeline */ + record_start(NULL, SPICE_AUDIO_FMT_S16, 2, 48000, audio); + fake_channel = TRUE; + } + + if (GST_IS_BIN(p->record.src)) + e = gst_bin_get_by_interface(GST_BIN(p->record.src), GST_TYPE_STREAM_VOLUME); + else + e = g_object_ref(p->record.src); + + if (GST_IS_STREAM_VOLUME(e)) + mute = gst_stream_volume_get_mute(GST_STREAM_VOLUME(e)); + else + g_object_get(e, "mute", &mute, NULL); + + if (fake_channel) { + SPICE_DEBUG("%s Stop faked RecordChannel", __func__); + record_stop(SPICE_GSTAUDIO(audio)); + } + return mute; +} + +static guint16* spice_gstaudio_get_record_volume(SpiceAudio *audio, guint8 *nchannels) +{ + SpiceGstaudioPrivate *p = SPICE_GSTAUDIO(audio)->priv; + GstElement *e; + gint i; + guint16 *volume; + gdouble vol; + gboolean fake_channel = FALSE; + + if (p->record.src == NULL || p->record.channels == 0) { + SPICE_DEBUG("%s RecordChannel not created yet, force start", __func__); + /* In order to get system volume, we start the pipeline */ + record_start(NULL, SPICE_AUDIO_FMT_S16, 2, 48000, audio); + fake_channel = TRUE; + } + + if (GST_IS_BIN(p->record.src)) + e = gst_bin_get_by_interface(GST_BIN(p->record.src), GST_TYPE_STREAM_VOLUME); + else + e = g_object_ref(p->record.src); + + if (GST_IS_STREAM_VOLUME(e)) + vol = gst_stream_volume_get_volume(GST_STREAM_VOLUME(e), GST_STREAM_VOLUME_FORMAT_CUBIC); + else + g_object_get(e, "volume", &vol, NULL); + + if (nchannels != NULL) + *nchannels = p->record.channels; + + volume = g_new(guint16, p->record.channels); + for (i = 0; i < p->record.channels; i++) { + volume[i] = (guint16) (vol * VOLUME_NORMAL); + SPICE_DEBUG("(record) volume at %d is %d (%%%0.2f)", i, volume[i], vol); + } + + if (fake_channel) { + SPICE_DEBUG("%s Stop faked RecordChannel", __func__); + record_stop(SPICE_GSTAUDIO(audio)); + } + return volume; +} -- 2.1.0 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel