From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9B725476AC for ; Tue, 19 Sep 2023 19:58:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7BCC368C970; Tue, 19 Sep 2023 22:57:21 +0300 (EEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2075.outbound.protection.outlook.com [40.92.89.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 35FF968C946 for ; Tue, 19 Sep 2023 22:57:19 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q00S+OMslPiWT0P82eQLRwdar8KKtqlA8wJML8Qj8owGFJaNPZsy8zLN9BNSU8jyDv/tRPb4lvK96RuxkdGSuhtTXSClhAM3qQXbhbWuydW1eV8sRVL88vR1wRZ232mPMOG2OGt+qp+tfVjC2GcsVZH3GloZNkGdsQf3ueGkV1TIPgM6i+XYcIPEYcZlMpm2vvFeIm0Irn/mOk1zT38/Xhc1SqSHiNl3fZWw9XszpDn1h6R+wh8yRnvEyS3lc/0gYcRW87rIE3hwifWC4tphi2GU5CF9fnmddzOCo1pUBf6A/E6HEgmAe7rG8eaztvvjNvSA4QbWq4x+EkcUG9rRKA== 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=iBbx1KRhsvBsRjnJjn74xq9OsNU3Yf9po4OiRt/InbI=; b=FsDrwJjtGfL+o8XidHA/Fgdp8E7zkMO8X2cdZhDNeKu9eu6KBIj5YYTyTr/M+dvkgryhX0gIomRdQy/8M/FDgdCRTGnYFyXvZRGf/K7Jv9PFqlgiXaEByzlu5IZnprqZIOJIP+ReWMzTc5AfaFSFzGHr52p5gjEFmVWSjEhWhrWUI8/qKRiP+wn1mqUrR6M9tQ+bidhoPTGsPNfLJ+sIASq0ZiOpJK+dgOOPAP/xibE7xdiKUbibFPUqTWs/1VBFXqLHl6hgOVrUF1X0oVCeVGQEGYBvLpCG6UvSpJYmV/6tVrXe81ASIGgEN+MpwCmTard7LABYD5XVNh6E9mEXSw== 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=iBbx1KRhsvBsRjnJjn74xq9OsNU3Yf9po4OiRt/InbI=; b=d2+uyNQwh2M2aEM0qZJckGzTpI/nAqv7T4QXcOLox8/7JGtbVlxOZSx4RiF1cBxrbjHbZOKCBu3T1IwsN2uEj6OhB6e9qSxJElo196ylGZiM3e0ymSGgjm3jaAB5ZKvXvtNbtcMXIbLUUsqKf3BzcLIK4n4TCqh/sFRd4kR/OYUs7AFW0Tbpkgm159q+ltUHROYPdqNHK03qxLvWXCCx4dHmRP6GwIaklE/w1jYO4tQKR+cdi5IYgp0orGYNLxwGocwhdkVpoLjU85IOjBZL/YBtiZkM05V00MjLE0AYSv6q+LpNlnQpBnJ91P3bwEmUiHky+9+JnFMztQCL+E66rg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:57:18 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:57:18 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:04 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [/mYq8w3S8uHMJciFSI+h7tFWuuWUKu4F] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-12-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: 7686bc1f-819c-4ebe-ad83-08dbb94aa0ca X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GCwdHVN3Og/Ib9Aj11cZ+PNdxZ3bMUIBpMLpkiW8YZSBAeIWfqNR8ehu3bPBKWrhrust6h8DroV9zbko62s4vTNdbP3efoKeyvk7FX3U9liMBDxXKBoPBMdenfQzmRhK80B2W798UxZT10aF9JSQymb847QrMLHrG26aNK4q8Oi/GXXyz02EXvffr6VwkBdwcxSY+jqJmIwEu9/n4PWbnyLBOKi2tq2fWOj4nmrsBAk5aFCUiLxz44NqSrYySWUqFVjHvGw238xyP1Xt84JzsNVv8GDqss0C8guz3hLiXmzDk8dGppjWiFWlGJ1GUjAD3BGHkEmfAwXSbzYf3ARn4rP7gguzKq6RKgx3Jj9GaZ7oYU8PnGSLLm47qFxVNb9AdSYZrFkh2cLniZsk3PWfKgp0VXv0qWBaTHgiPcDt9o6qhgFqSaNweYoa54d9D6asToxjyCAc7mrd3FVAZx00xGBCR8mI07/p7hgoqII05Iiwcq8YZ1LW/uZhfOlfNX/7+8X4OylBnzTvei9NrbMvbs9z/uI5r/uYeeblHKnNWn+fi1qQGiBU1E4jXMQhccWoE1hsQK2XBXW/EDfBSuYfWNz2MfuLyUZpBLHWYABlwRNCwTToHnx8sscJe7Wst91g X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?BtLGPde0VTqR46q0V6ErOTDj+L8h6SlS29uhQHZ19UBhkp5SK9OxWjLLa2fA?= =?us-ascii?Q?P8U+BAtlLt6fmOOD2NAf/WxpNwHTFmrmE6pZOL22NWtFXAUX2IH66BfvOIub?= =?us-ascii?Q?5hE20xjmGcA6v6/8B7bN/At9aIcgMb9+mh0wxwdZW+3DsD9ILhfdUUuE/OiY?= =?us-ascii?Q?MhMQDrd6T2qnewFPrcfyVEM8SNtn3/p+FTJt4/87OrrEGK9pEYKHbxkOROYg?= =?us-ascii?Q?5d86BQ/mwuVs3zfPdPOog8EjAMvA1pwe37kWPWkqH52TT2uxEZyYSRQTywK4?= =?us-ascii?Q?3Jmq5ZnX2Ar9EiAZnV9f7MPN+VfXcYo1ZU3EmVEUnLt6kZ57uUlglV0ZlmDZ?= =?us-ascii?Q?Bxpce80glVg/A3OGh5OcvpJckEMp473xhb0biAUfkMeuKElK8UEydjgrB9CS?= =?us-ascii?Q?dZjeDuGToN4E9QAiO8uOWZN889hWULc+XdZLBAgZ/9pGvUOrnmJFWq8uRVfb?= =?us-ascii?Q?x2wi/Q5BNdObkvAyWac11LWSzIb84PyU6yg8+D7VLj2p9il8ioQmYhkMqNEy?= =?us-ascii?Q?nbkVvw4QOaxN4DxCHdkDlPAFErFxOrGMhX98zrRZYy6IrOSmvQcqz59gmRL3?= =?us-ascii?Q?N/9IE83RaqvEqUorEJrGb5Wjodb4FlmBke5yPFm0svIgCqH3C3r1Sf0OoZTq?= =?us-ascii?Q?bbiAMbPQzwW5L7HoVNIU0ROnvSiYtcXZZe7W++lmeGvF+r1o4Hb5aZVv0tSO?= =?us-ascii?Q?xLkvFSO+U/R/H/mDIWM91CZK+T9PchiXy1gsz0ffwA1Aq2h8Rm+iRGZSn4d+?= =?us-ascii?Q?ZG9+uqikEZjd2TnG+kTBr1UUKo3UuV4wckZVzHMb4zVQ9tM+M52p0YEDSW6j?= =?us-ascii?Q?ywWAMpfzTAoKI+Iy1XIz+lXKSVaSKiIPk9cEnOMSOZZp1XaYB4HwBbqDoAF9?= =?us-ascii?Q?PvS04A8al+EgE0DwNTn+PNO60t+ayI3v8t7QFJJdQ8TWgPHtrOqXqNvZoEUK?= =?us-ascii?Q?nhMp0eFWIOemjbAig/5OY4c1UBUf7jrbrOgdVE92mNDwm/gS4V4sMguPmDak?= =?us-ascii?Q?cmAt2O25U/xY+w2meBdakj7svob/buU2LZtDf6l4wi0j/DhGc5QaOTuya8ok?= =?us-ascii?Q?4ECH4KIUQICIS8w6aLMthjnZpJv7fwQ1TkEOtqHtW2fhTM/FQQ3dkT/IIHxI?= =?us-ascii?Q?e5kJaXxVEBnHajObMCJ+0iMwBMbYdYseODZVvlQc099alxlyiPvQ/waiTDA0?= =?us-ascii?Q?mVX8j45Y4N6W9WOg0ZLl4tqTThltzjQZKol1Y1V+wh4Qigki5Om65f3nvHhI?= =?us-ascii?Q?+VwsdbfqGot8/IdpzfqS?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7686bc1f-819c-4ebe-ad83-08dbb94aa0ca X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:57:18.2065 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 12/42] avcodec/decode: Use RefStruct API for hwaccel_picture_private 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Avoids allocations and therefore error checks: Syncing hwaccel_picture_private across threads can't fail any more. Also gets rid of an unnecessary pointer in structures and in the parameter list of ff_hwaccel_frame_priv_alloc(). Signed-off-by: Andreas Rheinhardt --- libavcodec/av1dec.c | 15 ++++----------- libavcodec/av1dec.h | 4 +--- libavcodec/decode.c | 28 ++++++---------------------- libavcodec/decode.h | 10 +++------- libavcodec/h264_picture.c | 19 +++++-------------- libavcodec/h264_slice.c | 3 +-- libavcodec/h264dec.h | 1 - libavcodec/hevc_refs.c | 7 +++---- libavcodec/hevcdec.c | 11 ++--------- libavcodec/hevcdec.h | 3 +-- libavcodec/hwaccel_internal.h | 3 ++- libavcodec/mpegpicture.c | 18 +++++------------- libavcodec/mpegpicture.h | 1 - libavcodec/vp8.c | 14 ++++---------- libavcodec/vp8.h | 4 +--- libavcodec/vp9.c | 15 +++++---------- libavcodec/vp9shared.h | 3 +-- libavcodec/vulkan_av1.c | 9 +++------ libavcodec/vulkan_h264.c | 9 +++------ libavcodec/vulkan_hevc.c | 9 +++------ 20 files changed, 53 insertions(+), 133 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 87056520dd..c02408548c 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -27,7 +27,6 @@ #include "libavutil/opt.h" #include "avcodec.h" #include "av1_parse.h" -#include "decode.h" #include "av1dec.h" #include "atsc_a53.h" #include "bytestream.h" @@ -640,8 +639,7 @@ static int get_pixel_format(AVCodecContext *avctx) static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f) { ff_thread_release_buffer(avctx, f->f); - av_buffer_unref(&f->hwaccel_priv_buf); - f->hwaccel_picture_private = NULL; + ff_refstruct_unref(&f->hwaccel_picture_private); ff_refstruct_unref(&f->header_ref); f->raw_frame_header = NULL; f->spatial_id = f->temporal_id = 0; @@ -666,12 +664,8 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s if (ret < 0) goto fail; - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) - goto fail; - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); dst->spatial_id = src->spatial_id; dst->temporal_id = src->temporal_id; @@ -915,8 +909,7 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f) break; } - ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private, - &f->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private); if (ret < 0) goto fail; diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h index acbeec4af3..b6a0c08e48 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -24,7 +24,6 @@ #include #include "libavutil/fifo.h" -#include "libavutil/buffer.h" #include "libavutil/frame.h" #include "libavutil/pixfmt.h" #include "avcodec.h" @@ -35,8 +34,7 @@ typedef struct AV1Frame { AVFrame *f; - AVBufferRef *hwaccel_priv_buf; - void *hwaccel_picture_private; + void *hwaccel_picture_private; ///< RefStruct reference AV1RawOBU *header_ref; ///< RefStruct reference backing raw_frame_header. AV1RawFrameHeader *raw_frame_header; diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 169ee79acd..7abfe7f0ce 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -28,18 +28,13 @@ #endif #include "libavutil/avassert.h" -#include "libavutil/avstring.h" -#include "libavutil/bprint.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" #include "libavutil/emms.h" -#include "libavutil/fifo.h" #include "libavutil/frame.h" #include "libavutil/hwcontext.h" #include "libavutil/imgutils.h" #include "libavutil/internal.h" -#include "libavutil/intmath.h" -#include "libavutil/opt.h" #include "avcodec.h" #include "avcodec_internal.h" @@ -51,6 +46,7 @@ #include "hwconfig.h" #include "internal.h" #include "packet_internal.h" +#include "refstruct.h" #include "thread.h" typedef struct DecodeContext { @@ -1790,34 +1786,22 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) return 0; } -int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private, - AVBufferRef **hwaccel_priv_buf) +int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private) { const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel); - AVBufferRef *ref; AVHWFramesContext *frames_ctx; - uint8_t *data; if (!hwaccel || !hwaccel->frame_priv_data_size) return 0; av_assert0(!*hwaccel_picture_private); - data = av_mallocz(hwaccel->frame_priv_data_size); - if (!data) - return AVERROR(ENOMEM); frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data; - - ref = av_buffer_create(data, hwaccel->frame_priv_data_size, - hwaccel->free_frame_priv, - frames_ctx->device_ctx, 0); - if (!ref) { - av_free(data); + *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0, + frames_ctx->device_ctx, + hwaccel->free_frame_priv); + if (!*hwaccel_picture_private) return AVERROR(ENOMEM); - } - - *hwaccel_priv_buf = ref; - *hwaccel_picture_private = ref->data; return 0; } diff --git a/libavcodec/decode.h b/libavcodec/decode.h index a52152e4a7..ce97c53933 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -21,7 +21,6 @@ #ifndef AVCODEC_DECODE_H #define AVCODEC_DECODE_H -#include "libavutil/buffer.h" #include "libavutil/frame.h" #include "libavutil/hwcontext.h" @@ -141,16 +140,13 @@ int ff_side_data_update_matrix_encoding(AVFrame *frame, /** * Allocate a hwaccel frame private data if the provided avctx - * uses a hwaccel method that needs it. The private data will - * be refcounted via the AVBuffer API (if allocated). + * uses a hwaccel method that needs it. The returned data is + * a RefStruct reference (if allocated). * * @param avctx The codec context * @param hwaccel_picture_private Pointer to return hwaccel_picture_private - * @param hwaccel_priv_buf Pointer to return the AVBufferRef owning - * hwaccel_picture_private * @return 0 on success, < 0 on error */ -int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private, - AVBufferRef **hwaccel_priv_buf); +int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private); #endif /* AVCODEC_DECODE_H */ diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c index 25d0d96ddb..9353e4b445 100644 --- a/libavcodec/h264_picture.c +++ b/libavcodec/h264_picture.c @@ -46,7 +46,7 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic) ff_thread_release_ext_buffer(h->avctx, &pic->tf); ff_thread_release_buffer(h->avctx, pic->f_grain); - av_buffer_unref(&pic->hwaccel_priv_buf); + ff_refstruct_unref(&pic->hwaccel_picture_private); av_buffer_unref(&pic->qscale_table_buf); av_buffer_unref(&pic->mb_type_buf); @@ -129,14 +129,8 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src) } } - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) { - ret = AVERROR(ENOMEM); - goto fail; - } - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); ret = av_buffer_replace(&dst->decode_error_flags, src->decode_error_flags); if (ret < 0) @@ -185,11 +179,8 @@ int ff_h264_replace_picture(H264Context *h, H264Picture *dst, const H264Picture goto fail; } - ret = av_buffer_replace(&dst->hwaccel_priv_buf, src->hwaccel_priv_buf); - if (ret < 0) - goto fail; - - dst->hwaccel_picture_private = src->hwaccel_picture_private; + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); ret = av_buffer_replace(&dst->decode_error_flags, src->decode_error_flags); if (ret < 0) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 632f5b23b2..6df80c9522 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -206,8 +206,7 @@ static int alloc_picture(H264Context *h, H264Picture *pic) goto fail; } - ret = ff_hwaccel_frame_priv_alloc(h->avctx, &pic->hwaccel_picture_private, - &pic->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(h->avctx, &pic->hwaccel_picture_private); if (ret < 0) goto fail; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 513856749a..7436e0a54f 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -117,7 +117,6 @@ typedef struct H264Picture { AVBufferRef *mb_type_buf; uint32_t *mb_type; - AVBufferRef *hwaccel_priv_buf; void *hwaccel_picture_private; ///< hardware accelerator private data AVBufferRef *ref_index_buf[2]; diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index c5c1203ef8..8f49704b54 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -27,6 +27,7 @@ #include "thread.h" #include "hevc.h" #include "hevcdec.h" +#include "refstruct.h" #include "threadframe.h" void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) @@ -51,8 +52,7 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) frame->collocated_ref = NULL; - av_buffer_unref(&frame->hwaccel_priv_buf); - frame->hwaccel_picture_private = NULL; + ff_refstruct_unref(&frame->hwaccel_picture_private); } } @@ -118,8 +118,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s) (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_BOTTOM_FIELD)) frame->frame->flags |= AV_FRAME_FLAG_INTERLACED; - ret = ff_hwaccel_frame_priv_alloc(s->avctx, &frame->hwaccel_picture_private, - &frame->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(s->avctx, &frame->hwaccel_picture_private); if (ret < 0) goto fail; diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 44a9680415..8316a815e7 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -28,7 +28,6 @@ #include "libavutil/attributes.h" #include "libavutil/avstring.h" #include "libavutil/common.h" -#include "libavutil/display.h" #include "libavutil/film_grain_params.h" #include "libavutil/internal.h" #include "libavutil/md5.h" @@ -37,13 +36,11 @@ #include "libavutil/timecode.h" #include "bswapdsp.h" -#include "bytestream.h" #include "cabac_functions.h" #include "codec_internal.h" #include "decode.h" #include "golomb.h" #include "hevc.h" -#include "hevc_data.h" #include "hevc_parse.h" #include "hevcdec.h" #include "hwaccel_internal.h" @@ -3416,12 +3413,8 @@ static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src) dst->flags = src->flags; dst->sequence = src->sequence; - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) - goto fail; - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); return 0; fail: diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index 94609e4699..1d29fc24d7 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -419,8 +419,7 @@ typedef struct HEVCFrame { AVBufferRef *rpl_tab_buf; AVBufferRef *rpl_buf; - AVBufferRef *hwaccel_priv_buf; - void *hwaccel_picture_private; + void *hwaccel_picture_private; ///< RefStruct reference /** * A sequence counter, so that old frames are output first diff --git a/libavcodec/hwaccel_internal.h b/libavcodec/hwaccel_internal.h index edfe283150..057b07323d 100644 --- a/libavcodec/hwaccel_internal.h +++ b/libavcodec/hwaccel_internal.h @@ -26,6 +26,7 @@ #include #include "avcodec.h" +#include "refstruct.h" #define HWACCEL_CAP_ASYNC_SAFE (1 << 0) #define HWACCEL_CAP_THREAD_SAFE (1 << 1) @@ -154,7 +155,7 @@ typedef struct FFHWAccel { * @param hwctx a pointer to an AVHWDeviceContext. * @param data the per-frame hardware accelerator private data to be freed. */ - void (*free_frame_priv)(void *hwctx, uint8_t *data); + void (*free_frame_priv)(FFRefStructOpaque hwctx, void *data); /** * Callback to flush the hwaccel state. diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index b7c804c8ec..4126756e9b 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -27,11 +27,11 @@ #include "avcodec.h" #include "encode.h" -#include "internal.h" #include "decode.h" #include "motion_est.h" #include "mpegpicture.h" #include "mpegutils.h" +#include "refstruct.h" #include "threadframe.h" static void av_noinline free_picture_tables(Picture *pic) @@ -171,8 +171,7 @@ static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic, pic->f->height = avctx->height; } - ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private, - &pic->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private); if (ret < 0) return ret; @@ -316,12 +315,11 @@ void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic) else if (pic->f) av_frame_unref(pic->f); - av_buffer_unref(&pic->hwaccel_priv_buf); + ff_refstruct_unref(&pic->hwaccel_picture_private); if (pic->needs_realloc) free_picture_tables(pic); - pic->hwaccel_picture_private = NULL; pic->field_picture = 0; pic->b_frame_score = 0; pic->needs_realloc = 0; @@ -380,14 +378,8 @@ int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src) if (ret < 0) goto fail; - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) { - ret = AVERROR(ENOMEM); - goto fail; - } - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); dst->field_picture = src->field_picture; dst->b_frame_score = src->b_frame_score; diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index 7919aa402c..477b3ac535 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -66,7 +66,6 @@ typedef struct Picture { int alloc_mb_height; ///< mb_height used to allocate tables int alloc_mb_stride; ///< mb_stride used to allocate tables - AVBufferRef *hwaccel_priv_buf; void *hwaccel_picture_private; ///< Hardware accelerator private data int field_picture; ///< whether or not the picture was encoded in separate fields diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index db325dc90b..4a51c551b8 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -108,8 +108,7 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) return ret; if (!(f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height))) goto fail; - ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private, - &f->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private); if (ret < 0) goto fail; @@ -124,8 +123,7 @@ fail: static void vp8_release_frame(VP8Context *s, VP8Frame *f) { ff_refstruct_unref(&f->seg_map); - av_buffer_unref(&f->hwaccel_priv_buf); - f->hwaccel_picture_private = NULL; + ff_refstruct_unref(&f->hwaccel_picture_private); ff_thread_release_ext_buffer(s->avctx, &f->tf); } @@ -139,12 +137,8 @@ static int vp8_ref_frame(VP8Context *s, VP8Frame *dst, const VP8Frame *src) if ((ret = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0) return ret; ff_refstruct_replace(&dst->seg_map, src->seg_map); - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) - return AVERROR(ENOMEM); - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); return 0; } diff --git a/libavcodec/vp8.h b/libavcodec/vp8.h index cb752d4498..eb9fa2f166 100644 --- a/libavcodec/vp8.h +++ b/libavcodec/vp8.h @@ -28,7 +28,6 @@ #include -#include "libavutil/buffer.h" #include "libavutil/mem_internal.h" #include "libavutil/thread.h" @@ -154,8 +153,7 @@ typedef struct VP8Frame { ThreadFrame tf; uint8_t *seg_map; ///< RefStruct reference - AVBufferRef *hwaccel_priv_buf; - void *hwaccel_picture_private; + void *hwaccel_picture_private; ///< RefStruct reference } VP8Frame; #define MAX_THREADS 8 diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 3cc27aa812..c9cc81ec94 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -30,6 +30,7 @@ #include "hwaccel_internal.h" #include "hwconfig.h" #include "profiles.h" +#include "refstruct.h" #include "thread.h" #include "threadframe.h" #include "pthread_internal.h" @@ -100,9 +101,8 @@ static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f) { ff_thread_release_ext_buffer(avctx, &f->tf); av_buffer_unref(&f->extradata); - av_buffer_unref(&f->hwaccel_priv_buf); + ff_refstruct_unref(&f->hwaccel_picture_private); f->segmentation_map = NULL; - f->hwaccel_picture_private = NULL; } static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) @@ -135,8 +135,7 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) f->segmentation_map = f->extradata->data; f->mv = (VP9mvrefPair *) (f->extradata->data + sz); - ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private, - &f->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private); if (ret < 0) goto fail; @@ -163,12 +162,8 @@ static int vp9_frame_ref(AVCodecContext *avctx, VP9Frame *dst, VP9Frame *src) dst->mv = src->mv; dst->uses_2pass = src->uses_2pass; - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) - goto fail; - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); return 0; diff --git a/libavcodec/vp9shared.h b/libavcodec/vp9shared.h index 543a496df8..e54f23544e 100644 --- a/libavcodec/vp9shared.h +++ b/libavcodec/vp9shared.h @@ -69,8 +69,7 @@ typedef struct VP9Frame { VP9mvrefPair *mv; int uses_2pass; - AVBufferRef *hwaccel_priv_buf; - void *hwaccel_picture_private; + void *hwaccel_picture_private; ///< RefStruct reference } VP9Frame; enum BlockLevel { diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c index b1373722ef..7c8dda7798 100644 --- a/libavcodec/vulkan_av1.c +++ b/libavcodec/vulkan_av1.c @@ -536,10 +536,10 @@ static int vk_av1_end_frame(AVCodecContext *avctx) return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp); } -static void vk_av1_free_frame_priv(void *_hwctx, uint8_t *data) +static void vk_av1_free_frame_priv(FFRefStructOpaque _hwctx, void *data) { - AVHWDeviceContext *hwctx = _hwctx; - AV1VulkanDecodePicture *ap = (AV1VulkanDecodePicture *)data; + AVHWDeviceContext *hwctx = _hwctx.nc; + AV1VulkanDecodePicture *ap = data; /* Workaround for a spec issue. */ if (ap->frame_id_set) @@ -547,9 +547,6 @@ static void vk_av1_free_frame_priv(void *_hwctx, uint8_t *data) /* Free frame resources, this also destroys the session parameters. */ ff_vk_decode_free_frame(hwctx, &ap->vp); - - /* Free frame context */ - av_free(ap); } const FFHWAccel ff_av1_vulkan_hwaccel = { diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c index cdc2c7fe30..2cb54bb1ff 100644 --- a/libavcodec/vulkan_h264.c +++ b/libavcodec/vulkan_h264.c @@ -530,16 +530,13 @@ static int vk_h264_end_frame(AVCodecContext *avctx) return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp); } -static void vk_h264_free_frame_priv(void *_hwctx, uint8_t *data) +static void vk_h264_free_frame_priv(FFRefStructOpaque _hwctx, void *data) { - AVHWDeviceContext *hwctx = _hwctx; - H264VulkanDecodePicture *hp = (H264VulkanDecodePicture *)data; + AVHWDeviceContext *hwctx = _hwctx.nc; + H264VulkanDecodePicture *hp = data; /* Free frame resources, this also destroys the session parameters. */ ff_vk_decode_free_frame(hwctx, &hp->vp); - - /* Free frame context */ - av_free(hp); } const FFHWAccel ff_h264_vulkan_hwaccel = { diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c index 395cbd3008..d5116bb48c 100644 --- a/libavcodec/vulkan_hevc.c +++ b/libavcodec/vulkan_hevc.c @@ -901,16 +901,13 @@ static int vk_hevc_end_frame(AVCodecContext *avctx) return ff_vk_decode_frame(avctx, pic->frame, vp, rav, rvp); } -static void vk_hevc_free_frame_priv(void *_hwctx, uint8_t *data) +static void vk_hevc_free_frame_priv(FFRefStructOpaque _hwctx, void *data) { - AVHWDeviceContext *hwctx = _hwctx; - HEVCVulkanDecodePicture *hp = (HEVCVulkanDecodePicture *)data; + AVHWDeviceContext *hwctx = _hwctx.nc; + HEVCVulkanDecodePicture *hp = data; /* Free frame resources */ ff_vk_decode_free_frame(hwctx, &hp->vp); - - /* Free frame context */ - av_free(hp); } const FFHWAccel ff_hevc_vulkan_hwaccel = { -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".