From patchwork Mon Mar 4 18:06:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 46791 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d808:b0:19e:cdac:8cce with SMTP id iv8csp159229pzb; Mon, 4 Mar 2024 10:07:41 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVkFKo36PzGxD77oMxqMuZSEa+/t5wQafef37klqC2UklGW/6GTwa4iRMYF6dvtGC6x17ED5ozyvpT3slRZXewXaiQpOYd05AtfcQ== X-Google-Smtp-Source: AGHT+IH1CSC9PVXR1PXx91jKr8Ju+dBxZY5uCR3709nOmG/3QWFyA+Re17JTxIYbq3hyjbMT3bTE X-Received: by 2002:a17:906:3b0b:b0:a44:b965:63e7 with SMTP id g11-20020a1709063b0b00b00a44b96563e7mr4005786ejf.2.1709575661069; Mon, 04 Mar 2024 10:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709575661; cv=none; d=google.com; s=arc-20160816; b=reEwkG+NU9IY3pw80Wl8GhtRPjvzKWg+3eNi65/GwsT+NLdkfP9pZEOyAiQAqBim3g xHBqUhiNFETham6M7kITiNsV0bde57A3C16kDY87z152xu76oLrOEtEPa892R+IOlwPE VKIjG4lc3or8uc6AiERhjnk4hVq3GIJTS52QaZ8oNVMNMdk4Mj7RxUftm44InzYuXtcB Y6RnRdGUeDL04rvV3MUP30eQsHqywKnJ1P0sqzolbvJIsw/xdPv4qWshHXFUw2WbkYvq 0CiE1dWG2zZPPWxLRrICG7O9Hv+jHupZc4vXwUl6mojJgMzMj+5sWl1HIeEf+yQ5kVfj q1Cw== 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:dkim-signature:delivered-to; bh=NLy/QXK7pcxB7vsZe4+gtJNPbZ/QMQnEGSdf7dnMWw4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=lWxRbMHptldiUR3qchbDbqUumqL7GNa8SORv8g2mAt+z1lgRTRh0qG0y/DpbgPfOSs WryTYyR4pDC5g5c01m6TrohXzw0j24sMqFXFGqORGxXsddTB8A5I89haoOJfDRiId+67 PwxEwT/RPm3I0bDCE+zmxhvN6UWct5CgxV9twJJhJOZPiDuvJUmuuFNH/F3oFvh125mh p169zOy6tjM9gcl0FUwTEyp2T/UI0XKs1TA/1r1NcOijYAEi1+TwXxGx5PiIuSyjswKg cTeSWl5pbt7uPsBJtMQlyqw5UbH6JiCJ1UwpD+vd4mGdz+VOBjWP900DjV1DRc151YCi dcaw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=fFsYASqB; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id oz32-20020a1709077da000b00a45523b20bbsi915891ejc.347.2024.03.04.10.07.40; Mon, 04 Mar 2024 10:07:41 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=fFsYASqB; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ACF6A68D4BF; Mon, 4 Mar 2024 20:07:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7BB4F68D362 for ; Mon, 4 Mar 2024 20:07:07 +0200 (EET) Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5ce2aada130so4214473a12.1 for ; Mon, 04 Mar 2024 10:07:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709575625; x=1710180425; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jQG475u1UYaFAcurlIG6Vs4Zvx9vqPmzxpkVU/qKI2w=; b=fFsYASqBeHkNgMrYp1VnO/g9sGWqfoyQEoAqV9CqEHUbwBOeUvpU60E3Fy5Q47FqJL l0+A243oYyIji+GOr+kqC8nLdCMumXwhw3QSrbBdTUxiQPu/g4nLHxOoZnPeMCv2PQgL SizOyLkjPeJRgyb6/cEX8VX7GES45IScBNH4zQ4B0R+q7uxhEEhEcqnmlPQbzIfmz8qH B4zXG/tCUQ4DfUouc1xBY/OX13HSlE9oaZRIzmHbLSq21qSmkQbh02HhPUh+29RUalK1 o/s6P3kkfB5EXe6Lgau57PRgA5LRN1Y7xnrNxdPQWSA8lwZ5iWsHLhGzcmEFhd2sX4h7 xLRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709575625; x=1710180425; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jQG475u1UYaFAcurlIG6Vs4Zvx9vqPmzxpkVU/qKI2w=; b=CGLFQTNtBvE3LJq2EMm9r9MclbsXKkL5KwxkWrrwmiS+Wq7JY0XEHvXHUFAbLkBwb3 sfxCzqhBGz2jjn4E9stDQAzutVGbVOQTqEIyzfqtLxKCZhewnK3fvUOXBLfj4qfJSASe L79RJ5Rzl9Of7MSgA7IiuCMo1/abn2ijO34JyGNwnSQwUD3t7SbEvrTa4IP8evn6i00R LomTiIwBmsVOUXVHI9b2L1x/GCSeerSpXzMggP9mZ61SMLAzoUjyJsYiUH0W6w3CJtCm BjmSf2NeUQPtLLk0mIzGyPFFyGs+AznbApEIf3nywyK+rxZqGKj4LToNRzTqHhJHIoVm BnEQ== X-Gm-Message-State: AOJu0YzVjEXH+tzo3PmsG/sFIReTJU8z4RNe75gQa+64CKLgVzxzxdEX armeSEDawlHbulSE9rt29F5fmOLEeq6B9Lb/ewMTos1BAdgpCXfUHPVrs7RG X-Received: by 2002:a17:90a:f007:b0:29b:1c83:4e06 with SMTP id bt7-20020a17090af00700b0029b1c834e06mr6970961pjb.36.1709575624874; Mon, 04 Mar 2024 10:07:04 -0800 (PST) Received: from localhost.localdomain ([190.194.169.124]) by smtp.gmail.com with ESMTPSA id gx15-20020a17090b124f00b00298ca46547fsm8089145pjb.36.2024.03.04.10.07.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 10:07:04 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Mar 2024 15:06:13 -0300 Message-ID: <20240304180613.7280-4-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240125134425.374-1-jamrial@gmail.com> References: <20240125134425.374-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc: move AVCodecContext.pts_correction* to DecodeContext 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: vgBrKoH+ge+g From: Anton Khirnov These fields are documented to be non-public and are only used in decode.c Signed-off-by: James Almer --- libavcodec/avcodec.h | 10 ---------- libavcodec/decode.c | 37 ++++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 035f08a8e0..fb0612ed26 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1860,16 +1860,6 @@ typedef struct AVCodecContext { */ const struct AVCodecDescriptor *codec_descriptor; - /** - * Current statistics for PTS correction. - * - decoding: maintained and used by libavcodec, not intended to be used by user apps - * - encoding: unused - */ - int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far - int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far - int64_t pts_correction_last_pts; /// PTS of the last frame - int64_t pts_correction_last_dts; /// DTS of the last frame - /** * Character encoding of the input subtitles file. * - decoding: set by user diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 6579c9cbbf..c20b2ebdb3 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -60,6 +60,11 @@ typedef struct DecodeContext { * The caller has submitted a NULL packet on input. */ int draining_started; + + int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far + int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far + int64_t pts_correction_last_pts; /// PTS of the last frame + int64_t pts_correction_last_dts; /// DTS of the last frame } DecodeContext; static DecodeContext *decode_ctx(AVCodecInternal *avci) @@ -240,24 +245,24 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) * @param dts the dts field of the decoded AVPacket * @return one of the input values, may be AV_NOPTS_VALUE */ -static int64_t guess_correct_pts(AVCodecContext *ctx, +static int64_t guess_correct_pts(DecodeContext *dc, int64_t reordered_pts, int64_t dts) { int64_t pts = AV_NOPTS_VALUE; if (dts != AV_NOPTS_VALUE) { - ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts; - ctx->pts_correction_last_dts = dts; + dc->pts_correction_num_faulty_dts += dts <= dc->pts_correction_last_dts; + dc->pts_correction_last_dts = dts; } else if (reordered_pts != AV_NOPTS_VALUE) - ctx->pts_correction_last_dts = reordered_pts; + dc->pts_correction_last_dts = reordered_pts; if (reordered_pts != AV_NOPTS_VALUE) { - ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts; - ctx->pts_correction_last_pts = reordered_pts; + dc->pts_correction_num_faulty_pts += reordered_pts <= dc->pts_correction_last_pts; + dc->pts_correction_last_pts = reordered_pts; } else if(dts != AV_NOPTS_VALUE) - ctx->pts_correction_last_pts = dts; + dc->pts_correction_last_pts = dts; - if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE) + if ((dc->pts_correction_num_faulty_pts<=dc->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE) && reordered_pts != AV_NOPTS_VALUE) pts = reordered_pts; else @@ -575,6 +580,7 @@ static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame) static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) { AVCodecInternal *avci = avctx->internal; + DecodeContext *dc = decode_ctx(avci); const FFCodec *const codec = ffcodec(avctx->codec); int ret, ok; @@ -630,7 +636,7 @@ FF_DISABLE_DEPRECATION_WARNINGS frame->top_field_first = !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST); FF_ENABLE_DEPRECATION_WARNINGS #endif - frame->best_effort_timestamp = guess_correct_pts(avctx, + frame->best_effort_timestamp = guess_correct_pts(dc, frame->pts, frame->pkt_dts); @@ -1672,6 +1678,7 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) int ff_decode_preinit(AVCodecContext *avctx) { AVCodecInternal *avci = avctx->internal; + DecodeContext *dc = decode_ctx(avci); int ret = 0; /* if the decoder init function was already called previously, @@ -1719,10 +1726,10 @@ int ff_decode_preinit(AVCodecContext *avctx) } } - avctx->pts_correction_num_faulty_pts = - avctx->pts_correction_num_faulty_dts = 0; - avctx->pts_correction_last_pts = - avctx->pts_correction_last_dts = INT64_MIN; + dc->pts_correction_num_faulty_pts = + dc->pts_correction_num_faulty_dts = 0; + dc->pts_correction_last_pts = + dc->pts_correction_last_dts = INT64_MIN; if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY && avctx->codec_descriptor->type == AVMEDIA_TYPE_VIDEO) @@ -1801,8 +1808,8 @@ void ff_decode_flush_buffers(AVCodecContext *avctx) av_packet_unref(avci->last_pkt_props); av_packet_unref(avci->in_pkt); - avctx->pts_correction_last_pts = - avctx->pts_correction_last_dts = INT64_MIN; + dc->pts_correction_last_pts = + dc->pts_correction_last_dts = INT64_MIN; av_bsf_flush(avci->bsf);