libvlc: better title/chapter handling
authorLukas Durfina <lukas.durfina@gmail.com>
Sat, 4 Oct 2008 20:00:52 +0000 (22:00 +0200)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Sat, 11 Oct 2008 12:57:05 +0000 (14:57 +0200)
Signed-off-by: Pierre d'Herbemont <pdherbemont@videolan.org>
include/vlc/libvlc.h
include/vlc/libvlc_events.h
src/control/event.c
src/control/media_player.c
src/libvlc.sym

index 7f2f384..c348a09 100644 (file)
@@ -268,7 +268,7 @@ VLC_PUBLIC_API void libvlc_media_add_option(
 
 /**
  * Retain a reference to a media descriptor object (libvlc_media_t). Use
- * libvlc_media_release() to decrement the reference count of a 
+ * libvlc_media_release() to decrement the reference count of a
  * media descriptor object.
  *
  * \param p_meta_desc a media descriptor object.
@@ -381,8 +381,8 @@ VLC_PUBLIC_API int
                                          libvlc_exception_t * p_e );
 
 /**
- * Sets media descriptor's user_data. user_data is specialized data 
- * accessed by the host application, VLC.framework uses it as a pointer to 
+ * Sets media descriptor's user_data. user_data is specialized data
+ * accessed by the host application, VLC.framework uses it as a pointer to
  * an native object that references a libvlc_media_t pointer
  *
  * \param p_md media descriptor object
@@ -395,8 +395,8 @@ VLC_PUBLIC_API void
                                            libvlc_exception_t * p_e);
 
 /**
- * Get media descriptor's user_data. user_data is specialized data 
- * accessed by the host application, VLC.framework uses it as a pointer to 
+ * Get media descriptor's user_data. user_data is specialized data
+ * accessed by the host application, VLC.framework uses it as a pointer to
  * an native object that references a libvlc_media_t pointer
  *
  * \param p_md media descriptor object
@@ -439,8 +439,8 @@ VLC_PUBLIC_API libvlc_media_player_t * libvlc_media_player_new_from_media( libvl
 /**
  * Release a media_player after use
  * Decrement the reference count of a media player object. If the
- * reference count is 0, then libvlc_media_player_release() will 
- * release the media player object. If the media player object 
+ * reference count is 0, then libvlc_media_player_release() will
+ * release the media player object. If the media player object
  * has been released, then it should not be used again.
  *
  * \param p_mi the Media Player to free
@@ -455,7 +455,7 @@ VLC_PUBLIC_API void libvlc_media_player_release( libvlc_media_player_t * );
  */
 VLC_PUBLIC_API void libvlc_media_player_retain( libvlc_media_player_t * );
 
-/** 
+/**
  * Set the media that will be used by the media_player. If any,
  * previous md will be released.
  *
@@ -605,6 +605,60 @@ VLC_PUBLIC_API int libvlc_media_player_get_chapter( libvlc_media_player_t *, lib
 VLC_PUBLIC_API int libvlc_media_player_get_chapter_count( libvlc_media_player_t *, libvlc_exception_t *);
 VLC_PUBLIC_API int libvlc_media_player_will_play        ( libvlc_media_player_t *, libvlc_exception_t *);
 
+/**
+ * Get title chapter count
+ *
+ * \param p_mi the Media Player
+ * \param i_title title
+ * \param p_e an initialized exception pointer
+ * \return number of chapters in title
+ */
+VLC_PUBLIC_API int libvlc_media_player_get_chapter_count_for_title(
+                       libvlc_media_player_t *, int, libvlc_exception_t *);
+
+/**
+ * Set movie title
+ *
+ * \param p_mi the Media Player
+ * \param i_title title number to play
+ * \param p_e an initialized exception pointer
+ */
+VLC_PUBLIC_API void libvlc_media_player_set_title( libvlc_media_player_t *, int, libvlc_exception_t *);
+
+/**
+ * Get movie title
+ *
+ * \param p_mi the Media Player
+ * \param p_e an initialized exception pointer
+ * \return title number currently playing
+ */
+VLC_PUBLIC_API int libvlc_media_player_get_title( libvlc_media_player_t *, libvlc_exception_t *);
+
+/**
+ * Get movie title count
+ *
+ * \param p_mi the Media Player
+ * \param p_e an initialized exception pointer
+ * \return title number count
+ */
+VLC_PUBLIC_API int libvlc_media_player_get_title_count( libvlc_media_player_t *, libvlc_exception_t *);
+
+/**
+ * Set previous chapter
+ *
+ * \param p_mi the Media Player
+ * \param p_e an initialized exception pointer
+ */
+VLC_PUBLIC_API void libvlc_media_player_previous_chapter( libvlc_media_player_t *, libvlc_exception_t *);
+
+/**
+ * Set next chapter
+ *
+ * \param p_mi the Media Player
+ * \param p_e an initialized exception pointer
+ */
+VLC_PUBLIC_API void libvlc_media_player_next_chapter( libvlc_media_player_t *, libvlc_exception_t *);
+
 /**
  * Get movie play rate
  *
@@ -1052,7 +1106,7 @@ VLC_PUBLIC_API void
 
 /**
  * Retain a reference to a media library object. This function will
- * increment the reference counting for this object. Use 
+ * increment the reference counting for this object. Use
  * libvlc_media_library_release() to decrement the reference count.
  *
  * \param p_mlib media library object
index 1aa0f2f..f72ee6c 100644 (file)
@@ -82,7 +82,9 @@ typedef enum libvlc_event_type_t {
     libvlc_MediaListPlayerStopped,
 
     libvlc_MediaDiscovererStarted,
-    libvlc_MediaDiscovererEnded
+    libvlc_MediaDiscovererEnded,
+
+    libvlc_MediaPlayerTitleChanged
 
 } libvlc_event_type_t;
 
@@ -135,6 +137,10 @@ typedef struct libvlc_event_t
             libvlc_time_t new_time;
         } media_player_time_changed;
         struct
+        {
+            int new_title;
+        } media_player_title_changed;
+        struct
         {
             libvlc_time_t new_seekable;
         } media_player_seekable_changed;
index ad3ee7e..940cc2b 100644 (file)
@@ -249,6 +249,7 @@ static const char event_type_to_name[][35] =
     EVENT(libvlc_MediaPlayerBackward),
     EVENT(libvlc_MediaPlayerEndReached),
     EVENT(libvlc_MediaPlayerTimeChanged),
+    EVENT(libvlc_MediaPlayerTitleChanged),
     EVENT(libvlc_MediaPlayerPositionChanged),
     EVENT(libvlc_MediaPlayerSeekableChanged),
     EVENT(libvlc_MediaPlayerPausableChanged),
index 237ce60..1248e1f 100644 (file)
@@ -370,6 +370,8 @@ libvlc_media_player_new( libvlc_instance_t * p_libvlc_instance,
             libvlc_MediaPlayerPositionChanged, p_e );
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
             libvlc_MediaPlayerTimeChanged, p_e );
+     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
+            libvlc_MediaPlayerTitleChanged, p_e );
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
             libvlc_MediaPlayerSeekableChanged, p_e );
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
@@ -857,7 +859,7 @@ int libvlc_media_player_get_chapter(
 
     p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
     if( !p_input_thread )
-        return -1.0;
+        return -1;
 
     var_Get( p_input_thread, "chapter", &val );
     vlc_object_release( p_input_thread );
@@ -874,7 +876,7 @@ int libvlc_media_player_get_chapter_count(
 
     p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
     if( !p_input_thread )
-        return -1.0;
+        return -1;
 
     var_Change( p_input_thread, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
     vlc_object_release( p_input_thread );
@@ -882,6 +884,126 @@ int libvlc_media_player_get_chapter_count(
     return val.i_int;
 }
 
+int libvlc_media_player_get_chapter_count_for_title(
+                                 libvlc_media_player_t *p_mi,
+                                 int i_title,
+                                 libvlc_exception_t *p_e )
+{
+    input_thread_t *p_input_thread;
+    vlc_value_t val;
+
+    p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
+    if( !p_input_thread )
+        return -1;
+
+    char *psz_name = NULL;
+    if( asprintf( psz_name,  "title %2i", i_title ) == -1 )
+    {
+        vlc_object_release( p_input_thread );
+        return -1;
+    }
+    var_Change( p_input_thread, psz_name, VLC_VAR_CHOICESCOUNT, &val, NULL );
+    vlc_object_release( p_input_thread );
+    free( psz_name );
+
+    return val.i_int;
+}
+
+void libvlc_media_player_set_title(
+                                 libvlc_media_player_t *p_mi,
+                                 int i_title,
+                                 libvlc_exception_t *p_e )
+{
+    input_thread_t *p_input_thread;
+    vlc_value_t val;
+    val.i_int = i_title;
+
+    p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
+    if( !p_input_thread )
+        return;
+
+    var_Set( p_input_thread, "title", val );
+    vlc_object_release( p_input_thread );
+
+    //send event
+    libvlc_event_t event;
+    event.type = libvlc_MediaPlayerTitleChanged;
+    event.u.media_player_title_changed.new_title = i_title;
+    libvlc_event_send( p_mi->p_event_manager, &event );
+}
+
+int libvlc_media_player_get_title(
+                                 libvlc_media_player_t *p_mi,
+                                 libvlc_exception_t *p_e )
+{
+    input_thread_t *p_input_thread;
+    vlc_value_t val;
+
+    p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
+    if( !p_input_thread )
+        return -1;
+
+    var_Get( p_input_thread, "title", &val );
+    vlc_object_release( p_input_thread );
+
+    return val.i_int;
+}
+
+int libvlc_media_player_get_title_count(
+                                 libvlc_media_player_t *p_mi,
+                                 libvlc_exception_t *p_e )
+{
+    input_thread_t *p_input_thread;
+    vlc_value_t val;
+
+    p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
+    if( !p_input_thread )
+        return -1;
+
+    var_Change( p_input_thread, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
+    vlc_object_release( p_input_thread );
+
+    return val.i_int;
+}
+
+void libvlc_media_player_next_chapter(
+                                 libvlc_media_player_t *p_mi,
+                                 libvlc_exception_t *p_e )
+{
+    input_thread_t *p_input_thread;
+
+    p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
+    if( !p_input_thread )
+        return;
+
+    int i_type = var_Type( p_input_thread, "next-chapter" );
+    vlc_value_t val;
+    val.b_bool = true;
+    var_Set( p_input_thread, (i_type & VLC_VAR_TYPE) != 0 ?
+                            "next-chapter":"next-title", val );
+
+    vlc_object_release( p_input_thread );
+}
+
+void libvlc_media_player_previous_chapter(
+                                 libvlc_media_player_t *p_mi,
+                                 libvlc_exception_t *p_e )
+{
+    input_thread_t *p_input_thread;
+
+    p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
+    if( !p_input_thread )
+        return;
+
+    int i_type = var_Type( p_input_thread, "next-chapter" );
+    vlc_value_t val;
+    val.b_bool = true;
+    var_Set( p_input_thread, (i_type & VLC_VAR_TYPE) != 0 ?
+                            "prev-chapter":"prev-title", val );
+
+    vlc_object_release( p_input_thread );
+}
+
 float libvlc_media_player_get_fps(
                                  libvlc_media_player_t *p_mi,
                                  libvlc_exception_t *p_e)
index ce03edd..d45147a 100644 (file)
@@ -110,6 +110,7 @@ libvlc_media_player_destroy
 libvlc_media_player_event_manager
 libvlc_media_player_get_chapter
 libvlc_media_player_get_chapter_count
+libvlc_media_player_get_chapter_count_for_title
 libvlc_media_player_get_drawable
 libvlc_media_player_get_fps
 libvlc_media_player_get_length
@@ -118,13 +119,17 @@ libvlc_media_player_get_position
 libvlc_media_player_get_rate
 libvlc_media_player_get_state
 libvlc_media_player_get_time
+libvlc_media_player_get_title
+libvlc_media_player_get_title_count
 libvlc_media_player_has_vout
 libvlc_media_player_is_seekable
 libvlc_media_player_new
 libvlc_media_player_new_from_input_thread
 libvlc_media_player_new_from_media
+libvlc_media_player_next_chapter
 libvlc_media_player_pause
 libvlc_media_player_play
+libvlc_media_player_previous_chapter
 libvlc_media_player_release
 libvlc_media_player_retain
 libvlc_media_player_set_chapter
@@ -133,6 +138,7 @@ libvlc_media_player_set_media
 libvlc_media_player_set_position
 libvlc_media_player_set_rate
 libvlc_media_player_set_time
+libvlc_media_player_set_title
 libvlc_media_player_stop
 libvlc_media_player_will_play
 libvlc_media_release