diff mbox series

[FFmpeg-devel,06/23] avutil/hwcontext_vdpau: Allocate public and priv device hwctx together

Message ID DU0P250MB0747C46C3D1CA16C67993BE58F482@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit f4df14b3545d9214a429cb14488550ca63f55aed
Headers show
Series [FFmpeg-devel,01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 12, 2024, 12:03 a.m. UTC
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VDPAUDeviceContext as one no longer has to
go through AVHWDeviceInternal.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/hwcontext_vdpau.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_vdpau.c b/libavutil/hwcontext_vdpau.c
index 5b78e95529..016300db1e 100644
--- a/libavutil/hwcontext_vdpau.c
+++ b/libavutil/hwcontext_vdpau.c
@@ -83,6 +83,11 @@  static const struct {
 };
 
 typedef struct VDPAUDeviceContext {
+    /**
+     * The public AVVDPAUDeviceContext. See hwcontext_vdpau.h for it.
+     */
+    AVVDPAUDeviceContext p;
+
     VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities *get_transfer_caps;
     VdpVideoSurfaceGetBitsYCbCr                     *get_data;
     VdpVideoSurfacePutBitsYCbCr                     *put_data;
@@ -115,8 +120,8 @@  static int count_pixfmts(const VDPAUPixFmtMap *map)
 
 static int vdpau_init_pixmfts(AVHWDeviceContext *ctx)
 {
-    AVVDPAUDeviceContext *hwctx = ctx->hwctx;
-    VDPAUDeviceContext    *priv = ctx->internal->priv;
+    VDPAUDeviceContext    *priv = ctx->hwctx;
+    AVVDPAUDeviceContext *hwctx = &priv->p;
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(priv->pix_fmts); i++) {
@@ -157,8 +162,8 @@  do {
 
 static int vdpau_device_init(AVHWDeviceContext *ctx)
 {
-    AVVDPAUDeviceContext *hwctx = ctx->hwctx;
-    VDPAUDeviceContext   *priv  = ctx->internal->priv;
+    VDPAUDeviceContext    *priv = ctx->hwctx;
+    AVVDPAUDeviceContext *hwctx = &priv->p;
     VdpStatus             err;
     int                   ret;
 
@@ -180,7 +185,7 @@  static int vdpau_device_init(AVHWDeviceContext *ctx)
 
 static void vdpau_device_uninit(AVHWDeviceContext *ctx)
 {
-    VDPAUDeviceContext *priv = ctx->internal->priv;
+    VDPAUDeviceContext *priv = ctx->hwctx;
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(priv->pix_fmts); i++)
@@ -191,7 +196,7 @@  static int vdpau_frames_get_constraints(AVHWDeviceContext *ctx,
                                         const void *hwconfig,
                                         AVHWFramesConstraints *constraints)
 {
-    VDPAUDeviceContext   *priv  = ctx->internal->priv;
+    VDPAUDeviceContext *priv  = ctx->hwctx;
     int nb_sw_formats = 0;
     int i;
 
@@ -219,7 +224,7 @@  static int vdpau_frames_get_constraints(AVHWDeviceContext *ctx,
 static void vdpau_buffer_free(void *opaque, uint8_t *data)
 {
     AVHWFramesContext          *ctx = opaque;
-    VDPAUDeviceContext *device_priv = ctx->device_ctx->internal->priv;
+    VDPAUDeviceContext *device_priv = ctx->device_ctx->hwctx;
     VdpVideoSurface            surf = (VdpVideoSurface)(uintptr_t)data;
 
     device_priv->surf_destroy(surf);
@@ -229,8 +234,8 @@  static AVBufferRef *vdpau_pool_alloc(void *opaque, size_t size)
 {
     AVHWFramesContext             *ctx = opaque;
     VDPAUFramesContext           *priv = ctx->internal->priv;
-    AVVDPAUDeviceContext *device_hwctx = ctx->device_ctx->hwctx;
-    VDPAUDeviceContext    *device_priv = ctx->device_ctx->internal->priv;
+    VDPAUDeviceContext    *device_priv = ctx->device_ctx->hwctx;
+    AVVDPAUDeviceContext *device_hwctx = &device_priv->p;
 
     AVBufferRef *ret;
     VdpVideoSurface surf;
@@ -255,7 +260,7 @@  static AVBufferRef *vdpau_pool_alloc(void *opaque, size_t size)
 
 static int vdpau_frames_init(AVHWFramesContext *ctx)
 {
-    VDPAUDeviceContext *device_priv = ctx->device_ctx->internal->priv;
+    VDPAUDeviceContext *device_priv = ctx->device_ctx->hwctx;
     VDPAUFramesContext        *priv = ctx->internal->priv;
 
     int i;
@@ -508,8 +513,7 @@  const HWContextType ff_hwcontext_type_vdpau = {
     .type                 = AV_HWDEVICE_TYPE_VDPAU,
     .name                 = "VDPAU",
 
-    .device_hwctx_size    = sizeof(AVVDPAUDeviceContext),
-    .device_priv_size     = sizeof(VDPAUDeviceContext),
+    .device_hwctx_size    = sizeof(VDPAUDeviceContext),
     .frames_priv_size     = sizeof(VDPAUFramesContext),
 
 #if HAVE_VDPAU_X11