[vlc-devel] [PATCH 06/12] libvlc: add libvlc_MediaPlayerDecoderStateChanged event

Thomas Guillem thomas at gllm.fr
Thu Jun 9 11:51:58 CEST 2016


---
 include/vlc/libvlc_events.h       |  7 +++++++
 include/vlc/libvlc_media_player.h | 11 +++++++++++
 lib/event.c                       |  1 +
 lib/libvlc_internal.h             |  1 +
 lib/media_player.c                | 32 ++++++++++++++++++++++++++++++++
 5 files changed, 52 insertions(+)

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index c5aecca..a3b94c2 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -84,6 +84,7 @@ enum libvlc_event_e {
     libvlc_MediaPlayerAudioVolume,
     libvlc_MediaPlayerAudioDevice,
     libvlc_MediaPlayerChapterChanged,
+    libvlc_MediaPlayerDecoderStateChanged,
 
     libvlc_MediaListItemAdded=0x200,
     libvlc_MediaListWillAddItem,
@@ -261,6 +262,12 @@ typedef struct libvlc_event_t
         {
             const char *device;
         } media_player_audio_device;
+
+        struct
+        {
+            int i_type; /**< see @ref libvlc_track_type_t */
+            int 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 2323b4d..e782c8a 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -158,6 +158,17 @@ typedef enum libvlc_position_t {
 } libvlc_position_t;
 
 /**
+ * Possible states of the @ref libvlc_MediaPlayerDecoderStateChanged event
+ */
+#define LIBVLC_DECODER_STATE_HW            (1<<0)
+#define LIBVLC_DECODER_STATE_ERROR_GENERIC (1<<1)
+#define LIBVLC_DECODER_STATE_ERROR_INPUT   (1<<2)
+#define LIBVLC_DECODER_STATE_ERROR_OUTPUT  (1<<3)
+
+#define LIBVLC_DECODER_STATE_ERROR (LIBVLC_DECODER_STATE_ERROR_GENERIC | \
+                                    LIBVLC_DECODER_STATE_ERROR_INPUT | \
+                                    LIBVLC_DECODER_STATE_ERROR_OUTPUT)
+/**
  * Opaque equalizer handle.
  *
  * Equalizer settings can be applied to a media player.
diff --git a/lib/event.c b/lib/event.c
index 6beeacd..a4ac794 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -202,6 +202,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 9fa3a47..b012ca7 100644
--- a/lib/libvlc_internal.h
+++ b/lib/libvlc_internal.h
@@ -32,6 +32,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_player.c b/lib/media_player.c
index a0860da..9884e67 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>
@@ -35,11 +36,18 @@
 #include <vlc_vout.h>
 #include <vlc_aout.h>
 #include <vlc_keys.h>
+#include <vlc_codec.h> /* DECODER_STATE_ */
 
 #include "libvlc_internal.h"
 #include "media_internal.h" // libvlc_media_set_state()
 #include "media_player_internal.h"
 
+static_assert( LIBVLC_DECODER_STATE_HW == DECODER_STATE_HW
+    && LIBVLC_DECODER_STATE_ERROR_GENERIC == DECODER_STATE_ERROR_GENERIC
+    && LIBVLC_DECODER_STATE_ERROR_INPUT == DECODER_STATE_ERROR_INPUT
+    && LIBVLC_DECODER_STATE_ERROR_OUTPUT == DECODER_STATE_ERROR_OUTPUT,
+    "mismatch between LIBVLC_DECODER_STATE_* and DECODER_STATE_*" );
+
 static int
 input_seekable_changed( vlc_object_t * p_this, char const * psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval,
@@ -409,6 +417,30 @@ input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
         event.u.media_player_chapter_changed.new_chapter = var_GetInteger( p_input, "chapter" );
         libvlc_event_send( p_mi->p_event_manager, &event );
     }
+    else if ( newval.i_int == INPUT_EVENT_VIDEO_DECODER_STATE )
+    {
+        event.type = libvlc_MediaPlayerDecoderStateChanged;
+        event.u.media_player_decoder_state_changed.i_type = libvlc_track_video;
+        event.u.media_player_decoder_state_changed.i_state =
+            var_GetInteger( p_input, "video-dec-state" );
+        libvlc_event_send( p_mi->p_event_manager, &event );
+    }
+    else if ( newval.i_int == INPUT_EVENT_AUDIO_DECODER_STATE )
+    {
+        event.type = libvlc_MediaPlayerDecoderStateChanged;
+        event.u.media_player_decoder_state_changed.i_type = libvlc_track_audio;
+        event.u.media_player_decoder_state_changed.i_state =
+            var_GetInteger( p_input, "audio-dec-state" );
+        libvlc_event_send( p_mi->p_event_manager, &event );
+    }
+    else if ( newval.i_int == INPUT_EVENT_SPU_DECODER_STATE )
+    {
+        event.type = libvlc_MediaPlayerDecoderStateChanged;
+        event.u.media_player_decoder_state_changed.i_type = libvlc_track_text;
+        event.u.media_player_decoder_state_changed.i_state =
+            var_GetInteger( p_input, "spu-dec-state" );
+        libvlc_event_send( p_mi->p_event_manager, &event );
+    }
 
     return VLC_SUCCESS;
 }
-- 
2.8.1



More information about the vlc-devel mailing list