From patchwork Tue Feb 1 13:06:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 34025 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp611036iov; Tue, 1 Feb 2022 05:20:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxf6tQo5WUMDK/TLNLnCCcjjwM54xE4iccCXrLFd1qsoRD17e+GCT/PMUzFYO6FYoq5IAcL X-Received: by 2002:a17:907:7203:: with SMTP id dr3mr20240691ejc.185.1643721647700; Tue, 01 Feb 2022 05:20:47 -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 f7si9216426ejj.794.2022.02.01.05.20.47; Tue, 01 Feb 2022 05:20:47 -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=jGGDDhmy; 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 63E9A68B42B; Tue, 1 Feb 2022 15:09:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074018.outbound.protection.outlook.com [40.92.74.18]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42CC068B3CE for ; Tue, 1 Feb 2022 15:08:37 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P/bc3RZxDfjj2Ul+kPuNWQjqdBSiAYp923MiMUZ+gjWOjwogL4weT77okDDWXoXWxp+uzsYkUhJri6v0Pra1TXH4wrH0qRJRPxClmcJBnZVmRGy3WZy0wQI9fBSbuqt/F3Ukk3JrDC0OzmkK6gOVDqt0XveiKroF9BF0mLGs3rsxPpEc2JbPV7Ye1MdNU/MTxooyAo9JolGmVIn70pvxxM5yzf3x986AHVHZ0xO4zbSdwBpDQspJEJV11iZzyXbQ5mrhSaxtBnxTztrRdJu/N4ioqPk71UM1mfQtcgwz8nAhqMIfzTO1V1D2E26cImHCRmqyVNmtOlBBKyJO7QXADg== 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=8RBDcRLZDeYxwr8s8k2rBsf9w/l/ZUOxoYyKpS6QGTw=; b=Hkll809azTvwG6TGzi5v+1QyYb40Wp8Zr5dPI+773kJjrr8onMilqJYfnQcMnLr39y2zI281Gm4fa9I5903yta84SdK72G6xm8PqdEbXjq2ozyBPMOa8nT6wzS6JgNVRAqol2sKAewzIrX8iWZy3Zsqy1PjWsKdyorMEooWGAxKwNQCdqTQijqTSllpAvLI/yzhk6HnksL62Bu+FotyarOtMY2q00qBfxf9yD+2PZeSDw49nRzkmDAHqRERax3yJyPHyP2XaakZHoOGIEKwj/XYFWurBvn8YBg+dWMMPqdQ2ukNSXu5VanV6zjYNg/H+xRVSQyvjBxnrgXFMZEJqpA== 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=8RBDcRLZDeYxwr8s8k2rBsf9w/l/ZUOxoYyKpS6QGTw=; b=jGGDDhmy+okicMc/dgBsUuSzoV8+iiVZW9g4DoxRCGqg54kCeJnrxV0kF1A8MNXDT9Tk0s2p7xfXgMZ6fsdnkXG2HKbitZ+nZMNV//Ky3kIAOrn3UzpKSU6T5nyJVrSud5Q7XXTV51cuBMJnXIbbonp276R/EjRmJl0yT89i7BytzdUwZKb+0m+M77s2g4I2B4nZOM5NKeytIvXjFVYvh+zKQw5rQIopczm2qAmJwcrWWFT4mBwxUnTN5mdUyxtXLCm8E9DG2A8liLDsb+BHJni2Gn/FgZ6bjRbkRfJNVGhNwl9/W4kPo/YWa2CjTIimeQUGj9E64zZdczf1AdBupA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by HE1PR0301MB2330.eurprd03.prod.outlook.com (2603:10a6:3:73::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.22; Tue, 1 Feb 2022 13:08:33 +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.4951.011; Tue, 1 Feb 2022 13:08:33 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Feb 2022 14:06:32 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [INqR+Xfcm2cnOTBqqPMiZW5uGIBYEWHo] X-ClientProxiedBy: AM6P195CA0092.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:86::33) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220201130706.1420875-34-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af118a8d-b669-4e6c-a2cf-08d9e583e1ce X-MS-TrafficTypeDiagnostic: HE1PR0301MB2330:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Yjq6IDouTrVkbqZ+v2Tt9JmP9t+YhdMkHKrUgaZLt0xy8dd0rFux+M3agfVJW2bp2ObhcAz09AB4BFphNA90yUi6TiThqFR+0mAKeD92iCBp8vGetbcY/S/TLEiHcPEEyT4Z19WRO/FsnCc4FBGOKkgshBlnMLZZDar/ILZKn2+v0ZZdYnlrM1i2NXy4ODNImsqCzf6TFSVDGbC5jLPdCvO2OCQ2wRFmQRqz4C1kGZ/YilYEu9ntFaXfakAbyA4HM6BGBTdAvKMuzU04MUxzLQ83NFbeq3bUW0UPjbRhHOw6ZEIsPquVkVDon8QEteqENj6TCRE8EYMcX9Y7SK6WPrwdb/evD7lrjRzI6CVX1qi8Ivj3WLXoiHd0v70YeQfgYXlZoodcMkSZ2P1rpX02oUcqKDzerW/9dB1IZMBcUPeS9/bTQLGiNSoFfEkU9exBQlUNbZDWFmC9ksz61CoLKN8SKzkUPUOVG1rIIp6fnyMI9WWapXUP2zKLM3j9Du3uosqOBLX8doOOIiIbI9lzi3Pg/9DYbzw9f3A7w+jOBcUpLj58O+MS1HxCm96kmODn X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lYDa8rBFWjJQFWvVgqD8uhZI+QyIWp94nd6V7qg7bpusU6q5nVeAKv5Kz5PNlbV+LJeLrFQJNXUJJBNx50wnQXRYcgmL5o3vAX5rQcCkqsL1dvx89gQKNsS/DRTKddMeSVx3HJ+GdUbTx4NrY7g5+EB6+zkrsBdLyP4FqolEVSJ1osC3U23jJwTJWrClJCQ1mvvLy7ao5OpX/bqD5GMf/EjRtmHdMJK4U4HpfUASYwXn0OTOddqkEv8m5FS/RACODRWJdRdNOvo0jYHDwUybITUsWOJtSA8wb0idhQJJTKUukvb0MaNNhtkxHt1ssP/5VvJuuv6+yuao6MhrGNhftKlPjsLJngL41qrxpPA5Hnzf2hRORChMu+71msYKqWA+keiR0uaWp3YCKRNYxS+k67JxgaTIHzCfpANNojNbhllL02awGZcs6i/uXIZEFLbYPRXFJmxLCpix8vHfF5pK5A0dqCOP8hUs8P1W0Vr+IJWfJC0Byqbu60w+xZsC1WYvJp2jJpzqeNzmmr+PcXn6x/6XKlQlwbBy45rfofci+YrvoWpzMbQ6Kw0m5cLUot3PFQxXt12bVJ0dFS7nN2iNayCN+eiGfYvgiGtSqoRddUgRGoFCGnXb2yAIjmRjZJmW9Smh/PAnfGxXccGAbZm2C6zbbQySGhOdKedWrlszV/KtY1VsvMW3b5Mk4ZKpxTiIRkDGR0UW/vmY25ZLf5nHl0OnlOzwCaEDU/3fUQGlQ/VJlRQ/ZJbtXiZqcJ+yZU4owTatQ5qqVYlt1rRFrJN+SH2+SDylxTvtpklwBKtTOt7yF6OcOtfY9r8RvTcEKjmuZ0aGR0AznRRDQ34Tc1jMKx1jjILfADbplOsbsN/eCPXykN0sd1wBfsNcXXu7bs/bEyHPpH99sObF2UG0WW5xemzG92IzdlJNx1BarfPu23tmZvDHW1s+svUPQRQ4lu7x7ie5FZgsyiID1gtZ4wHufA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: af118a8d-b669-4e6c-a2cf-08d9e583e1ce X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 13:08:04.2465 (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: HE1PR0301MB2330 Subject: [FFmpeg-devel] [PATCH v2 35/69] 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: qavdqnR7xGm9 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 08c795ba17..3dd04d6e82 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -118,16 +118,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 86f2b5fcb1..4f64fd28a7 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -391,7 +391,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; @@ -1023,8 +1023,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, @@ -1034,13 +1034,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); @@ -1889,10 +1889,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 a177b2d6c6..836fa2eaa3 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -45,6 +45,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