1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avutil/hwcontext_vdpau: 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 VDPAUDeviceContext as one no longer has to
go through AVHWDeviceInternal.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-02-11 16:50:56 +01:00
parent e2e2ee7711
commit f4df14b354

View File

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