[vlc-commits] picture_pool: split picture_pool_NonEmpty and picture_pool_Reset

Rémi Denis-Courmont git at videolan.org
Wed Oct 29 20:27:50 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct 29 16:43:38 2014 +0200| [07e428de4dcc31bbd09c0cd4165853da5d6b5b26] | committer: Rémi Denis-Courmont

picture_pool: split picture_pool_NonEmpty and picture_pool_Reset

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

 include/vlc_picture_pool.h      |   13 +++++++++---
 src/misc/picture_pool.c         |   44 +++++++++++++++++++++++++--------------
 src/video_output/video_output.c |    4 ++--
 3 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/include/vlc_picture_pool.h b/include/vlc_picture_pool.h
index d4574dc..ec7bb39 100644
--- a/include/vlc_picture_pool.h
+++ b/include/vlc_picture_pool.h
@@ -94,17 +94,24 @@ 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
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 3fb8a69..21db31c 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -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;
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index cdbe6b3..6a321d1 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -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();
 }



More information about the vlc-commits mailing list