[vlc-devel] [PATCH] libvlc: expand media player API to reveal full information about titles and chapters

Thomas Guillem thomas at gllm.fr
Mon Jan 26 10:07:20 CET 2015


On Sun, Jan 25, 2015, at 10:27, Alexey Sokolov wrote:
> Caller needs to free() one of returned psz_name, but not the other one?
> 
> 23.01.2015 12:46, Felix Paul Kühne пишет:
> > ---
> >  include/vlc/libvlc_media_player.h | 45 +++++++++++++++++++++++
> >  lib/libvlc.sym                    |  2 ++
> >  lib/media_player.c                | 76 +++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 123 insertions(+)
> >
> > diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
> > index c55e85d..d50ea9d 100644
> > --- a/include/vlc/libvlc_media_player.h
> > +++ b/include/vlc/libvlc_media_player.h
> > @@ -60,6 +60,31 @@ typedef struct libvlc_track_description_t
> >  
> >  } libvlc_track_description_t;
> >  
> > +
> > +/**
> > + * Description for chapters.
> > + * It contains information about time and byte off set as well as
> > + * name (description string).
> > + */
> > +typedef struct libvlc_chapter_description_t
> > +{
> > +    int64_t i_byte_offset;
> > +    int64_t i_time_offset;
> > +    char *psz_name;
> > +} libvlc_chapter_description_t;
> > +
> > +/**
> > + * Description for titles. It contains id, name (description string), duration and size,
> > + * and information if it is a menu.
> > + */
> > +typedef struct libvlc_title_description_t
> > +{
> > +    bool b_menu;
> > +    char *psz_name;
> > +    int64_t i_duration;
> > +    int64_t i_size;
> > +} libvlc_title_description_t;
> > +
> >  /**
> >   * Description for audio output. It contains
> >   * name, description and pointer to next record.
> > @@ -1129,6 +1154,16 @@ LIBVLC_API libvlc_track_description_t *
> >          libvlc_video_get_title_description( libvlc_media_player_t *p_mi );
> >  
> >  /**
> > + * Get the full description of a title
> > + *
> > + * \param p_mi the media player
> > + * \return structure containing the full description of the respective title
> > + * \version LibVLC 3.0.0 and later.
> > + */
> > +LIBVLC_API libvlc_title_description_t *
> > +    libvlc_media_player_get_full_title_description( libvlc_media_player_t *p_mi, int i_title );

You should explain how to release the libvlc_title_description_t
returned.

> > +
> > +/**
> >   * Get the description of available chapters for specific title.
> >   *
> >   * \param p_mi the media player
> > @@ -1139,6 +1174,16 @@ LIBVLC_API libvlc_track_description_t *
> >          libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi, int i_title );
> >  
> >  /**
> > + * Get the full description of a chapter
> > + *
> > + * \param p_mi the media player
> > + * \return structure containing the full description of the respective chapter
> > + * \version LibVLC 3.0.0 and later.
> > + */
> > +LIBVLC_API libvlc_chapter_description_t *
> > +    libvlc_media_player_get_full_chapter_description( libvlc_media_player_t *p_mi, int i_title, int i_chapter );

Same for libvlc_chapter_description_t.

Maybe you should add 2 functions that release these 2 structs.

> > +
> > +/**
> >   * Get current crop filter geometry.
> >   *
> >   * \param p_mi the media player
> > diff --git a/lib/libvlc.sym b/lib/libvlc.sym
> > index 7810ed7..4be9f47 100644
> > --- a/lib/libvlc.sym
> > +++ b/lib/libvlc.sym
> > @@ -141,6 +141,8 @@ 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_chapter_description
> > +libvlc_media_player_get_full_title_description
> >  libvlc_media_player_get_hwnd
> >  libvlc_media_player_get_length
> >  libvlc_media_player_get_media
> > diff --git a/lib/media_player.c b/lib/media_player.c
> > index 3ca1e10..fd10452 100644
> > --- a/lib/media_player.c
> > +++ b/lib/media_player.c
> > @@ -1223,6 +1223,82 @@ int libvlc_media_player_get_title_count( libvlc_media_player_t *p_mi )
> >      return i_ret == VLC_SUCCESS ? val.i_int : -1;
> >  }
> >  
> > +libvlc_title_description_t *
> > +libvlc_media_player_get_full_title_description( libvlc_media_player_t *p_mi, int i_title )
> > +{
> > +    input_thread_t *p_input = libvlc_get_input_thread( p_mi );
> > +    libvlc_title_description_t *p_title_description = NULL;
> > +
> > +    if (!p_input)
> > +        return NULL;
> > +
> > +    input_title_t *p_title = NULL;
> > +
> > +    if (input_Control(p_input, INPUT_GET_TITLE_INFO, &p_title, &i_title) != VLC_SUCCESS) {
> > +        vlc_object_release(p_input);
> > +        return NULL;
> > +    }
> > +    vlc_object_release(p_input);
> > +
> > +    if (!p_title)
> > +        return NULL;
> > +
> > +    p_title_description = (libvlc_title_description_t *) malloc(sizeof(libvlc_title_description_t *));
> > +    if (!p_title_description) {
> > +        libvlc_printerr("Not enough memory");
> > +        return NULL;
> > +    }
> > +
> > +    p_title_description->b_menu = p_title->b_menu;
> > +    if (p_title->psz_name)
> > +        p_title_description->psz_name = strdup(p_title->psz_name);
> > +    else
> > +        p_title_description->psz_name = NULL;
> > +    p_title_description->i_duration = p_title->i_length;
> > +    p_title_description->i_size = p_title->i_size;
> > +
> > +    return p_title_description;
> > +}
> > +
> > +libvlc_chapter_description_t *
> > +libvlc_media_player_get_full_chapter_description( libvlc_media_player_t *p_mi, int i_title, int i_chapter )
> > +{
> > +    input_thread_t *p_input = libvlc_get_input_thread( p_mi );
> > +    libvlc_chapter_description_t *p_chapter_description = NULL;
> > +
> > +    if (!p_input)
> > +        return NULL;
> > +
> > +    input_title_t *p_title = NULL;
> > +
> > +    if (input_Control(p_input, INPUT_GET_TITLE_INFO, &p_title, &i_title) != VLC_SUCCESS) {
> > +        vlc_object_release(p_input);
> > +        return NULL;
> > +    }
> > +    vlc_object_release(p_input);
> > +
> > +    if (!p_title)
> > +        return NULL;
> > +
> > +    if (i_chapter >= p_title->i_seekpoint)
> > +        return NULL;
> > +
> > +    p_chapter_description = (libvlc_chapter_description_t *) malloc(sizeof(libvlc_chapter_description_t *));
> > +    if (!p_chapter_description) {
> > +        libvlc_printerr("Not enough memory");
> > +        return NULL;
> > +    }
> > +
> > +    p_chapter_description->i_byte_offset = p_title->seekpoint[i_chapter]->i_byte_offset;
> > +    p_chapter_description->i_time_offset = p_title->seekpoint[i_chapter]->i_time_offset;
> > +    if (p_title->seekpoint[i_chapter]->psz_name)
> > +        p_chapter_description->psz_name = p_title->seekpoint[i_chapter]->psz_name;
> > +    else
> > +        p_chapter_description->psz_name = NULL;
> > +
> > +    return p_chapter_description;
> > +}
> > +
> >  void libvlc_media_player_next_chapter( libvlc_media_player_t *p_mi )
> >  {
> >      input_thread_t *p_input_thread;
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



More information about the vlc-devel mailing list