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 20F414627E for ; Tue, 13 Jun 2023 17:18:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2FF0768C2F0; Tue, 13 Jun 2023 20:17:59 +0300 (EEST) Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A39B46882BA for ; Tue, 13 Jun 2023 20:17:52 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id B9FCA10602CF for ; Tue, 13 Jun 2023 17:17:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1686676672; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=0mcavmGYPVjtqSi1uUrXnamDmn1kD6A7KbC5eh9X4fk=; b=Wshxv3YczWakv7nDAS+nHCpqSXr5hDcPRMBMLhV7Yt76+6Wr12xW1MNpqzA/SvhL S1P8sxXXtW8ngOLnBMUd279cN1l4t5MHHsiNS/Oi2T+2XGOH7zhYhA7XbXhtuV4brKD aP/yQpL71jBIo91KqsJwJFdNm+aokYkg3KnApZxGkDFhfNqWbfWVXqcGqXeF+FidM5v chFfOvpQYeXqMXPT7f9e1DTKHDY14D2PjFXo6kcOKRMpewWOtVkeBI78qqHVTyushhV DYXbsNAN+IyALtEwWPpqCqUZnY7PJdUpg9UowdwdKFVI33p40Y6n5k837roMwyir8iv v5aAmptWqA== Date: Tue, 13 Jun 2023 19:17:52 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_280843_1582375107.1686676672169" Subject: Re: [FFmpeg-devel] [RFC] [PATCH 1/5] hwcontext: add a new AVHWFramesContext.opaque field 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: ------=_Part_280843_1582375107.1686676672169 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Jun 13, 2023, 18:56 by andreas.rheinhardt@outlook.com: > Lynne: > >> + dst->opaque = av_buffer_ref(src->opaque); >> + if (!dst->opaque) { >> + ret = AVERROR(ENOMEM); >> + goto fail; >> + } >> > > According to the doxy, opaque can be left unset (and will be given that > it is a new field), yet av_buffer_ref(NULL) will crash. We have > av_buffer_replace() for something like that. > Fixed. ------=_Part_280843_1582375107.1686676672169 Content-Type: text/x-diff; charset=us-ascii; name=0001-hwcontext-add-a-new-AVHWFramesContext.opaque-field.patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-hwcontext-add-a-new-AVHWFramesContext.opaque-field.patch >From 02cd540d4cd10ad009e949f097bd3f0250a31fde Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 13 Jun 2023 06:10:50 +0200 Subject: [PATCH 1/6] hwcontext: add a new AVHWFramesContext.opaque field This is a public field, settable before frames context initialization, and propagated to any derived contexts. API users can use it to store state and determine which context is one of theirs. This also allows decoders which create their own contexts to store some state which would be freed only at context destruction. --- libavutil/hwcontext.c | 3 +++ libavutil/hwcontext.h | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index 3396598269..bbb824abfc 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -238,6 +238,7 @@ static void hwframe_ctx_free(void *opaque, uint8_t *data) av_buffer_unref(&ctx->internal->source_frames); av_buffer_unref(&ctx->device_ref); + av_buffer_unref(&ctx->opaque); av_freep(&ctx->hwctx); av_freep(&ctx->internal->priv); @@ -913,6 +914,8 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, dst->sw_format = src->sw_format; dst->width = src->width; dst->height = src->height; + if ((ret = av_buffer_replace(&dst->opaque, src->opaque)) < 0) + goto fail; dst->internal->source_frames = av_buffer_ref(source_frame_ctx); if (!dst->internal->source_frames) { diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index 7ff08c8608..7655bee33f 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -227,6 +227,15 @@ typedef struct AVHWFramesContext { * Must be set by the user before calling av_hwframe_ctx_init(). */ int width, height; + + /** + * Opaque data. Can be set before calling av_hwframe_ctx_init(). + * MUST NOT be set afterwards. Will be unref'd along with the + * main context at closure. + * + * Will be propagated to any derived contexts. + */ + AVBufferRef *opaque; } AVHWFramesContext; /** -- 2.40.1 ------=_Part_280843_1582375107.1686676672169 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". ------=_Part_280843_1582375107.1686676672169--