From patchwork Sun Jan 30 06:27:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 33925 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp1771354iov; Sat, 29 Jan 2022 22:32:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+uF+5rqF5+lP0eZv/qyeZC7rUFtqLufjFH3Ny0dUMXM+pdD+UPbF/xVxImu3ywLK7KItD X-Received: by 2002:a17:907:924d:: with SMTP id kb13mr12687109ejb.507.1643524332547; Sat, 29 Jan 2022 22:32:12 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qf38si2507396ejc.14.2022.01.29.22.32.12; Sat, 29 Jan 2022 22:32:12 -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=@outlook.com header.s=selector1 header.b=KwD9CSCn; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 820C368B290; Sun, 30 Jan 2022 08:29:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05olkn2011.outbound.protection.outlook.com [40.92.90.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 32A8068B205 for ; Sun, 30 Jan 2022 08:28:54 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W6F0ysN1Kyz3o1ubdHtNPVK6YveCRlqlLv5NeL5TSH5kR4uTmiWoAiwcNh49FhDwjvDN69PWKdUDn7UZGJL4RjkK8dKQwDEg8bWREbV3wQhvntPRWSPnsmox1krG6C2k/0S89wNTjlxvPhyO1f7sLEOUaHFNhRgG+7lJnRikfqyCkg7Jq+EjXkVh/yc865Gwy3qYqo9wyiUjcGYpZeOJkMuvSjHpN1ZXJnNfAoGci9dLXlDiYI0KU2NKu8TGdX8x5gG5RUzUzqE4b7en8ST1PdTgi/XcsZYIqf1+n5hGiOWZedleuSVg7J/lB+/QyxQsqPvbqFlHOylviqgb8LaIWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yBtA/7GQtX1/AiaXz7snALZF2nkIKNhwi+7mGioRO2w=; b=O76hPu3pUhLV1Pxvl6dZcIF+NF8b8YeIymHO28UeAumD5FXWl7YgTCMpmqupH/Kcuc+NgMTwKpa+tOpHa9zVabMYCvu0DVBiB1sFpXRBk3K9wynMbhb9O4u6fFOteF5AjTbeaGmVowpt0g5BsWYUz3iSsaJ6EPyx3GcfeDwVGILiH0jSW1q1jcOV91Soe1eUx0B8Kewol+iNcns7wmZ0YTzKMsPF1RNOHSg+OTuRJySAPvXmfvgpx03a0oYUXusOaDxpF7V+f5YjOIuOkENALyf+VrH7LTKuHKPXApLDPv49mpcAJA+3ZHxokknmBwDMi/ITm+6uWLd2KPJ/PMi0OQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yBtA/7GQtX1/AiaXz7snALZF2nkIKNhwi+7mGioRO2w=; b=KwD9CSCnRA/LqvkI1r6L8Drb/FM0fHIX3HU7oqju+yYvjYafgqzEjXE+/YiXjGY1F7h92Z7CqKbfn8ArnmarfxCeJ9aK79bNbcUoWK7DlkPcjA79uvih27Gt5czifgNjFl8qiIj6kujQMDPUihBff2IyvJBh9xOrLFL66ba+6Hr7oEKsLLfY2rhtfDp2qKeAKV9mBBd5g7CbJbaUSd/LE6jAbjlPAYAAI1PstTmo4UU5OdwSYshiWFUgCpxz7PGtNcAO977LYiHutbn5zPjt5jleW5WrW78Uy9kFe2i9DAtxazNjcfe6zT0Er6eiYGCDLF7w5yylXt+nyyrwF5nXqw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by PAXPR03MB7666.eurprd03.prod.outlook.com (2603:10a6:102:202::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.20; Sun, 30 Jan 2022 06:28:53 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%6]) with mapi id 15.20.4930.021; Sun, 30 Jan 2022 06:28:53 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Jan 2022 07:27:33 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [q3TUB346QO2uN9GVUtjtWW/YA9wdDw3O] X-ClientProxiedBy: AM6PR10CA0044.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:80::21) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220130062749.936489-24-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95786e31-34a2-4177-df24-08d9e3b9c925 X-MS-TrafficTypeDiagnostic: PAXPR03MB7666:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dM60SvNw0KmPfWspMVBFfz8pyeaNNWEFRpkmpNbyBVLJjhckCb74AISWK7MqO7hk91btluLEFLZkGvnpSa7bYfNHxjb5H2N2LpSkg35f30kdm+FPCffveKHde+VRPtsOYx3y7hw2RYeXwFPLyDdfH7Kamc86OM3U9DEYg5Zk3cVmOat4OP+Ej9NuTV4JhNdlQ9l6kxKenHGHYPLSNEnc/w6DV9FnTANTcg8YjHGeUeisO4vT5PJ/N/R775+Sd4SqrO0B3aGa0iwxhuaV+EYrk8zcoUF9Xscm2XvmPcXBJzGpO20J6kZGN30ljW5fNlD77qTk5A+kDkoCyN1R24rnH/+h0R0zS42mOwBbybpHGaWKNYiYu2nZ0yDcrxAZAUjU2FE36gg1jHzWCDgdh20LmZavdsajIdGRkYeLKKZjvcId/UzPI3MUvOawjyIM1lFm2mPTbkhBZjPa7jBSQf0uu+A4nJkcoGwQRJ8cx2qH1nglexH36tjZbY3bVh8D/7ZjmLNRv2tMRLtPMdU6Xujy+mcRuxf7ugUh0SAxbHw5WSsR3LLutOVOnwdIWY9JQGFo X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mbRP+oT1t424qnQ2RaNAjx2daEI3lL5vGVnKLUBdlTDRWzfDaiJKgTqoYQGgXpTW17syaksJICZfKE+mz8Wp9wBjy5tWRFHc6Dq5GTWXvn7RfwyHsNjKcyAwKGTra3r1t8D3Cxajo6Ldgf7KUCxkJfTFfx2k9PoUKMbyM2TtaHCTLXXJV7kc1iIOQe1LZBPr/MeUB4Wx2JOdMh5j9mNxULo6Un5oDI4XbGNxWER10kdj+I++IqaGdCYlHrEKwF2DDk0DPvnHvJ+xxMlX45I21+mwHdGiOTDR5uyqvmWOnTKUbU1vR7WJBwWDkx4C6Dp4dQis3//snDBDqJPHiED9reWD++qjYGMAJ9/dCrwSxJZOVJQuzWrHfj+OcMkOqlpbBNQ+kjv28PXCtzzc7+VHPkY0yvA6K89PLTVQWCovKUv3eSfkcss3o/k5rvHHd5KVS3MYeu/e9B92Aww9wjUjOc06K7lsRwkPUIWy8/JLsw2JMgE0AQjuHZnw4r5QrHsXwjzJmYJIsewJw7ETwEc0hczNZz1LpbQoJsRosNdE9+y1u1hlBUp61dolZq4/nWdlXAXQ2PzfZuCwNpshSNtu04eCf+YK1QEv12iHShVZxw+ZmUSvNyZfOUbJEoY28VNBcwFqjgdjqAhXMD92VIh+iBvqlqHhu7K7FBMZDgVDyuc48Do5iyM1WD5YifsbPd67t/prHTKmzDwmMM5ySh8cqErm8poB1DaAmYrGrA2H/MeXR84EjiQ5iUxNzILfg5BjhtDBdi9PXAU343uaJw/vdA1ZqsV8clpnVoUEaKmXT2vE0h2zgzqmL3FnoIBwrCOTGl3GCJUAh6qN7DM4vJFpGtbwWA2qOn4D0Hugufwg863Opudt1doLkcOg/Bu5DBGdRYn9KAalZ1uwX+tQYpexkxlEW8dmkysAznd08yobv3PMKkP445lohvZr/xGdmxIMwFDRckrA5munq2ojCVaJlg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95786e31-34a2-4177-df24-08d9e3b9c925 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2022 06:28:53.3574 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR03MB7666 Subject: [FFmpeg-devel] [PATCH 25/41] avcodec/mpegvideo: Move pts and dts fields to MPVMainEncContext 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Nay8bu1CPTKe user_specified_pts, dts_delta and reordered_pts are only used by the main thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 10 ---------- libavcodec/mpegvideo_enc.c | 22 +++++++++++----------- libavcodec/mpegvideoenc.h | 11 +++++++++++ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index cab3abcc77..a334acb3aa 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -121,16 +121,6 @@ typedef struct MPVContext { Picture **input_picture; ///< next pictures on display order for encoding Picture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding - int64_t user_specified_pts; ///< last non-zero pts from AVFrame which was passed into avcodec_send_frame() - /** - * pts difference between the first and second input frame, used for - * calculating dts of the first frame when there's a delay */ - int64_t dts_delta; - /** - * reordered pts to be used as dts for the next output frame when there's - * a delay */ - int64_t reordered_pts; - /** bit output */ PutBitContext pb; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 9477a02ae1..9b05b44d36 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -389,7 +389,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n"); return AVERROR(EINVAL); } - s->user_specified_pts = AV_NOPTS_VALUE; + m->user_specified_pts = AV_NOPTS_VALUE; if (m->gop_size <= 1) { s->intra_only = 1; @@ -1021,8 +1021,8 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg) display_picture_number = s->input_picture_number++; if (pts != AV_NOPTS_VALUE) { - if (s->user_specified_pts != AV_NOPTS_VALUE) { - int64_t last = s->user_specified_pts; + if (m->user_specified_pts != AV_NOPTS_VALUE) { + int64_t last = m->user_specified_pts; if (pts <= last) { av_log(s->avctx, AV_LOG_ERROR, @@ -1032,13 +1032,13 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg) } if (!s->low_delay && display_picture_number == 1) - s->dts_delta = pts - last; + m->dts_delta = pts - last; } - s->user_specified_pts = pts; + m->user_specified_pts = pts; } else { - if (s->user_specified_pts != AV_NOPTS_VALUE) { - s->user_specified_pts = - pts = s->user_specified_pts + 1; + if (m->user_specified_pts != AV_NOPTS_VALUE) { + m->user_specified_pts = + pts = m->user_specified_pts + 1; av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts); @@ -1887,10 +1887,10 @@ vbv_retry: pkt->pts = s->current_picture.f->pts; if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) { if (!s->current_picture.f->coded_picture_number) - pkt->dts = pkt->pts - s->dts_delta; + pkt->dts = pkt->pts - m->dts_delta; else - pkt->dts = s->reordered_pts; - s->reordered_pts = pkt->pts; + pkt->dts = m->reordered_pts; + m->reordered_pts = pkt->pts; } else pkt->dts = pkt->pts; if (s->current_picture.f->key_frame) diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 3deee6d5fb..227701b3e3 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -43,6 +43,17 @@ typedef struct MPVMainEncContext { int gop_size; int picture_in_gop_number; ///< 0-> first pic in gop, ... + /** last non-zero pts from AVFrame which was passed into avcodec_send_frame() */ + int64_t user_specified_pts; + /** + * pts difference between the first and second input frame, used for + * calculating dts of the first frame when there's a delay */ + int64_t dts_delta; + /** + * reordered pts to be used as dts for the next output frame when there's + * a delay */ + int64_t reordered_pts; + /* bit rate control */ int64_t total_bits; int frame_bits; ///< bits used for the current frame