From patchwork Tue Jan 31 13:14:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40195 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp34918pzj; Tue, 31 Jan 2023 05:15:07 -0800 (PST) X-Google-Smtp-Source: AK7set9fETqbbEoy4OY/v/MpNoYoeZLD1YrTUPPalz34BuOJ76PAXTRpla4wPmpIYm2qcpznMLPt X-Received: by 2002:a17:906:5350:b0:878:5f8e:26c0 with SMTP id j16-20020a170906535000b008785f8e26c0mr3551278ejo.7.1675170907607; Tue, 31 Jan 2023 05:15:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675170907; cv=none; d=google.com; s=arc-20160816; b=NZ+w+sG/gOG77apKkVY9OqtiTX4tijXmQGUzPPM+YQQG8Rb+qvkodESxeoaN6DfCye oWiR/OtIxUYabyaEVcCLiblx+QIb51xK14bgCeVjyfN7j4A19RSYgjsXbk5QObB1ZnNA QIRLtoIud02cIoooNfOBHiRqgmflkTB57JOgBUtRVs3z+ChLtvZ+ia9nFKl92btIRYlx w5Z2M9l/7wZRaLllzCyIkHbn9RKmAYET24+1cPZD2aLkF+PqL0wxpneaazI8fwCVGjWz 9SvUkjme0baHngcSxOdhPJ1e3jfXKegVU+qf8Jx1Rc8/yfGYHWsnF5p8hty6UwOTMO1u CodA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=5jcsexUn8GTzHSHmpCbbAQj/HIwIdAkZ3D3yz0JUb/k=; b=NQuq0AR4wKq/yQaNZMAYvUhwGGL9Fj/X3RpRWdYA8Eb2Fgr4S5OB69MJoAkz0Njpcb RkuSE9A3lIX5GpXaCn6pkDfxk73DkTajuXCD6T8j+dp0l9Ia/H2u7J/vBLUVU35nrLUO SSfpW38FGExIEvNyW8ARyoUxxQANJKF69xcZngXwwbyV9qeTosIN12cfXeZ2n+ormfmi BRv9QSPZRZBl/ta44E9FkbWfghOtFLbs8kGbxvZC6dOgR9KcBQ4Nv7ccsPbycinrSKt+ iJUWseebo7jTPXaU5jfqp4JlKKrmKL093Rlu6WTsPYphmnBpYOYJ0Aek2RCfzSsZZPoE N0PA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 24-20020a170906001800b007ba49ec6d3bsi19836848eja.390.2023.01.31.05.15.01; Tue, 31 Jan 2023 05:15:07 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F80168BDF2; Tue, 31 Jan 2023 15:14:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EBCAD68AF6B for ; Tue, 31 Jan 2023 15:14:51 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 978B32404EC for ; Tue, 31 Jan 2023 14:14:51 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id AZn2MrvKJzKb for ; Tue, 31 Jan 2023 14:14:51 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 06112240178 for ; Tue, 31 Jan 2023 14:14:51 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B0ED43A0191 for ; Tue, 31 Jan 2023 14:14:50 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Jan 2023 14:14:47 +0100 Message-Id: <20230131131447.24732-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <601087569af7d6b82fe47f82c28dd17b99e7e59f.camel@intel.com> References: <601087569af7d6b82fe47f82c28dd17b99e7e59f.camel@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix propagating durations and opaques 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" X-TUID: 9TRES4NPTt/W input_image is freed by the time the output packet is constructed, so we need to store copies in VAAPIEncodePicture. --- Is this better? --- libavcodec/vaapi_encode.c | 22 +++++++++++++++++----- libavcodec/vaapi_encode.h | 4 ++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 6787b90e8d6..bfca315a7ad 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -695,7 +695,7 @@ static int vaapi_encode_output(AVCodecContext *avctx, pkt->flags |= AV_PKT_FLAG_KEY; pkt->pts = pic->pts; - pkt->duration = pic->input_image->duration; + pkt->duration = pic->duration; vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer); if (vas != VA_STATUS_SUCCESS) { @@ -706,10 +706,11 @@ static int vaapi_encode_output(AVCodecContext *avctx, } // for no-delay encoders this is handled in generic codec - if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY) { - err = ff_encode_reordered_opaque(avctx, pkt, pic->input_image); - if (err < 0) - goto fail; + if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY && + avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) { + pkt->opaque = pic->opaque; + pkt->opaque_ref = pic->opaque_ref; + pic->opaque_ref = NULL; } av_buffer_unref(&pic->output_buffer_ref); @@ -785,6 +786,8 @@ static int vaapi_encode_free(AVCodecContext *avctx, av_frame_free(&pic->input_image); av_frame_free(&pic->recon_image); + av_buffer_unref(&pic->opaque_ref); + av_freep(&pic->param_buffers); av_freep(&pic->slices); // Output buffer should already be destroyed. @@ -1152,6 +1155,15 @@ static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame) pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3]; pic->pts = frame->pts; + pic->duration = frame->duration; + + if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) { + err = av_buffer_replace(&pic->opaque_ref, frame->opaque_ref); + if (err < 0) + goto fail; + + pic->opaque = frame->opaque; + } av_frame_move_ref(pic->input_image, frame); diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index 359f954ffff..a1e639f56b0 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -75,8 +75,12 @@ typedef struct VAAPIEncodePicture { int64_t display_order; int64_t encode_order; int64_t pts; + int64_t duration; int force_idr; + void *opaque; + AVBufferRef *opaque_ref; + #if VA_CHECK_VERSION(1, 0, 0) // ROI regions. VAEncROI *roi;