[vlc-devel] [RFC PATCH 8/8] libvlc: add libvlc_MediaPlayerDecoderStateChanged event

Thomas Guillem thomas at gllm.fr
Thu Apr 21 18:24:38 CEST 2016


---
 include/vlc/libvlc_events.h       |  9 +++++
 include/vlc/libvlc_media_player.h |  8 +++++
 lib/event.c                       |  1 +
 lib/libvlc_internal.h             |  1 +
 lib/media.c                       |  1 +
 lib/media_discoverer.c            |  1 +
 lib/media_library.c               |  1 +
 lib/media_list.c                  |  1 +
 lib/media_player.c                | 74 +++++++++++++++++++++++++++++++++++++++
 9 files changed, 97 insertions(+)

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index 45ce86e..5e04866 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -85,6 +85,7 @@ enum libvlc_event_e {
     libvlc_MediaPlayerAudioVolume,
     libvlc_MediaPlayerAudioDevice,
     libvlc_MediaPlayerChapterChanged,
+    libvlc_MediaPlayerDecoderStateChanged,
 
     libvlc_MediaListItemAdded=0x200,
     libvlc_MediaListWillAddItem,
@@ -266,6 +267,14 @@ typedef struct libvlc_event_t
         {
             const char *device;
         } media_player_audio_device;
+
+        struct
+        {
+            libvlc_track_type_t     i_type;
+            int                     i_id;
+            const char *            psz_module_name;
+            libvlc_decoder_state_t  i_state;
+        } media_player_decoder_state_changed;
     } u; /**< Type-dependent event description */
 } libvlc_event_t;
 
diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 73562b8..f02bb2e 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -158,6 +158,14 @@ typedef enum libvlc_position_t {
 } libvlc_position_t;
 
 /**
+ * Possible states of the @ref libvlc_MediaPlayerDecoderStateChanged event
+ */
+typedef enum libvlc_decoder_state_t {
+    libvlc_decoder_state_error_generic,
+    libvlc_decoder_state_error_output,
+} libvlc_decoder_state_t;
+
+/**
  * Opaque equalizer handle.
  *
  * Equalizer settings can be applied to a media player.
diff --git a/lib/event.c b/lib/event.c
index 56db14f..5db9b12 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -203,6 +203,7 @@ static const event_name_t event_list[] = {
     DEF(MediaPlayerAudioVolume)
     DEF(MediaPlayerAudioDevice)
     DEF(MediaPlayerChapterChanged)
+    DEF(MediaPlayerDecoderStateChanged)
 
     DEF(MediaListItemAdded)
     DEF(MediaListWillAddItem)
diff --git a/lib/libvlc_internal.h b/lib/libvlc_internal.h
index ac853b6..33ba19a 100644
--- a/lib/libvlc_internal.h
+++ b/lib/libvlc_internal.h
@@ -33,6 +33,7 @@
 #include <vlc/libvlc.h>
 #include <vlc/libvlc_dialog.h>
 #include <vlc/libvlc_media.h>
+#include <vlc/libvlc_media_player.h>
 #include <vlc/libvlc_events.h>
 
 #include <vlc_common.h>
diff --git a/lib/media.c b/lib/media.c
index 32379a1..2f1e108 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -30,6 +30,7 @@
 
 #include <vlc/libvlc.h>
 #include <vlc/libvlc_media.h>
+#include <vlc/libvlc_media_player.h>
 #include <vlc/libvlc_media_list.h> // For the subitems, here for convenience
 #include <vlc/libvlc_events.h>
 
diff --git a/lib/media_discoverer.c b/lib/media_discoverer.c
index d65fea9..cec0d7e 100644
--- a/lib/media_discoverer.c
+++ b/lib/media_discoverer.c
@@ -29,6 +29,7 @@
 
 #include <vlc/libvlc.h>
 #include <vlc/libvlc_media.h>
+#include <vlc/libvlc_media_player.h>
 #include <vlc/libvlc_media_list.h>
 #include <vlc/libvlc_media_discoverer.h>
 #include <vlc/libvlc_events.h>
diff --git a/lib/media_library.c b/lib/media_library.c
index 8b69165..f53a659 100644
--- a/lib/media_library.c
+++ b/lib/media_library.c
@@ -28,6 +28,7 @@
 
 #include <vlc/libvlc.h>
 #include <vlc/libvlc_media.h>
+#include <vlc/libvlc_media_player.h>
 #include <vlc/libvlc_media_list.h>
 #include <vlc/libvlc_media_library.h>
 #include <vlc/libvlc_events.h>
diff --git a/lib/media_list.c b/lib/media_list.c
index 82fee60..3c4c7bc 100644
--- a/lib/media_list.c
+++ b/lib/media_list.c
@@ -29,6 +29,7 @@
 
 #include <vlc/libvlc.h>
 #include <vlc/libvlc_media.h>
+#include <vlc/libvlc_media_player.h>
 #include <vlc/libvlc_media_list.h>
 #include <vlc/libvlc_events.h>
 
diff --git a/lib/media_player.c b/lib/media_player.c
index 4761fee..6003176 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -28,6 +28,7 @@
 
 #include <vlc/libvlc.h>
 #include <vlc/libvlc_media.h>
+#include <vlc/libvlc_media_player.h>
 #include <vlc/libvlc_events.h>
 
 #include <vlc_demux.h>
@@ -85,6 +86,12 @@ add_es_callbacks( input_thread_t *p_input_thread, libvlc_media_player_t *p_mi );
 static void
 del_es_callbacks( input_thread_t *p_input_thread, libvlc_media_player_t *p_mi );
 
+static void
+attach_input_thread_events( input_thread_t *, libvlc_media_player_t * );
+
+static void
+detach_input_thread_events( input_thread_t *, libvlc_media_player_t * );
+
 static int
 snapshot_was_taken( vlc_object_t *p_this, char const *psz_cmd,
                     vlc_value_t oldval, vlc_value_t newval, void *p_data );
@@ -149,6 +156,8 @@ static void release_input_thread( libvlc_media_player_t *p_mi )
                      input_event_changed, p_mi );
     del_es_callbacks( p_input_thread, p_mi );
 
+    detach_input_thread_events( p_input_thread, p_mi );
+
     /* We owned this one */
     input_Stop( p_input_thread );
     input_Close( p_input_thread );
@@ -461,6 +470,52 @@ input_es_selected( vlc_object_t * p_this, char const * psz_cmd,
     return VLC_SUCCESS;
 }
 
+static void input_decoder_state_changed(const vlc_event_t *p_event,
+                                        void *p_data)
+{
+    libvlc_media_player_t *mp = p_data;
+
+    libvlc_event_t event;
+    libvlc_track_type_t i_type;
+    libvlc_decoder_state_t i_state;
+
+    switch( p_event->u.input_decoder_state_changed.i_cat )
+    {
+    case AUDIO_ES:
+        i_type = libvlc_track_audio;
+        break;
+    case VIDEO_ES:
+        i_type = libvlc_track_video;
+        break;
+    case SPU_ES:
+        i_type = libvlc_track_text;
+        break;
+    default:
+        return;
+    }
+
+    switch( p_event->u.input_decoder_state_changed.state )
+    {
+    case DECODER_ERROR_GENERIC:
+        i_state = libvlc_decoder_state_error_generic;
+        break;
+    case DECODER_ERROR_OUTPUT:
+        i_state = libvlc_decoder_state_error_output;
+        break;
+    default:
+        return;
+    }
+
+    event.u.media_player_decoder_state_changed.i_type = i_type;
+    event.u.media_player_decoder_state_changed.i_id =
+        p_event->u.input_decoder_state_changed.i_es_id;
+    event.u.media_player_decoder_state_changed.psz_module_name =
+        p_event->u.input_decoder_state_changed.psz_module_name;
+    event.u.media_player_decoder_state_changed.i_state = i_state;
+
+    libvlc_event_send(mp->p_event_manager, &event);
+}
+
 /**************************************************************************
  * Snapshot Taken Event.
  *
@@ -887,6 +942,22 @@ static void del_es_callbacks( input_thread_t *p_input_thread, libvlc_media_playe
     var_DelCallback( p_input_thread, "spu-es", input_es_selected, p_mi );
 }
 
+static void attach_input_thread_events( input_thread_t *p_input_thread,
+                                        libvlc_media_player_t *p_mi )
+{
+    vlc_event_attach( &p_input_thread->event_manager,
+                      vlc_InputDecoderStateChanged, input_decoder_state_changed,
+                      p_mi );
+}
+
+static void detach_input_thread_events( input_thread_t *p_input_thread,
+                                        libvlc_media_player_t *p_mi )
+{
+    vlc_event_detach( &p_input_thread->event_manager,
+                      vlc_InputDecoderStateChanged, input_decoder_state_changed,
+                      p_mi );
+}
+
 /**************************************************************************
  * Tell media player to start playing.
  **************************************************************************/
@@ -930,9 +1001,12 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
     var_AddCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
     add_es_callbacks( p_input_thread, p_mi );
 
+    attach_input_thread_events( p_input_thread, p_mi );
+
     if( input_Start( p_input_thread ) )
     {
         unlock_input(p_mi);
+        detach_input_thread_events( p_input_thread, p_mi );
         del_es_callbacks( p_input_thread, p_mi );
         var_DelCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
         var_DelCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
-- 
2.8.0.rc3



More information about the vlc-devel mailing list