[Spice-devel] [spice-gtk PATCH 4/5] audio: add functions to get volume/mute from client
Marc-André Lureau
mlureau at redhat.com
Wed Mar 18 10:43:22 PDT 2015
Hi
----- Original Message -----
> pulse: returns the value stored in playback and record channels as they
> are updated by pulse itself.
Are they?
>
> gstreamer: pulsesink and pulsesrc returns the current volume/mute of the
> stream but it can vary if other elements are used.
Instead of adding "sync_data" function (the name is confusing btw), it would be cleaner to have overridable getter get_volume() & get_mute() on SpiceAudio.
> ---
> gtk/spice-audio-priv.h | 9 ++++++
> gtk/spice-audio.c | 23 +++++++++++++++
> gtk/spice-gstaudio.c | 79
> ++++++++++++++++++++++++++++++++++++++++++++++++++
> gtk/spice-pulse.c | 41 ++++++++++++++++++++++++++
> 4 files changed, 152 insertions(+)
>
> diff --git a/gtk/spice-audio-priv.h b/gtk/spice-audio-priv.h
> index 898c5a7..c27831e 100644
> --- a/gtk/spice-audio-priv.h
> +++ b/gtk/spice-audio-priv.h
> @@ -31,4 +31,13 @@ struct _SpiceAudioPrivate {
>
> G_END_DECLS
>
> +gboolean spice_audio_get_playback_sync_data (SpiceAudio *self, guint8
> *nchannels, guint16 **volume, gboolean *mute);
> +gboolean spice_audio_get_record_sync_data (SpiceAudio *self, guint8
> *nchannels, guint16 **volume, gboolean *mute);
> +
> +gboolean spice_pulse_get_playback_sync_data (SpiceAudio *audio, guint8
> *nchannels, guint16 **volume, gboolean *mute);
> +gboolean spice_pulse_get_record_sync_data (SpiceAudio *audio, guint8
> *nchannels, guint16 **volume, gboolean *mute);
> +
> +gboolean spice_gstaudio_get_playback_sync_data (SpiceAudio *audio, guint8
> *nchannels, guint16 **volume, gboolean *mute);
> +gboolean spice_gstaudio_get_record_sync_data (SpiceAudio *audio, guint8
> *nchannels, guint16 **volume, gboolean *mute);
> +
> #endif /* __SPICE_AUDIO_PRIVATE_H__ */
> diff --git a/gtk/spice-audio.c b/gtk/spice-audio.c
> index 329ab6a..fddf963 100644
> --- a/gtk/spice-audio.c
> +++ b/gtk/spice-audio.c
> @@ -191,6 +191,29 @@ static void session_enable_audio(GObject *gobject,
> GParamSpec *pspec,
> update_audio_channels(SPICE_AUDIO(user_data), SPICE_SESSION(gobject));
> }
>
> +G_GNUC_INTERNAL
> +gboolean spice_audio_get_playback_sync_data (SpiceAudio *self, guint8
> *nchannels,
> + guint16 **volume, gboolean
> *mute)
> +{
> +#ifdef WITH_PULSE
> + return spice_pulse_get_playback_sync_data (self, nchannels, volume,
> mute);
> +#elif defined(WITH_GSTAUDIO)
> + return spice_gstaudio_get_playback_sync_data (self, nchannels, volume,
> mute);
> +#endif
> +}
> +
> +G_GNUC_INTERNAL
> +gboolean spice_audio_get_record_sync_data (SpiceAudio *self, guint8
> *nchannels,
> + guint16 **volume, gboolean *mute)
> +{
> +#ifdef WITH_PULSE
> + return spice_pulse_get_record_sync_data (self, nchannels, volume, mute);
> +#elif defined(WITH_GSTAUDIO)
> + return spice_gstaudio_get_record_sync_data (self, nchannels, volume,
> mute);
> +#endif
> +}
> +
> +
> /**
> * spice_audio_new:
> * @session: the #SpiceSession to connect to
> diff --git a/gtk/spice-gstaudio.c b/gtk/spice-gstaudio.c
> index 892028c..48f8f8c 100644
> --- a/gtk/spice-gstaudio.c
> +++ b/gtk/spice-gstaudio.c
> @@ -26,6 +26,7 @@
> #include "spice-common.h"
> #include "spice-session.h"
> #include "spice-util.h"
> +#include "spice-audio-priv.h"
>
> #define SPICE_GSTAUDIO_GET_PRIVATE(obj) \
> (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_GSTAUDIO,
> SpiceGstaudioPrivate))
> @@ -543,3 +544,81 @@ SpiceGstaudio *spice_gstaudio_new(SpiceSession *session,
> GMainContext *context,
>
> return gstaudio;
> }
> +
> +G_GNUC_INTERNAL
> +gboolean spice_gstaudio_get_playback_sync_data(SpiceAudio *audio,
> + guint8 *nchannels,
> + guint16 **volume,
> + gboolean *mute)
> +{
> + SpiceGstaudioPrivate *p = SPICE_GSTAUDIO(audio)->priv;
> + gint i;
> + gdouble vol;
> + GstElement *e;
> +
> + 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)) {
> + vol = gst_stream_volume_get_volume(GST_STREAM_VOLUME(e),
> GST_STREAM_VOLUME_FORMAT_LINEAR);
> + *mute = gst_stream_volume_get_mute(GST_STREAM_VOLUME(e));
> + } else {
> + g_object_get(e,
> + "volume", &vol,
> + "mute", mute,
> + 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);
> + }
> + return TRUE;
> +}
> +
> +G_GNUC_INTERNAL
> +gboolean spice_gstaudio_get_record_sync_data(SpiceAudio *audio,
> + guint8 *nchannels,
> + guint16 **volume,
> + gboolean *mute)
> +{
> + SpiceGstaudioPrivate *p = SPICE_GSTAUDIO(audio)->priv;
> + gint i;
> + gdouble vol;
> + GstElement *e;
> +
> + 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)) {
> + vol = gst_stream_volume_get_volume(GST_STREAM_VOLUME(e),
> GST_STREAM_VOLUME_FORMAT_LINEAR);
> + *mute = gst_stream_volume_get_mute(GST_STREAM_VOLUME(e));
> + } else {
> + g_object_get(e,
> + "volume", &vol,
> + "mute", mute,
> + 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);
> + }
> + return TRUE;
> +}
> diff --git a/gtk/spice-pulse.c b/gtk/spice-pulse.c
> index b9ced66..7ac26b2 100644
> --- a/gtk/spice-pulse.c
> +++ b/gtk/spice-pulse.c
> @@ -22,6 +22,7 @@
> #include "spice-session-priv.h"
> #include "spice-channel-priv.h"
> #include "spice-util-priv.h"
> +#include "spice-audio-priv.h"
>
> #include <pulse/glib-mainloop.h>
> #include <pulse/pulseaudio.h>
> @@ -1001,3 +1002,43 @@ error:
> g_object_unref(pulse);
> return NULL;
> }
> +
> +G_GNUC_INTERNAL
> +gboolean spice_pulse_get_playback_sync_data(SpiceAudio *audio,
> + guint8 *nchannels,
> + guint16 **volume,
> + gboolean *mute)
> +{
> + SpicePulsePrivate *p = SPICE_PULSE(audio)->priv;
> + guint16 *pvol;
> +
> + g_object_get(p->pchannel,
> + "nchannels", nchannels,
> + "volume", &pvol,
> + "mute", mute,
> + NULL);
> + *volume = g_new(guint16, *nchannels);
> + memcpy (*volume, pvol, sizeof(guint16) * (*nchannels));
> + /* Always return TRUE as we get the value stored in the channel */
> + return TRUE;
> +}
> +
> +G_GNUC_INTERNAL
> +gboolean spice_pulse_get_record_sync_data (SpiceAudio *audio,
> + guint8 *nchannels,
> + guint16 **volume,
> + gboolean *mute)
> +{
> + SpicePulsePrivate *p = SPICE_PULSE(audio)->priv;
> + guint16 *rvol;
> +
> + g_object_get(p->rchannel,
> + "nchannels", nchannels,
> + "volume", &rvol,
> + "mute", mute,
> + NULL);
> + *volume = g_new(guint16, *nchannels);
> + memcpy (*volume, rvol, sizeof(guint16) * (*nchannels));
> + /* Always return TRUE as we get the value stored in the channel */
> + return TRUE;
> +}
> --
> 2.1.0
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
>
More information about the Spice-devel
mailing list