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 6425B4028F for ; Wed, 19 Jan 2022 13:45:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0E72268B09E; Wed, 19 Jan 2022 15:45:23 +0200 (EET) Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6BE5168AF9C for ; Wed, 19 Jan 2022 15:45:16 +0200 (EET) Received: by mail-ot1-f48.google.com with SMTP id n22-20020a9d2016000000b0059bd79f7777so2707631ota.2 for ; Wed, 19 Jan 2022 05:45:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=ZT0ZJLYiiQMYajtdbuZvcUf6mbjXcKpSh6VoDuaUoY8=; b=OfFpdCuHWl6SLyiNc/TGFi3UQnlsfguK6qTsOsTbUUR5WEo/XcbO7ozKavMY/JINAf tLkahg1jQuPfuN81hJ9c+BsA7loi5o3BnxRA59Qs7+TfKmM23HMAJ2AgRNunguH9LRFO lqQvWVdmuzJ9sOe/+1Q15rRjYlodCB7mrzIfILL6On7M+0LoM55C4z+vnWo6rx7BlTlP z7S69CrksnRMFxYUJq2etihza1o5rF8SvBXkpwWU3uGZV0xmTjSdzLgs45NpeppdFXU2 Qyh8feWvoF6r7AjtNPLMMOhXPdsCTNtRVvpO+AaLHiLWdJjmamJM2ceHWvSPdfb/YAal lOvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=ZT0ZJLYiiQMYajtdbuZvcUf6mbjXcKpSh6VoDuaUoY8=; b=VdwrfZ9n47LjHSZctoErXZB+OYqSY8E/cxNVJnpKMpLsNnOlNB35MuE2SRwIaZwLgB H/OOoIA88zCgdmJOa/KNZqBFZKQajVTbxn9VAyQe7Md+R1u6Ygr+izggnFaLg1mN0aZ8 cTlvNCzN643i3eX0j+saryFsBeOfHuC+hwhoyuY7uxjJf7R4uNzCpboLadPmhb4fwPZc 3ziH+/hQwh3HXM+f3VwYVHvE5M0TWxzcaC959TnEkgjX29MsXIGD77h1C0/DRCke8GXG tl18NVaIs9aEd8Qu4yep4HAylRIcm7KnR0AV9Dl4kgNnEdh0hRzbTUMft+ozwrPF0aWh r9pA== X-Gm-Message-State: AOAM533cK8hJJxEGjgs07ls8Ge/Ff9HJigEBdxXNwB3dKPaG5LhNNaPX XdMSYdFzIhUWK476DqMJHue5FtH/eHI= X-Google-Smtp-Source: ABdhPJzRvjqxA6Poobh+RO0kFJrlkRie7eyNgumvQc3MtN0YQhU65QJnfjj08/3BSLiK18BKqgaXQQ== X-Received: by 2002:a05:6830:4d2:: with SMTP id s18mr21067263otd.158.1642599914089; Wed, 19 Jan 2022 05:45:14 -0800 (PST) Received: from [192.168.0.13] ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id 17sm9197085oij.21.2022.01.19.05.45.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Jan 2022 05:45:13 -0800 (PST) Message-ID: <51796511-a27c-3318-9d97-bb8ce4c972a0@gmail.com> Date: Wed, 19 Jan 2022 10:45:12 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20220119134040.774-1-anton@khirnov.net> <20220119134040.774-3-anton@khirnov.net> From: James Almer In-Reply-To: <20220119134040.774-3-anton@khirnov.net> Subject: Re: [FFmpeg-devel] [PATCH 3/3] lavu/hwcontext: clarify behavior on av_hwframe_map() failure 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 1/19/2022 10:40 AM, Anton Khirnov wrote: > Clear anything that av_hwframe_map() might have done to the destination > frame, but leave caller-provided fields unchanged. > --- > libavutil/hwcontext.c | 23 +++++++++++++++++++++-- > libavutil/hwcontext.h | 4 ++++ > 2 files changed, 25 insertions(+), 2 deletions(-) > > diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c > index 31c7840dba..ae33da1262 100644 > --- a/libavutil/hwcontext.c > +++ b/libavutil/hwcontext.c > @@ -18,6 +18,7 @@ > > #include "config.h" > > +#include "avassert.h" > #include "buffer.h" > #include "common.h" > #include "hwcontext.h" > @@ -788,6 +789,8 @@ fail: > > 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; > @@ -825,7 +828,7 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags) > ret = src_frames->internal->hw_type->map_from(src_frames, > dst, src, flags); > if (ret != AVERROR(ENOSYS)) > - return ret; > + goto fail; What if ret is 0? Is the stuff in the fail label meant to run on success? > } > } > > @@ -837,11 +840,27 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags) > ret = dst_frames->internal->hw_type->map_to(dst_frames, > dst, src, flags); > if (ret != AVERROR(ENOSYS)) > - return ret; > + goto fail; > } > } > > return AVERROR(ENOSYS); > + > +fail: > + // if the caller provided dst frames context, it should be preserved > + // by this function > + av_assert0(orig_dst_frames == NULL || > + orig_dst_frames == dst->hw_frames_ctx); > + > + // preserve user-provided dst frame fields, but clean > + // anything we might have set > + dst->hw_frames_ctx = NULL; > + av_frame_unref(dst); > + > + dst->hw_frames_ctx = orig_dst_frames; > + dst->format = orig_dst_fmt; > + > + return ret; > } > > int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, > diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h > index 04d19d89c2..c18b7e1e8b 100644 > --- a/libavutil/hwcontext.h > +++ b/libavutil/hwcontext.h > @@ -571,6 +571,10 @@ enum { > * possible with the given arguments and hwframe setup, while other return > * values indicate that it failed somehow. > * > + * On failure, the destination frame will be left blank, except for the > + * hw_frames_ctx/format fields thay may have been set by the caller - those will > + * be preserved as they were. > + * > * @param dst Destination frame, to contain the mapping. > * @param src Source frame, to be mapped. > * @param flags Some combination of AV_HWFRAME_MAP_* flags. _______________________________________________ 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".