[Spice-devel] [spice-gtk PATCH v2 4/7] audio: gstaudio implements spice-audio get functions

Victor Toso victortoso at redhat.com
Mon Mar 23 06:26:28 PDT 2015


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 | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 125 insertions(+)

diff --git a/gtk/spice-gstaudio.c b/gtk/spice-gstaudio.c
index 892028c..ef2e2c0 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;
@@ -543,3 +551,120 @@ 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;
+
+    if (p->playback.sink == NULL) {
+        SPICE_DEBUG("calling '%s' before start", __func__);
+        return FALSE;
+    }
+
+    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);
+
+    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;
+
+    if (p->playback.sink == NULL || p->playback.channels == 0) {
+        SPICE_DEBUG("calling '%s' before start", __func__);
+        return NULL;
+    }
+
+    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("(playback) volume[%d] = %d (%f)", i, volume[i], vol);
+    }
+
+    return volume;
+}
+
+static gboolean spice_gstaudio_get_record_mute(SpiceAudio *audio)
+{
+    SpiceGstaudioPrivate *p = SPICE_GSTAUDIO(audio)->priv;
+    GstElement *e;
+    gboolean mute;
+
+    if (p->record.src != NULL) {
+        SPICE_DEBUG("calling '%s' before start", __func__);
+        return FALSE;
+    }
+
+    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);
+
+    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;
+
+    if (p->record.src == NULL || p->record.channels == 0) {
+        SPICE_DEBUG("calling '%s' before start", __func__);
+        return NULL;
+    }
+
+    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);
+    }
+    return volume;
+}
-- 
2.1.0



More information about the Spice-devel mailing list