[vlc-devel] [PATCH 1/3] picture_pool: add picture_pool_ChangePause

Thomas Guillem thomas at gllm.fr
Thu Nov 26 19:03:02 CET 2015


---
 include/vlc_picture_pool.h |  9 +++++++++
 src/misc/picture_pool.c    | 27 ++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/vlc_picture_pool.h b/include/vlc_picture_pool.h
index ec4bf39..1b92aa4 100644
--- a/include/vlc_picture_pool.h
+++ b/include/vlc_picture_pool.h
@@ -158,6 +158,15 @@ VLC_API void picture_pool_Enum( picture_pool_t *,
 unsigned picture_pool_Reset( picture_pool_t * );
 
 /**
+ * Set the picture pool paused state.
+ *
+ * When picture_pool is paused, picture_pool_Wait won't wait if there are no
+ * pictures available.
+ * picture_pool_Reset() will also reset the paused state.
+ */
+void picture_pool_ChangePause( picture_pool_t *, bool paused );
+
+/**
  * Reserves pictures from a pool and creates a new pool with those.
  *
  * When the new pool is released, pictures are returned to the master pool.
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index f82cb16..14b372a 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -42,6 +42,7 @@ struct picture_pool_t {
     vlc_mutex_t lock;
     vlc_cond_t  wait;
 
+    bool               paused;
     unsigned long long available;
     atomic_ushort      refs;
     unsigned short     picture_count;
@@ -131,6 +132,7 @@ picture_pool_t *picture_pool_NewExtended(const picture_pool_configuration_t *cfg
     pool->picture_count = cfg->picture_count;
     memcpy(pool->picture, cfg->picture,
            cfg->picture_count * sizeof (picture_t *));
+    pool->paused = false;
     return pool;
 }
 
@@ -236,9 +238,20 @@ picture_t *picture_pool_Wait(picture_pool_t *pool)
     vlc_mutex_lock(&pool->lock);
     assert(pool->refs > 0);
 
-    while (pool->available == 0)
+    /* Wait for pictures available or paused state */
+    while (pool->available == 0 && !pool->paused)
         vlc_cond_wait(&pool->wait, &pool->lock);
 
+    /* Don't wait if no pictures are available and if the pool is paused.
+     * Indeed, if paused, no pictures will be displayed (and released) anymore
+     * and this function would wait indefinitely. */
+    if (pool->available == 0)
+    {
+        assert(pool->paused);
+        vlc_mutex_unlock(&pool->lock);
+        return NULL;
+    }
+
     i = ffsll(pool->available);
     assert(i > 0);
     pool->available &= ~(1ULL << (i - 1));
@@ -262,6 +275,17 @@ picture_t *picture_pool_Wait(picture_pool_t *pool)
     return clone;
 }
 
+void picture_pool_ChangePause(picture_pool_t *pool, bool paused)
+{
+    vlc_mutex_lock(&pool->lock);
+    assert(pool->refs > 0);
+
+    pool->paused = paused;
+    if (pool->paused)
+        vlc_cond_signal(&pool->wait);
+    vlc_mutex_unlock(&pool->lock);
+}
+
 unsigned picture_pool_Reset(picture_pool_t *pool)
 {
     unsigned ret;
@@ -270,6 +294,7 @@ unsigned picture_pool_Reset(picture_pool_t *pool)
     assert(pool->refs > 0);
     ret = pool->picture_count - popcountll(pool->available);
     pool->available = (1ULL << pool->picture_count) - 1;
+    pool->paused = false;
     vlc_mutex_unlock(&pool->lock);
 
     return ret;
-- 
2.1.4



More information about the vlc-devel mailing list