[vlc-devel] commit: embedded snapshot: guard against spurious vlc_object_wait wakeups. (Olivier Aubert )

git version control git at videolan.org
Mon Sep 8 18:28:33 CEST 2008


vlc | branch: master | Olivier Aubert <olivier.aubert at liris.cnrs.fr> | Mon Sep  8 18:17:33 2008 +0200| [920e215b79126a690d327c795c9f4bd03c6ddfd1] | committer: Olivier Aubert 

embedded snapshot: guard against spurious vlc_object_wait wakeups.

Thanks courmisch for noticing this.
It still uses the old, and soon to be deprecated I imagine, vlc_object_wait API, but well, we cannot go faster than the music, can we?

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

 src/control/mediacontrol_audio_video.c |   11 ++++++++++-
 src/video_output/vout_intf.c           |   11 +++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/control/mediacontrol_audio_video.c b/src/control/mediacontrol_audio_video.c
index e0a6f7c..3552098 100644
--- a/src/control/mediacontrol_audio_video.c
+++ b/src/control/mediacontrol_audio_video.c
@@ -88,9 +88,18 @@ mediacontrol_snapshot( mediacontrol_Instance *self,
     var_SetString( p_vout, "snapshot-path", path );
     var_SetString( p_vout, "snapshot-format", "png" );
 
+    
     vlc_object_lock( p_cache );
+    /* Initialize p_cache->p_private with p_cache own value, to be
+       used as a sentinel against spurious vlc_object_wait wakeups.
+
+       If a legitimate wakeup occurs, then p_cache->p_private will hold either
+       NULL (in case of error) or a pointer to a p_snapshot data structure.
+    */
+    p_cache->p_private = p_cache;
     vout_Control( p_vout, VOUT_SNAPSHOT );
-    vlc_object_wait( p_cache );
+    while ( p_cache->p_private == p_cache )
+        vlc_object_wait( p_cache );
     vlc_object_release( p_vout );
 
     p_snapshot = ( snapshot_t* ) p_cache->p_private;
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 332c834..15fddce 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -632,16 +632,17 @@ int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
         snapshot_t *p_snapshot;
         size_t i_size;
 
-        /* Object must be locked. We will unlock it once we get the
-           snapshot and written it to p_private */
-        p_dest->p_private = NULL;
-
+        /* Object must be locked by the caller function. We will
+           unlock it once we get the snapshot and have written it to
+           p_cache->p_private. */
+	
         /* Save the snapshot to a memory zone */
         p_block = image_Write( p_image, p_pic, &fmt_in, &fmt_out );
         if( !p_block )
         {
             msg_Err( p_vout, "Could not get snapshot" );
             image_HandlerDelete( p_image );
+	    p_dest->p_private = NULL;
             vlc_object_signal_unlocked( p_dest );
             vlc_object_release( p_dest );
             return VLC_EGENERIC;
@@ -654,6 +655,7 @@ int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
         {
             block_Release( p_block );
             image_HandlerDelete( p_image );
+	    p_dest->p_private = NULL;
             vlc_object_signal_unlocked( p_dest );
             vlc_object_release( p_dest );
             return VLC_ENOMEM;
@@ -671,6 +673,7 @@ int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
             block_Release( p_block );
             free( p_snapshot );
             image_HandlerDelete( p_image );
+	    p_dest->p_private = NULL;
             vlc_object_signal_unlocked( p_dest );
             vlc_object_release( p_dest );
             return VLC_ENOMEM;




More information about the vlc-devel mailing list