X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcontrol%2Faudio.c;h=4fc9b2200b91c56f9a187ebd5feb0d0a7db817ce;hb=618605e3423f647ccbab98a12d4c6827b5572120;hp=f6b7bdc61944b304df47b30249eca7c5c8c2abb0;hpb=2dfa55bd53357dc8bfcb6c94ec9a204dc9d3fe65;p=vlc diff --git a/src/control/audio.c b/src/control/audio.c index f6b7bdc619..4fc9b2200b 100644 --- a/src/control/audio.c +++ b/src/control/audio.c @@ -22,100 +22,315 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "libvlc_internal.h" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + #include +#include +#include +#include #include #include +#include "libvlc_internal.h" +#include "media_player_internal.h" + /* - * Remember to release the returned input_thread_t since it is locked at + * Remember to release the returned aout_instance_t since it is locked at * the end of this function. */ -static input_thread_t *GetInput( libvlc_input_t *p_input, - libvlc_exception_t *p_exception ) +static aout_instance_t *GetAOut( libvlc_media_player_t *mp ) { - input_thread_t *p_input_thread = NULL; + assert( mp != NULL ); - if( !p_input ) - { - libvlc_exception_raise( p_exception, "Input is NULL" ); + input_thread_t *p_input = libvlc_get_input_thread( mp ); + if( p_input == NULL ) return NULL; + + aout_instance_t * p_aout = input_GetAout( p_input ); + vlc_object_release( p_input ); + if( p_aout == NULL ) + libvlc_printerr( "No active audio output" ); + return p_aout; +} + +/***************************************** + * Get the list of available audio outputs + *****************************************/ +libvlc_audio_output_t * + libvlc_audio_output_list_get( libvlc_instance_t *p_instance ) +{ + VLC_UNUSED( p_instance ); + libvlc_audio_output_t *p_list = NULL, + *p_actual = NULL, + *p_previous = NULL; + module_t **module_list = module_list_get( NULL ); + + for (size_t i = 0; module_list[i]; i++) + { + module_t *p_module = module_list[i]; + + if( module_provides( p_module, "audio output" ) ) + { + if( p_actual == NULL) + { + p_actual = ( libvlc_audio_output_t * ) + malloc( sizeof( libvlc_audio_output_t ) ); + if( p_actual == NULL ) + { + libvlc_printerr( "Not enough memory" ); + libvlc_audio_output_list_release( p_list ); + module_list_free( module_list ); + return NULL; + } + if( p_list == NULL ) + { + p_list = p_actual; + p_previous = p_actual; + } + } + p_actual->psz_name = strdup( module_get_object( p_module ) ); + p_actual->psz_description = strdup( module_get_name( p_module, true ) ); + p_actual->p_next = NULL; + if( p_previous != p_actual ) /* not first item */ + p_previous->p_next = p_actual; + p_previous = p_actual; + p_actual = p_actual->p_next; + } } - p_input_thread = (input_thread_t*)vlc_object_get( - p_input->p_instance->p_libvlc_int, - p_input->i_input_id ); - if( !p_input_thread ) + module_list_free( module_list ); + + return p_list; +} + +/******************************************** + * Free the list of available audio outputs + ***********************************************/ +void libvlc_audio_output_list_release( libvlc_audio_output_t *p_list ) +{ + libvlc_audio_output_t *p_actual, *p_before; + p_actual = p_list; + + while ( p_actual ) { - libvlc_exception_raise( p_exception, "Input does not exist" ); - return NULL; + free( p_actual->psz_name ); + free( p_actual->psz_description ); + p_before = p_actual; + p_actual = p_before->p_next; + free( p_before ); } +} + - return p_input_thread; +/*********************** + * 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; } -/* - * Remember to release the returned aout_instance_t since it is locked at - * the end of this function. - */ -static aout_instance_t *GetAOut( libvlc_instance_t *p_instance, - libvlc_exception_t *p_exception ) +/**************************** + * Get count of devices. + *****************************/ +int libvlc_audio_output_device_count( libvlc_instance_t *p_instance, + const char *psz_audio_output ) { - aout_instance_t * p_aout = NULL; + char *psz_config_name; + if( !psz_audio_output ) + return 0; + if( asprintf( &psz_config_name, "%s-audio-device", psz_audio_output ) == -1 ) + return 0; - p_aout = vlc_object_find( p_instance->p_libvlc_int, VLC_OBJECT_AOUT, FIND_CHILD ); - if( !p_aout ) + 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 ) { - libvlc_exception_raise( p_exception, "No active audio output" ); + // 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] ); + } - return p_aout; + 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_get_mute : Get the volume state, true if muted + * libvlc_audio_output_get_device_type : Get the current audio device type *****************************************************************************/ -void libvlc_audio_toggle_mute( libvlc_instance_t *p_instance, - libvlc_exception_t *p_e ) +int libvlc_audio_output_get_device_type( libvlc_media_player_t *mp ) { - aout_VolumeMute( p_instance->p_libvlc_int, NULL ); + 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; } -vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance, - libvlc_exception_t *p_e ) +/***************************************************************************** + * 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 ) { - /* - * If the volume level is 0, then the channel is muted - */ - audio_volume_t i_volume; + 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 ); +} - i_volume = libvlc_audio_get_volume(p_instance, p_e); - if ( i_volume == 0 ) - return VLC_TRUE; - return VLC_FALSE; +/***************************************************************************** + * libvlc_audio_get_mute : Get the volume state, true if muted + *****************************************************************************/ +void libvlc_audio_toggle_mute( libvlc_media_player_t *mp ) +{ +#warning FIXME: no playlist + aout_ToggleMute( mp, NULL ); } -void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t mute, - libvlc_exception_t *p_e ) +int libvlc_audio_get_mute( libvlc_media_player_t *mp ) { - if ( mute ^ libvlc_audio_get_mute( p_instance, p_e ) ) - { - aout_VolumeMute( p_instance->p_libvlc_int, NULL ); - } + return (libvlc_audio_get_volume(mp) == 0); +} + +void libvlc_audio_set_mute( libvlc_media_player_t *mp, int mute ) +{ +#warning Not quite thread-safe + if ( !mute != !libvlc_audio_get_mute( mp ) ) +#warning FIXME: no playlist + aout_ToggleMute( mp, NULL ); } /***************************************************************************** * libvlc_audio_get_volume : Get the current volume (range 0-200 %) *****************************************************************************/ -int libvlc_audio_get_volume( libvlc_instance_t *p_instance, - libvlc_exception_t *p_e ) +int libvlc_audio_get_volume( libvlc_media_player_t *mp ) { audio_volume_t i_volume; - aout_VolumeGet( p_instance->p_libvlc_int, &i_volume ); +#warning FIXME: no playlist + aout_VolumeGet( mp, &i_volume ); return (i_volume*200+AOUT_VOLUME_MAX/2)/AOUT_VOLUME_MAX; } @@ -124,135 +339,148 @@ int libvlc_audio_get_volume( libvlc_instance_t *p_instance, /***************************************************************************** * libvlc_audio_set_volume : Set the current volume *****************************************************************************/ -void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume, - libvlc_exception_t *p_e ) +int libvlc_audio_set_volume( libvlc_media_player_t *mp, int i_volume ) { - if( i_volume >= 0 && i_volume <= 200 ) - { - i_volume = (i_volume * AOUT_VOLUME_MAX + 100) / 200; - - aout_VolumeSet( p_instance->p_libvlc_int, i_volume ); - } - else + if( i_volume < 0 || i_volume > 200 ) { - libvlc_exception_raise( p_e, "Volume out of range" ); + libvlc_printerr( "Volume out of range" ); + return -1; } + + i_volume = (i_volume * AOUT_VOLUME_MAX + 100) / 200; +#warning FIXME: no playlist + aout_VolumeSet( mp, i_volume ); + return 0; } /***************************************************************************** - * libvlc_audio_get_track : Get the current audio track + * libvlc_audio_get_track_count : Get the number of available audio tracks *****************************************************************************/ -int libvlc_audio_get_track( libvlc_input_t *p_input, - libvlc_exception_t *p_e ) +int libvlc_audio_get_track_count( libvlc_media_player_t *p_mi ) { - input_thread_t *p_input_thread = GetInput( p_input, p_e ); - int i_track = 0; + input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi ); + int i_track_count; + + if( !p_input_thread ) + return -1; + + i_track_count = var_CountChoices( p_input_thread, "audio-es" ); - i_track = var_GetInteger( p_input_thread, "audio-es" ); vlc_object_release( p_input_thread ); + return i_track_count; +} - return i_track; +/***************************************************************************** + * libvlc_audio_get_track_description : Get the description of available audio tracks + *****************************************************************************/ +libvlc_track_description_t * + libvlc_audio_get_track_description( libvlc_media_player_t *p_mi ) +{ + return libvlc_get_track_description( p_mi, "audio-es" ); } /***************************************************************************** - * libvlc_audio_set_track : Set the current audio track + * libvlc_audio_get_track : Get the current audio track *****************************************************************************/ -void libvlc_audio_set_track( libvlc_input_t *p_input, int i_track, - libvlc_exception_t *p_e ) +int libvlc_audio_get_track( libvlc_media_player_t *p_mi ) { - input_thread_t *p_input_thread = GetInput( p_input, p_e ); + input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi ); vlc_value_t val_list; - int i_ret = -1; + vlc_value_t val; + int i_track = -1; int i; + if( !p_input_thread ) + return -1; + + if( var_Get( p_input_thread, "audio-es", &val ) < 0 ) + { + vlc_object_release( p_input_thread ); + libvlc_printerr( "Audio track information not found" ); + return -1; + } + var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL ); for( i = 0; i < val_list.p_list->i_count; i++ ) { - vlc_value_t val = val_list.p_list->p_values[i]; - if( i_track == val.i_int ) + if( val_list.p_list->p_values[i].i_int == val.i_int ) { - i_ret = var_SetInteger( p_input_thread, "audio-es", i_track ); - if( i_ret < 0 ) - { - libvlc_exception_raise( p_e, "Setting audio track failed" ); - } - vlc_object_release( p_input_thread ); - return; + i_track = i; + break; } } - libvlc_exception_raise( p_e, "Audio track out of range" ); + var_FreeList( &val_list, NULL ); vlc_object_release( p_input_thread ); + return i_track; } /***************************************************************************** - * libvlc_audio_get_channel : Get the current audio channel + * libvlc_audio_set_track : Set the current audio track *****************************************************************************/ -char *libvlc_audio_get_channel( libvlc_instance_t *p_instance, - libvlc_exception_t *p_e ) +int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track ) { - aout_instance_t *p_aout = GetAOut( p_instance, p_e ); - char *psz_channel = NULL; - vlc_value_t val; + input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi ); + vlc_value_t val_list; + vlc_value_t newval; + int i_ret; + + if( !p_input_thread ) + return -1; - var_Get( p_aout, "audio-channels", &val ); - switch( val.i_int ) + var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL ); + if( (i_track < 0) || (i_track > val_list.p_list->i_count) ) { - case AOUT_VAR_CHAN_RSTEREO: - psz_channel = strdup("reverse stereo"); - break; - case AOUT_VAR_CHAN_STEREO: - psz_channel = strdup("stereo"); - break; - case AOUT_VAR_CHAN_LEFT: - psz_channel = strdup("left"); - break; - case AOUT_VAR_CHAN_RIGHT: - psz_channel = strdup("right"); - break; - case AOUT_VAR_CHAN_DOLBYS: - psz_channel = strdup("dolby"); - break; - default: - psz_channel = strdup("disabled"); - break; + libvlc_printerr( "Audio track out of range" ); + i_ret = -1; + goto end; } + + newval = val_list.p_list->p_values[i_track]; + i_ret = var_Set( p_input_thread, "audio-es", newval ); + if( i_ret < 0 ) + { + libvlc_printerr( "Audio track out of range" ); /* Race... */ + i_ret = -1; + goto end; + } + i_ret = 0; + +end: + var_FreeList( &val_list, NULL ); + vlc_object_release( p_input_thread ); + return i_ret; +} + +/***************************************************************************** + * libvlc_audio_get_channel : Get the current audio channel + *****************************************************************************/ +int libvlc_audio_get_channel( libvlc_media_player_t *mp ) +{ + aout_instance_t *p_aout = GetAOut( mp ); + if( !p_aout ) + return 0; + + int val = var_GetInteger( p_aout, "audio-channels" ); vlc_object_release( p_aout ); - return psz_channel; + return val; } /***************************************************************************** * libvlc_audio_set_channel : Set the current audio channel *****************************************************************************/ -void libvlc_audio_set_channel( libvlc_instance_t *p_instance, char *psz_channel, - libvlc_exception_t *p_e ) +int libvlc_audio_set_channel( libvlc_media_player_t *mp, int channel ) { - aout_instance_t *p_aout = GetAOut( p_instance, p_e ); - vlc_value_t val_list, text_list; - int i_ret = -1, i; + aout_instance_t *p_aout = GetAOut( mp ); + int ret = 0; - i_ret = var_Change( p_aout, "audio-channels", VLC_VAR_GETCHOICES, &val_list, &text_list ); - if( (i_ret < 0) || !psz_channel ) - { - libvlc_exception_raise( p_e, "Audio channel out of range" ); - vlc_object_release( p_aout ); - return; - } + if( !p_aout ) + return -1; - for( i = 0; i < val_list.p_list->i_count; i++ ) + if( var_SetInteger( p_aout, "audio-channels", channel ) < 0 ) { - vlc_value_t val = val_list.p_list->p_values[i]; - vlc_value_t text = text_list.p_list->p_values[i]; - - if( strncasecmp( psz_channel, text.psz_string, strlen(text.psz_string) ) == 0 ) - { - i_ret = var_Set( p_aout, "audio-channels", val ); - if( i_ret < 0 ) - { - break; - } - } + libvlc_printerr( "Audio channel out of range" ); + ret = -1; } - libvlc_exception_raise( p_e, "Audio channel out of range" ); vlc_object_release( p_aout ); + return ret; } -