]> git.sesse.net Git - vlc/commitdiff
aout: add event callback to request gain change from aout module
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 19 Jul 2012 14:13:35 +0000 (17:13 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 19 Jul 2012 17:34:53 +0000 (20:34 +0300)
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).

include/vlc_aout.h
src/audio_output/output.c

index dcf236007ccec623013cbc70cb3ac3652531a046..3ed9a52ff7223f6baa91fe8d5e81295e1502392e 100644 (file)
@@ -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 * );
index e6e57add626869d41677fc2678f2566cce4ceb10..c62645360c49b8b88ec6063d371b4677d3c8cd0c 100644 (file)
@@ -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);