From patchwork Mon Feb 12 00:03:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 46213 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9002:b0:19e:cdac:8cce with SMTP id d2csp403136pzc; Sun, 11 Feb 2024 16:04:55 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV4SAR66d8D9UYudD01DMyh/qlQ2JVf1JU5aX/MHwvnqhscaWJMeQ5oG7XBqaujAJKpCM9RkDn3piHMgOoOAaMvCDK5q/vDDajW5g== X-Google-Smtp-Source: AGHT+IGEt08z/aegaWf3BvG52/bRlGyb36yUiDyI0ZUmvhsapp20LOib+3C/lPdkLPFZKseBjMvK X-Received: by 2002:a05:6402:5d90:b0:561:9f62:8dad with SMTP id if16-20020a0564025d9000b005619f628dadmr1327366edb.18.1707696295025; Sun, 11 Feb 2024 16:04:55 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVyIARZgjaNmRfrmA7R5Sau8MfRJCHLe2D3wZ2Kl0fnSqJHrw27cYLR1uB7/hHrtyNCfawA0qFahrb3aHCxKhZgnZ2HRvMcuiDXSGwSkOhi4QXGK1o2jz/7F6WUGAOUgqKpkcymp2iiEuKkW0uOMIQwGRveWVF54dOEXhcAwfooWtazZhvFEsfR+TSAZOD+wc8RTAjX80+Q/8myDSXLHWvaaJpyumcRLTLHnYlh2aypoDMQYWLJDMWy87BoLkrz/rs49fV0jTaU48/VaXoBhyd67xHbL5+GUAFCj79NJajInywjheYeiZhRlZ1xwipgxaY1oJR/bA8wfLjx8IZjX0Kb/sV85ZDe49mvRzdjXHB4Es6IFmNEqPmOSAQZflvrsJv/EHmiITwYseYJBm87Jp9ZYjInpdH8hkq2+meq5r7HvqGSN+J02+p3KUXFwvKZyrDEukTCfzQ7TO3MVvn/03GUvZeHMN/YUdtCo7xSNZZFmcA3wmA/qa+UXdRlWsMm9G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CYiP/Uj+/c3LPLsfRerWOkbw5Vua4= Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e24-20020a50d4d8000000b0056001f8ca6dsi2190791edj.483.2024.02.11.16.04.54; Sun, 11 Feb 2024 16:04:55 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=VreIRljJ; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9001768D135; Mon, 12 Feb 2024 02:03:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02olkn2037.outbound.protection.outlook.com [40.92.48.37]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3A87068D206 for ; Mon, 12 Feb 2024 02:03:14 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LhdNRQFaiJ1tR+pE5u5/jkSv/d2QyGY+riEpgxdXsmp0wwBaP3N1MT+8hFtEuKVGxS4jlkOPduQqDZes6LHY2e0XcGKTDkWC19NUcnN0gRx7sQ43+7czC32XgBxdpl9AnCwzu+5tmc789c/Aj763jMCYXWhgp0+9wwoaroQ2gUALbsWBJD4tGUzCzpo8WmaplfCimXE/sTfV9Ui+NnASUD/v72EUd/LuAJSJSkLqIs6UjdVjKywUu0pT1ulGx1KvU3haXpglB4Zt9g+sp0zgJdiephMoewh1LICXWrecVrrZatSmBNhtLKkgLmocfrad+DRdQpWOSkg5+XikLTRUfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PtZGCpmuYVEr8vaqgAlrXQ3UYwZecVzoAf/Z8RA8riQ=; b=kCzj0gdwd8p95cqRQLXv7+wM0aslw1t0tSZE8WBK+ZP30qxt3l1r/YT8MMJ7aDtseYBU9D+uXQ04b1e9g3y6jVVkMMrH78Y9eWheoVVvsp+om6Ly+rQd2fw+j0eYzS6LlcBYrv9w3pWoXKYzkqrkyfvX1g2kqApmW9+dGaj/4GcwnN6FSPvzL6FyMF4Qkh3CH+ITro0BQosvxpGks675A4iGDf/+rlDhuXMR2fO+qiC8QPow+1gNXOlsPA0hEKOvmqFawfbfjYizZF+3uy1Z2yISOHiKA2lTTON7bhDIhWGn9w5pT2QkFoLbLW2aLvdgPHS7V2YdJPGPTwbHE0HqPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PtZGCpmuYVEr8vaqgAlrXQ3UYwZecVzoAf/Z8RA8riQ=; b=VreIRljJnHZ7lYLcATDj7TSH3tME0QsgDgLqz6yY0EeWxWGuYcdpjBBCmM8lCPo9Nwxl7n0wPUtWK3teZQshjlvX1GJT2aeTMq4Jbk5B2vlr6YG7cZhiQ249QJh0stRWRUd87ivDJbI9MWJJZKH3qyWbkBSpxCDYw0C/jDECatOaVdKsSOjAgdFnneP17E94QIyXvrmfzkbQeVVG+ocT9g+s92+rGu4J3+RuZoWUhzjCR2i6i9MydpWLh0Mz4ph0ggdePm3eIqeSZjtkFzacdhAl10FPhwteGGRo5rhYfUhVnq85rgZr1H8DV3E1HChPg1X5qlB4rvGrePXXPU/R0g== Received: from DU0P250MB0747.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:3cb::16) by AS8P250MB0072.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:374::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.33; Mon, 12 Feb 2024 00:03:13 +0000 Received: from DU0P250MB0747.EURP250.PROD.OUTLOOK.COM ([fe80::db07:87f6:7c75:38cc]) by DU0P250MB0747.EURP250.PROD.OUTLOOK.COM ([fe80::db07:87f6:7c75:38cc%3]) with mapi id 15.20.7270.036; Mon, 12 Feb 2024 00:03:12 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Feb 2024 01:03:35 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [wcDlR91VaUrX5UurVfzZqySmEbeYVKef] X-ClientProxiedBy: FR3P281CA0146.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:95::18) To DU0P250MB0747.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:3cb::16) X-Microsoft-Original-Message-ID: <20240212000335.27984-22-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0P250MB0747:EE_|AS8P250MB0072:EE_ X-MS-Office365-Filtering-Correlation-Id: c4cf74d0-dbb3-4ed8-5428-08dc2b5e00b1 X-MS-Exchange-SLBlob-MailProps: YfhX3sd/0TUSvyb7a5WmOzXakAQ9VWBaq6RCic1ZT+Xgu7pr9Hda4E7yW9zCXrKE+7DoqddqPMbMykPMyuZ2rsXr8HpYVv207sdBJIEM2ekZt10zbg1qru7xtDAgb1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ESy4+ZQCGD49QVIYpZ7ppPHZXBNK93c8bwqrNzYDvWi55CIQ9M0t6ZmXk5yKlZ9m1uYR/iwThfZ+EerNIUoXMtsbJWEI+pNIgax2J9WCNjBlR6EcMgLIhAb6NSz0M619mjGqiV60+cTED7O56R3f0X4NhI13dPdgFYlLB7Zoy7tvqUGfJc0RH6B+uOFmgo+tTs1FY6htlkhod7NcjZMPMJlk7mqP3Y33DdzHZDenK0FYgb5jlsG6d6s5PzZFv/+JHQEO0m9A7Vp0hRINH75noSgFxLh8pcrW5GMAMLrpgz4Lr5ce/HLnHix6NVAKBBBrdo+uJ0qaG7w6xonepzo9oKXtAwtklTVEKSCgywWIyyw5V9dMuU7JtM61oA0iSI8DeTFWpEzNv4RDOwKDyANEMyshWmulx6FOcguy6mDkpRAqwd4FCeXJJtsjvVbs4wdsE35aneFRt/QKY4+vd7Dx644cf6q1TER8KcBS8MN/IRm4PoxhQEDasLxAYDLF7dPlcWWbQIFo6R7w0TJ6uQZin/PWGCL/dplpvu5BlYzUJxj6MbfshoEtLIN9XQtTweUpZBnwvtA9NyhTZeBhvajIQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c4cf74d0-dbb3-4ed8-5428-08dc2b5e00b1 X-MS-Exchange-CrossTenant-AuthSource: DU0P250MB0747.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2024 00:03:12.0968 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P250MB0072 Subject: [FFmpeg-devel] [PATCH 23/23] avutil/hwcontext: Allocate AVHWFramesCtx jointly with its internals X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: p6DrnhHxVOyn This is possible because the lifetime of these structures coincide. It has the advantage of allowing to remove AVHWFramesInternal from the public header; given that AVHWFramesInternal.priv is no more, most accesses to AVHWFramesInternal are no more; indeed, the only field accessed of it outside of hwcontext.c is the internal frame pool, making this commit very simple. Signed-off-by: Andreas Rheinhardt --- libavutil/hwcontext.c | 158 ++++++++++++++--------------- libavutil/hwcontext.h | 8 -- libavutil/hwcontext_cuda.c | 5 +- libavutil/hwcontext_d3d11va.c | 7 +- libavutil/hwcontext_d3d12va.c | 4 +- libavutil/hwcontext_dxva2.c | 7 +- libavutil/hwcontext_internal.h | 14 ++- libavutil/hwcontext_opencl.c | 4 +- libavutil/hwcontext_qsv.c | 6 +- libavutil/hwcontext_vaapi.c | 6 +- libavutil/hwcontext_vdpau.c | 7 +- libavutil/hwcontext_videotoolbox.c | 4 +- libavutil/hwcontext_vulkan.c | 8 +- 13 files changed, 121 insertions(+), 117 deletions(-) diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index 8ecefd2bc4..a0192f4fa9 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -232,23 +232,23 @@ static const AVClass hwframe_ctx_class = { static void hwframe_ctx_free(void *opaque, uint8_t *data) { - AVHWFramesContext *ctx = (AVHWFramesContext*)data; + FFHWFramesContext *ctxi = (FFHWFramesContext*)data; + AVHWFramesContext *ctx = &ctxi->p; - if (ctx->internal->pool_internal) - av_buffer_pool_uninit(&ctx->internal->pool_internal); + if (ctxi->pool_internal) + av_buffer_pool_uninit(&ctxi->pool_internal); - if (ctx->internal->hw_type->frames_uninit) - ctx->internal->hw_type->frames_uninit(ctx); + if (ctxi->hw_type->frames_uninit) + ctxi->hw_type->frames_uninit(ctx); if (ctx->free) ctx->free(ctx); - av_buffer_unref(&ctx->internal->source_frames); + av_buffer_unref(&ctxi->source_frames); av_buffer_unref(&ctx->device_ref); av_freep(&ctx->hwctx); - av_freep(&ctx->internal); av_freep(&ctx); } @@ -256,16 +256,14 @@ AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in) { FFHWDeviceContext *device_ctx = (FFHWDeviceContext*)device_ref_in->data; const HWContextType *hw_type = device_ctx->hw_type; + FFHWFramesContext *ctxi; AVHWFramesContext *ctx; AVBufferRef *buf, *device_ref = NULL; - ctx = av_mallocz(sizeof(*ctx)); - if (!ctx) + ctxi = av_mallocz(sizeof(*ctxi)); + if (!ctxi) return NULL; - - ctx->internal = av_mallocz(sizeof(*ctx->internal)); - if (!ctx->internal) - goto fail; + ctx = &ctxi->p; if (hw_type->frames_hwctx_size) { ctx->hwctx = av_mallocz(hw_type->frames_hwctx_size); @@ -289,13 +287,12 @@ AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in) ctx->format = AV_PIX_FMT_NONE; ctx->sw_format = AV_PIX_FMT_NONE; - ctx->internal->hw_type = hw_type; + ctxi->hw_type = hw_type; return buf; fail: av_buffer_unref(&device_ref); - av_freep(&ctx->internal); av_freep(&ctx->hwctx); av_freep(&ctx); return NULL; @@ -331,24 +328,25 @@ fail: int av_hwframe_ctx_init(AVBufferRef *ref) { - AVHWFramesContext *ctx = (AVHWFramesContext*)ref->data; + FFHWFramesContext *ctxi = (FFHWFramesContext*)ref->data; + AVHWFramesContext *ctx = &ctxi->p; const enum AVPixelFormat *pix_fmt; int ret; - if (ctx->internal->source_frames) { + if (ctxi->source_frames) { /* A derived frame context is already initialised. */ return 0; } /* validate the pixel format */ - for (pix_fmt = ctx->internal->hw_type->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++) { + for (pix_fmt = ctxi->hw_type->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++) { if (*pix_fmt == ctx->format) break; } if (*pix_fmt == AV_PIX_FMT_NONE) { av_log(ctx, AV_LOG_ERROR, "The hardware pixel format '%s' is not supported by the device type '%s'\n", - av_get_pix_fmt_name(ctx->format), ctx->internal->hw_type->name); + av_get_pix_fmt_name(ctx->format), ctxi->hw_type->name); return AVERROR(ENOSYS); } @@ -358,14 +356,14 @@ int av_hwframe_ctx_init(AVBufferRef *ref) return ret; /* format-specific init */ - if (ctx->internal->hw_type->frames_init) { - ret = ctx->internal->hw_type->frames_init(ctx); + if (ctxi->hw_type->frames_init) { + ret = ctxi->hw_type->frames_init(ctx); if (ret < 0) goto fail; } - if (ctx->internal->pool_internal && !ctx->pool) - ctx->pool = ctx->internal->pool_internal; + if (ctxi->pool_internal && !ctx->pool) + ctx->pool = ctxi->pool_internal; /* preallocate the frames in the pool, if requested */ if (ctx->initial_pool_size > 0) { @@ -376,8 +374,8 @@ int av_hwframe_ctx_init(AVBufferRef *ref) return 0; fail: - if (ctx->internal->hw_type->frames_uninit) - ctx->internal->hw_type->frames_uninit(ctx); + if (ctxi->hw_type->frames_uninit) + ctxi->hw_type->frames_uninit(ctx); return ret; } @@ -385,12 +383,12 @@ int av_hwframe_transfer_get_formats(AVBufferRef *hwframe_ref, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats, int flags) { - AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data; + FFHWFramesContext *ctxi = (FFHWFramesContext*)hwframe_ref->data; - if (!ctx->internal->hw_type->transfer_get_formats) + if (!ctxi->hw_type->transfer_get_formats) return AVERROR(ENOSYS); - return ctx->internal->hw_type->transfer_get_formats(ctx, dir, formats); + return ctxi->hw_type->transfer_get_formats(&ctxi->p, dir, formats); } static int transfer_data_alloc(AVFrame *dst, const AVFrame *src, int flags) @@ -445,7 +443,6 @@ fail: int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags) { - AVHWFramesContext *ctx; int ret; if (!dst->buf[0]) @@ -458,41 +455,41 @@ int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags) * the specific combination of hardware. */ if (src->hw_frames_ctx && dst->hw_frames_ctx) { - AVHWFramesContext *src_ctx = - (AVHWFramesContext*)src->hw_frames_ctx->data; - AVHWFramesContext *dst_ctx = - (AVHWFramesContext*)dst->hw_frames_ctx->data; + FFHWFramesContext *src_ctx = + (FFHWFramesContext*)src->hw_frames_ctx->data; + FFHWFramesContext *dst_ctx = + (FFHWFramesContext*)dst->hw_frames_ctx->data; - if (src_ctx->internal->source_frames) { + if (src_ctx->source_frames) { av_log(src_ctx, AV_LOG_ERROR, "A device with a derived frame context cannot be used as " "the source of a HW -> HW transfer."); return AVERROR(ENOSYS); } - if (dst_ctx->internal->source_frames) { + if (dst_ctx->source_frames) { av_log(src_ctx, AV_LOG_ERROR, "A device with a derived frame context cannot be used as " "the destination of a HW -> HW transfer."); return AVERROR(ENOSYS); } - ret = src_ctx->internal->hw_type->transfer_data_from(src_ctx, dst, src); + ret = src_ctx->hw_type->transfer_data_from(&src_ctx->p, dst, src); if (ret == AVERROR(ENOSYS)) - ret = dst_ctx->internal->hw_type->transfer_data_to(dst_ctx, dst, src); + ret = dst_ctx->hw_type->transfer_data_to(&dst_ctx->p, dst, src); if (ret < 0) return ret; } else { if (src->hw_frames_ctx) { - ctx = (AVHWFramesContext*)src->hw_frames_ctx->data; + FFHWFramesContext *ctx = (FFHWFramesContext*)src->hw_frames_ctx->data; - ret = ctx->internal->hw_type->transfer_data_from(ctx, dst, src); + ret = ctx->hw_type->transfer_data_from(&ctx->p, dst, src); if (ret < 0) return ret; } else if (dst->hw_frames_ctx) { - ctx = (AVHWFramesContext*)dst->hw_frames_ctx->data; + FFHWFramesContext *ctx = (FFHWFramesContext*)dst->hw_frames_ctx->data; - ret = ctx->internal->hw_type->transfer_data_to(ctx, dst, src); + ret = ctx->hw_type->transfer_data_to(&ctx->p, dst, src); if (ret < 0) return ret; } else { @@ -504,10 +501,11 @@ int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags) int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) { - AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data; + FFHWFramesContext *ctxi = (FFHWFramesContext*)hwframe_ref->data; + AVHWFramesContext *ctx = &ctxi->p; int ret; - if (ctx->internal->source_frames) { + if (ctxi->source_frames) { // This is a derived frame context, so we allocate in the source // and map the frame immediately. AVFrame *src_frame; @@ -521,7 +519,7 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) if (!src_frame) return AVERROR(ENOMEM); - ret = av_hwframe_get_buffer(ctx->internal->source_frames, + ret = av_hwframe_get_buffer(ctxi->source_frames, src_frame, 0); if (ret < 0) { av_frame_free(&src_frame); @@ -529,7 +527,7 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) } ret = av_hwframe_map(frame, src_frame, - ctx->internal->source_allocation_map_flags); + ctxi->source_allocation_map_flags); if (ret) { av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived " "frame context: %d.\n", ret); @@ -544,7 +542,7 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) return 0; } - if (!ctx->internal->hw_type->frames_get_buffer) + if (!ctxi->hw_type->frames_get_buffer) return AVERROR(ENOSYS); if (!ctx->pool) @@ -554,7 +552,7 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) if (!frame->hw_frames_ctx) return AVERROR(ENOMEM); - ret = ctx->internal->hw_type->frames_get_buffer(ctx, frame); + ret = ctxi->hw_type->frames_get_buffer(ctx, frame); if (ret < 0) { av_buffer_unref(&frame->hw_frames_ctx); return ret; @@ -792,19 +790,18 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags) { AVBufferRef *orig_dst_frames = dst->hw_frames_ctx; enum AVPixelFormat orig_dst_fmt = dst->format; - AVHWFramesContext *src_frames, *dst_frames; HWMapDescriptor *hwmap; int ret; if (src->hw_frames_ctx && dst->hw_frames_ctx) { - src_frames = (AVHWFramesContext*)src->hw_frames_ctx->data; - dst_frames = (AVHWFramesContext*)dst->hw_frames_ctx->data; + FFHWFramesContext *src_frames = (FFHWFramesContext*)src->hw_frames_ctx->data; + FFHWFramesContext *dst_frames = (FFHWFramesContext*)dst->hw_frames_ctx->data; if ((src_frames == dst_frames && - src->format == dst_frames->sw_format && - dst->format == dst_frames->format) || - (src_frames->internal->source_frames && - src_frames->internal->source_frames->data == + src->format == dst_frames->p.sw_format && + dst->format == dst_frames->p.format) || + (src_frames->source_frames && + src_frames->source_frames->data == (uint8_t*)dst_frames)) { // This is an unmap operation. We don't need to directly // do anything here other than fill in the original frame, @@ -821,12 +818,12 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags) } if (src->hw_frames_ctx) { - src_frames = (AVHWFramesContext*)src->hw_frames_ctx->data; + FFHWFramesContext *src_frames = (FFHWFramesContext*)src->hw_frames_ctx->data; - if (src_frames->format == src->format && - src_frames->internal->hw_type->map_from) { - ret = src_frames->internal->hw_type->map_from(src_frames, - dst, src, flags); + if (src_frames->p.format == src->format && + src_frames->hw_type->map_from) { + ret = src_frames->hw_type->map_from(&src_frames->p, + dst, src, flags); if (ret >= 0) return ret; else if (ret != AVERROR(ENOSYS)) @@ -835,12 +832,12 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags) } if (dst->hw_frames_ctx) { - dst_frames = (AVHWFramesContext*)dst->hw_frames_ctx->data; + FFHWFramesContext *dst_frames = (FFHWFramesContext*)dst->hw_frames_ctx->data; - if (dst_frames->format == dst->format && - dst_frames->internal->hw_type->map_to) { - ret = dst_frames->internal->hw_type->map_to(dst_frames, - dst, src, flags); + if (dst_frames->p.format == dst->format && + dst_frames->hw_type->map_to) { + ret = dst_frames->hw_type->map_to(&dst_frames->p, + dst, src, flags); if (ret >= 0) return ret; else if (ret != AVERROR(ENOSYS)) @@ -874,21 +871,21 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, int flags) { AVBufferRef *dst_ref = NULL; - AVHWFramesContext *dst = NULL; - AVHWFramesContext *src = (AVHWFramesContext*)source_frame_ctx->data; + FFHWFramesContext *dsti = NULL; + FFHWFramesContext *srci = (FFHWFramesContext*)source_frame_ctx->data; + AVHWFramesContext *dst, *src = &srci->p; int ret; - if (src->internal->source_frames) { + if (srci->source_frames) { AVHWFramesContext *src_src = - (AVHWFramesContext*)src->internal->source_frames->data; + (AVHWFramesContext*)srci->source_frames->data; AVHWDeviceContext *dst_dev = (AVHWDeviceContext*)derived_device_ctx->data; if (src_src->device_ctx == dst_dev) { // This is actually an unmapping, so we just return a // reference to the source frame context. - *derived_frame_ctx = - av_buffer_ref(src->internal->source_frames); + *derived_frame_ctx = av_buffer_ref(srci->source_frames); if (!*derived_frame_ctx) { ret = AVERROR(ENOMEM); goto fail; @@ -903,31 +900,32 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, goto fail; } - dst = (AVHWFramesContext*)dst_ref->data; + dsti = (FFHWFramesContext*)dst_ref->data; + dst = &dsti->p; dst->format = format; dst->sw_format = src->sw_format; dst->width = src->width; dst->height = src->height; - dst->internal->source_frames = av_buffer_ref(source_frame_ctx); - if (!dst->internal->source_frames) { + dsti->source_frames = av_buffer_ref(source_frame_ctx); + if (!dsti->source_frames) { ret = AVERROR(ENOMEM); goto fail; } - dst->internal->source_allocation_map_flags = + dsti->source_allocation_map_flags = flags & (AV_HWFRAME_MAP_READ | AV_HWFRAME_MAP_WRITE | AV_HWFRAME_MAP_OVERWRITE | AV_HWFRAME_MAP_DIRECT); ret = AVERROR(ENOSYS); - if (src->internal->hw_type->frames_derive_from) - ret = src->internal->hw_type->frames_derive_from(dst, src, flags); + if (srci->hw_type->frames_derive_from) + ret = srci->hw_type->frames_derive_from(dst, src, flags); if (ret == AVERROR(ENOSYS) && - dst->internal->hw_type->frames_derive_to) - ret = dst->internal->hw_type->frames_derive_to(dst, src, flags); + dsti->hw_type->frames_derive_to) + ret = dsti->hw_type->frames_derive_to(dst, src, flags); if (ret == AVERROR(ENOSYS)) ret = 0; if (ret) @@ -937,8 +935,8 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, return 0; fail: - if (dst) - av_buffer_unref(&dst->internal->source_frames); + if (dsti) + av_buffer_unref(&dsti->source_frames); av_buffer_unref(&dst_ref); return ret; } diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index 091bceb2f9..bac30debae 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -102,8 +102,6 @@ typedef struct AVHWDeviceContext { void *user_opaque; } AVHWDeviceContext; -typedef struct AVHWFramesInternal AVHWFramesInternal; - /** * This struct describes a set or pool of "hardware" frames (i.e. those with * data not located in normal system memory). All the frames in the pool are @@ -120,12 +118,6 @@ typedef struct AVHWFramesContext { */ const AVClass *av_class; - /** - * Private data used internally by libavutil. Must not be accessed in any - * way by the caller. - */ - AVHWFramesInternal *internal; - /** * A reference to the parent AVHWDeviceContext. This reference is owned and * managed by the enclosing AVHWFramesContext, but the caller may derive diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c index 1c61b36d69..b430b42f62 100644 --- a/libavutil/hwcontext_cuda.c +++ b/libavutil/hwcontext_cuda.c @@ -165,8 +165,9 @@ static int cuda_frames_init(AVHWFramesContext *ctx) if (size < 0) return size; - ctx->internal->pool_internal = av_buffer_pool_init2(size, ctx, cuda_pool_alloc, NULL); - if (!ctx->internal->pool_internal) + ffhwframesctx(ctx)->pool_internal = + av_buffer_pool_init2(size, ctx, cuda_pool_alloc, NULL); + if (!ffhwframesctx(ctx)->pool_internal) return AVERROR(ENOMEM); } diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c index 19fcf37a84..24b3546e7b 100644 --- a/libavutil/hwcontext_d3d11va.c +++ b/libavutil/hwcontext_d3d11va.c @@ -319,9 +319,10 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx) return AVERROR(ENOMEM); s->nb_surfaces = ctx->initial_pool_size; - ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(AVD3D11FrameDescriptor), - ctx, d3d11va_pool_alloc, NULL); - if (!ctx->internal->pool_internal) + ffhwframesctx(ctx)->pool_internal = + av_buffer_pool_init2(sizeof(AVD3D11FrameDescriptor), + ctx, d3d11va_pool_alloc, NULL); + if (!ffhwframesctx(ctx)->pool_internal) return AVERROR(ENOMEM); return 0; diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c index 16c07868f3..353807359b 100644 --- a/libavutil/hwcontext_d3d12va.c +++ b/libavutil/hwcontext_d3d12va.c @@ -297,10 +297,10 @@ static int d3d12va_frames_init(AVHWFramesContext *ctx) return AVERROR(EINVAL); } - ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(AVD3D12VAFrame), + ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2(sizeof(AVD3D12VAFrame), ctx, d3d12va_pool_alloc, NULL); - if (!ctx->internal->pool_internal) + if (!ffhwframesctx(ctx)->pool_internal) return AVERROR(ENOMEM); return 0; diff --git a/libavutil/hwcontext_dxva2.c b/libavutil/hwcontext_dxva2.c index 0922776342..77f34919a8 100644 --- a/libavutil/hwcontext_dxva2.c +++ b/libavutil/hwcontext_dxva2.c @@ -208,9 +208,10 @@ static int dxva2_init_pool(AVHWFramesContext *ctx) return AVERROR_UNKNOWN; } - ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(*s->surfaces_internal), - ctx, dxva2_pool_alloc, NULL); - if (!ctx->internal->pool_internal) + ffhwframesctx(ctx)->pool_internal = + av_buffer_pool_init2(sizeof(*s->surfaces_internal), + ctx, dxva2_pool_alloc, NULL); + if (!ffhwframesctx(ctx)->pool_internal) return AVERROR(ENOMEM); frames_hwctx->surfaces = s->surfaces_internal; diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h index 1476def1d7..e32b786238 100644 --- a/libavutil/hwcontext_internal.h +++ b/libavutil/hwcontext_internal.h @@ -90,7 +90,12 @@ typedef struct HWContextType { AVHWFramesContext *src_ctx, int flags); } HWContextType; -struct AVHWFramesInternal { +typedef struct FFHWFramesContext { + /** + * The public AVHWFramesContext. See hwcontext.h for it. + */ + AVHWFramesContext p; + const HWContextType *hw_type; AVBufferPool *pool_internal; @@ -105,7 +110,12 @@ struct AVHWFramesInternal { * frame context when trying to allocate in the derived context. */ int source_allocation_map_flags; -}; +} FFHWFramesContext; + +static inline FFHWFramesContext *ffhwframesctx(AVHWFramesContext *ctx) +{ + return (FFHWFramesContext*)ctx; +} typedef struct HWMapDescriptor { /** diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c index c5af1aec74..b449c5c31b 100644 --- a/libavutil/hwcontext_opencl.c +++ b/libavutil/hwcontext_opencl.c @@ -1714,10 +1714,10 @@ static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc) static int opencl_frames_init(AVHWFramesContext *hwfc) { if (!hwfc->pool) { - hwfc->internal->pool_internal = + ffhwframesctx(hwfc)->pool_internal = av_buffer_pool_init2(sizeof(cl_mem), hwfc, &opencl_pool_alloc, NULL); - if (!hwfc->internal->pool_internal) + if (!ffhwframesctx(hwfc)->pool_internal) return AVERROR(ENOMEM); } diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index f524a663b1..378cd5e826 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -605,9 +605,9 @@ static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc) return ret; #endif - ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(mfxFrameSurface1), - ctx, qsv_pool_alloc, NULL); - if (!ctx->internal->pool_internal) + ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2(sizeof(mfxFrameSurface1), + ctx, qsv_pool_alloc, NULL); + if (!ffhwframesctx(ctx)->pool_internal) return AVERROR(ENOMEM); frames_hwctx->surfaces = s->surfaces_internal; diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 2c75f5f5b1..56d03aa4cd 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -633,10 +633,10 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc) avfc->surface_ids = NULL; } - hwfc->internal->pool_internal = + ffhwframesctx(hwfc)->pool_internal = av_buffer_pool_init2(sizeof(VASurfaceID), hwfc, &vaapi_pool_alloc, NULL); - if (!hwfc->internal->pool_internal) { + if (!ffhwframesctx(hwfc)->pool_internal) { av_log(hwfc, AV_LOG_ERROR, "Failed to create VAAPI surface pool.\n"); err = AVERROR(ENOMEM); goto fail; @@ -654,7 +654,7 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc) goto fail; } } else { - test_surface = av_buffer_pool_get(hwfc->internal->pool_internal); + test_surface = av_buffer_pool_get(ffhwframesctx(hwfc)->pool_internal); if (!test_surface) { av_log(hwfc, AV_LOG_ERROR, "Unable to allocate a surface from " "internal buffer pool.\n"); diff --git a/libavutil/hwcontext_vdpau.c b/libavutil/hwcontext_vdpau.c index 0a1a33f8b1..081b863e0c 100644 --- a/libavutil/hwcontext_vdpau.c +++ b/libavutil/hwcontext_vdpau.c @@ -281,9 +281,10 @@ static int vdpau_frames_init(AVHWFramesContext *ctx) } if (!ctx->pool) { - ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(VdpVideoSurface), ctx, - vdpau_pool_alloc, NULL); - if (!ctx->internal->pool_internal) + ffhwframesctx(ctx)->pool_internal = + av_buffer_pool_init2(sizeof(VdpVideoSurface), ctx, + vdpau_pool_alloc, NULL); + if (!ffhwframesctx(ctx)->pool_internal) return AVERROR(ENOMEM); } diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c index 823cf9a8ee..9f82b104c3 100644 --- a/libavutil/hwcontext_videotoolbox.c +++ b/libavutil/hwcontext_videotoolbox.c @@ -286,9 +286,9 @@ static int vt_frames_init(AVHWFramesContext *ctx) } if (!ctx->pool) { - ctx->internal->pool_internal = av_buffer_pool_init2( + ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2( sizeof(CVPixelBufferRef), ctx, vt_pool_alloc_buffer, NULL); - if (!ctx->internal->pool_internal) + if (!ffhwframesctx(ctx)->pool_internal) return AVERROR(ENOMEM); } diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 449a6a2fef..f6ecdcbfda 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -2399,10 +2399,10 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc) /* If user did not specify a pool, hwfc->pool will be set to the internal one * in hwcontext.c just after this gets called */ if (!hwfc->pool) { - hwfc->internal->pool_internal = av_buffer_pool_init2(sizeof(AVVkFrame), - hwfc, vulkan_pool_alloc, - NULL); - if (!hwfc->internal->pool_internal) + ffhwframesctx(hwfc)->pool_internal = av_buffer_pool_init2(sizeof(AVVkFrame), + hwfc, vulkan_pool_alloc, + NULL); + if (!ffhwframesctx(hwfc)->pool_internal) return AVERROR(ENOMEM); }