vlc | branch: master | Felix Paul Kühne <[email protected]> | Mon Jan 26 20:37:02 2015 +0100| [8bb74ef54dcf937d21627d1cc4d3a9741e02295c] | committer: Felix Paul Kühne
libvlc: expand media player API to retrieve information about all available titles of the currently playing media item > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8bb74ef54dcf937d21627d1cc4d3a9741e02295c --- NEWS | 2 + include/vlc/libvlc_media_player.h | 43 +++++++++++++++++++- include/vlc_input.h | 4 +- lib/libvlc.sym | 2 + lib/media_player.c | 80 ++++++++++++++++++++++++++++++++++++- src/input/control.c | 35 +++++++++++++++- 6 files changed, 160 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index beb19ad..fadc7e6 100644 --- a/NEWS +++ b/NEWS @@ -119,6 +119,8 @@ libVLC: * Add libvlc_audio_output_device_get to get the currently selected audio output device identifier (if there is one available) * Add libvlc_media_get_type to get the type of the media + * Add libvlc_media_player_get_full_title_descriptions to get full title info of the media + * Deprecate libvlc_video_get_title_description Logging * Support for the SystemD Journal diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h index 9939cfe..d0c2120 100644 --- a/include/vlc/libvlc_media_player.h +++ b/include/vlc/libvlc_media_player.h @@ -1,7 +1,7 @@ /***************************************************************************** * libvlc_media_player.h: libvlc_media_player external API ***************************************************************************** - * Copyright (C) 1998-2010 VLC authors and VideoLAN + * Copyright (C) 1998-2015 VLC authors and VideoLAN * $Id$ * * Authors: Clément Stenac <[email protected]> @@ -61,6 +61,18 @@ typedef struct libvlc_track_description_t } libvlc_track_description_t; /** + * Description for titles. It contains name (description string), + * duration in milliseconds if known, + * and information if it was recognized as a menu by the demuxer. + */ +typedef struct libvlc_title_description_t +{ + int64_t i_duration; + char *psz_name; + bool b_menu; +} libvlc_title_description_t; + +/** * Description for audio output. It contains * name, description and pointer to next record. */ @@ -1127,10 +1139,37 @@ LIBVLC_API int libvlc_video_set_spu_delay( libvlc_media_player_t *p_mi, int64_t * \return list containing description of available titles. * It must be freed with libvlc_track_description_list_release() */ -LIBVLC_API libvlc_track_description_t * +LIBVLC_DEPRECATED LIBVLC_API libvlc_track_description_t * libvlc_video_get_title_description( libvlc_media_player_t *p_mi ); /** + * Get the full description of available titles + * + * \version LibVLC 3.0.0 and later. + * + * \param p_mi the media player + * \param address to store an allocated array of title descriptions + * descriptions (must be freed with libvlc_title_descriptions_release() + * by the caller) [OUT] + * + * \return the number of titles (-1 on error) + */ +LIBVLC_API int libvlc_media_player_get_full_title_descriptions( libvlc_media_player_t *p_mi, + libvlc_title_description_t ***titles ); + +/** + * Release a title description + * + * \version LibVLC 3.0.0 and later + * + * \param title description array to release + * \param number of title descriptions to release + */ +LIBVLC_API + void libvlc_title_descriptions_release( libvlc_title_description_t **p_titles, + unsigned i_count ); + +/** * Get the description of available chapters for specific title. * * \param p_mi the media player diff --git a/include/vlc_input.h b/include/vlc_input.h index 04f0ddf..4a397fc 100644 --- a/include/vlc_input.h +++ b/include/vlc_input.h @@ -1,7 +1,7 @@ /***************************************************************************** * vlc_input.h: Core input structures ***************************************************************************** - * Copyright (C) 1999-2006 VLC authors and VideoLAN + * Copyright (C) 1999-2015 VLC authors and VideoLAN * $Id$ * * Authors: Christophe Massiot <[email protected]> @@ -92,7 +92,6 @@ typedef struct input_title_t /* Title seekpoint */ int i_seekpoint; seekpoint_t **seekpoint; - } input_title_t; static inline input_title_t *vlc_input_title_New(void) @@ -454,6 +453,7 @@ enum input_query_e /* titles */ INPUT_GET_TITLE_INFO, /* arg1=input_title_t** arg2= int * res=can fail */ + INPUT_GET_FULL_TITLE_INFO, /* arg1=input_title_t*** arg2= int * res=can fail */ /* Attachments */ INPUT_GET_ATTACHMENTS, /* arg1=input_attachment_t***, arg2=int* res=can fail */ diff --git a/lib/libvlc.sym b/lib/libvlc.sym index c0c206f..44e0eda 100644 --- a/lib/libvlc.sym +++ b/lib/libvlc.sym @@ -149,6 +149,7 @@ libvlc_media_player_get_chapter libvlc_media_player_get_chapter_count libvlc_media_player_get_chapter_count_for_title libvlc_media_player_get_fps +libvlc_media_player_get_full_title_descriptions libvlc_media_player_get_hwnd libvlc_media_player_get_length libvlc_media_player_get_media @@ -204,6 +205,7 @@ libvlc_set_fullscreen libvlc_set_log_verbosity libvlc_set_user_agent libvlc_set_app_id +libvlc_title_descriptions_release libvlc_toggle_fullscreen libvlc_toggle_teletext libvlc_track_description_release diff --git a/lib/media_player.c b/lib/media_player.c index eca77d9..4e17b19 100644 --- a/lib/media_player.c +++ b/lib/media_player.c @@ -1,7 +1,7 @@ /***************************************************************************** * media_player.c: Libvlc API Media Instance management functions ***************************************************************************** - * Copyright (C) 2005-2011 VLC authors and VideoLAN + * Copyright (C) 2005-2015 VLC authors and VideoLAN * * Authors: Clément Stenac <[email protected]> * @@ -1330,6 +1330,84 @@ int libvlc_media_player_get_title_count( libvlc_media_player_t *p_mi ) return i_ret == VLC_SUCCESS ? val.i_int : -1; } +int libvlc_media_player_get_full_title_descriptions( libvlc_media_player_t *p_mi, + libvlc_title_description_t *** pp_titles ) +{ + assert( p_mi ); + + input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi ); + + if( !p_input_thread ) + return -1; + + input_title_t **p_input_title = NULL; + int *i_titles = 0; + + /* fetch data */ + int ret = input_Control(p_input_thread, INPUT_GET_FULL_TITLE_INFO, &p_input_title, &i_titles); + vlc_object_release( p_input_thread ); + + if( ret != VLC_SUCCESS || p_input_title == NULL) + { + return -1; + } + + if (i_titles == 0) + { + return 0; + } + + const int ci_title_count = (const int)i_titles; + + *pp_titles = calloc( ci_title_count, sizeof(**pp_titles) ); + if( !*pp_titles ) + { + return -1; + } + + /* fill array */ + for( int i = 0; i < ci_title_count; i++) + { + libvlc_title_description_t *p_title = calloc( 1, sizeof(*p_title) ); + if( unlikely(p_title == NULL) ) + { + libvlc_title_descriptions_release( *pp_titles, ci_title_count ); + free( p_title ); + return -1; + } + (*pp_titles)[i] = p_title; + + /* we want to return milliseconds to match the rest of the API */ + p_title->i_duration = p_input_title[i]->i_length / 1000; + p_title->b_menu = p_input_title[i]->b_menu; + if( p_input_title[i]->psz_name ) + { + p_title->psz_name = strdup( p_input_title[i]->psz_name ); + } + else + { + p_title->psz_name = NULL; + } + vlc_input_title_Delete( p_input_title[i] ); + } + + return ci_title_count; +} + +void libvlc_title_descriptions_release( libvlc_title_description_t **p_titles, + unsigned i_count ) +{ + for (unsigned i = 0; i < i_count; i++ ) + { + if ( !p_titles[i] ) + continue; + + free( p_titles[i]->psz_name ); + free( p_titles[i] ); + } + free( p_titles ); +} + void libvlc_media_player_next_chapter( libvlc_media_player_t *p_mi ) { input_thread_t *p_input_thread; diff --git a/src/input/control.c b/src/input/control.c index 30c70ae..72656f4 100644 --- a/src/input/control.c +++ b/src/input/control.c @@ -1,7 +1,7 @@ /***************************************************************************** * control.c ***************************************************************************** - * Copyright (C) 1999-2004 VLC authors and VideoLAN + * Copyright (C) 1999-2015 VLC authors and VideoLAN * $Id$ * * Authors: Gildas Bazin <[email protected]> @@ -358,6 +358,39 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args ) } } + case INPUT_GET_FULL_TITLE_INFO: + { + input_title_t ***array = (input_title_t ***)va_arg( args, input_title_t *** ); + int *count = (int *) va_arg( args, int * ); + + vlc_mutex_lock( &p_input->p->p_item->lock ); + + const int i_titles = p_input->p->i_title; + *count = i_titles; + + if( i_titles == 0 ) + { + vlc_mutex_unlock( &p_input->p->p_item->lock ); + return VLC_EGENERIC; + } + + *array = calloc( i_titles, sizeof(**array) ); + if (!array ) + { + vlc_mutex_unlock( &p_input->p->p_item->lock ); + return VLC_ENOMEM; + } + + for( int i = 0; i < i_titles; i++ ) + { + (*array)[i] = vlc_input_title_Duplicate( p_input->p->title[i] ); + } + + vlc_mutex_unlock( &p_input->p->p_item->lock ); + + return VLC_SUCCESS; + } + case INPUT_GET_VIDEO_FPS: pf = (double*)va_arg( args, double * ); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
