Commit 950e621e authored by Rémi Denis-Courmont's avatar 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).
parent 99693981
......@@ -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 * );
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment