[vlc-commits] commit: libvlc_media_player_set_pause: race-free pause/resume function ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Sun Jun 27 15:54:29 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 27 16:52:58 2010 +0300| [4faa38ecba8274d50fb03ff070ff18df9f4f9875] | committer: Rémi Denis-Courmont 

libvlc_media_player_set_pause: race-free pause/resume function

While -confusingly IMHO- libvlc_media_player_pause() toggles the pause
state, libvlc_media_player_set_pause() sets it.

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

 include/vlc/libvlc_media_player.h |    9 +++++++++
 src/control/media_player.c        |   32 +++++++++++++++++++++++---------
 src/libvlc.sym                    |    1 +
 3 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 0c1a4ef..435bb4f 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -177,6 +177,15 @@ VLC_PUBLIC_API int libvlc_media_player_is_playing ( libvlc_media_player_t *p_mi
 VLC_PUBLIC_API int libvlc_media_player_play ( libvlc_media_player_t *p_mi );
 
 /**
+ * Pause or resume (no effect if there is no media)
+ *
+ * \param mp the Media Player
+ * \param do_pause play/resume if zero, pause if non-zero
+ */
+VLC_PUBLIC_API void libvlc_media_player_set_pause ( libvlc_media_player_t *mp,
+                                                    int do_pause );
+
+/**
  * Toggle pause (no effect if there is no media)
  *
  * \param p_mi the Media Player
diff --git a/src/control/media_player.c b/src/control/media_player.c
index a9104ee..158cf3d 100644
--- a/src/control/media_player.c
+++ b/src/control/media_player.c
@@ -690,10 +690,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
     return 0;
 }
 
-/**************************************************************************
- * Pause.
- **************************************************************************/
-void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
+void libvlc_media_player_set_pause( libvlc_media_player_t *p_mi, int paused )
 {
     input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi );
     if( !p_input_thread )
@@ -702,18 +699,35 @@ void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
     libvlc_state_t state = libvlc_media_player_get_state( p_mi );
     if( state == libvlc_Playing || state == libvlc_Buffering )
     {
-        if( libvlc_media_player_can_pause( p_mi ) )
-            input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S );
-        else
-            libvlc_media_player_stop( p_mi );
+        if( paused )
+        {
+            if( libvlc_media_player_can_pause( p_mi ) )
+                input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S );
+            else
+                libvlc_media_player_stop( p_mi );
+        }
     }
     else
-        input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
+    {
+        if( !paused )
+            input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
+    }
 
     vlc_object_release( p_input_thread );
 }
 
 /**************************************************************************
+ * Toggle pause.
+ **************************************************************************/
+void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
+{
+    libvlc_state_t state = libvlc_media_player_get_state( p_mi );
+    bool playing = (state == libvlc_Playing || state == libvlc_Buffering);
+
+    libvlc_media_player_set_pause( p_mi, playing );
+}
+
+/**************************************************************************
  * Tells whether the media player is currently playing.
  *
  * Enter with lock held.
diff --git a/src/libvlc.sym b/src/libvlc.sym
index b732453..fa92d46 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -129,6 +129,7 @@ libvlc_media_player_is_playing
 libvlc_media_player_new
 libvlc_media_player_new_from_media
 libvlc_media_player_next_chapter
+libvlc_media_player_set_pause
 libvlc_media_player_pause
 libvlc_media_player_play
 libvlc_media_player_previous_chapter



More information about the vlc-commits mailing list