From patchwork Mon Apr 29 21:14:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48392 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1509:b0:1a9:af23:56c1 with SMTP id nq9csp2271875pzb; Mon, 29 Apr 2024 14:18:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVnQPSyRVRkvEQtJePH9FaTuAeCVDGhlvJ6CIk04TYRX2Fx/WxtD46yYNOuQtNsZryqXpZ9KETS7XKULhCBBtrBsItPMyRPO+RKXg== X-Google-Smtp-Source: AGHT+IE8GTGeOdihZmYRDhzrn0NO+3L9YyRY5K7ZyXLi8tLAvMJRdOoKHTu4q9HBgXjQV+0WPSU8 X-Received: by 2002:a50:ab0d:0:b0:56c:d1b:e088 with SMTP id s13-20020a50ab0d000000b0056c0d1be088mr565085edc.19.1714425497240; Mon, 29 Apr 2024 14:18:17 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t3-20020a508d43000000b0057294932645si178097edt.602.2024.04.29.14.18.16; Mon, 29 Apr 2024 14:18:17 -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; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=HQX+L9Y5; 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 1339868D59D; Tue, 30 Apr 2024 00:16:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04olkn2041.outbound.protection.outlook.com [40.92.73.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4386968D599 for ; Tue, 30 Apr 2024 00:16:14 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XQvKFOGnes6fdhSJ3G9ZxP6z1PzvoX/d2k6+Eb29GYh32kbwndOEKTsqXs79cnn/z2EOeXLN5TLCZxVR3TIgO9d9rVOX9jEggRi7pCruER0NlwdiEtnLdDjMe/NVe2C9vsggYFu3REHdjb2DRpUEX2jtA8CdgcTCA7saek6KYmx7MTYvZBvNKeBEoJCvvSYuTDR/of1T2TItUEv8gh13uI7dxgoKHeycBdZTgFbP2F87SojDsjCv/3b5p2DCYxWoYVe1eYpwsSjzTxizzLSW5E894K15c5KKqG2hDLWKmYQY7gDsLug8l4a/R593DWFHub/g71uE64yloOG/J3Rx3w== 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=Yy3dE6dw0kajLuuuemxyHttA3K40vpZphkUIiz8tL1w=; b=Q2K6SZMLmGcwKQT2pgaOe2zXoWm1pGArSwlFDhiWzLi15CRCG90SjDQR3Zd/tqckzBZFoBLUta6MsginGj/2KTf/FkwqczDSpEbUhLSnyvO11MjBzNLIrcKYkZFx0e/YS9eVzemXX+JVp2f/vXl+ehpOvWPjZ5dRk24D3Hi5ENYz9P1NOUCbvnLH/PX0K5eBsEJ5l0WVNLg8ndDafqrPTMef1E+2TH3ZkgMyb+EA4P7gQzRh7GVot1v+JLsGFVLgzQyeN6IAODYsbDGQUTAiYjGAM5i0sEaRFU3A+EI8bQ8NGR9I5LvyRh0MUsbscgG3zPYo4DoBbu5t8neue4YfsA== 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=Yy3dE6dw0kajLuuuemxyHttA3K40vpZphkUIiz8tL1w=; b=HQX+L9Y5zqFUwgd3dbTHIM2CLghxa85Ovtf2PO/+YOSrluyGPE4Z8tyq4GdlH4tqkueyoI0VlvR1WlsLasEoN2ashQlz0GrDnZ6eNpV0yBZIhj6WFUyD2c1D5Th1u7ak2kVNbN1jzy5Scf/uj9dpNTB/kge1Ws/CfXWXuiGKsl4VCosYEc5HyM9nFCt8r2Cc9m599XxYBQGKpj194FdBEHmayuaRYCQWqR9q9sDCm3A4EK0TQ9tZrbxYENcy9gAOnVIAEJaA2isWNHLIwV7UxIlbgbi9Pn6a6tQTCHOjEQNaf6fpx46pNVQJSrSfBEetoEVlB/CCTdZgaRfeveSUTQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by GVXP250MB1057.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:1b5::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Mon, 29 Apr 2024 21:16:13 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb%3]) with mapi id 15.20.7519.031; Mon, 29 Apr 2024 21:16:12 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Apr 2024 23:14:16 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [aiQ2Mii/C6s/H3qJNvToJlIIAe1uWuYox0qr6Mex8jQ=] X-ClientProxiedBy: ZR0P278CA0199.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:6a::21) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240429211438.3274834-21-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|GVXP250MB1057:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a00dce4-f9ef-40f3-dc2d-08dc68919913 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|440099019|3412199016|1710799017; X-Microsoft-Antispam-Message-Info: jRGCCYEAEAGopXLxDsjBjZ8SrFsyFemwzQrqjAlDRkb0GowRrVJDPOccyyH1b7rI69cqFVadklwg+FmGGhTR0G9oc3EiQexp1M1odIIrq71hGZx/5hVfuM39Rp9wLxRWa0RwAYdHzjXPYUJ6Tc8E0FXqgyvq6sny8aNkN3IG3MN435tE2n4QZ8ugRxLj87ddVdgSOXkzY66NRZNWdnPAZ+UEfL0mW2XvPjin8SW1Y/v0UTpo1QJ9vpMPvR+oowc6MYUlEOqKYwNZdrRkX/JWktdXWGfFmvChSYjsb5PKI2mQOWOkH9X+g52+CvERPsMsa3FTHic5ZfXF6VbuTRr+Ed0dxeLSk2iRRtFQOHdZgSQw8QDkIbHpOhQBnjm0JZxDrtl7s9NhUJfGI3kXaSVU7uZ3LdeKZRrNrUO0oeNOfzSI5YmcCe7eyXXDrrqGAJ6bbYgjnF628ursP1YzE537+2XqHILtrWa1ip/H76/fY9Vu29dAUsYQNq6bkSeFZSF515kSA6Orlv2vbpxRiXG94bQI3FpGUqQSpDRWYFJ8kWyvbVSlvK+KexjH6VUnne/QY+Mu1PB/jk5CAu+5VS/lAPrLAsL2zbZAsu9kPy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xuXFrUoGmg+KRS0iMOh/Sv7nQ+KjCI3i5lDyQ8fW01K19cQGvp5v6VU9WxfPs8I7BWW12ntWzYhZPaZJab/jG5raLk6eNBbmkDYQ8tv9XlJNCSFmfAVfGsuQXo5S3SANnp45fWNmjBqwJkV7kdxR1r9QXSPtloEtxp7QErSoJTMdyBv36sLXU/14Au/7rYrndVLWGRS1CDwyJUiRK/8sbshJCCV7ULtgjqEIc+qkLIw0yth7Lt06e8fPMlaoNkScEVjB+BYI0pKscWka7SHq7geymV5NcuJJfBEu1OQyA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a00dce4-f9ef-40f3-dc2d-08dc68919913 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:16:12.9189 (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: GVXP250MB1057 Subject: [FFmpeg-devel] [PATCH 35/57] avcodec/mpegvideo_enc: Reindentation 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: yh9qbSirZz1t Also try to use loop-scope for iterators. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 193 ++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 97 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 5b0a2edfa6..ce827712af 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1480,129 +1480,128 @@ fail: */ static int set_bframe_chain_length(MpegEncContext *s) { - int i; - /* Either nothing to do or can't do anything */ if (s->reordered_input_picture[0] || !s->input_picture[0]) return 0; /* set next picture type & ordering */ - if (s->frame_skip_threshold || s->frame_skip_factor) { - if (s->picture_in_gop_number < s->gop_size && - s->next_pic.ptr && - skip_check(s, s->input_picture[0], s->next_pic.ptr)) { - // FIXME check that the gop check above is +-1 correct - ff_mpeg_unref_picture(s->input_picture[0]); + if (s->frame_skip_threshold || s->frame_skip_factor) { + if (s->picture_in_gop_number < s->gop_size && + s->next_pic.ptr && + skip_check(s, s->input_picture[0], s->next_pic.ptr)) { + // FIXME check that the gop check above is +-1 correct + ff_mpeg_unref_picture(s->input_picture[0]); - ff_vbv_update(s, 0); + ff_vbv_update(s, 0); - return 0; - } + return 0; } + } - if (/*s->picture_in_gop_number >= s->gop_size ||*/ - !s->next_pic.ptr || s->intra_only) { - s->reordered_input_picture[0] = s->input_picture[0]; - s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; - s->reordered_input_picture[0]->coded_picture_number = - s->coded_picture_number++; - } else { - int b_frames = 0; - - if (s->avctx->flags & AV_CODEC_FLAG_PASS2) { - for (i = 0; i < s->max_b_frames + 1; i++) { - int pict_num = s->input_picture[0]->display_picture_number + i; - - if (pict_num >= s->rc_context.num_entries) - break; - if (!s->input_picture[i]) { - s->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P; - break; - } + if (/*s->picture_in_gop_number >= s->gop_size ||*/ + !s->next_pic.ptr || s->intra_only) { + s->reordered_input_picture[0] = s->input_picture[0]; + s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; + s->reordered_input_picture[0]->coded_picture_number = + s->coded_picture_number++; + } else { + int b_frames = 0; - s->input_picture[i]->f->pict_type = - s->rc_context.entry[pict_num].new_pict_type; - } - } + if (s->avctx->flags & AV_CODEC_FLAG_PASS2) { + for (int i = 0; i < s->max_b_frames + 1; i++) { + int pict_num = s->input_picture[0]->display_picture_number + i; - if (s->b_frame_strategy == 0) { - b_frames = s->max_b_frames; - while (b_frames && !s->input_picture[b_frames]) - b_frames--; - } else if (s->b_frame_strategy == 1) { - for (i = 1; i < s->max_b_frames + 1; i++) { - if (s->input_picture[i] && - s->input_picture[i]->b_frame_score == 0) { - s->input_picture[i]->b_frame_score = - get_intra_count(s, - s->input_picture[i ]->f->data[0], - s->input_picture[i - 1]->f->data[0], - s->linesize) + 1; - } - } - for (i = 0; i < s->max_b_frames + 1; i++) { - if (!s->input_picture[i] || - s->input_picture[i]->b_frame_score - 1 > - s->mb_num / s->b_sensitivity) - break; + if (pict_num >= s->rc_context.num_entries) + break; + if (!s->input_picture[i]) { + s->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P; + break; } - b_frames = FFMAX(0, i - 1); + s->input_picture[i]->f->pict_type = + s->rc_context.entry[pict_num].new_pict_type; + } + } - /* reset scores */ - for (i = 0; i < b_frames + 1; i++) { - s->input_picture[i]->b_frame_score = 0; - } - } else if (s->b_frame_strategy == 2) { - b_frames = estimate_best_b_count(s); - if (b_frames < 0) { - ff_mpeg_unref_picture(s->input_picture[0]); - return b_frames; + if (s->b_frame_strategy == 0) { + b_frames = s->max_b_frames; + while (b_frames && !s->input_picture[b_frames]) + b_frames--; + } else if (s->b_frame_strategy == 1) { + int i; + for (i = 1; i < s->max_b_frames + 1; i++) { + if (s->input_picture[i] && + s->input_picture[i]->b_frame_score == 0) { + s->input_picture[i]->b_frame_score = + get_intra_count(s, + s->input_picture[i ]->f->data[0], + s->input_picture[i - 1]->f->data[0], + s->linesize) + 1; } } + for (i = 0; i < s->max_b_frames + 1; i++) { + if (!s->input_picture[i] || + s->input_picture[i]->b_frame_score - 1 > + s->mb_num / s->b_sensitivity) + break; + } - emms_c(); + b_frames = FFMAX(0, i - 1); - for (i = b_frames - 1; i >= 0; i--) { - int type = s->input_picture[i]->f->pict_type; - if (type && type != AV_PICTURE_TYPE_B) - b_frames = i; + /* reset scores */ + for (i = 0; i < b_frames + 1; i++) { + s->input_picture[i]->b_frame_score = 0; } - if (s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_B && - b_frames == s->max_b_frames) { - av_log(s->avctx, AV_LOG_ERROR, - "warning, too many B-frames in a row\n"); + } else if (s->b_frame_strategy == 2) { + b_frames = estimate_best_b_count(s); + if (b_frames < 0) { + ff_mpeg_unref_picture(s->input_picture[0]); + return b_frames; } + } - if (s->picture_in_gop_number + b_frames >= s->gop_size) { - if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) && - s->gop_size > s->picture_in_gop_number) { - b_frames = s->gop_size - s->picture_in_gop_number - 1; - } else { - if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) - b_frames = 0; - s->input_picture[b_frames]->f->pict_type = AV_PICTURE_TYPE_I; - } - } + emms_c(); - if ((s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && b_frames && - s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I) - b_frames--; + for (int i = b_frames - 1; i >= 0; i--) { + int type = s->input_picture[i]->f->pict_type; + if (type && type != AV_PICTURE_TYPE_B) + b_frames = i; + } + if (s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_B && + b_frames == s->max_b_frames) { + av_log(s->avctx, AV_LOG_ERROR, + "warning, too many B-frames in a row\n"); + } - s->reordered_input_picture[0] = s->input_picture[b_frames]; - if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) - s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; - s->reordered_input_picture[0]->coded_picture_number = - s->coded_picture_number++; - for (i = 0; i < b_frames; i++) { - s->reordered_input_picture[i + 1] = s->input_picture[i]; - s->reordered_input_picture[i + 1]->f->pict_type = - AV_PICTURE_TYPE_B; - s->reordered_input_picture[i + 1]->coded_picture_number = - s->coded_picture_number++; + if (s->picture_in_gop_number + b_frames >= s->gop_size) { + if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) && + s->gop_size > s->picture_in_gop_number) { + b_frames = s->gop_size - s->picture_in_gop_number - 1; + } else { + if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) + b_frames = 0; + s->input_picture[b_frames]->f->pict_type = AV_PICTURE_TYPE_I; } } + if ((s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && b_frames && + s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I) + b_frames--; + + s->reordered_input_picture[0] = s->input_picture[b_frames]; + if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) + s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; + s->reordered_input_picture[0]->coded_picture_number = + s->coded_picture_number++; + for (int i = 0; i < b_frames; i++) { + s->reordered_input_picture[i + 1] = s->input_picture[i]; + s->reordered_input_picture[i + 1]->f->pict_type = + AV_PICTURE_TYPE_B; + s->reordered_input_picture[i + 1]->coded_picture_number = + s->coded_picture_number++; + } + } + return 0; }