From fb61a75b1aa78f524e8137f7fdff9a3ab87b3000 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Thu, 9 May 2019 12:35:59 +0900 Subject: [PATCH] pulsesink: Apply individual volume ratio to volume/mute properties It relates to the commit below. - 82a861316c7d53940a4ba5c5ea6b80e4e9b2fbb0 - pulseutil: Add API for setting volume ratio Change-Id: I376d2049e63c01cfe8e25d4e1d68786045cce8fc Signed-off-by: Sangchul Lee --- ext/pulse/pulsesink.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/ext/pulse/pulsesink.c b/ext/pulse/pulsesink.c index 2a58b78..ad404da 100644 --- a/ext/pulse/pulsesink.c +++ b/ext/pulse/pulsesink.c @@ -915,7 +915,9 @@ gst_pulseringbuffer_acquire (GstAudioRingBuffer * buf, const pa_buffer_attr *actual; pa_channel_map channel_map; pa_operation *o = NULL; +#ifndef __TIZEN__ pa_cvolume v; +#endif pa_cvolume *pv = NULL; pa_stream_flags_t flags; const gchar *name; @@ -1018,6 +1020,7 @@ gst_pulseringbuffer_acquire (GstAudioRingBuffer * buf, GST_INFO_OBJECT (psink, "prebuf: %d", wanted.prebuf); GST_INFO_OBJECT (psink, "minreq: %d", wanted.minreq); +#ifndef __TIZEN__ /* configure volume when we changed it, else we leave the default */ if (psink->volume_set) { GST_LOG_OBJECT (psink, "have volume of %f", psink->volume); @@ -1031,17 +1034,20 @@ gst_pulseringbuffer_acquire (GstAudioRingBuffer * buf, } else { pv = NULL; } +#endif /* construct the flags */ flags = PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY | PA_STREAM_START_CORKED; +#ifndef __TIZEN__ if (psink->mute_set) { if (psink->mute) flags |= PA_STREAM_START_MUTED; else flags |= PA_STREAM_START_UNMUTED; } +#endif /* we always start corked (see flags above) */ pbuf->corked = TRUE; @@ -1069,6 +1075,18 @@ gst_pulseringbuffer_acquire (GstAudioRingBuffer * buf, GST_INFO_OBJECT (psink, "negotiated to: %s", print_buf); #endif +#ifdef __TIZEN__ + { + uint32_t idx; + if ((idx = pa_stream_get_index (pbuf->stream)) == PA_INVALID_INDEX) + goto no_index; + if (psink->volume_set) + gst_pulse_set_volume_ratio (idx, "out", psink->volume); + if (psink->mute_set) + if (psink->mute) + gst_pulse_set_volume_ratio (idx, "out", 0); + } +#endif /* After we passed the volume off of to PA we never want to set it again, since it is PA's job to save/restore volumes. */ psink->volume_set = psink->mute_set = FALSE; @@ -1127,6 +1145,15 @@ connect_failed: pa_strerror (pa_context_errno (pbuf->context))), (NULL)); goto unlock_and_fail; } +#ifdef __TIZEN__ +no_index: + { + GST_ELEMENT_ERROR (psink, RESOURCE, FAILED, + ("Failed to get stream index: %s", + pa_strerror (pa_context_errno (pbuf->context))), (NULL)); + goto unlock_and_fail; + } +#endif } /* free the stream that we acquired before */ @@ -2518,15 +2545,19 @@ gst_pulsesink_finalize (GObject * object) static void gst_pulsesink_set_volume (GstPulseSink * psink, gdouble volume) { +#ifndef __TIZEN__ pa_cvolume v; pa_operation *o = NULL; +#endif GstPulseRingBuffer *pbuf; uint32_t idx; +#ifndef __TIZEN__ if (!mainloop) goto no_mainloop; pa_threaded_mainloop_lock (mainloop); +#endif GST_DEBUG_OBJECT (psink, "setting volume to %f", volume); @@ -2537,6 +2568,7 @@ gst_pulsesink_set_volume (GstPulseSink * psink, gdouble volume) if ((idx = pa_stream_get_index (pbuf->stream)) == PA_INVALID_INDEX) goto no_index; +#ifndef __TIZEN__ if (pbuf->is_pcm) gst_pulse_cvolume_from_linear (&v, pbuf->channels, volume); else @@ -2548,17 +2580,26 @@ gst_pulsesink_set_volume (GstPulseSink * psink, gdouble volume) &v, NULL, NULL))) goto volume_failed; +#else + if (!psink->mute) + gst_pulse_set_volume_ratio (idx, "out", volume); + psink->volume = volume; +#endif + /* We don't really care about the result of this call */ unlock: +#ifndef __TIZEN__ if (o) pa_operation_unref (o); pa_threaded_mainloop_unlock (mainloop); +#endif return; /* ERRORS */ +#ifndef __TIZEN__ no_mainloop: { psink->volume = volume; @@ -2567,6 +2608,7 @@ no_mainloop: GST_DEBUG_OBJECT (psink, "we have no mainloop"); return; } +#endif no_buffer: { psink->volume = volume; @@ -2580,6 +2622,7 @@ no_index: GST_DEBUG_OBJECT (psink, "we don't have a stream index"); goto unlock; } +#ifndef __TIZEN__ volume_failed: { GST_ELEMENT_ERROR (psink, RESOURCE, FAILED, @@ -2587,19 +2630,24 @@ volume_failed: pa_strerror (pa_context_errno (pbuf->context))), (NULL)); goto unlock; } +#endif } static void gst_pulsesink_set_mute (GstPulseSink * psink, gboolean mute) { +#ifndef __TIZEN__ pa_operation *o = NULL; +#endif GstPulseRingBuffer *pbuf; uint32_t idx; +#ifndef __TIZEN__ if (!mainloop) goto no_mainloop; pa_threaded_mainloop_lock (mainloop); +#endif GST_DEBUG_OBJECT (psink, "setting mute state to %d", mute); @@ -2610,21 +2658,29 @@ gst_pulsesink_set_mute (GstPulseSink * psink, gboolean mute) if ((idx = pa_stream_get_index (pbuf->stream)) == PA_INVALID_INDEX) goto no_index; +#ifndef __TIZEN__ if (!(o = pa_context_set_sink_input_mute (pbuf->context, idx, mute, NULL, NULL))) goto mute_failed; +#else + gst_pulse_set_volume_ratio (idx, "out", mute ? 0 : psink->volume); + psink->mute = mute; +#endif /* We don't really care about the result of this call */ unlock: +#ifndef __TIZEN__ if (o) pa_operation_unref (o); pa_threaded_mainloop_unlock (mainloop); +#endif return; /* ERRORS */ +#ifndef __TIZEN__ no_mainloop: { psink->mute = mute; @@ -2633,6 +2689,7 @@ no_mainloop: GST_DEBUG_OBJECT (psink, "we have no mainloop"); return; } +#endif no_buffer: { psink->mute = mute; @@ -2646,6 +2703,7 @@ no_index: GST_DEBUG_OBJECT (psink, "we don't have a stream index"); goto unlock; } +#ifndef __TIZEN__ mute_failed: { GST_ELEMENT_ERROR (psink, RESOURCE, FAILED, @@ -2653,6 +2711,7 @@ mute_failed: pa_strerror (pa_context_errno (pbuf->context))), (NULL)); goto unlock; } +#endif } static void @@ -3052,18 +3111,26 @@ gst_pulsesink_get_property (GObject * object, break; case PROP_VOLUME: { +#ifndef __TIZEN__ gdouble volume; gst_pulsesink_get_sink_input_info (pulsesink, &volume, NULL); g_value_set_double (value, volume); +#else + g_value_set_double (value, pulsesink->volume); +#endif break; } case PROP_MUTE: { +#ifndef __TIZEN__ gboolean mute; gst_pulsesink_get_sink_input_info (pulsesink, NULL, &mute); g_value_set_boolean (value, mute); +#else + g_value_set_boolean (value, pulsesink->mute); +#endif break; } case PROP_CLIENT_NAME: -- 2.7.4