[vlc-commits] libvlc: add corked and uncorked events (fixes #14444)

Rémi Denis-Courmont git at videolan.org
Mon Jul 27 15:45:08 CEST 2015


vlc/vlc-2.2 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jul 27 13:42:38 2015 +0300| [435215d39000c40c441cc91c906a01a5d93b1490] | committer: Jean-Baptiste Kempf

libvlc: add corked and uncorked events (fixes #14444)

This exposes (audio) policy cork events to LibVLC applications. The
intended usage is for applications to pause/resume playback.

We decided against pausing and resuming automatically as it would most
likely confuse the playback state machine of existing applications. By
default, the OS decides might either mute or duck the audio stream.

Cc: Harald Sitter <sitter at kde.org>
(cherry picked from commit 32bf025b29cd796ff2140423d2309b3375fbea56)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=435215d39000c40c441cc91c906a01a5d93b1490
---

 include/vlc/libvlc_events.h |    2 ++
 lib/event.c                 |    2 ++
 lib/media_player.c          |   28 +++++++++++++++++++++++++++-
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index f268fb5..fa6b738 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -74,6 +74,8 @@ enum libvlc_event_e {
     libvlc_MediaPlayerLengthChanged,
     libvlc_MediaPlayerVout,
     libvlc_MediaPlayerScrambledChanged,
+    libvlc_MediaPlayerCorked = libvlc_MediaPlayerScrambledChanged + 3 + 1,
+    libvlc_MediaPlayerUncorked,
 
     libvlc_MediaListItemAdded=0x200,
     libvlc_MediaListWillAddItem,
diff --git a/lib/event.c b/lib/event.c
index aa285f9..8ae3b8c 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -281,6 +281,8 @@ static const event_name_t event_list[] = {
     DEF(MediaPlayerLengthChanged)
     DEF(MediaPlayerVout)
     DEF(MediaPlayerScrambledChanged)
+    DEF(MediaPlayerCorked)
+    DEF(MediaPlayerUncorked)
 
     DEF(MediaListItemAdded)
     DEF(MediaListWillAddItem)
diff --git a/lib/media_player.c b/lib/media_player.c
index b4a5f10..8938965 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -58,6 +58,10 @@ input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
                      void * p_userdata );
 
 static int
+corks_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
+              vlc_value_t cur, void *opaque);
+
+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 );
 
@@ -365,10 +369,25 @@ static int snapshot_was_taken(vlc_object_t *p_this, char const *psz_cmd,
 
     return VLC_SUCCESS;
 }
-
 /* */
 static void libvlc_media_player_destroy( libvlc_media_player_t * );
 
+static int corks_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
+                         vlc_value_t cur, void *opaque)
+{
+    libvlc_media_player_t *mp = (libvlc_media_player_t *)obj;
+
+    if (!old.i_int != !cur.i_int)
+    {
+        libvlc_event_t event;
+
+        event.type = cur.i_int ? libvlc_MediaPlayerCorked
+                               : libvlc_MediaPlayerUncorked;
+        libvlc_event_send(mp->p_event_manager, &event);
+    }
+    VLC_UNUSED(name); VLC_UNUSED(opaque);
+    return VLC_SUCCESS;
+}
 
 /**************************************************************************
  * Create a Media Instance object.
@@ -540,6 +559,10 @@ libvlc_media_player_new( libvlc_instance_t *instance )
 
     register_event(mp, Vout);
     register_event(mp, ScrambledChanged);
+    register_event(mp, Corked);
+    register_event(mp, Uncorked);
+
+    var_AddCallback(mp, "corks", corks_changed, NULL);
 
     /* Snapshot initialization */
     register_event(mp, SnapshotTaken);
@@ -590,6 +613,9 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
     var_DelCallback( p_mi->p_libvlc,
                      "snapshot-file", snapshot_was_taken, p_mi );
 
+    /* Detach callback from the media player / input manager object */
+    var_DelCallback( p_mi, "corks", corks_changed, NULL );
+
     /* No need for lock_input() because no other threads knows us anymore */
     if( p_mi->input.p_thread )
         release_input_thread(p_mi, true);



More information about the vlc-commits mailing list