[vlc-devel] [PATCH] libvlc: expand media player API to retrieve information about all available titles of the currently playing media item

Felix Paul Kühne fkuehne at videolan.org
Thu Jun 4 10:40:00 CEST 2015


---
 include/vlc/libvlc_media_player.h | 41 +++++++++++++++++++-
 include/vlc_input.h               |  4 +-
 lib/libvlc.sym                    |  2 +
 lib/media_player.c                | 79 ++++++++++++++++++++++++++++++++++++++-
 src/input/control.c               | 35 ++++++++++++++++-
 5 files changed, 156 insertions(+), 5 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index c55e85d..cbe99a0 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 <zorglub at videolan.org>
@@ -61,6 +61,18 @@ typedef struct libvlc_track_description_t
 } libvlc_track_description_t;
 
 /**
+ * Description for titles. It contains name (description string),
+ * duration in microseconds if known,
+ * and information if it was recognized as a menu by the demuxer.
+ */
+typedef struct libvlc_title_description_t
+{
+    int64_t i_duration;
+    bool b_menu;
+    char *psz_name;
+} libvlc_title_description_t;
+
+/**
  * Description for audio output. It contains
  * name, description and pointer to next record.
  */
@@ -1129,6 +1141,33 @@ 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_media_tracks_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 titles 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 6ec305b..458a306 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 <massiot at via.ecp.fr>
@@ -90,7 +90,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)
@@ -455,6 +454,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 7810ed7..3cb6d76 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -141,6 +141,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
@@ -196,6 +197,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 3ca1e10..5e7cfdb 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 <zorglub at videolan.org>
  *
@@ -1223,6 +1223,83 @@ 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;
+
+        p_title->i_duration = p_input_title[i]->i_length;
+        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 2e4633f..cdbc49d 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 <gbazin at videolan.org>
@@ -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 * );
 
-- 
2.4.1




More information about the vlc-devel mailing list