From patchwork Wed Jul 13 09:17:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36773 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:6da0:b0:8b:e47:9dbf with SMTP id wl32csp226091pzb; Wed, 13 Jul 2022 02:18:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sLy4sXKl7vyVdar9khgse7Y53tL5JX7cWGR+Oktql23fkvbo9IxcTD/vE7PM/LW1QNKaAw X-Received: by 2002:a05:6402:510e:b0:43a:c671:7cd0 with SMTP id m14-20020a056402510e00b0043ac6717cd0mr3483383edd.103.1657703925369; Wed, 13 Jul 2022 02:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657703925; cv=none; d=google.com; s=arc-20160816; b=zn6aSeGS+ZkZGrbUQBAnI5iXYFWSpVk9af7sxMZwrQL9QaNwFqc0RNTkQNpPye7pDf BPM8qAd3b36YX4gzzwzIZ2TuE2ZcaeTf4S6wN2zNeQwOWzL6QtvLP2SG5rt1q0v/2B0u cEM2a3ogys2CS6be0eWgFsGAGP8fFW4+ND0e2HEXggHaCXdBt7S0bhazc4ZTaWDZBmBS 1wxg7A/iEUMez5sFOGE5JJ/34kvzQ7GsRuuE+YDX5JdeTsnwOswfWQ70XkHYpNhBQmow /Ca3IEDTCfav35svVs1noRl8NGPM8/HS8q2uRk9a5Jax/MAj/tISGDlC9PINdmPHMyQG PMtw== 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=CAnnF4e6J749iJzjYyUw8Y0puYiO6sbhHmv6Ylp+cUc=; b=wJ7sRtU1NcZTuZXe+qMLjk6SvWFGalth6nJnS77cVWbx7VaL7EGORtqkgFfKYBcOZn QfXS6MfjE2u5iD+tWbrT0kJ3OtSLFCuTqCJOOp490jeMUITiGnLrD9h+psj3WOVTdzC3 /eTOs7fT6V05LYpl8YKZFNkEa6+8AFcrgmyuJ6jrVPdeImBPT1Tb53NGVBG+XZ51+JeS adhNs9fKZWWXxmvWehb2Zv75a3p+fVoasrxSZ4QXaNQ5/7iYGdckB0+WAPsQ7FN+5lyz oPXJ9YQGIquOYoF+S/GnNFlCxhfZ23KJnxp1+WR3QFbXRxD5dS8WZxPVpAoADeRtbPpq 1u7A== 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 l22-20020a1709060e1600b00726abda6121si15551350eji.533.2022.07.13.02.18.44; Wed, 13 Jul 2022 02:18:45 -0700 (PDT) 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 5D55668B994; Wed, 13 Jul 2022 12:17:44 +0300 (EEST) 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 02E4768B93E for ; Wed, 13 Jul 2022 12:17:37 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 259D42404FE for ; Wed, 13 Jul 2022 11:17:33 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id YJLfSOe3N8M6 for ; Wed, 13 Jul 2022 11:17:32 +0200 (CEST) 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 5E80524017E for ; Wed, 13 Jul 2022 11:17:28 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id C94FD3A02CB; Wed, 13 Jul 2022 11:17:27 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Jul 2022 11:17:18 +0200 Message-Id: <20220713091725.16638-2-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713091725.16638-1-anton@khirnov.net> References: <20220713091725.16638-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/9] lavc: use AVFrame.duration instead of AVFrame.pkt_duration 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: sQ4TBXTBbbnB --- libavcodec/crystalhd.c | 2 +- libavcodec/cuviddec.c | 2 +- libavcodec/decode.c | 14 ++++++++++---- libavcodec/encode.c | 11 ++++++++++- libavcodec/gifdec.c | 2 +- libavcodec/libdav1d.c | 2 +- libavcodec/mfenc.c | 2 +- libavcodec/rawdec.c | 2 +- 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c index cf74f22e7d..211a485918 100644 --- a/libavcodec/crystalhd.c +++ b/libavcodec/crystalhd.c @@ -546,7 +546,7 @@ static inline CopyRet copy_frame(AVCodecContext *avctx, frame->pts = pkt_pts; frame->pkt_pos = -1; - frame->pkt_duration = 0; + frame->duration = 0; frame->pkt_size = -1; if (!priv->need_second_field) { diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c index b544b3361d..d1b5dbc6f5 100644 --- a/libavcodec/cuviddec.c +++ b/libavcodec/cuviddec.c @@ -624,7 +624,7 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame) * So set pkt_pts and clear all the other pkt_ fields. */ frame->pkt_pos = -1; - frame->pkt_duration = 0; + frame->duration = 0; frame->pkt_size = -1; frame->interlaced_frame = !parsed_frame.is_deinterlacing && !parsed_frame.dispinfo.progressive_frame; diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 1893caa6a6..14ce4c2e2f 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -394,8 +394,8 @@ FF_ENABLE_DEPRECATION_WARNINGS frame->pts += diff_ts; if(frame->pkt_dts!=AV_NOPTS_VALUE) frame->pkt_dts += diff_ts; - if (frame->pkt_duration >= diff_ts) - frame->pkt_duration -= diff_ts; + if (frame->duration >= diff_ts) + frame->duration -= diff_ts; } else { av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n"); } @@ -417,7 +417,7 @@ FF_ENABLE_DEPRECATION_WARNINGS int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding, (AVRational){1, avctx->sample_rate}, avctx->pkt_timebase); - frame->pkt_duration = diff_ts; + frame->duration = diff_ts; } else { av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n"); } @@ -549,6 +549,12 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) frame->pts, frame->pkt_dts); +#if FF_API_PKT_DURATION +FF_DISABLE_DEPRECATION_WARNINGS + frame->pkt_duration = frame->duration; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + /* the only case where decode data is not set should be decoders * that do not call ff_get_buffer() */ av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) || @@ -1267,7 +1273,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) { frame->pts = pkt->pts; frame->pkt_pos = pkt->pos; - frame->pkt_duration = pkt->duration; + frame->duration = pkt->duration; frame->pkt_size = pkt->size; for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) { diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 1f39ab1a2f..310fe20777 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -339,7 +339,7 @@ static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src) return ret; avctx->internal->last_audio_frame = 1; - return 0; + goto finish; } else if (src->nb_samples > avctx->frame_size) { av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d)\n", src->nb_samples, avctx->frame_size); return AVERROR(EINVAL); @@ -351,6 +351,15 @@ static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src) if (ret < 0) return ret; +finish: + +#if FF_API_PKT_DURATION +FF_DISABLE_DEPRECATION_WARNINGS + if (dst->pkt_duration && dst->pkt_duration != dst->duration) + dst->duration = dst->pkt_duration; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + return 0; } diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c index 3936de1cd2..fbb1ef6ad5 100644 --- a/libavcodec/gifdec.c +++ b/libavcodec/gifdec.c @@ -475,7 +475,7 @@ static int gif_decode_frame(AVCodecContext *avctx, AVFrame *rframe, s->frame->pts = avpkt->pts; s->frame->pkt_dts = avpkt->dts; - s->frame->pkt_duration = avpkt->duration; + s->frame->duration = avpkt->duration; if (avpkt->size >= 6) { s->keyframe = memcmp(avpkt->data, gif87a_sig, 6) == 0 || diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 0a46cf2264..126bc3ae06 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -415,7 +415,7 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) frame->pkt_dts = p->m.timestamp; frame->pkt_pos = p->m.offset; frame->pkt_size = p->m.size; - frame->pkt_duration = p->m.duration; + frame->duration = p->m.duration; frame->key_frame = p->frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY; switch (p->frame_hdr->frame_type) { diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c index bbe78605a9..4646302430 100644 --- a/libavcodec/mfenc.c +++ b/libavcodec/mfenc.c @@ -344,7 +344,7 @@ static IMFSample *mf_v_avframe_to_sample(AVCodecContext *avctx, const AVFrame *f return NULL; } - IMFSample_SetSampleDuration(sample, mf_to_mf_time(avctx, frame->pkt_duration)); + IMFSample_SetSampleDuration(sample, mf_to_mf_time(avctx, frame->duration)); return sample; } diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c index c10b20d4f9..bf9a2b1f56 100644 --- a/libavcodec/rawdec.c +++ b/libavcodec/rawdec.c @@ -234,7 +234,7 @@ static int raw_decode(AVCodecContext *avctx, AVFrame *frame, return res; frame->pkt_pos = avctx->internal->last_pkt_props->pos; - frame->pkt_duration = avctx->internal->last_pkt_props->duration; + frame->duration = avctx->internal->last_pkt_props->duration; if (context->tff >= 0) { frame->interlaced_frame = 1;