avutil/hwcontext_qsv: Allocate public and priv device hwctx together

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>
release/7.0
Andreas Rheinhardt 9 months ago
parent 32fd27df2f
commit 028907b08a
  1. 18
      libavutil/hwcontext_qsv.c

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

Loading…
Cancel
Save