[vlc-commits] picture_pool: stop meddling with picture reference counters

Rémi Denis-Courmont git at videolan.org
Sun Jun 28 11:13:33 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jun 27 16:34:00 2015 +0300| [18302141dc501da2592302399258917888e43d57] | committer: Rémi Denis-Courmont

picture_pool: stop meddling with picture reference counters

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

 src/misc/picture_pool.c |   36 ++++++++++++------------------------
 src/test/picture_pool.c |    7 ++++++-
 2 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index c544253..f893062 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -69,14 +69,8 @@ void picture_pool_Release(picture_pool_t *pool)
     if (likely(!destroy))
         return;
 
-    for (unsigned i = 0; i < pool->picture_count; i++) {
-        picture_t *picture = pool->picture[i];
-        picture_priv_t *priv = (picture_priv_t *)picture;
-
-        picture_Release(priv->gc.opaque->picture);
-        free(priv->gc.opaque);
-        free(picture);
-    }
+    for (unsigned i = 0; i < pool->picture_count; i++)
+        picture_Release(pool->picture[i]);
 
     vlc_mutex_destroy(&pool->lock);
     free(pool);
@@ -89,7 +83,7 @@ static void picture_pool_ReleasePicture(picture_t *picture)
     picture_pool_t *pool = sys->pool;
 
     if (pool->pic_unlock != NULL)
-        pool->pic_unlock(picture);
+        pool->pic_unlock(sys->picture);
 
     vlc_mutex_lock(&pool->lock);
     assert(!(pool->available & (1ULL << sys->offset)));
@@ -97,6 +91,9 @@ static void picture_pool_ReleasePicture(picture_t *picture)
     vlc_mutex_unlock(&pool->lock);
 
     picture_pool_Release(pool);
+
+    free(sys);
+    free(picture);
 }
 
 static picture_t *picture_pool_ClonePicture(picture_pool_t *pool,
@@ -147,16 +144,8 @@ picture_pool_t *picture_pool_NewExtended(const picture_pool_configuration_t *cfg
     pool->available = (1ULL << cfg->picture_count) - 1;
     pool->refs = 1;
     pool->picture_count = cfg->picture_count;
-
-    for (unsigned i = 0; i < cfg->picture_count; i++) {
-        picture_t *picture = picture_pool_ClonePicture(pool, cfg->picture[i], i);
-        if (unlikely(picture == NULL))
-            abort();
-
-        atomic_init(&((picture_priv_t *)picture)->gc.refs, 0);
-
-        pool->picture[i] = picture;
-    }
+    memcpy(pool->picture, cfg->picture,
+           cfg->picture_count * sizeof (picture_t *));
     return pool;
 
 }
@@ -224,7 +213,7 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
     assert(pool->refs > 0);
 
     for (unsigned i = 0; i < pool->picture_count; i++) {
-        picture_t *picture = pool->picture[i];
+        picture_t *picture = pool->picture[i], *clone;
 
         if (!(pool->available & (1ULL << i)))
             continue;
@@ -240,10 +229,9 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
             continue;
         }
 
-        assert(atomic_load(&((picture_priv_t *)picture)->gc.refs) == 0);
-        atomic_init(&((picture_priv_t *)picture)->gc.refs, 1);
-        picture->p_next = NULL;
-        return picture;
+        clone = picture_pool_ClonePicture(pool, picture, i);
+        assert(unlikely(clone == NULL) || clone->p_next == NULL);
+        return clone;
     }
 
     vlc_mutex_unlock(&pool->lock);
diff --git a/src/test/picture_pool.c b/src/test/picture_pool.c
index 93d70c0..2ff3d51 100644
--- a/src/test/picture_pool.c
+++ b/src/test/picture_pool.c
@@ -60,8 +60,13 @@ static void test(bool zombie)
         picture_Release(pics[i]);
 
     for (unsigned i = 0; i < PICTURES; i++) {
+        void *plane = pics[i]->p[0].p_pixels;
+        assert(plane != NULL);
         picture_Release(pics[i]);
-        assert(picture_pool_Get(pool) == pics[i]);
+
+        pics[i] = picture_pool_Get(pool);
+        assert(pics[i] != NULL);
+        assert(pics[i]->p[0].p_pixels == plane);
     }
 
     for (unsigned i = 0; i < PICTURES; i++)



More information about the vlc-commits mailing list