diff mbox series

[FFmpeg-devel,16/23] avutil/hwcontext_dxva2: Allocate pub and priv frames hwctx together

Message ID DU0P250MB0747A47D0A6AAEA22A524BA18F482@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM
State New
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 fail Make fate failed
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed

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 DXVA2FramesContext as one no longer has to
go through AVHWFramesInternal.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/hwcontext_dxva2.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_dxva2.c b/libavutil/hwcontext_dxva2.c
index 2c11f151ff..0922776342 100644
--- a/libavutil/hwcontext_dxva2.c
+++ b/libavutil/hwcontext_dxva2.c
@@ -57,6 +57,11 @@  typedef struct DXVA2Mapping {
 } DXVA2Mapping;
 
 typedef struct DXVA2FramesContext {
+    /**
+     * The public AVDXVA2FramesContext. See hwcontext_dxva2.h for it.
+     */
+    AVDXVA2FramesContext p;
+
     IDirect3DSurface9 **surfaces_internal;
     int              nb_surfaces_used;
 
@@ -99,8 +104,8 @@  DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x0
 static void dxva2_frames_uninit(AVHWFramesContext *ctx)
 {
     AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
-    AVDXVA2FramesContext *frames_hwctx = ctx->hwctx;
-    DXVA2FramesContext *s = ctx->internal->priv;
+    DXVA2FramesContext              *s = ctx->hwctx;
+    AVDXVA2FramesContext *frames_hwctx = &s->p;
     int i;
 
     if (frames_hwctx->decoder_to_release)
@@ -135,8 +140,8 @@  static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
 static AVBufferRef *dxva2_pool_alloc(void *opaque, size_t size)
 {
     AVHWFramesContext      *ctx = (AVHWFramesContext*)opaque;
-    DXVA2FramesContext       *s = ctx->internal->priv;
-    AVDXVA2FramesContext *hwctx = ctx->hwctx;
+    DXVA2FramesContext       *s = ctx->hwctx;
+    AVDXVA2FramesContext *hwctx = &s->p;
 
     if (s->nb_surfaces_used < hwctx->nb_surfaces) {
         s->nb_surfaces_used++;
@@ -149,9 +154,9 @@  static AVBufferRef *dxva2_pool_alloc(void *opaque, size_t size)
 
 static int dxva2_init_pool(AVHWFramesContext *ctx)
 {
-    AVDXVA2FramesContext *frames_hwctx = ctx->hwctx;
     AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
-    DXVA2FramesContext              *s = ctx->internal->priv;
+    DXVA2FramesContext              *s = ctx->hwctx;
+    AVDXVA2FramesContext *frames_hwctx = &s->p;
     int decode = (frames_hwctx->surface_type == DXVA2_VideoDecoderRenderTarget);
 
     int i;
@@ -216,8 +221,8 @@  static int dxva2_init_pool(AVHWFramesContext *ctx)
 
 static int dxva2_frames_init(AVHWFramesContext *ctx)
 {
-    AVDXVA2FramesContext *hwctx = ctx->hwctx;
-    DXVA2FramesContext       *s = ctx->internal->priv;
+    DXVA2FramesContext       *s = ctx->hwctx;
+    AVDXVA2FramesContext *hwctx = &s->p;
     int ret;
 
     if (hwctx->surface_type != DXVA2_VideoDecoderRenderTarget &&
@@ -586,8 +591,7 @@  const HWContextType ff_hwcontext_type_dxva2 = {
     .name                 = "DXVA2",
 
     .device_hwctx_size    = sizeof(AVDXVA2DeviceContext),
-    .frames_hwctx_size    = sizeof(AVDXVA2FramesContext),
-    .frames_priv_size     = sizeof(DXVA2FramesContext),
+    .frames_hwctx_size    = sizeof(DXVA2FramesContext),
 
     .device_create        = dxva2_device_create,
     .frames_init          = dxva2_frames_init,