[vlc-devel] [PATCH 2/5] picture_pool: add a helper to allocate an expandable picture pool from video_format_t

Steve Lhomme robux4 at ycbcr.xyz
Wed Dec 5 09:59:03 CET 2018


And make picture_pool_NewFromFormat() use it.
---
 include/vlc_picture_pool.h | 44 ++++++++++++++++++++++++++++++++++++++
 src/misc/picture_pool.c    | 26 ++++++----------------
 2 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/include/vlc_picture_pool.h b/include/vlc_picture_pool.h
index e1ebb7191b..cea640100a 100644
--- a/include/vlc_picture_pool.h
+++ b/include/vlc_picture_pool.h
@@ -188,6 +188,50 @@ VLC_USED;
  */
 VLC_API unsigned picture_pool_GetSize(const picture_pool_t *);
 
+/**
+ * Allocates pictures from the heap and creates an expandable picture pool with
+ * them.
+ *
+ * @param fmt video format of pictures to allocate from the heap
+ * @param count number of pictures to allocate when the pool is initialized
+ * @param expand_ctx the context to pass to expand_cb
+ * @param expand_cb the callback to allocate pictures on init and expansion
+ *
+ * @return a pointer to the new pool on success, NULL on error
+ */
+static inline picture_pool_t *picture_pool_NewFromFormatEx(const video_format_t *fmt,
+                                                           unsigned count,
+                                                           void *expand_ctx,
+                                                           picture_t* (*expand_cb)(void *, const video_format_t*))
+{
+    picture_t *picture[count ? count : 1];
+    picture_pool_t *pool = NULL;
+    picture_pool_configuration_t cfg = { 0 };
+    unsigned i;
+
+    for (i = 0; i < count; i++) {
+        picture[i] = expand_cb(expand_ctx, fmt);
+        if (picture[i] == NULL)
+            goto error;
+    }
+
+    cfg.picture_count = count;
+    cfg.picture       = picture;
+    cfg.expand_ctx    = expand_ctx;
+    cfg.expand_cb     = expand_cb;
+    cfg.expand_fmt    = fmt;
+
+    pool = picture_pool_NewExtended(&cfg);
+    if (!pool)
+        goto error;
+
+    return pool;
+
+error:
+    while (i > 0)
+        picture_Release(picture[--i]);
+    return NULL;
+}
 
 #endif /* VLC_PICTURE_POOL_H */
 
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index b52e1837e6..69393e2e56 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -168,28 +168,16 @@ picture_pool_t *picture_pool_New(unsigned count, picture_t *const *tab)
     return picture_pool_NewExtended(&cfg);
 }
 
+static picture_t *DefaultPoolAlloc(void *ctx, const video_format_t *fmt)
+{
+    (void) ctx;
+    return picture_NewFromFormat(fmt);
+}
+
 picture_pool_t *picture_pool_NewFromFormat(const video_format_t *fmt,
                                            unsigned count)
 {
-    picture_t *picture[count ? count : 1];
-    unsigned i;
-
-    for (i = 0; i < count; i++) {
-        picture[i] = picture_NewFromFormat(fmt);
-        if (picture[i] == NULL)
-            goto error;
-    }
-
-    picture_pool_t *pool = picture_pool_New(count, picture);
-    if (!pool)
-        goto error;
-
-    return pool;
-
-error:
-    while (i > 0)
-        picture_Release(picture[--i]);
-    return NULL;
+    return picture_pool_NewFromFormatEx(fmt, count, NULL, DefaultPoolAlloc);
 }
 
 picture_pool_t *picture_pool_Reserve(picture_pool_t *master, unsigned count)
-- 
2.17.1



More information about the vlc-devel mailing list