diff mbox series

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

Message ID DU0P250MB0747AF85A955F80FF300D1C88F482@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 028907b08ad9f327cbb405cff2df2b19d0e358e5
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 QSVDeviceContext as one no longer has to
go through AVHWDeviceInternal.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/hwcontext_qsv.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index a67552b5ac..99d974f25f 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -70,6 +70,11 @@  typedef struct QSVDevicePriv {
 } QSVDevicePriv;
 
 typedef struct QSVDeviceContext {
+    /**
+     * The public AVQSVDeviceContext. See hwcontext_qsv.h for it.
+     */
+    AVQSVDeviceContext p;
+
     mfxHDL              handle;
     mfxHandleType       handle_type;
     mfxVersion          ver;
@@ -268,8 +273,8 @@  static int qsv_fill_border(AVFrame *dst, const AVFrame *src)
 
 static int qsv_device_init(AVHWDeviceContext *ctx)
 {
-    AVQSVDeviceContext *hwctx = ctx->hwctx;
-    QSVDeviceContext       *s = ctx->internal->priv;
+    QSVDeviceContext       *s = ctx->hwctx;
+    AVQSVDeviceContext *hwctx = &s->p;
     int   hw_handle_supported = 0;
     mfxHandleType handle_type;
     enum AVHWDeviceType device_type;
@@ -378,7 +383,7 @@  static int qsv_init_child_ctx(AVHWFramesContext *ctx)
 {
     AVQSVFramesContext     *hwctx = ctx->hwctx;
     QSVFramesContext           *s = ctx->internal->priv;
-    QSVDeviceContext *device_priv = ctx->device_ctx->internal->priv;
+    QSVDeviceContext *device_priv = ctx->device_ctx->hwctx;
 
     AVBufferRef *child_device_ref = NULL;
     AVBufferRef *child_frames_ref = NULL;
@@ -1108,7 +1113,8 @@  static int qsv_init_internal_session(AVHWFramesContext *ctx,
                                      mfxSession *session, int upload)
 {
     AVQSVFramesContext *frames_hwctx = ctx->hwctx;
-    QSVDeviceContext   *device_priv  = ctx->device_ctx->internal->priv;
+    QSVDeviceContext   *device_priv  = ctx->device_ctx->hwctx;
+    AVQSVDeviceContext *hwctx        = &device_priv->p;
     int opaque = 0;
 
     mfxFrameAllocator frame_allocator = {
@@ -1123,7 +1129,6 @@  static int qsv_init_internal_session(AVHWFramesContext *ctx,
     mfxVideoParam par;
     mfxStatus err;
     int                   ret = AVERROR_UNKNOWN;
-    AVQSVDeviceContext *hwctx = ctx->device_ctx->hwctx;
     /* hwctx->loader is non-NULL for oneVPL user and NULL for non-oneVPL user */
     void             **loader = &hwctx->loader;
 
@@ -2246,8 +2251,7 @@  const HWContextType ff_hwcontext_type_qsv = {
     .type                   = AV_HWDEVICE_TYPE_QSV,
     .name                   = "QSV",
 
-    .device_hwctx_size      = sizeof(AVQSVDeviceContext),
-    .device_priv_size       = sizeof(QSVDeviceContext),
+    .device_hwctx_size      = sizeof(QSVDeviceContext),
     .frames_hwctx_size      = sizeof(AVQSVFramesContext),
     .frames_priv_size       = sizeof(QSVFramesContext),