From fefe9b605325bd04251e9ca877d9a8bd5b56295f Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Thu, 8 Dec 2022 11:27:30 +0100 Subject: [PATCH] lib: add libvlc_audio_set_mixmode --- include/vlc/libvlc_media_player.h | 46 +++++++++++++++++++++++++++++++ lib/audio.c | 42 ++++++++++++++++++++++++++++ lib/libvlc.sym | 2 ++ 3 files changed, 90 insertions(+) diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h index 2403413eb6c1..c118f2b2c7b7 100644 --- a/include/vlc/libvlc_media_player.h +++ b/include/vlc/libvlc_media_player.h @@ -2229,6 +2229,17 @@ typedef enum libvlc_audio_output_stereomode_t { libvlc_AudioStereoMode_Mono = 7, } libvlc_audio_output_stereomode_t; +/** + * Audio mix modes + */ +typedef enum libvlc_audio_output_mixmode_t { + libvlc_AudioMixMode_Unset = 0, + libvlc_AudioMixMode_Stereo = 1, + libvlc_AudioMixMode_Binaural = 2, + libvlc_AudioMixMode_4_0 = 3, + libvlc_AudioMixMode_5_1 = 4, + libvlc_AudioMixMode_7_1 = 5, +} libvlc_audio_output_mixmode_t; /** * Gets the list of available audio output modules. @@ -2429,6 +2440,41 @@ LIBVLC_API libvlc_audio_output_stereomode_t libvlc_audio_get_stereomode( libvlc_ LIBVLC_API int libvlc_audio_set_stereomode( libvlc_media_player_t *p_mi, libvlc_audio_output_stereomode_t mode ); +/** + * Get current audio mix-mode. + * + * \param p_mi media player + * \return the audio mix-mode, \see libvlc_audio_output_mixmode_t + * \version LibVLC 4.0.0 or later + */ +LIBVLC_API libvlc_audio_output_mixmode_t libvlc_audio_get_mixmode( libvlc_media_player_t *p_mi ); + +/** + * Set current audio mix-mode. + * + * By default (libvlc_AudioMixMode_Unset), the audio output will keep its + * original channel configuration (play stereo as stereo, or 5.1 as 5.1). Yet, + * the OS and Audio API might refuse a channel configuration and asks VLC to + * adapt (Stereo played as 5.1 or vice-versa). + * + * This function allows to force a channel configuration, it will only work if + * the OS and Audio API accept this configuration (otherwise, it won't have any + * effects). Here are some examples: + * - Play multi-channels (5.1, 7.1...) as stereo (libvlc_AudioMixMode_Stereo) + * - Play Stereo or 5.1 as 7.1 (libvlc_AudioMixMode_7_1) + * - Play multi-channels as stereo with a binaural effect + * (libvlc_AudioMixMode_Binaural). It might be selected automatically if the + * OS and Audio API can detect if a headphone is plugged. + * + * \param p_mi media player + * \param channel the audio mix-mode, \see libvlc_audio_output_mixmode_t + * \return 0 on success, -1 on error + * \version LibVLC 4.0.0 or later + */ +LIBVLC_API int libvlc_audio_set_mixmode( libvlc_media_player_t *p_mi, + libvlc_audio_output_mixmode_t mode ); + + /** * Get current audio delay. * diff --git a/lib/audio.c b/lib/audio.c index eea0142e698b..49900aa4c559 100644 --- a/lib/audio.c +++ b/lib/audio.c @@ -390,6 +390,48 @@ int libvlc_audio_set_stereomode( libvlc_media_player_t *mp, libvlc_audio_output_ return ret; } +/***************************************************************************** + * libvlc_audio_get_mixmode : Get the current audio mix-mode + *****************************************************************************/ +libvlc_audio_output_mixmode_t libvlc_audio_get_mixmode( libvlc_media_player_t *mp ) +{ + audio_output_t *p_aout = GetAOut( mp ); + if( !p_aout ) + return libvlc_AudioMixMode_Unset; + + int val = var_GetInteger( p_aout, "mix-mode" ); + aout_Release(p_aout); + return val; +} + +/***************************************************************************** + * libvlc_audio_set_mixmode : Set the current audio mix-mode + *****************************************************************************/ +int libvlc_audio_set_mixmode( libvlc_media_player_t *mp, libvlc_audio_output_mixmode_t mode ) +{ + static_assert(libvlc_AudioMixMode_Unset == AOUT_VAR_CHAN_UNSET && + libvlc_AudioMixMode_Stereo == AOUT_MIX_MODE_STEREO && + libvlc_AudioMixMode_Binaural == AOUT_MIX_MODE_BINAURAL && + libvlc_AudioMixMode_4_0 == AOUT_MIX_MODE_4_0 && + libvlc_AudioMixMode_5_1 == AOUT_MIX_MODE_5_1 && + libvlc_AudioMixMode_7_1 == AOUT_MIX_MODE_7_1, + "Mismatch with mix-mode LibVLC/VLC enums"); + + audio_output_t *p_aout = GetAOut( mp ); + int ret = 0; + + if( !p_aout ) + return -1; + + if( var_SetInteger( p_aout, "mix-mode", mode ) < 0 ) + { + libvlc_printerr( "Audio mix-mode out of range" ); + ret = -1; + } + aout_Release(p_aout); + return ret; +} + /***************************************************************************** * libvlc_audio_get_delay : Get the current audio delay *****************************************************************************/ diff --git a/lib/libvlc.sym b/lib/libvlc.sym index 83d3157a7c0d..cfa6cd095c1f 100644 --- a/lib/libvlc.sym +++ b/lib/libvlc.sym @@ -19,6 +19,7 @@ libvlc_audio_output_device_set libvlc_audio_output_list_get libvlc_audio_output_list_release libvlc_audio_output_set +libvlc_audio_get_mixmode libvlc_audio_get_stereomode libvlc_audio_get_delay libvlc_audio_get_mute @@ -26,6 +27,7 @@ libvlc_audio_get_track libvlc_audio_get_track_count libvlc_audio_get_track_description libvlc_audio_get_volume +libvlc_audio_set_mixmode libvlc_audio_set_stereomode libvlc_audio_set_delay libvlc_audio_set_mute