]> git.sesse.net Git - vlc/commitdiff
picture_pool: split picture_pool_NonEmpty and picture_pool_Reset
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 29 Oct 2014 14:43:38 +0000 (16:43 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 29 Oct 2014 19:27:49 +0000 (21:27 +0200)
include/vlc_picture_pool.h
src/misc/picture_pool.c
src/video_output/video_output.c

index d4574dc5a1dfd2d873c6f286ee612462f886bb33..ec7bb39e3aa1800d7ac80a82bb79b40a27ee0c30 100644 (file)
@@ -93,18 +93,25 @@ VLC_API void picture_pool_Delete( picture_pool_t * );
  */
 VLC_API picture_t * picture_pool_Get( picture_pool_t * ) VLC_USED;
 
+/**
+ * Forcefully return all pictures in the pool to free/unallocated state.
+ *
+ * @warning This can only be called when it is known that all pending
+ * references to the picture pool are stale, e.g. a decoder failed to
+ * release pictures properly when it terminated.
+ */
+void picture_pool_Reset( picture_pool_t * );
+
 /**
  * It forces the next picture_pool_Get to return a picture even if no
  * pictures are free.
  *
- * If b_reset is true, all pictures will be marked as free.
- *
  * It does it by releasing itself the oldest used picture if none is
  * available.
  * XXX it should be used with great care, the only reason you may need
  * it is to workaround a bug.
  */
-VLC_API void picture_pool_NonEmpty( picture_pool_t *, bool reset );
+VLC_API void picture_pool_NonEmpty( picture_pool_t * );
 
 /**
  * It reserves picture_count pictures from the given pool and returns
index 3fb8a695d477485668ea3cb5de9194d4a81bf01a..21db31c688d0878f0e85fc3a9334ded132d5935d 100644 (file)
@@ -289,31 +289,43 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
     return NULL;
 }
 
-void picture_pool_NonEmpty(picture_pool_t *pool, bool reset)
+void picture_pool_Reset(picture_pool_t *pool)
 {
-    picture_t *old = NULL;
-
     for (int i = 0; i < pool->picture_count; i++) {
         if (pool->picture_reserved[i])
             continue;
 
         picture_t *picture = pool->picture[i];
-        if (reset) {
-            if (atomic_load(&picture->gc.refcount) > 0)
-                Unlock(picture);
-            atomic_store(&picture->gc.refcount, 0);
-        } else if (atomic_load(&picture->gc.refcount) == 0) {
-            return;
-        } else if (!old || picture->gc.p_sys->tick < old->gc.p_sys->tick) {
-            old = picture;
-        }
+        if (atomic_load(&picture->gc.refcount) > 0)
+            Unlock(picture);
+        atomic_store(&picture->gc.refcount, 0);
     }
-    if (!reset && old) {
-        if (atomic_load(&old->gc.refcount) > 0)
-            Unlock(old);
-        atomic_store(&old->gc.refcount, 0);
+}
+
+void picture_pool_NonEmpty(picture_pool_t *pool)
+{
+    picture_t *oldest = NULL;
+
+    for (int i = 0; i < pool->picture_count; i++) {
+        if (pool->picture_reserved[i])
+            continue;
+
+        picture_t *picture = pool->picture[i];
+        if (atomic_load(&picture->gc.refcount) == 0)
+            return; /* Nothing to do */
+
+        if (oldest == NULL || picture->gc.p_sys->tick < oldest->gc.p_sys->tick)
+            oldest = picture;
     }
+
+    if (oldest == NULL)
+        return; /* Cannot fix! */
+
+    if (atomic_load(&oldest->gc.refcount) > 0)
+        Unlock(oldest);
+    atomic_store(&oldest->gc.refcount, 0);
 }
+
 int picture_pool_GetSize(picture_pool_t *pool)
 {
     return pool->picture_count;
index cdbe6b3eeb1def19eb3213ec5eb2816d89fc45a8..6a321d14f10b448284a3ae7fc173384d6659fcc0 100644 (file)
@@ -363,7 +363,7 @@ void vout_FixLeaks( vout_thread_t *vout )
     msg_Err(vout, "pictures leaked, trying to workaround");
 
     /* */
-    picture_pool_NonEmpty(vout->p->decoder_pool, false);
+    picture_pool_NonEmpty(vout->p->decoder_pool);
 
     vlc_mutex_unlock(&vout->p->picture_lock);
 }
@@ -1232,7 +1232,7 @@ static void ThreadReset(vout_thread_t *vout)
 {
     ThreadFlush(vout, true, INT64_MAX);
     if (vout->p->decoder_pool)
-        picture_pool_NonEmpty(vout->p->decoder_pool, true);
+        picture_pool_Reset(vout->p->decoder_pool);
     vout->p->pause.is_on = false;
     vout->p->pause.date  = mdate();
 }