[vlc-devel] [PATCH] Add new functions to libvlc to enable recording of the current media.

Mark Lee mark.lee at capricasoftware.co.uk
Sun Jul 29 20:17:21 CEST 2012


New API functions:

 libvlc_media_player_is_recordable
 libvlc_media_player_set_record
 libvlc_media_player_get_record

New event emitted by the media player event manager when a change in the recordable state is detected:

 libvlc_MediaPlayerRecordableChanged
---
 include/vlc/libvlc_events.h       |    5 +++
 include/vlc/libvlc_media_player.h |   58 ++++++++++++++++++++++++++++++
 lib/event.c                       |    1 +
 lib/libvlc.sym                    |    3 ++
 lib/media_player.c                |   72 +++++++++++++++++++++++++++++++++++++
 5 files changed, 139 insertions(+)

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index 2cfedbf..f3a8327 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -72,6 +72,7 @@ enum libvlc_event_e {
     libvlc_MediaPlayerSnapshotTaken,
     libvlc_MediaPlayerLengthChanged,
     libvlc_MediaPlayerVout,
+    libvlc_MediaPlayerRecordableChanged,
 
     libvlc_MediaListItemAdded=0x200,
     libvlc_MediaListWillAddItem,
@@ -165,6 +166,10 @@ typedef struct libvlc_event_t
         } media_player_pausable_changed;
         struct
         {
+            int new_recordable;
+        } media_player_recordable_changed;
+        struct
+        {
             int new_count;
         } media_player_vout;
 
diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 809ed5f..822f0cd 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1580,6 +1580,64 @@ LIBVLC_API int libvlc_audio_set_delay( libvlc_media_player_t *p_mi, int64_t i_de
 
 /** @} audio */
 
+/**
+ * Can the media player record the current media?
+ *
+ * Media must be playing or buffering before it can be recorded.
+ *
+ * The media player event manager will emit a libvlc_MediaPlayerRecordableChanged event
+ * when the recordable state changes. The event data will describe the new recordable
+ * state, so invocation of this API method is not strictly necessary.
+ *
+ * A libvlc_MediaPlayerRecordableChanged event will not be emitted if the media is
+ * stopped (notified by a libvlc_MediaPlayerStoppedEvent) or finishes (notified by a
+ * libvlc_MediaPlayerFinished event).
+ *
+ * A calling application should therefore register a callback for those events so that it
+ * may query the new recordable state and begin recording at the appropriate time.
+ *
+ * \param p_mi media player
+ * \return true if the media player can record, false if it can not
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API int libvlc_media_player_is_recordable( libvlc_media_player_t *p_mi );
+
+/**
+ * Set whether or not recording is enabled.
+ *
+ * Media must be buffering or playing before it can be recorded.
+ *
+ * Media will be saved to the appropriate media directory for the user, for example
+ * "~/Videos". The saved media file will not be immediately available in that directory
+ * until recording has finished.
+ *
+ * Recording can be started and stopped on-the-fly once the media has started playing;
+ * each time recording is stopped and restarted a new file will be created.
+ *
+ * Recording will be stopped when the media stops playing, and must be explicitly enabled
+ * again to restart recording, i.e. the recording state is not automatically preserved
+ * when playing subsequent media.
+ *
+ * Features such as next/previous chapter, set time or position and so on are ineffective
+ * when recording is enabled. However, pausing the media is possible and will pause the
+ * recording.
+ *
+ * \param p_mi media player
+ * \param b_record start recording if true, stop recording if false
+ * \return zero on success, -1 on error
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API int libvlc_media_player_set_record( libvlc_media_player_t *p_mi, bool b_record );
+
+/**
+ * Get whether or not the media is currently being recorded.
+ *
+ * \param p_mi media player
+ * \return true if recording, false if not
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API int libvlc_media_player_get_record( libvlc_media_player_t *p_mi );
+
 /** @} media_player */
 
 # ifdef __cplusplus
diff --git a/lib/event.c b/lib/event.c
index c71a48a..e2415c9 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -279,6 +279,7 @@ static const event_name_t event_list[] = {
     DEF(MediaPlayerSnapshotTaken)
     DEF(MediaPlayerLengthChanged)
     DEF(MediaPlayerVout)
+    DEF(MediaPlayerRecordableChanged)
 
     DEF(MediaListItemAdded)
     DEF(MediaListWillAddItem)
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index 974e04f..f9d8e8e 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -129,12 +129,14 @@ libvlc_media_player_get_media
 libvlc_media_player_get_nsobject
 libvlc_media_player_get_position
 libvlc_media_player_get_rate
+libvlc_media_player_get_record
 libvlc_media_player_get_state
 libvlc_media_player_get_time
 libvlc_media_player_get_title
 libvlc_media_player_get_title_count
 libvlc_media_player_get_xwindow
 libvlc_media_player_has_vout
+libvlc_media_player_is_recordable
 libvlc_media_player_is_seekable
 libvlc_media_player_is_playing
 libvlc_media_player_new
@@ -153,6 +155,7 @@ libvlc_media_player_set_media
 libvlc_media_player_set_nsobject
 libvlc_media_player_set_position
 libvlc_media_player_set_rate
+libvlc_media_player_set_record
 libvlc_media_player_set_time
 libvlc_media_player_set_title
 libvlc_media_player_set_xwindow
diff --git a/lib/media_player.c b/lib/media_player.c
index f30f184..a984a7d 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -64,6 +64,10 @@ input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval,
                         void * p_userdata );
 static int
+input_recordable_changed( vlc_object_t * p_this, char const * psz_cmd,
+                        vlc_value_t oldval, vlc_value_t newval,
+                        void * p_userdata );
+static int
 input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
                      vlc_value_t oldval, vlc_value_t newval,
                      void * p_userdata );
@@ -132,6 +136,8 @@ static void release_input_thread( libvlc_media_player_t *p_mi, bool b_input_abor
                      input_seekable_changed, p_mi );
     var_DelCallback( p_input_thread, "can-pause",
                     input_pausable_changed, p_mi );
+    var_DelCallback( p_input_thread, "can-record",
+                     input_recordable_changed, p_mi );
     var_DelCallback( p_input_thread, "intf-event",
                      input_event_changed, p_mi );
 
@@ -227,6 +233,24 @@ input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
 }
 
 static int
+input_recordable_changed( vlc_object_t * p_this, char const * psz_cmd,
+                        vlc_value_t oldval, vlc_value_t newval,
+                        void * p_userdata )
+{
+    VLC_UNUSED(oldval);
+    VLC_UNUSED(p_this);
+    VLC_UNUSED(psz_cmd);
+    libvlc_media_player_t * p_mi = p_userdata;
+    libvlc_event_t event;
+
+    event.type = libvlc_MediaPlayerRecordableChanged;
+    event.u.media_player_recordable_changed.new_recordable = newval.b_bool;
+
+    libvlc_event_send( p_mi->p_event_manager, &event );
+    return VLC_SUCCESS;
+}
+
+static int
 input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
                      vlc_value_t oldval, vlc_value_t newval,
                      void * p_userdata )
@@ -514,6 +538,8 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     register_event(mp, TitleChanged);
     register_event(mp, PausableChanged);
 
+    register_event(mp, RecordableChanged);
+
     register_event(mp, Vout);
 
     /* Snapshot initialization */
@@ -731,12 +757,14 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
 
     var_AddCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
     var_AddCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
+    var_AddCallback( p_input_thread, "can-record", input_recordable_changed, p_mi );
     var_AddCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
 
     if( input_Start( p_input_thread ) )
     {
         unlock_input(p_mi);
         var_DelCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
+        var_DelCallback( p_input_thread, "can-record", input_recordable_changed, p_mi );
         var_DelCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
         var_DelCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
         vlc_object_release( p_input_thread );
@@ -1408,3 +1436,47 @@ void libvlc_media_player_next_frame( libvlc_media_player_t *p_mi )
         vlc_object_release( p_input_thread );
     }
 }
+
+int libvlc_media_player_is_recordable( libvlc_media_player_t *p_mi )
+{
+    input_thread_t *p_input_thread;
+    bool b_can_record;
+
+    p_input_thread = libvlc_get_input_thread( p_mi );
+    if( !p_input_thread )
+        return 0;
+
+    b_can_record = var_GetBool( p_input_thread, "can-record" );
+
+    vlc_object_release( p_input_thread );
+    return b_can_record;
+}
+
+int libvlc_media_player_set_record( libvlc_media_player_t *p_mi, bool b_record )
+{
+    input_thread_t *p_input_thread;
+
+    p_input_thread = libvlc_get_input_thread( p_mi );
+    if( !p_input_thread )
+        return -1;
+
+    var_SetBool( p_input_thread, "record", b_record );
+
+    vlc_object_release( p_input_thread );
+    return 0;
+}
+
+int libvlc_media_player_get_record( libvlc_media_player_t *p_mi )
+{
+    input_thread_t *p_input_thread;
+    bool b_record;
+
+    p_input_thread = libvlc_get_input_thread( p_mi );
+    if( !p_input_thread )
+        return 0;
+
+    b_record = var_GetBool( p_input_thread, "record" );
+
+    vlc_object_release( p_input_thread );
+    return b_record;
+}
-- 
1.7.9.5




More information about the vlc-devel mailing list