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

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jul 27 13:42:38 2015 +0300| [32bf025b29cd796ff2140423d2309b3375fbea56] | committer: Rémi Denis-Courmont

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>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=32bf025b29cd796ff2140423d2309b3375fbea56
---

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

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index c99e25c..171b8d5 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -77,6 +77,8 @@ enum libvlc_event_e {
     libvlc_MediaPlayerESAdded,
     libvlc_MediaPlayerESDeleted,
     libvlc_MediaPlayerESSelected,
+    libvlc_MediaPlayerCorked,
+    libvlc_MediaPlayerUncorked,
 
     libvlc_MediaListItemAdded=0x200,
     libvlc_MediaListWillAddItem,
diff --git a/lib/event.c b/lib/event.c
index 4a95cee..b164376 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -283,6 +283,8 @@ static const event_name_t event_list[] = {
     DEF(MediaPlayerESAdded)
     DEF(MediaPlayerESDeleted)
     DEF(MediaPlayerESSelected)
+    DEF(MediaPlayerCorked)
+    DEF(MediaPlayerUncorked)
 
     DEF(MediaListItemAdded)
     DEF(MediaListWillAddItem)
diff --git a/lib/media_player.c b/lib/media_player.c
index b826346..462dceb 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -67,6 +67,10 @@ input_es_selected( vlc_object_t * p_this, char const * psz_cmd,
                    vlc_value_t oldval, vlc_value_t newval,
                    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 void
 add_es_callbacks( input_thread_t *p_input_thread, libvlc_media_player_t *p_mi );
 
@@ -462,6 +466,23 @@ static int snapshot_was_taken(vlc_object_t *p_this, char const *psz_cmd,
     return VLC_SUCCESS;
 }
 
+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.
  *
@@ -637,6 +658,10 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     register_event(mp, ESAdded);
     register_event(mp, ESDeleted);
     register_event(mp, ESSelected);
+    register_event(mp, Corked);
+    register_event(mp, Uncorked);
+
+    var_AddCallback(mp, "corks", corks_changed, NULL);
 
     /* Snapshot initialization */
     register_event(mp, SnapshotTaken);
@@ -687,6 +712,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);



More information about the vlc-commits mailing list