<div dir="ltr">looks good, ack<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 14, 2015 at 2:18 PM, Victor Toso <span dir="ltr"><<a href="mailto:victortoso@redhat.com" target="_blank">victortoso@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Gstaudio rely on sink/src elements to get the volume/mute.<br>
(e.g. pulsesink and pulsesrc, the values are updated by PulseAudio<br>
itself when requested)<br>
---<br>
gtk/spice-gstaudio.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++-<br>
1 file changed, 190 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/gtk/spice-gstaudio.c b/gtk/spice-gstaudio.c<br>
index 892028c..33de8e8 100644<br>
--- a/gtk/spice-gstaudio.c<br>
+++ b/gtk/spice-gstaudio.c<br>
@@ -50,6 +50,16 @@ struct _SpiceGstaudioPrivate {<br>
<br>
static gboolean connect_channel(SpiceAudio *audio, SpiceChannel *channel);<br>
static void channel_weak_notified(gpointer data, GObject *where_the_object_was);<br>
+static void spice_gstaudio_get_playback_volume_info_async(SpiceAudio *audio,<br>
+ GCancellable *cancellable, SpiceMainChannel *main_channel,<br>
+ GAsyncReadyCallback callback, gpointer user_data);<br>
+static gboolean spice_gstaudio_get_playback_volume_info_finish(SpiceAudio *audio,<br>
+ GAsyncResult *res, gboolean *mute, guint8 *nchannels, guint16 **volume, GError **error);<br>
+static void spice_gstaudio_get_record_volume_info_async(SpiceAudio *audio,<br>
+ GCancellable *cancellable, SpiceMainChannel *main_channel,<br>
+ GAsyncReadyCallback callback, gpointer user_data);<br>
+static gboolean spice_gstaudio_get_record_volume_info_finish(SpiceAudio *audio,<br>
+ GAsyncResult *res, gboolean *mute, guint8 *nchannels, guint16 **volume, GError **error);<br>
<br>
static void spice_gstaudio_finalize(GObject *obj)<br>
{<br>
@@ -108,6 +118,10 @@ static void spice_gstaudio_class_init(SpiceGstaudioClass *klass)<br>
SpiceAudioClass *audio_class = SPICE_AUDIO_CLASS(klass);<br>
<br>
audio_class->connect_channel = connect_channel;<br>
+ audio_class->get_playback_volume_info_async = spice_gstaudio_get_playback_volume_info_async;<br>
+ audio_class->get_playback_volume_info_finish = spice_gstaudio_get_playback_volume_info_finish;<br>
+ audio_class->get_record_volume_info_async = spice_gstaudio_get_record_volume_info_async;<br>
+ audio_class->get_record_volume_info_finish = spice_gstaudio_get_record_volume_info_finish;<br>
<br>
gobject_class->finalize = spice_gstaudio_finalize;<br>
gobject_class->dispose = spice_gstaudio_dispose;<br>
@@ -370,6 +384,7 @@ static void playback_volume_changed(GObject *object, GParamSpec *pspec, gpointer<br>
g_return_if_fail(nchannels > 0);<br>
<br>
vol = 1.0 * volume[0] / VOLUME_NORMAL;<br>
+ SPICE_DEBUG("%s volume changed to %u (%0.2f)", __func__, volume[0], 100*vol);<br>
<br>
if (GST_IS_BIN(p->playback.sink))<br>
e = gst_bin_get_by_interface(GST_BIN(p->playback.sink), GST_TYPE_STREAM_VOLUME);<br>
@@ -395,7 +410,7 @@ static void playback_mute_changed(GObject *object, GParamSpec *pspec, gpointer d<br>
return;<br>
<br>
g_object_get(object, "mute", &mute, NULL);<br>
- SPICE_DEBUG("playback mute changed %u", mute);<br>
+ SPICE_DEBUG("%s mute changed to %u", __func__, mute);<br>
<br>
if (GST_IS_BIN(p->playback.sink))<br>
e = gst_bin_get_by_interface(GST_BIN(p->playback.sink), GST_TYPE_STREAM_VOLUME);<br>
@@ -428,6 +443,7 @@ static void record_volume_changed(GObject *object, GParamSpec *pspec, gpointer d<br>
g_return_if_fail(nchannels > 0);<br>
<br>
vol = 1.0 * volume[0] / VOLUME_NORMAL;<br>
+ SPICE_DEBUG("%s volume changed to %u (%0.2f)", __func__, volume[0], 100*vol);<br>
<br>
/* TODO directsoundsrc doesn't support IDirectSoundBuffer_SetVolume */<br>
/* TODO pulsesrc doesn't support volume property, it's all coming! */<br>
@@ -456,6 +472,7 @@ static void record_mute_changed(GObject *object, GParamSpec *pspec, gpointer dat<br>
return;<br>
<br>
g_object_get(object, "mute", &mute, NULL);<br>
+ SPICE_DEBUG("%s mute changed to %u", __func__, mute);<br>
<br>
if (GST_IS_BIN(p->record.src))<br>
e = gst_bin_get_by_interface(GST_BIN(p->record.src), GST_TYPE_STREAM_VOLUME);<br>
@@ -543,3 +560,175 @@ SpiceGstaudio *spice_gstaudio_new(SpiceSession *session, GMainContext *context,<br>
<br>
return gstaudio;<br>
}<br>
+<br>
+static void spice_gstaudio_get_playback_volume_info_async(SpiceAudio *audio,<br>
+ GCancellable *cancellable,<br>
+ SpiceMainChannel *main_channel,<br>
+ GAsyncReadyCallback callback,<br>
+ gpointer user_data)<br>
+{<br>
+ GSimpleAsyncResult *simple;<br>
+<br>
+ simple = g_simple_async_result_new(G_OBJECT(audio),<br>
+ callback,<br>
+ user_data,<br>
+ spice_gstaudio_get_playback_volume_info_async);<br>
+ g_simple_async_result_set_check_cancellable (simple, cancellable);<br>
+<br>
+ g_simple_async_result_set_op_res_gboolean(simple, TRUE);<br>
+ g_simple_async_result_complete_in_idle(simple);<br>
+}<br>
+<br>
+static gboolean spice_gstaudio_get_playback_volume_info_finish(SpiceAudio *audio,<br>
+ GAsyncResult *res,<br>
+ gboolean *mute,<br>
+ guint8 *nchannels,<br>
+ guint16 **volume,<br>
+ GError **error)<br>
+{<br>
+ SpiceGstaudioPrivate *p = SPICE_GSTAUDIO(audio)->priv;<br>
+ GstElement *e;<br>
+ gboolean lmute;<br>
+ gdouble vol;<br>
+ gboolean fake_channel = FALSE;<br>
+ GSimpleAsyncResult *simple = (GSimpleAsyncResult *) res;<br>
+<br>
+ g_return_val_if_fail(g_simple_async_result_is_valid(res,<br>
+ G_OBJECT(audio), spice_gstaudio_get_playback_volume_info_async), FALSE);<br>
+<br>
+ if (g_simple_async_result_propagate_error(simple, error)) {<br>
+ return FALSE;<br>
+ }<br>
+<br>
+ if (p->playback.sink == NULL || p->playback.channels == 0) {<br>
+ SPICE_DEBUG("%s PlaybackChannel not created yet, force start", __func__);<br>
+ /* In order to get system volume, we start the pipeline */<br>
+ playback_start(NULL, SPICE_AUDIO_FMT_S16, 2, 48000, audio);<br>
+ fake_channel = TRUE;<br>
+ }<br>
+<br>
+ if (GST_IS_BIN(p->playback.sink))<br>
+ e = gst_bin_get_by_interface(GST_BIN(p->playback.sink), GST_TYPE_STREAM_VOLUME);<br>
+ else<br>
+ e = g_object_ref(p->playback.sink);<br>
+<br>
+ if (GST_IS_STREAM_VOLUME(e)) {<br>
+ vol = gst_stream_volume_get_volume(GST_STREAM_VOLUME(e), GST_STREAM_VOLUME_FORMAT_CUBIC);<br>
+ lmute = gst_stream_volume_get_mute(GST_STREAM_VOLUME(e));<br>
+ } else {<br>
+ g_object_get(e,<br>
+ "volume", &vol,<br>
+ "mute", &lmute, NULL);<br>
+ }<br>
+ g_object_unref(e);<br>
+<br>
+ if (fake_channel) {<br>
+ SPICE_DEBUG("%s Stop faked PlaybackChannel", __func__);<br>
+ playback_stop(NULL, audio);<br>
+ }<br>
+<br>
+ if (mute != NULL) {<br>
+ *mute = lmute;<br>
+ }<br>
+<br>
+ if (nchannels != NULL) {<br>
+ *nchannels = p->playback.channels;<br>
+ }<br>
+<br>
+ if (volume != NULL) {<br>
+ gint i;<br>
+ *volume = g_new(guint16, p->playback.channels);<br>
+ for (i = 0; i < p->playback.channels; i++) {<br>
+ (*volume)[i] = (guint16) (vol * VOLUME_NORMAL);<br>
+ SPICE_DEBUG("(playback) volume at %d is %u (%0.2f%%)", i, (*volume)[i], 100*vol);<br>
+ }<br>
+ }<br>
+<br>
+ return g_simple_async_result_get_op_res_gboolean(simple);<br>
+}<br>
+<br>
+static void spice_gstaudio_get_record_volume_info_async(SpiceAudio *audio,<br>
+ GCancellable *cancellable,<br>
+ SpiceMainChannel *main_channel,<br>
+ GAsyncReadyCallback callback,<br>
+ gpointer user_data)<br>
+{<br>
+ GSimpleAsyncResult *simple;<br>
+<br>
+ simple = g_simple_async_result_new(G_OBJECT(audio),<br>
+ callback,<br>
+ user_data,<br>
+ spice_gstaudio_get_record_volume_info_async);<br>
+ g_simple_async_result_set_check_cancellable (simple, cancellable);<br>
+<br>
+ g_simple_async_result_set_op_res_gboolean(simple, TRUE);<br>
+ g_simple_async_result_complete_in_idle(simple);<br>
+}<br>
+<br>
+static gboolean spice_gstaudio_get_record_volume_info_finish(SpiceAudio *audio,<br>
+ GAsyncResult *res,<br>
+ gboolean *mute,<br>
+ guint8 *nchannels,<br>
+ guint16 **volume,<br>
+ GError **error)<br>
+{<br>
+ SpiceGstaudioPrivate *p = SPICE_GSTAUDIO(audio)->priv;<br>
+ GstElement *e;<br>
+ gboolean lmute;<br>
+ gdouble vol;<br>
+ gboolean fake_channel = FALSE;<br>
+ GSimpleAsyncResult *simple = (GSimpleAsyncResult *) res;<br>
+<br>
+ g_return_val_if_fail(g_simple_async_result_is_valid(res,<br>
+ G_OBJECT(audio), spice_gstaudio_get_record_volume_info_async), FALSE);<br>
+<br>
+ if (g_simple_async_result_propagate_error(simple, error)) {<br>
+ return FALSE;<br>
+ }<br>
+<br>
+ if (p->record.src == NULL || p->record.channels == 0) {<br>
+ SPICE_DEBUG("%s RecordChannel not created yet, force start", __func__);<br>
+ /* In order to get system volume, we start the pipeline */<br>
+ record_start(NULL, SPICE_AUDIO_FMT_S16, 2, 48000, audio);<br>
+ fake_channel = TRUE;<br>
+ }<br>
+<br>
+ if (GST_IS_BIN(p->record.src))<br>
+ e = gst_bin_get_by_interface(GST_BIN(p->record.src), GST_TYPE_STREAM_VOLUME);<br>
+ else<br>
+ e = g_object_ref(p->record.src);<br>
+<br>
+ if (GST_IS_STREAM_VOLUME(e)) {<br>
+ vol = gst_stream_volume_get_volume(GST_STREAM_VOLUME(e), GST_STREAM_VOLUME_FORMAT_CUBIC);<br>
+ lmute = gst_stream_volume_get_mute(GST_STREAM_VOLUME(e));<br>
+ } else {<br>
+ g_object_get(e,<br>
+ "volume", &vol,<br>
+ "mute", &lmute, NULL);<br>
+ }<br>
+ g_object_unref(e);<br>
+<br>
+ if (fake_channel) {<br>
+ SPICE_DEBUG("%s Stop faked RecordChannel", __func__);<br>
+ record_stop(SPICE_GSTAUDIO(audio));<br>
+ }<br>
+<br>
+ if (mute != NULL) {<br>
+ *mute = lmute;<br>
+ }<br>
+<br>
+ if (nchannels != NULL) {<br>
+ *nchannels = p->record.channels;<br>
+ }<br>
+<br>
+ if (volume != NULL) {<br>
+ gint i;<br>
+ *volume = g_new(guint16, p->record.channels);<br>
+ for (i = 0; i < p->record.channels; i++) {<br>
+ (*volume)[i] = (guint16) (vol * VOLUME_NORMAL);<br>
+ SPICE_DEBUG("(record) volume at %d is %u (%0.2f%%)", i, (*volume)[i], 100*vol);<br>
+ }<br>
+ }<br>
+<br>
+ return g_simple_async_result_get_op_res_gboolean(simple);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.1.0<br>
<br>
_______________________________________________<br>
Spice-devel mailing list<br>
<a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Marc-André Lureau</div>
</div>