[vlc-commits] nvdec: move the nvdec_pool code in a separate file

Steve Lhomme git at videolan.org
Fri Sep 4 13:49:14 CEST 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Sep  4 08:59:25 2020 +0200| [3ecc34abe9575fa563ca8771f44e594df0501bbf] | committer: Steve Lhomme

nvdec: move the nvdec_pool code in a separate file

It may also be merged in the core, in vlc_picture_pool.h.

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

 modules/hw/nvdec/Makefile.am |   3 +-
 modules/hw/nvdec/hw_pool.c   | 120 +++++++++++++++++++++++++++++++++++++++++++
 modules/hw/nvdec/hw_pool.h   |  48 +++++++++++++++++
 modules/hw/nvdec/nvdec.c     | 100 +-----------------------------------
 4 files changed, 171 insertions(+), 100 deletions(-)

diff --git a/modules/hw/nvdec/Makefile.am b/modules/hw/nvdec/Makefile.am
index 74cdea9af3..eaeeb89e0a 100644
--- a/modules/hw/nvdec/Makefile.am
+++ b/modules/hw/nvdec/Makefile.am
@@ -1,7 +1,8 @@
 nvdecdir = $(pluginsdir)/nvdec
 
 libnvdec_plugin_la_SOURCES = \
-	hw/nvdec/nvdec.c hw/nvdec/nvdec_fmt.h
+	hw/nvdec/nvdec.c hw/nvdec/nvdec_fmt.h \
+	hw/nvdec/hw_pool.c hw/nvdec/hw_pool.h
 libnvdec_plugin_la_LIBADD = $(LIBDL) libvlc_hxxxhelper.la
 if HAVE_NVDEC
 codec_LTLIBRARIES += libnvdec_plugin.la
diff --git a/modules/hw/nvdec/hw_pool.c b/modules/hw/nvdec/hw_pool.c
new file mode 100644
index 0000000000..63c6f1911f
--- /dev/null
+++ b/modules/hw/nvdec/hw_pool.c
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * hw_pool.c: hw based picture pool
+ *****************************************************************************
+ * Copyright (C) 2019-2020 VLC authors and VideoLAN
+ *
+ * Authors: Jai Luthra <me at jailuthra.in>
+ *          Quentin Chateau <quentin.chateau at deepskycorp.com>
+ *          Steve Lhomme <robux4 at videolabs.io>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_picture_pool.h>
+#include <vlc_atomic.h>
+#include "hw_pool.h"
+
+struct nvdec_pool_t {
+    vlc_video_context           *vctx;
+
+    nvdec_pool_owner_t          *owner;
+
+    void                        *res[64];
+    size_t                      pool_size;
+
+    picture_pool_t              *picture_pool;
+
+    vlc_atomic_rc_t             rc;
+};
+
+void nvdec_pool_AddRef(nvdec_pool_t *pool)
+{
+    vlc_atomic_rc_inc(&pool->rc);
+}
+
+void nvdec_pool_Release(nvdec_pool_t *pool)
+{
+    if (!vlc_atomic_rc_dec(&pool->rc))
+        return;
+
+    pool->owner->release_resources(pool->owner, pool->res, pool->pool_size);
+
+    picture_pool_Release(pool->picture_pool);
+    vlc_video_context_Release(pool->vctx);
+}
+
+nvdec_pool_t* nvdec_pool_Create(nvdec_pool_owner_t *owner,
+                                const video_format_t *fmt, vlc_video_context *vctx,
+                                void *buffers[], size_t pics_count)
+{
+    nvdec_pool_t *pool = calloc(1, sizeof(*pool));
+    if (unlikely(!pool))
+        return NULL;
+
+    picture_t *pics[pics_count];
+    for (size_t i=0; i < pics_count; i++)
+    {
+        pics[i] = picture_NewFromResource(fmt, &(picture_resource_t){ 0 });
+        if (!pics[i])
+        {
+            while (i--)
+                picture_Release(pics[i]);
+            goto error;
+        }
+        pool->res[i] = buffers[i];
+        pics[i]->p_sys = buffers[i];
+    }
+
+    pool->picture_pool = picture_pool_New(pics_count, pics);
+    if (!pool->picture_pool)
+        goto free_pool;
+
+    pool->owner = owner;
+    pool->vctx = vctx;
+    pool->pool_size = pics_count;
+    vlc_video_context_Hold(pool->vctx);
+
+    vlc_atomic_rc_init(&pool->rc);
+    return pool;
+
+free_pool:
+    for (size_t i=0; i < pics_count; i++)
+    {
+        if (pics[i] != NULL)
+            picture_Release(pics[i]);
+    }
+error:
+    free(pool);
+    return NULL;
+}
+
+picture_t* nvdec_pool_Wait(nvdec_pool_t *pool)
+{
+    picture_t *pic = picture_pool_Wait(pool->picture_pool);
+    if (!pic)
+        return NULL;
+
+    void *surface = pic->p_sys;
+    pic->p_sys = NULL;
+    pic->context = pool->owner->attach_picture(pool->owner, pool, surface);
+    if (likely(pic->context != NULL))
+        return pic;
+
+    picture_Release(pic);
+    return NULL;
+}
diff --git a/modules/hw/nvdec/hw_pool.h b/modules/hw/nvdec/hw_pool.h
new file mode 100644
index 0000000000..59362116b3
--- /dev/null
+++ b/modules/hw/nvdec/hw_pool.h
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * hw_pool.h: hw based picture pool
+ *****************************************************************************
+ * Copyright (C) 2019-2020 VLC authors and VideoLAN
+ *
+ * Authors: Jai Luthra <me at jailuthra.in>
+ *          Quentin Chateau <quentin.chateau at deepskycorp.com>
+ *          Steve Lhomme <robux4 at videolabs.io>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#include <vlc_picture.h>
+#include <vlc_codec.h>
+
+typedef struct nvdec_pool_t  nvdec_pool_t;
+typedef struct nvdec_pool_owner  nvdec_pool_owner_t;
+
+struct nvdec_pool_owner
+{
+    void *sys;
+    void (*release_resources)(nvdec_pool_owner_t *, void *buffers[], size_t pics_count);
+    picture_context_t * (*attach_picture)(nvdec_pool_owner_t *, nvdec_pool_t *, void *surface);
+};
+
+nvdec_pool_t* nvdec_pool_Create(nvdec_pool_owner_t *,
+                                const video_format_t *, vlc_video_context *,
+                                void *buffers[], size_t pics_count);
+void nvdec_pool_AddRef(nvdec_pool_t *);
+void nvdec_pool_Release(nvdec_pool_t *);
+
+/**
+ * Wait for a new picture to be available from the pool.
+ *
+ * The picture.p_sys is always NULL.
+ */
+picture_t* nvdec_pool_Wait(nvdec_pool_t *);
diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
index 658a7e0099..3ab19f7146 100644
--- a/modules/hw/nvdec/nvdec.c
+++ b/modules/hw/nvdec/nvdec.c
@@ -37,6 +37,7 @@
 #include <ffnvcodec/dynlink_loader.h>
 #include "../../codec/hxxx_helper.h"
 #include "nvdec_fmt.h"
+#include "hw_pool.h"
 
 static int OpenDecoder(vlc_object_t *);
 static void CloseDecoder(vlc_object_t *);
@@ -79,27 +80,6 @@ vlc_module_end ()
 #define OUTPUT_WIDTH_ALIGN   16
 
 typedef struct nvdec_ctx  nvdec_ctx_t;
-typedef struct nvdec_pool_owner  nvdec_pool_owner_t;
-
-typedef struct nvdec_pool_t {
-    vlc_video_context           *vctx;
-
-    nvdec_pool_owner_t          *owner;
-
-    void                        *res[64];
-    size_t                      pool_size;
-
-    picture_pool_t              *picture_pool;
-
-    vlc_atomic_rc_t             rc;
-} nvdec_pool_t;
-
-struct nvdec_pool_owner
-{
-    void *sys;
-    void (*release_resources)(nvdec_pool_owner_t *, void *buffers[], size_t pics_count);
-    picture_context_t * (*attach_picture)(nvdec_pool_owner_t *, nvdec_pool_t *, void *surface);
-};
 
 typedef struct pic_pool_context_nvdec_t {
   pic_context_nvdec_t ctx;
@@ -148,68 +128,6 @@ static void PoolRelease(nvdec_pool_owner_t *owner, void *buffers[], size_t pics_
     free(p_sys);
 }
 
-static void nvdec_pool_AddRef(nvdec_pool_t *pool)
-{
-    vlc_atomic_rc_inc(&pool->rc);
-}
-
-static void nvdec_pool_Release(nvdec_pool_t *pool)
-{
-    if (!vlc_atomic_rc_dec(&pool->rc))
-        return;
-
-    pool->owner->release_resources(pool->owner, pool->res, pool->pool_size);
-
-    picture_pool_Release(pool->picture_pool);
-    vlc_video_context_Release(pool->vctx);
-}
-
-static nvdec_pool_t* nvdec_pool_Create(nvdec_pool_owner_t *owner,
-                                       const video_format_t *fmt,
-                                       vlc_video_context *vctx,
-                                       void *buffers[], size_t pics_count)
-{
-    nvdec_pool_t *pool = calloc(1, sizeof(*pool));
-    if (unlikely(!pool))
-        return NULL;
-
-    picture_t *pics[pics_count];
-    for (size_t i=0; i < pics_count; i++)
-    {
-        pics[i] = picture_NewFromResource(fmt, &(picture_resource_t) { 0 });
-        if (!pics[i])
-        {
-            while (i--)
-                picture_Release(pics[i]);
-            goto error;
-        }
-        pool->res[i] = buffers[i];
-        pics[i]->p_sys = buffers[i];
-    }
-
-    pool->picture_pool = picture_pool_New(pics_count, pics);
-    if (!pool->picture_pool)
-        goto free_pool;
-
-    pool->owner = owner;
-    pool->vctx = vctx;
-    pool->pool_size = pics_count;
-    vlc_video_context_Hold(pool->vctx);
-
-    vlc_atomic_rc_init(&pool->rc);
-    return pool;
-
-free_pool:
-    for (size_t i=0; i < pics_count; i++)
-    {
-        if (pics[i] != NULL)
-            picture_Release(pics[i]);
-    }
-error:
-    free(pool);
-    return NULL;
-}
-
 static void nvdec_picture_CtxDestroy(struct picture_context_t *picctx)
 {
     pic_pool_context_nvdec_t *srcpic = NVDEC_PICPOOLCTX_FROM_PICCTX(picctx);
@@ -230,22 +148,6 @@ static struct picture_context_t *nvdec_picture_CtxClone(struct picture_context_t
     return &clonectx->ctx.ctx;
 }
 
-static picture_t* nvdec_pool_Wait(nvdec_pool_t *pool)
-{
-    picture_t *pic = picture_pool_Wait(pool->picture_pool);
-    if (!pic)
-        return NULL;
-
-    void *surface = pic->p_sys;
-    pic->p_sys = NULL;
-    pic->context = pool->owner->attach_picture(pool->owner, pool, surface);
-    if (likely(pic->context != NULL))
-        return pic;
-
-    picture_Release(pic);
-    return NULL;
-}
-
 static picture_context_t * PoolAttachPicture(nvdec_pool_owner_t *owner, nvdec_pool_t *pool, void *surface)
 {
     nvdec_ctx_t *p_sys = container_of(owner, nvdec_ctx_t, pool_owner);



More information about the vlc-commits mailing list