[vlc-commits] aout: add event callback to request gain change from aout module

Rémi Denis-Courmont git at videolan.org
Thu Jul 19 19:35:27 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jul 19 17:13:35 2012 +0300| [950e621e03e7d3095bdd870316a89760a96e8c6f] | committer: Rémi Denis-Courmont

aout: add event callback to request gain change from aout module

This is more flexible than the current approach:
- Gain can be changed if the aout has a custom (native) volume control.
- The callback approach does not break the encapsulation principles
  (so audio_output_t/module_need() could be used somewhere else).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=950e621e03e7d3095bdd870316a89760a96e8c6f
---

 include/vlc_aout.h        |   10 ++++++++--
 src/audio_output/output.c |   11 +++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index dcf2360..3ed9a52 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -155,6 +155,7 @@ struct audio_output
         void (*time_report)(audio_output_t *, mtime_t);
         void (*volume_report)(audio_output_t *, float);
         void (*mute_report)(audio_output_t *, bool);
+        int (*gain_request)(audio_output_t *, float);
     } event;
 };
 
@@ -224,6 +225,11 @@ VLC_API const char * aout_FormatPrintChannels( const audio_sample_format_t * ) V
 
 VLC_API void aout_VolumeSoftInit( audio_output_t * );
 
+static inline void aout_TimeReport(audio_output_t *aout, mtime_t date)
+{
+    aout->event.time_report(aout, date);
+}
+
 static inline void aout_VolumeReport(audio_output_t *aout, float volume)
 {
     aout->event.volume_report(aout, volume);
@@ -234,9 +240,9 @@ static inline void aout_MuteReport(audio_output_t *aout, bool mute)
     aout->event.mute_report(aout, mute);
 }
 
-static inline void aout_TimeReport(audio_output_t *aout, mtime_t date)
+static inline int aout_GainRequest(audio_output_t *aout, float gain)
 {
-    aout->event.time_report(aout, date);
+    return aout->event.gain_request(aout, gain);
 }
 
 VLC_API int aout_ChannelsRestart( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * );
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index e6e57ad..c626453 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -103,6 +103,16 @@ static void aout_OutputMuteReport (audio_output_t *aout, bool mute)
     var_SetBool (aout, "mute", mute);
 }
 
+static int aout_OutputGainRequest (audio_output_t *aout, float gain)
+{
+    aout_owner_t *owner = aout_owner (aout);
+
+    aout_assert_locked (aout);
+    aout_volume_SetVolume (owner->volume, gain);
+    /* XXX: ideally, return -1 if format cannot be amplified */
+    return 0;
+}
+
 /*****************************************************************************
  * aout_OutputNew : allocate a new output and rework the filter pipeline
  *****************************************************************************
@@ -120,6 +130,7 @@ int aout_OutputNew( audio_output_t *p_aout,
     p_aout->event.time_report = aout_OutputTimeReport;
     p_aout->event.volume_report = aout_OutputVolumeReport;
     p_aout->event.mute_report = aout_OutputMuteReport;
+    p_aout->event.gain_request = aout_OutputGainRequest;
 
     /* Find the best output plug-in. */
     owner->module = module_need (p_aout, "audio output", "$aout", false);



More information about the vlc-commits mailing list