Commit 14863071 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

LibVLC audio: take a player object for most functions, remove exceptions

parent d3472830
...@@ -928,12 +928,12 @@ VLC_PUBLIC_API void libvlc_audio_output_list_release( libvlc_audio_output_t * ); ...@@ -928,12 +928,12 @@ VLC_PUBLIC_API void libvlc_audio_output_list_release( libvlc_audio_output_t * );
* Set the audio output. * Set the audio output.
* Change will be applied after stop and play. * Change will be applied after stop and play.
* *
* \param p_instance libvlc instance * \param mp media player
* \param psz_name name of audio output, * \param psz_name name of audio output,
* use psz_name of \see libvlc_audio_output_t * use psz_name of \see libvlc_audio_output_t
* \return true if function succeded * \return true if function succeded
*/ */
VLC_PUBLIC_API int libvlc_audio_output_set( libvlc_instance_t *, VLC_PUBLIC_API int libvlc_audio_output_set( libvlc_media_player_t *,
const char * ); const char * );
/** /**
...@@ -972,13 +972,13 @@ VLC_PUBLIC_API char * libvlc_audio_output_device_id( libvlc_instance_t *, ...@@ -972,13 +972,13 @@ VLC_PUBLIC_API char * libvlc_audio_output_device_id( libvlc_instance_t *,
int ); int );
/** /**
* Set device for using * Set audio output device. Changes are only effective after stop and play.
* *
* \param p_instance libvlc instance * \param mp media player
* \param psz_audio_output - name of audio output, \see libvlc_audio_output_t * \param psz_audio_output - name of audio output, \see libvlc_audio_output_t
* \param psz_device_id device * \param psz_device_id device
*/ */
VLC_PUBLIC_API void libvlc_audio_output_device_set( libvlc_instance_t *, VLC_PUBLIC_API void libvlc_audio_output_device_set( libvlc_media_player_t *,
const char *, const char *,
const char * ); const char * );
...@@ -986,124 +986,115 @@ VLC_PUBLIC_API void libvlc_audio_output_device_set( libvlc_instance_t *, ...@@ -986,124 +986,115 @@ VLC_PUBLIC_API void libvlc_audio_output_device_set( libvlc_instance_t *,
* Get current audio device type. Device type describes something like * Get current audio device type. Device type describes something like
* character of output sound - stereo sound, 2.1, 5.1 etc * character of output sound - stereo sound, 2.1, 5.1 etc
* *
* \param p_instance vlc instance * \param mp media player
* \param p_e an initialized exception pointer
* \return the audio devices type \see libvlc_audio_output_device_types_t * \return the audio devices type \see libvlc_audio_output_device_types_t
*/ */
VLC_PUBLIC_API int libvlc_audio_output_get_device_type( VLC_PUBLIC_API int libvlc_audio_output_get_device_type(
libvlc_instance_t *, libvlc_exception_t * ); libvlc_media_player_t * );
/** /**
* Set current audio device type. * Set current audio device type.
* *
* \param p_instance vlc instance * \param mp vlc instance
* \param device_type the audio device type, * \param device_type the audio device type,
according to \see libvlc_audio_output_device_types_t according to \see libvlc_audio_output_device_types_t
* \param p_e an initialized exception pointer * \param p_e an initialized exception pointer
*/ */
VLC_PUBLIC_API void libvlc_audio_output_set_device_type( libvlc_instance_t *, VLC_PUBLIC_API void libvlc_audio_output_set_device_type( libvlc_media_player_t *,
int, int );
libvlc_exception_t * );
/** /**
* Toggle mute status. * Toggle mute status.
* *
* \param p_instance libvlc instance * \param mp media player
*/ */
VLC_PUBLIC_API void libvlc_audio_toggle_mute( libvlc_instance_t * ); VLC_PUBLIC_API void libvlc_audio_toggle_mute( libvlc_media_player_t * );
/** /**
* Get current mute status. * Get current mute status.
* *
* \param p_instance libvlc instance * \param mp media player
* \return the mute status (boolean) * \return the mute status (boolean)
*/ */
VLC_PUBLIC_API int libvlc_audio_get_mute( libvlc_instance_t * ); VLC_PUBLIC_API int libvlc_audio_get_mute( libvlc_media_player_t * );
/** /**
* Set mute status. * Set mute status.
* *
* \param p_instance libvlc instance * \param mp media player
* \param status If status is true then mute, otherwise unmute * \param status If status is true then mute, otherwise unmute
*/ */
VLC_PUBLIC_API void libvlc_audio_set_mute( libvlc_instance_t *, int ); VLC_PUBLIC_API void libvlc_audio_set_mute( libvlc_media_player_t *, int );
/** /**
* Get current audio level. * Get current audio level.
* *
* \param p_instance libvlc instance * \param mp media player
* \param p_e an initialized exception pointer * \param p_e an initialized exception pointer
* \return the audio level (int) * \return the audio level (int)
*/ */
VLC_PUBLIC_API int libvlc_audio_get_volume( libvlc_instance_t * ); VLC_PUBLIC_API int libvlc_audio_get_volume( libvlc_media_player_t * );
/** /**
* Set current audio level. * Set current audio level.
* *
* \param p_instance libvlc instance * \param mp media player
* \param i_volume the volume (int) * \param i_volume the volume (int)
* \param p_e an initialized exception pointer * \return 0 if the volume was set, -1 if it was out of range
*/ */
VLC_PUBLIC_API void libvlc_audio_set_volume( libvlc_instance_t *, int, libvlc_exception_t *); VLC_PUBLIC_API int libvlc_audio_set_volume( libvlc_media_player_t *, int );
/** /**
* Get number of available audio tracks. * Get number of available audio tracks.
* *
* \param p_mi media player * \param p_mi media player
* \param p_e an initialized exception * \return the number of available audio tracks (int), or -1 if unavailable
* \return the number of available audio tracks (int)
*/ */
VLC_PUBLIC_API int libvlc_audio_get_track_count( libvlc_media_player_t *, libvlc_exception_t * ); VLC_PUBLIC_API int libvlc_audio_get_track_count( libvlc_media_player_t * );
/** /**
* Get the description of available audio tracks. * Get the description of available audio tracks.
* *
* \param p_mi media player * \param p_mi media player
* \param p_e an initialized exception * \return list with description of available audio tracks, or NULL
* \return list with description of available audio tracks
*/ */
VLC_PUBLIC_API libvlc_track_description_t * VLC_PUBLIC_API libvlc_track_description_t *
libvlc_audio_get_track_description( libvlc_media_player_t *, libvlc_exception_t * ); libvlc_audio_get_track_description( libvlc_media_player_t * );
/** /**
* Get current audio track. * Get current audio track.
* *
* \param p_mi media player * \param p_mi media player
* \param p_e an initialized exception pointer * \return the audio track (int), or -1 if none.
* \return the audio track (int)
*/ */
VLC_PUBLIC_API int libvlc_audio_get_track( libvlc_media_player_t *, libvlc_exception_t * ); VLC_PUBLIC_API int libvlc_audio_get_track( libvlc_media_player_t * );
/** /**
* Set current audio track. * Set current audio track.
* *
* \param p_mi media player * \param p_mi media player
* \param i_track the track (int) * \param i_track the track (int)
* \param p_e an initialized exception pointer * \return 0 on success, -1 on error
*/ */
VLC_PUBLIC_API void libvlc_audio_set_track( libvlc_media_player_t *, int, libvlc_exception_t * ); VLC_PUBLIC_API int libvlc_audio_set_track( libvlc_media_player_t *, int );
/** /**
* Get current audio channel. * Get current audio channel.
* *
* \param p_instance vlc instance * \param mp media player
* \param p_e an initialized exception pointer
* \return the audio channel \see libvlc_audio_output_channel_t * \return the audio channel \see libvlc_audio_output_channel_t
*/ */
VLC_PUBLIC_API int VLC_PUBLIC_API int libvlc_audio_get_channel( libvlc_media_player_t * );
libvlc_audio_get_channel( libvlc_instance_t *, libvlc_exception_t * );
/** /**
* Set current audio channel. * Set current audio channel.
* *
* \param p_instance vlc instance * \param p_mi media player
* \param channel the audio channel, \see libvlc_audio_output_channel_t * \param channel the audio channel, \see libvlc_audio_output_channel_t
* \param p_e an initialized exception pointer * \return 0 on success, -1 on error
*/ */
VLC_PUBLIC_API void libvlc_audio_set_channel( libvlc_instance_t *, VLC_PUBLIC_API int libvlc_audio_set_channel( libvlc_media_player_t *, int );
int,
libvlc_exception_t * );
/** @} audio */ /** @} audio */
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
# include "config.h" # include "config.h"
#endif #endif
#include <assert.h>
#include <vlc/libvlc.h> #include <vlc/libvlc.h>
#include <vlc/libvlc_media.h> #include <vlc/libvlc_media.h>
#include <vlc/libvlc_media_player.h> #include <vlc/libvlc_media_player.h>
...@@ -41,22 +43,18 @@ ...@@ -41,22 +43,18 @@
* Remember to release the returned aout_instance_t since it is locked at * Remember to release the returned aout_instance_t since it is locked at
* the end of this function. * the end of this function.
*/ */
static aout_instance_t *GetAOut( libvlc_instance_t *p_instance, static aout_instance_t *GetAOut( libvlc_media_player_t *mp )
libvlc_exception_t *p_exception )
{ {
if( !p_instance ) assert( mp != NULL );
return NULL;
aout_instance_t * p_aout = NULL; input_thread_t *p_input = libvlc_get_input_thread( mp );
if( p_input == NULL )
p_aout = vlc_object_find( p_instance->p_libvlc_int, VLC_OBJECT_AOUT, FIND_CHILD );
if( !p_aout )
{
libvlc_exception_raise( p_exception );
libvlc_printerr( "No active audio output" );
return 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; return p_aout;
} }
...@@ -132,16 +130,12 @@ void libvlc_audio_output_list_release( libvlc_audio_output_t *p_list ) ...@@ -132,16 +130,12 @@ void libvlc_audio_output_list_release( libvlc_audio_output_t *p_list )
/*********************** /***********************
* Set the audio output. * Set the audio output.
***********************/ ***********************/
int libvlc_audio_output_set( libvlc_instance_t *p_instance, int libvlc_audio_output_set( libvlc_media_player_t *mp, const char *psz_name )
const char *psz_name )
{ {
if( module_exists( psz_name ) ) if( !module_exists( psz_name ) )
{ return -1;
config_PutPsz( p_instance->p_libvlc_int, "aout", psz_name ); var_SetString( mp, "aout", psz_name );
return true; return 0;
}
else
return false;
} }
/**************************** /****************************
...@@ -261,26 +255,28 @@ char * libvlc_audio_output_device_id( libvlc_instance_t *p_instance, ...@@ -261,26 +255,28 @@ char * libvlc_audio_output_device_id( libvlc_instance_t *p_instance,
/***************************** /*****************************
* Set device for using * Set device for using
*****************************/ *****************************/
void libvlc_audio_output_device_set( libvlc_instance_t *p_instance, void libvlc_audio_output_device_set( libvlc_media_player_t *mp,
const char *psz_audio_output, const char *psz_audio_output,
const char *psz_device_id ) const char *psz_device_id )
{ {
char *psz_config_name = NULL; char *psz_config_name;
if( !psz_audio_output || !psz_device_id ) if( !psz_audio_output || !psz_device_id )
return; return;
if( asprintf( &psz_config_name, "%s-audio-device", psz_audio_output ) == -1 ) if( asprintf( &psz_config_name, "%s-audio-device", psz_audio_output ) == -1 )
return; return;
config_PutPsz( p_instance->p_libvlc_int, psz_config_name, psz_device_id ); 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 ); free( psz_config_name );
} }
/***************************************************************************** /*****************************************************************************
* libvlc_audio_output_get_device_type : Get the current audio device type * libvlc_audio_output_get_device_type : Get the current audio device type
*****************************************************************************/ *****************************************************************************/
int libvlc_audio_output_get_device_type( libvlc_instance_t *p_instance, int libvlc_audio_output_get_device_type( libvlc_media_player_t *mp )
libvlc_exception_t *p_e )
{ {
aout_instance_t *p_aout = GetAOut( p_instance, p_e ); aout_instance_t *p_aout = GetAOut( mp );
if( p_aout ) if( p_aout )
{ {
int i_device_type = var_GetInteger( p_aout, "audio-device" ); int i_device_type = var_GetInteger( p_aout, "audio-device" );
...@@ -293,50 +289,48 @@ int libvlc_audio_output_get_device_type( libvlc_instance_t *p_instance, ...@@ -293,50 +289,48 @@ int libvlc_audio_output_get_device_type( libvlc_instance_t *p_instance,
/***************************************************************************** /*****************************************************************************
* libvlc_audio_output_set_device_type : Set the audio device type * libvlc_audio_output_set_device_type : Set the audio device type
*****************************************************************************/ *****************************************************************************/
void libvlc_audio_output_set_device_type( libvlc_instance_t *p_instance, void libvlc_audio_output_set_device_type( libvlc_media_player_t *mp,
int device_type, int device_type )
libvlc_exception_t *p_e )
{ {
aout_instance_t *p_aout = GetAOut( p_instance, p_e ); aout_instance_t *p_aout = GetAOut( mp );
if( !p_aout ) if( !p_aout )
return; return;
if( var_SetInteger( p_aout, "audio-device", device_type ) < 0 ) if( var_SetInteger( p_aout, "audio-device", device_type ) < 0 )
{
libvlc_exception_raise( p_e );
libvlc_printerr( "Error setting audio device" ); libvlc_printerr( "Error setting audio device" );
}
vlc_object_release( p_aout ); vlc_object_release( p_aout );
} }
/***************************************************************************** /*****************************************************************************
* libvlc_audio_get_mute : Get the volume state, true if muted * libvlc_audio_get_mute : Get the volume state, true if muted
*****************************************************************************/ *****************************************************************************/
void libvlc_audio_toggle_mute( libvlc_instance_t *p_instance ) void libvlc_audio_toggle_mute( libvlc_media_player_t *mp )
{ {
aout_ToggleMute( p_instance->p_libvlc_int, NULL ); #warning FIXME: no playlist
aout_ToggleMute( mp, NULL );
} }
int libvlc_audio_get_mute( libvlc_instance_t *p_instance ) int libvlc_audio_get_mute( libvlc_media_player_t *mp )
{ {
return (libvlc_audio_get_volume(p_instance) == 0); return (libvlc_audio_get_volume(mp) == 0);
} }
void libvlc_audio_set_mute( libvlc_instance_t *p_instance, int mute ) void libvlc_audio_set_mute( libvlc_media_player_t *mp, int mute )
{ {
if ( !mute != !libvlc_audio_get_mute( p_instance ) ) #warning Not quite thread-safe
{ if ( !mute != !libvlc_audio_get_mute( mp ) )
aout_ToggleMute( p_instance->p_libvlc_int, NULL ); #warning FIXME: no playlist
} aout_ToggleMute( mp, NULL );
} }
/***************************************************************************** /*****************************************************************************
* libvlc_audio_get_volume : Get the current volume (range 0-200 %) * libvlc_audio_get_volume : Get the current volume (range 0-200 %)
*****************************************************************************/ *****************************************************************************/
int libvlc_audio_get_volume( libvlc_instance_t *p_instance ) int libvlc_audio_get_volume( libvlc_media_player_t *mp )
{ {
audio_volume_t i_volume; 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; return (i_volume*200+AOUT_VOLUME_MAX/2)/AOUT_VOLUME_MAX;
} }
...@@ -345,27 +339,24 @@ int libvlc_audio_get_volume( libvlc_instance_t *p_instance ) ...@@ -345,27 +339,24 @@ int libvlc_audio_get_volume( libvlc_instance_t *p_instance )
/***************************************************************************** /*****************************************************************************
* libvlc_audio_set_volume : Set the current volume * libvlc_audio_set_volume : Set the current volume
*****************************************************************************/ *****************************************************************************/
void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume, int libvlc_audio_set_volume( libvlc_media_player_t *mp, int i_volume )
libvlc_exception_t *p_e )
{ {
if( i_volume >= 0 && i_volume <= 200 ) 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
{
libvlc_exception_raise( p_e );
libvlc_printerr( "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_count : Get the number of available audio tracks * libvlc_audio_get_track_count : Get the number of available audio tracks
*****************************************************************************/ *****************************************************************************/
int libvlc_audio_get_track_count( libvlc_media_player_t *p_mi, int libvlc_audio_get_track_count( libvlc_media_player_t *p_mi )
libvlc_exception_t *p_e )
{ {
input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi ); input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
int i_track_count; int i_track_count;
...@@ -383,8 +374,7 @@ int libvlc_audio_get_track_count( libvlc_media_player_t *p_mi, ...@@ -383,8 +374,7 @@ int libvlc_audio_get_track_count( libvlc_media_player_t *p_mi,
* libvlc_audio_get_track_description : Get the description of available audio tracks * libvlc_audio_get_track_description : Get the description of available audio tracks
*****************************************************************************/ *****************************************************************************/
libvlc_track_description_t * libvlc_track_description_t *
libvlc_audio_get_track_description( libvlc_media_player_t *p_mi, libvlc_audio_get_track_description( libvlc_media_player_t *p_mi )
libvlc_exception_t *p_e )
{ {
return libvlc_get_track_description( p_mi, "audio-es" ); return libvlc_get_track_description( p_mi, "audio-es" );
} }
...@@ -392,8 +382,7 @@ libvlc_track_description_t * ...@@ -392,8 +382,7 @@ libvlc_track_description_t *
/***************************************************************************** /*****************************************************************************
* libvlc_audio_get_track : Get the current audio track * libvlc_audio_get_track : Get the current audio track
*****************************************************************************/ *****************************************************************************/
int libvlc_audio_get_track( libvlc_media_player_t *p_mi, int libvlc_audio_get_track( libvlc_media_player_t *p_mi )
libvlc_exception_t *p_e )
{ {
input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi ); input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
vlc_value_t val_list; vlc_value_t val_list;
...@@ -407,7 +396,6 @@ int libvlc_audio_get_track( libvlc_media_player_t *p_mi, ...@@ -407,7 +396,6 @@ int libvlc_audio_get_track( libvlc_media_player_t *p_mi,
if( var_Get( p_input_thread, "audio-es", &val ) < 0 ) if( var_Get( p_input_thread, "audio-es", &val ) < 0 )
{ {
vlc_object_release( p_input_thread ); vlc_object_release( p_input_thread );
libvlc_exception_raise( p_e );
libvlc_printerr( "Audio track information not found" ); libvlc_printerr( "Audio track information not found" );
return -1; return -1;
} }
...@@ -429,22 +417,21 @@ int libvlc_audio_get_track( libvlc_media_player_t *p_mi, ...@@ -429,22 +417,21 @@ int libvlc_audio_get_track( libvlc_media_player_t *p_mi,
/***************************************************************************** /*****************************************************************************
* libvlc_audio_set_track : Set the current audio track * libvlc_audio_set_track : Set the current audio track
*****************************************************************************/ *****************************************************************************/
void libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track, int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track )
libvlc_exception_t *p_e )
{ {
input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi ); input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
vlc_value_t val_list; vlc_value_t val_list;
vlc_value_t newval; vlc_value_t newval;
int i_ret = -1; int i_ret;
if( !p_input_thread ) if( !p_input_thread )
return; return -1;
var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL ); 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) ) if( (i_track < 0) || (i_track > val_list.p_list->i_count) )
{ {
libvlc_exception_raise( p_e );
libvlc_printerr( "Audio track out of range" ); libvlc_printerr( "Audio track out of range" );
i_ret = -1;
goto end; goto end;
} }
...@@ -452,22 +439,24 @@ void libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track, ...@@ -452,22 +439,24 @@ void libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track,
i_ret = var_Set( p_input_thread, "audio-es", newval ); i_ret = var_Set( p_input_thread, "audio-es", newval );
if( i_ret < 0 ) if( i_ret < 0 )
{ {
libvlc_exception_raise( p_e );
libvlc_printerr( "Audio track out of range" ); /* Race... */ libvlc_printerr( "Audio track out of range" ); /* Race... */
i_ret = -1;
goto end;
} }
i_ret = 0;
end: end:
var_FreeList( &val_list, NULL ); var_FreeList( &val_list, N