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

libvlc_video_*: rewrite

 - enable (non-ES) settings even if no output is present
 - best effort at handling multiple outputs
 - remove exceptions
 - libvlc_video_get_size returns both dimensions
 - libvlc_video_take_snapshot takes a parameter to select the output
parent b01e357d
...@@ -444,11 +444,12 @@ VLC_PUBLIC_API float libvlc_media_player_get_fps( libvlc_media_player_t * ); ...@@ -444,11 +444,12 @@ VLC_PUBLIC_API float libvlc_media_player_get_fps( libvlc_media_player_t * );
/** end bug */ /** end bug */
/** /**
* Does this media player have a video output? * How many video outputs does this media player have?
* *
* \param p_md the media player * \param p_md the media player
* \return the number of video outputs
*/ */
VLC_PUBLIC_API int libvlc_media_player_has_vout( libvlc_media_player_t * ); VLC_PUBLIC_API unsigned libvlc_media_player_has_vout( libvlc_media_player_t * );
/** /**
* Is this media player seekable? * Is this media player seekable?
...@@ -488,18 +489,17 @@ VLC_PUBLIC_API void libvlc_track_description_release( libvlc_track_description_t ...@@ -488,18 +489,17 @@ VLC_PUBLIC_API void libvlc_track_description_release( libvlc_track_description_t
*/ */
/** /**
* Toggle fullscreen status on a non-embedded video output. * Toggle fullscreen status on non-embedded video outputs.
* *
* @warning The same limitations applies to this function * @warning The same limitations applies to this function
* as to libvlc_set_fullscreen(). * as to libvlc_set_fullscreen().
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param p_e an initialized exception pointer
*/ */
VLC_PUBLIC_API void libvlc_toggle_fullscreen( libvlc_media_player_t *, libvlc_exception_t * ); VLC_PUBLIC_API void libvlc_toggle_fullscreen( libvlc_media_player_t * );
/** /**
* Enable or disable fullscreen on a non-embedded video output. * Enable or disable fullscreen on non-embedded video outputs.
* *
* @warning With most window managers, only a top-level windows can switch to * @warning With most window managers, only a top-level windows can switch to
* full-screen mode. Hence, this function will not operate properly if * full-screen mode. Hence, this function will not operate properly if
...@@ -511,18 +511,16 @@ VLC_PUBLIC_API void libvlc_toggle_fullscreen( libvlc_media_player_t *, libvlc_ex ...@@ -511,18 +511,16 @@ VLC_PUBLIC_API void libvlc_toggle_fullscreen( libvlc_media_player_t *, libvlc_ex
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param b_fullscreen boolean for fullscreen status * \param b_fullscreen boolean for fullscreen status
* \param p_e an initialized exception pointer
*/ */
VLC_PUBLIC_API void libvlc_set_fullscreen( libvlc_media_player_t *, int, libvlc_exception_t * ); VLC_PUBLIC_API void libvlc_set_fullscreen( libvlc_media_player_t *, int );
/** /**
* Get current fullscreen status. * Get current fullscreen status.
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param p_e an initialized exception pointer
* \return the fullscreen status (boolean) * \return the fullscreen status (boolean)
*/ */
VLC_PUBLIC_API int libvlc_get_fullscreen( libvlc_media_player_t *, libvlc_exception_t * ); VLC_PUBLIC_API int libvlc_get_fullscreen( libvlc_media_player_t * );
/** /**
* Enable or disable key press events handling, according to the LibVLC hotkeys * Enable or disable key press events handling, according to the LibVLC hotkeys
...@@ -557,35 +555,48 @@ void libvlc_video_set_key_input( libvlc_media_player_t *mp, unsigned on ); ...@@ -557,35 +555,48 @@ void libvlc_video_set_key_input( libvlc_media_player_t *mp, unsigned on );
VLC_PUBLIC_API VLC_PUBLIC_API
void libvlc_video_set_mouse_input( libvlc_media_player_t *mp, unsigned on ); void libvlc_video_set_mouse_input( libvlc_media_player_t *mp, unsigned on );
/**
* Get the pixel dimensions of a video.
*
* \param mp media player
* \param num number of the video (starting from, and most commonly 0)
* \param px pointer to get the pixel width [OUT]
* \param py pointer to get the pixel height [OUT]
* \return 0 on success, -1 if the specified video does not exist
*/
VLC_PUBLIC_API
int libvlc_video_get_size( libvlc_media_player_t *mp, unsigned num,
unsigned *px, unsigned *py );
/** /**
* Get current video height. * Get current video height.
* You should use libvlc_video_get_size() instead.
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param p_e an initialized exception pointer * \return the video pixel height or 0 if not applicable
* \return the video height
*/ */
VLC_PUBLIC_API int libvlc_video_get_height( libvlc_media_player_t *, libvlc_exception_t * ); VLC_DEPRECATED_API
int libvlc_video_get_height( libvlc_media_player_t * );
/** /**
* Get current video width. * Get current video width.
* You should use libvlc_video_get_size() instead.
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param p_e an initialized exception pointer * \return the video pixel width or 0 if not applicable
* \return the video width
*/ */
VLC_PUBLIC_API int libvlc_video_get_width( libvlc_media_player_t *, libvlc_exception_t * ); VLC_DEPRECATED_API
int libvlc_video_get_width( libvlc_media_player_t * );
/** /**
* Get the current video scaling factor. * Get the current video scaling factor.
* See also libvlc_video_set_scale(). * See also libvlc_video_set_scale().
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param p_e an initialized exception pointer
* \return the currently configured zoom factor, or 0. if the video is set * \return the currently configured zoom factor, or 0. if the video is set
* to fit to the output window/drawable automatically. * to fit to the output window/drawable automatically.
*/ */
VLC_PUBLIC_API float libvlc_video_get_scale( libvlc_media_player_t *, VLC_PUBLIC_API float libvlc_video_get_scale( libvlc_media_player_t * );
libvlc_exception_t *p_e );
/** /**
* Set the video scaling factor. That is the ratio of the number of pixels on * Set the video scaling factor. That is the ratio of the number of pixels on
...@@ -597,46 +608,42 @@ VLC_PUBLIC_API float libvlc_video_get_scale( libvlc_media_player_t *, ...@@ -597,46 +608,42 @@ VLC_PUBLIC_API float libvlc_video_get_scale( libvlc_media_player_t *,
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param i_factor the scaling factor, or zero * \param i_factor the scaling factor, or zero
* \param p_e an initialized exception pointer
*/ */
VLC_PUBLIC_API void libvlc_video_set_scale( libvlc_media_player_t *, float, VLC_PUBLIC_API void libvlc_video_set_scale( libvlc_media_player_t *, float );
libvlc_exception_t *p_e );
/** /**
* Get current video aspect ratio. * Get current video aspect ratio.
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param p_e an initialized exception pointer * \return the video aspect ratio or NULL if unspecified
* \return the video aspect ratio * (the result must be released with free() or libvlc_free()).
*/ */
VLC_PUBLIC_API char *libvlc_video_get_aspect_ratio( libvlc_media_player_t *, libvlc_exception_t * ); VLC_PUBLIC_API char *libvlc_video_get_aspect_ratio( libvlc_media_player_t * );
/** /**
* Set new video aspect ratio. * Set new video aspect ratio.
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param psz_aspect new video aspect-ratio * \param psz_aspect new video aspect-ratio or NULL to reset to default
* \param p_e an initialized exception pointer * \note Invalid aspect ratios are ignored.
*/ */
VLC_PUBLIC_API void libvlc_video_set_aspect_ratio( libvlc_media_player_t *, const char *, libvlc_exception_t * ); VLC_PUBLIC_API void libvlc_video_set_aspect_ratio( libvlc_media_player_t *, const char * );
/** /**
* Get current video subtitle. * Get current video subtitle.
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param p_e an initialized exception pointer * \return the video subtitle selected, or -1 if none
* \return the video subtitle selected
*/ */
VLC_PUBLIC_API int libvlc_video_get_spu( libvlc_media_player_t *, libvlc_exception_t * ); VLC_PUBLIC_API int libvlc_video_get_spu( libvlc_media_player_t * );
/** /**
* Get the number of available video subtitles. * Get the number of available video subtitles.
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param p_e an initialized exception pointer
* \return the number of available video subtitles * \return the number of available video subtitles
*/ */
VLC_PUBLIC_API int libvlc_video_get_spu_count( libvlc_media_player_t *, libvlc_exception_t * ); VLC_PUBLIC_API int libvlc_video_get_spu_count( libvlc_media_player_t * );
/** /**
* Get the description of available video subtitles. * Get the description of available video subtitles.
...@@ -653,9 +660,9 @@ VLC_PUBLIC_API libvlc_track_description_t * ...@@ -653,9 +660,9 @@ VLC_PUBLIC_API libvlc_track_description_t *
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param i_spu new video subtitle to select * \param i_spu new video subtitle to select
* \param p_e an initialized exception pointer * \return 0 on success, -1 if out of range
*/ */
VLC_PUBLIC_API void libvlc_video_set_spu( libvlc_media_player_t *, int , libvlc_exception_t * ); VLC_PUBLIC_API int libvlc_video_set_spu( libvlc_media_player_t *, unsigned );
/** /**
* Set new video subtitle file. * Set new video subtitle file.
...@@ -692,19 +699,18 @@ VLC_PUBLIC_API libvlc_track_description_t * ...@@ -692,19 +699,18 @@ VLC_PUBLIC_API libvlc_track_description_t *
* Get current crop filter geometry. * Get current crop filter geometry.
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param p_e an initialized exception pointer * \return the crop filter geometry or NULL if unset
* \return the crop filter geometry
*/ */
VLC_PUBLIC_API char *libvlc_video_get_crop_geometry( libvlc_media_player_t *, libvlc_exception_t * ); VLC_PUBLIC_API char *libvlc_video_get_crop_geometry( libvlc_media_player_t * );
/** /**
* Set new crop filter geometry. * Set new crop filter geometry.
* *
* \param p_mediaplayer the media player * \param p_mediaplayer the media player
* \param psz_geometry new crop filter geometry * \param psz_geometry new crop filter geometry (NULL to unset)
* \param p_e an initialized exception pointer
*/ */
VLC_PUBLIC_API void libvlc_video_set_crop_geometry( libvlc_media_player_t *, const char *, libvlc_exception_t * ); VLC_PUBLIC_API
void libvlc_video_set_crop_geometry( libvlc_media_player_t *, const char * );
/** /**
* Toggle teletext transparent status on video output. * Toggle teletext transparent status on video output.
...@@ -726,7 +732,6 @@ VLC_PUBLIC_API int libvlc_video_get_track_count( libvlc_media_player_t * ); ...@@ -726,7 +732,6 @@ VLC_PUBLIC_API int libvlc_video_get_track_count( libvlc_media_player_t * );
* Get the description of available video tracks. * Get the description of available video tracks.
* *
* \param p_mi media player * \param p_mi media player
* \param p_e an initialized exception
* \return list with description of available video tracks, or NULL on error * \return list with description of available video tracks, or NULL on error
*/ */
VLC_PUBLIC_API libvlc_track_description_t * VLC_PUBLIC_API libvlc_track_description_t *
...@@ -736,19 +741,19 @@ VLC_PUBLIC_API libvlc_track_description_t * ...@@ -736,19 +741,19 @@ VLC_PUBLIC_API libvlc_track_description_t *
* Get current video track. * Get current video track.
* *
* \param p_mi media player * \param p_mi media player
* \param p_e an initialized exception pointer * \return the video track (int) or -1 if none
* \return the video track (int)
*/ */
VLC_PUBLIC_API int libvlc_video_get_track( libvlc_media_player_t *, libvlc_exception_t * ); VLC_PUBLIC_API int libvlc_video_get_track( libvlc_media_player_t * );
/** /**
* Set video track. * Set video 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 if out of range
*/ */
VLC_PUBLIC_API void libvlc_video_set_track( libvlc_media_player_t *, int, libvlc_exception_t * ); VLC_PUBLIC_API
int libvlc_video_set_track( libvlc_media_player_t *, int );
/** /**
* Take a snapshot of the current video window. * Take a snapshot of the current video window.
...@@ -757,24 +762,24 @@ VLC_PUBLIC_API void libvlc_video_set_track( libvlc_media_player_t *, int, libvlc ...@@ -757,24 +762,24 @@ VLC_PUBLIC_API void libvlc_video_set_track( libvlc_media_player_t *, int, libvlc
* If i_width XOR i_height is 0, original aspect-ratio is preserved. * If i_width XOR i_height is 0, original aspect-ratio is preserved.
* *
* \param p_mi media player instance * \param p_mi media player instance
* \param num number of video output (typically 0 for the first/only one)
* \param psz_filepath the path where to save the screenshot to * \param psz_filepath the path where to save the screenshot to
* \param i_width the snapshot's width * \param i_width the snapshot's width
* \param i_height the snapshot's height * \param i_height the snapshot's height
* \param p_e an initialized exception pointer * \return 0 on success, -1 if the video was not found
*/ */
VLC_PUBLIC_API void libvlc_video_take_snapshot( libvlc_media_player_t *, const char *,unsigned int, unsigned int, libvlc_exception_t * ); VLC_PUBLIC_API
int libvlc_video_take_snapshot( libvlc_media_player_t *, unsigned num,
const char *,unsigned int, unsigned int );
/** /**
* Enable or disable deinterlace filter * Enable or disable deinterlace filter
* *
* \param p_mi libvlc media player * \param p_mi libvlc media player
* \param b_enable boolean to enable or disable deinterlace filter * \param psz_mode type of deinterlace filter, NULL to disable
* \param psz_mode type of deinterlace filter to use
* \param p_e an initialized exception pointer
*/ */
VLC_PUBLIC_API void libvlc_video_set_deinterlace( libvlc_media_player_t *, VLC_PUBLIC_API void libvlc_video_set_deinterlace( libvlc_media_player_t *,
int , const char *, const char * );
libvlc_exception_t *);
/** /**
* Get an integer marquee option value * Get an integer marquee option value
......
...@@ -356,7 +356,17 @@ libvlc_media_player_new( libvlc_instance_t *instance ) ...@@ -356,7 +356,17 @@ libvlc_media_player_new( libvlc_instance_t *instance )
var_Create (mp, "mouse-events", VLC_VAR_BOOL); var_Create (mp, "mouse-events", VLC_VAR_BOOL);
var_SetBool (mp, "mouse-events", true); var_SetBool (mp, "mouse-events", true);
/* Audio */ var_Create (mp, "fullscreen", VLC_VAR_BOOL);
var_Create (mp, "autoscale", VLC_VAR_BOOL);
var_SetBool (mp, "autoscale", true);
var_Create (mp, "scale", VLC_VAR_FLOAT);
var_SetFloat (mp, "scale", 1.);
var_Create (mp, "aspect-ratio", VLC_VAR_STRING);
var_Create (mp, "crop", VLC_VAR_STRING);
var_Create (mp, "deinterlace", VLC_VAR_INTEGER);
var_Create (mp, "deinterlace-mode", VLC_VAR_STRING);
/* Audio */
var_Create (mp, "aout", VLC_VAR_STRING | VLC_VAR_DOINHERIT); var_Create (mp, "aout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
mp->p_md = NULL; mp->p_md = NULL;
......
...@@ -44,27 +44,41 @@ ...@@ -44,27 +44,41 @@
/* /*
* Remember to release the returned vout_thread_t. * Remember to release the returned vout_thread_t.
*/ */
static vout_thread_t *GetVout( libvlc_media_player_t *p_mi, static vout_thread_t **GetVouts( libvlc_media_player_t *p_mi, size_t *n )
libvlc_exception_t *p_exception )
{ {
input_thread_t *p_input = libvlc_get_input_thread( p_mi ); input_thread_t *p_input = libvlc_get_input_thread( p_mi );
vout_thread_t *p_vout = NULL; if( !p_input )
return NULL;
if( p_input ) vout_thread_t **pp_vouts;
{ if (input_Control( p_input, INPUT_GET_VOUTS, &pp_vouts, n))
p_vout = input_GetVout( p_input );
if( !p_vout )
{
libvlc_exception_raise( p_exception );
libvlc_printerr( "No active video output" );
}
vlc_object_release( p_input );
}
else
{ {
libvlc_exception_raise( p_exception ); *n = 0;
libvlc_printerr( "No active input" ); pp_vouts = NULL;
} }
vlc_object_release (p_input);
return pp_vouts;
}
static vout_thread_t *GetVout (libvlc_media_player_t *mp, size_t num)
{
vout_thread_t *p_vout = NULL;
size_t n;
vout_thread_t **pp_vouts = GetVouts (mp, &n);
if (pp_vouts == NULL)
goto err;
if (num < n)
p_vout = pp_vouts[num];
for (size_t i = 0; i < n; i++)
if (i != num)
vlc_object_release (pp_vouts[i]);
free (pp_vouts);
if (p_vout == NULL)
err:
libvlc_printerr ("Video output not active");
return p_vout; return p_vout;
} }
...@@ -72,49 +86,43 @@ static vout_thread_t *GetVout( libvlc_media_player_t *p_mi, ...@@ -72,49 +86,43 @@ static vout_thread_t *GetVout( libvlc_media_player_t *p_mi,
* Exported functions * Exported functions
**********************************************************************/ **********************************************************************/
void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen, void libvlc_set_fullscreen( libvlc_media_player_t *p_mi, int b_fullscreen )
libvlc_exception_t *p_e )
{ {
/* We only work on the first vout */ /* This will work even if the video is not currently active */
vout_thread_t *p_vout = GetVout( p_mi, p_e ); var_SetBool (p_mi, "fullscreen", !!b_fullscreen);
/* GetVout will raise the exception for us */
if( !p_vout ) return;
var_SetBool( p_vout, "fullscreen", b_fullscreen ); /* Apply to current video outputs (if any) */
size_t n;
vlc_object_release( p_vout ); vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
for (size_t i = 0; i < n; i++)
{
var_SetBool (pp_vouts[i], "fullscreen", b_fullscreen);
vlc_object_release (pp_vouts[i]);
}
free (pp_vouts);
} }
int libvlc_get_fullscreen( libvlc_media_player_t *p_mi, int libvlc_get_fullscreen( libvlc_media_player_t *p_mi )
libvlc_exception_t *p_e )
{ {
/* We only work on the first vout */ return var_GetBool (p_mi, "fullscreen");
vout_thread_t *p_vout = GetVout( p_mi, p_e );
int i_ret;
/* GetVout will raise the exception for us */
if( !p_vout ) return 0;
i_ret = var_GetBool( p_vout, "fullscreen" );
vlc_object_release( p_vout );
return i_ret;
} }
void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi, void libvlc_toggle_fullscreen( libvlc_media_player_t *p_mi )
libvlc_exception_t *p_e )
{ {
/* We only work on the first vout */ var_ToggleBool (p_mi, "fullscreen");
vout_thread_t *p_vout = GetVout( p_mi, p_e ); bool b_fullscreen = var_GetBool (p_mi, "fullscreen");
/* GetVout will raise the exception for us */
if( !p_vout ) return;
var_ToggleBool( p_vout, "fullscreen" ); /* Apply to current video outputs (if any) */
size_t n;
vout_thread_t **pp_vouts = GetVouts (p_mi, &n);
for (size_t i = 0; i < n; i++)
{
vout_thread_t *p_vout = pp_vouts[i];
vlc_object_release( p_vout ); var_SetBool (p_vout, "fullscreen", b_fullscreen);
vlc_object_release (p_vout);
}
free (pp_vouts);
} }
void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on ) void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on )
...@@ -127,145 +135,122 @@ void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on ) ...@@ -127,145 +135,122 @@ void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on )
var_SetBool (p_mi, "mouse-events", !!on); var_SetBool (p_mi, "mouse-events", !!on);
} }
void int
libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, const char *psz_filepath, libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
unsigned int i_width, unsigned int i_height, libvlc_exception_t *p_e ) const char *psz_filepath,
unsigned int i_width, unsigned int i_height )
{ {
vout_thread_t *p_vout;
assert( psz_filepath ); assert( psz_filepath );
/* We must have an input */ vout_thread_t *p_vout = GetVout (p_mi, num);
if( !p_mi->p_input_thread ) if (p_vout == NULL)
{ return -1;
libvlc_exception_raise( p_e );
libvlc_printerr( "Input does not exist" );
return;
}
/* GetVout will raise the exception for us */
p_vout = GetVout( p_mi, p_e );
if( !p_vout ) return;
var_SetInteger( p_vout, "snapshot-width", i_width ); /* FIXME: This is not atomic. Someone else could change the values,
* at least in theory. */
var_SetInteger( p_vout, "snapshot-width", i_width);
var_SetInteger( p_vout, "snapshot-height", i_height ); var_SetInteger( p_vout, "snapshot-height", i_height );
var_SetString( p_vout, "snapshot-path", psz_filepath ); var_SetString( p_vout, "snapshot-path", psz_filepath );
var_SetString( p_vout, "snapshot-format", "png" ); var_SetString( p_vout, "snapshot-format", "png" );
var_TriggerCallback (p_vout, "video-snapshot" );
var_TriggerCallback( p_vout, "video-snapshot" ); return 0;
vlc_object_release( p_vout );
} }
int libvlc_video_get_height( libvlc_media_player_t *p_mi, int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
libvlc_exception_t *p_e ) unsigned *restrict px, unsigned *restrict py )
{ {
int height; vout_thread_t *p_vout = GetVout (p_mi, num);
if (p_vout == NULL)
vout_thread_t *p_vout = GetVout( p_mi, p_e ); return -1;
if( !p_vout ) return 0;