+
+/***********************
+ * Set the audio output.
+ ***********************/
+int libvlc_audio_output_set( libvlc_media_player_t *mp, const char *psz_name )
+{
+ if( !module_exists( psz_name ) )
+ return -1;
+ var_SetString( mp, "aout", psz_name );
+ return 0;
+}
+
+/****************************
+ * Get count of devices.
+ *****************************/
+int libvlc_audio_output_device_count( libvlc_instance_t *p_instance,
+ const char *psz_audio_output )
+{
+ char *psz_config_name;
+ if( !psz_audio_output )
+ return 0;
+ if( asprintf( &psz_config_name, "%s-audio-device", psz_audio_output ) == -1 )
+ return 0;
+
+ module_config_t *p_module_config = config_FindConfig(
+ VLC_OBJECT( p_instance->p_libvlc_int ), psz_config_name );
+
+ if( p_module_config && p_module_config->pf_update_list )
+ {
+ vlc_value_t val;
+ val.psz_string = strdup( p_module_config->value.psz );
+
+ p_module_config->pf_update_list(
+ VLC_OBJECT( p_instance->p_libvlc_int ), psz_config_name, val, val, NULL );
+ free( val.psz_string );
+ free( psz_config_name );
+
+ return p_module_config->i_list;
+ }
+
+ free( psz_config_name );
+ return 0;
+}
+
+/********************************
+ * Get long name of device
+ *********************************/
+char * libvlc_audio_output_device_longname( libvlc_instance_t *p_instance,
+ const char *psz_audio_output,
+ int i_device )
+{
+ char *psz_config_name;
+ if( !psz_audio_output )
+ return NULL;
+ if( asprintf( &psz_config_name, "%s-audio-device", psz_audio_output ) == -1 )
+ return NULL;
+
+ module_config_t *p_module_config = config_FindConfig(
+ VLC_OBJECT( p_instance->p_libvlc_int ), psz_config_name );
+
+ if( p_module_config )
+ {
+ // refresh if there arent devices
+ if( p_module_config->i_list < 2 && p_module_config->pf_update_list )
+ {
+ vlc_value_t val;
+ val.psz_string = strdup( p_module_config->value.psz );
+
+ p_module_config->pf_update_list(
+ VLC_OBJECT( p_instance->p_libvlc_int ), psz_config_name, val, val, NULL );
+ free( val.psz_string );
+ }
+ free( psz_config_name );
+
+ if( i_device >= 0 && i_device < p_module_config->i_list )
+ {
+ if( p_module_config->ppsz_list_text[i_device] )
+ return strdup( p_module_config->ppsz_list_text[i_device] );
+ else
+ return strdup( p_module_config->ppsz_list[i_device] );
+ }
+ }
+
+ free( psz_config_name );
+ return NULL;
+}
+
+/********************************
+ * Get id name of device
+ *********************************/
+char * libvlc_audio_output_device_id( libvlc_instance_t *p_instance,
+ const char *psz_audio_output,
+ int i_device )
+{
+ char *psz_config_name;
+ if( !psz_audio_output )
+ return NULL;
+ if( asprintf( &psz_config_name, "%s-audio-device", psz_audio_output ) == -1)
+ return NULL;
+
+ module_config_t *p_module_config = config_FindConfig(
+ VLC_OBJECT( p_instance->p_libvlc_int ), psz_config_name );
+
+ if( p_module_config )
+ {
+ // refresh if there arent devices
+ if( p_module_config->i_list < 2 && p_module_config->pf_update_list )
+ {
+ vlc_value_t val;
+ val.psz_string = strdup( p_module_config->value.psz );
+
+ p_module_config->pf_update_list(
+ VLC_OBJECT( p_instance->p_libvlc_int ), psz_config_name, val, val, NULL );
+ free( val.psz_string );
+ }
+ free( psz_config_name );
+
+ if( i_device >= 0 && i_device < p_module_config->i_list )
+ return strdup( p_module_config->ppsz_list[i_device] );
+
+ }
+
+ free( psz_config_name );
+ return NULL;
+}
+
+/*****************************
+ * Set device for using
+ *****************************/
+void libvlc_audio_output_device_set( libvlc_media_player_t *mp,
+ const char *psz_audio_output,
+ const char *psz_device_id )
+{
+ char *psz_config_name;
+ if( !psz_audio_output || !psz_device_id )
+ return;
+ if( asprintf( &psz_config_name, "%s-audio-device", psz_audio_output ) == -1 )
+ return;
+ if( !var_Type( mp, psz_audio_output ) )
+ /* Don't recreate the same variable over and over and over... */
+ var_Create( mp, psz_audio_output, VLC_VAR_STRING );
+ var_SetString( mp, psz_config_name, psz_device_id );
+ free( psz_config_name );
+}
+
+/*****************************************************************************
+ * libvlc_audio_output_get_device_type : Get the current audio device type
+ *****************************************************************************/
+int libvlc_audio_output_get_device_type( libvlc_media_player_t *mp )
+{
+ aout_instance_t *p_aout = GetAOut( mp );
+ if( p_aout )
+ {
+ int i_device_type = var_GetInteger( p_aout, "audio-device" );
+ vlc_object_release( p_aout );
+ return i_device_type;
+ }
+ return libvlc_AudioOutputDevice_Error;
+}
+
+/*****************************************************************************
+ * libvlc_audio_output_set_device_type : Set the audio device type
+ *****************************************************************************/
+void libvlc_audio_output_set_device_type( libvlc_media_player_t *mp,
+ int device_type )
+{
+ aout_instance_t *p_aout = GetAOut( mp );
+ if( !p_aout )
+ return;
+ if( var_SetInteger( p_aout, "audio-device", device_type ) < 0 )
+ libvlc_printerr( "Error setting audio device" );
+ vlc_object_release( p_aout );
+}
+
+/*****************************************************************************
+ * libvlc_audio_get_mute : Get the volume state, true if muted
+ *****************************************************************************/
+void libvlc_audio_toggle_mute( libvlc_media_player_t *mp )
+{
+ aout_ToggleMute( mp, NULL );
+}
+
+int libvlc_audio_get_mute( libvlc_media_player_t *mp )
+{
+ return (libvlc_audio_get_volume(mp) == 0);
+}
+
+void libvlc_audio_set_mute( libvlc_media_player_t *mp, int mute )
+{
+ aout_SetMute( VLC_OBJECT(mp), NULL, !!mute );
+}
+