From patchwork Wed Mar 27 01:38:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 47514 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp321957pzb; Tue, 26 Mar 2024 18:38:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUXKGXIPT8tUQf7JC0IrzVefucRS/g7BgBcQgXOj/w/Bx29EfSNcG+Xhl5jz3YUyTPqYJO0Pbtpn3o5UGyZHfZDAODetALnelxeRA== X-Google-Smtp-Source: AGHT+IFhjk2ovgk/oFYiaHr793OiYYoUser7E1uejfueyhQMQdQjptPLA5ZVLdJ/b/ZccjL7eChO X-Received: by 2002:a50:9b0b:0:b0:56b:ec02:a146 with SMTP id o11-20020a509b0b000000b0056bec02a146mr7403348edi.1.1711503536068; Tue, 26 Mar 2024 18:38:56 -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 h24-20020a0564020e9800b0056be932cddfsi4099129eda.181.2024.03.26.18.38.55; Tue, 26 Mar 2024 18:38:56 -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=STwl7e8P; 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 ACEB268D6CF; Wed, 27 Mar 2024 03:38:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04olkn2075.outbound.protection.outlook.com [40.92.73.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6E24968D6C3 for ; Wed, 27 Mar 2024 03:38:39 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZzzYPHTs5rKalFWfNd5YmgnQTE3oxWYFowNq6MPUUfDKJuC983vTzdOjKemkR87k/2ZeU5w6Nd7NNtJGZC9sNfpLC4I6fgnJGEFMTl76Zm3Lbkhfo/XZ/65tLu1wb2RBfFaxkit1SzgIBBwGmdInXydsIRnlVBsoe997IHgaxZ5Pg4WQV6IUhwt2RnTSSwErwZRKOAc5HergVktxq7mbEVv1byKDwYGNRakm2vIOc65HnCT1rVjukKOGizZ0naTS6rBu1Lai721Kctse1AT2xnHfFA1TsIvkF6KvXEc3oXI793gmWNiIwDu8abYDMd8ffVMOj2CM3MFrT9HMyBGJZw== 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=LmtqnqeLIlIYBB3czTyjh1QOqw2Rdbp0eSJVGV3vTXY=; b=jt3v4jDTHRpng9g5J6joXDOnHpURC11S16zClEZvamd1iWgpJtcCl+8C1598/5QBd2Zei19eK0tSlTHmMeLwgv3Qfl7RN5XTCvjMP2h5fCW5C1/nkx79VZTKARRhlbnGZZ0ONuGYzRJoaoAs9PL6UxiTehEcmeRa/DclPq8wGToFzRRsC/8n3KddZZoAsBPZbMbdGB5xVqRcagjdEGOMTygTvmZ1UW5pvMHDFfeaEHGfwbqj2AiEzMu3An8HtAONL5wrI6nuHzOvmTDcu4H3eYIYq1BkMGhSMl9aUDKEE1LtTGfohx+btOX0zbKDqxNjqZDfIqZRo40xpz5gx8Zo6w== 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=LmtqnqeLIlIYBB3czTyjh1QOqw2Rdbp0eSJVGV3vTXY=; b=STwl7e8Phfxlo9TpKxZ258j2Ckl/hUeU9NZvjikLPQeAB+vmwMHdDvlJeG1qVzRUZlKTzHZDxwTNbcpZ4MudAMSo0EqdcLJnnFZtKuG9cSKhi/J1+cf1i3AIj2y0Dwv/pqew8bL0vujlCufelnVOik/oSP8gzVbBmUkM/+54PObaFCEThRMqWdeNtzaDI++zK9fBz4PctsvL9aUTGHg4ygxi9UgC+hWzpQXUFfKtNyoAo/FkVU7RPQXbiA5Cm1rPfVNCqUTGzYN5yhYH90LnNmKMGcG04AWPGpzzVlrwb7hCReIw4dcGgecoJA/jM+a2Qn2sg7aO/t5gM3XOWLNEUQ== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by AM8P250MB0344.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:32b::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.31; Wed, 27 Mar 2024 01:38:30 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d%4]) with mapi id 15.20.7409.028; Wed, 27 Mar 2024 01:38:30 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 27 Mar 2024 02:38:17 +0100 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [mFbLhHJmTmuMZakHo6yIGbKnN1IsrNOvr849oIR7xrc=] X-ClientProxiedBy: ZR0P278CA0075.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::8) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240327013819.265196-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|AM8P250MB0344:EE_ X-MS-Office365-Filtering-Correlation-Id: b261f8f8-7379-4329-2db3-08dc4dfe9b5f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 40HTkJ4FdMjmxy3JaZhg4TrXc5ER0mstBteiOS5cCUqnkS+HvFBy6oo2d3hi7w6wGtG5z/MvCCRczSp7MZnMaHATMQCFqUQNpqlJ6p0hf8Ntao5Daq9oLXQtg8/dCAyON2q/Ld8mJp5pbokqocaXb9fqclnaMy5N77FLYipCRT/76sR1CICeiciorwUU13ya4rqEQY1g+Yd6SwUbOJCPh+mgadmGrX/PEaiX5iQHAUR2UKlaeWHGzOS4ZUbZcCqGZqqXqiAW8jPepDu9JxdarR0K4EUXsYOXtwuKtzkUapquxG0bG9VEAPmHivN2Yw2AgcGD7iz6wGzKYU6D1kyRKdJnoz5SoT7GJmJlctF4/12TPBQox1CDfi7HqrTp8CorUo8bGlkJdpnTV1D5nx6qSKT6NrFY8OWboZVWfuygN+7jf6W839EYu7WL9zna976ecQKCnFYCv1qRDNfiPk0gtB1GEak/39YYfKpIKIWCGYGbuHxPH0PRgKO3OxPq1aHUEks3WOBBAbtpikA7UokrhzpR9jcTTzRwVh/7Gg4BJ5LriKKL7cEsDXFGA9Gn3aK47S11L5yFrHG5+7hx46Pex/YTsCSmpM37w7aULlH8q/8ydZKkAlMIsoZZ0zpxw3KR X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0XIcxHrkXU8EXXqA7t9EjJJSylFuY+3CZo7YMGMbvgOKJzZcwVAufBGQ3k9MQlUQvyByAmmYrFy34r8d5X3PT0iIJ+EF7xjUbaxMHl/u1dQ+YYNwkmeXLFJi9WrHkVpRBZ+VTGXoBfdnQ3C8QKb84GK0wEguAyfz5dXCmGAbSjzSF/nr+pjlQpBXL4HubOXMvJPj41N3pOFGhcIep0htIqMXP4MJIDrUGhM6L3iG6ZKA1WXmEN4Ah1OeaNSEDy0peeoi8rulq20Lp4j1N/V1s8Oa6Mv7qGlBxUDQ/IFIGR8vNcu1o9RU9bHmyc3io/MMDOIUZnZAjHKGFdNtWzbhfW05Lu6Mq7LU1u1puRAZwkPHBjZ6R4Wqk4K8ElSql5kEQeSr+MP7kEa2hYU2oHTU0uuzQYT2+3vdDNCnNyswAh8i6LwES778B8293apOkMCrvK2AP4zmue7aqZ2SyewIpaLtshYdXBeURNnTNBsMOPAiLHdqBri2VkcdsUeMSWMnGYuo06XMfoFA1xgE9GhTDNKPehS248STTW5sn7iwKUEhjp4L7SmmHup55+qAKhE/D5q6M5lf8gBUysqLf+5Wls/5dhZBV2NQ6I53l3xOahVXHVz+ykMC08pbsbWoMfZHmP0MVm3hJ/nyIeXoafH6BB5sxpYJWpqeo9YIsU5ar2EqPPr9OiGScg2SNbA/8eW9/fy3u68+ZiY/XQr4UEONGavTFTCCs/ATeBw+BO6MTOnhhu7621oKtTZFhXFY0PLEyxqFcVFTJUJh/bDLuodQ6iaBKIQ9tQ/fBX/VfWeA0K/6/3hn3EKrJt6Q6GCwYIF2hetDEKO8KFegRPM3tYGz4TDgU2v+vzpjgIuaQ/PEDBKWVmzCE0D6iFoE64JMGxEIkpCG7Bc9UAn+6r1878ZVPj3Ip/Vby+ZWL0XkxvQTNmnrXhZHKMPbOLboDgMvjFJxrXFIpPeNRNshL77eUNbOQkCFy2feYb21yKwQwf87Uo2fJnse9TN2ADkwZFeThFK4DKk0oEyn6ipj/VIEv9fkKgv/UWcIU6PLWW985K47AA8MuIbGTalka2/tzIDM2GWhBH2F+wbszBpWYgOUfFYtaOMVDNGeoikgdoxDojzUMvJyjn0vR1mOKXQzPLKmfxfQNejyMmzCUuW/v2G38f7KGwivLdsn7apqUmEkjlJXHPAnUav4oPSYLxszAssbxu6w2JgOT70Dr9jEe9rYCDSmcg5GWWSSHQZVYH4vVhVpA1bUJdmCI0o5DcAXlmQ59slEuWBLpEJUY7ICD4FhdivaRA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b261f8f8-7379-4329-2db3-08dc4dfe9b5f X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 01:38:30.5111 (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: AM8P250MB0344 Subject: [FFmpeg-devel] [PATCH 4/6] avcodec/h264_refs: Use smaller scope, don't use av_uninit 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: Tu9iZPkomof3 In particular, declare iterators with loop scope. Also remove av_uninit while at it, because they are now unnecessary due to the changes of the preceding commit. Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_refs.c | 121 ++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 68 deletions(-) diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c index c2ba4b9b9e..99820142b9 100644 --- a/libavcodec/h264_refs.c +++ b/libavcodec/h264_refs.c @@ -38,8 +38,7 @@ static void pic_as_field(H264Ref *pic, const int parity) { - int i; - for (i = 0; i < FF_ARRAY_ELEMS(pic->data); ++i) { + for (int i = 0; i < FF_ARRAY_ELEMS(pic->data); ++i) { if (parity == PICT_BOTTOM_FIELD) pic->data[i] += pic->linesize[i]; pic->reference = parity; @@ -104,13 +103,12 @@ static int build_def_list(H264Ref *def, int def_len, static int add_sorted(H264Picture **sorted, H264Picture * const *src, int len, int limit, int dir) { - int i, best_poc; int out_i = 0; for (;;) { - best_poc = dir ? INT_MIN : INT_MAX; + int best_poc = dir ? INT_MIN : INT_MAX; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { const int poc = src[i]->poc; if (((poc > limit) ^ dir) && ((poc < best_poc) ^ dir)) { best_poc = poc; @@ -134,12 +132,11 @@ static int mismatches_ref(const H264Context *h, const H264Picture *pic) static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) { - int i, len; - int j; + int len; if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { H264Picture *sorted[32]; - int cur_poc, list; + int cur_poc; int lens[2]; if (FIELD_PICTURE(h)) @@ -147,7 +144,7 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) else cur_poc = h->cur_pic_ptr->poc; - for (list = 0; list < 2; list++) { + for (int list = 0; list < 2; list++) { len = add_sorted(sorted, h->short_ref, h->short_ref_count, cur_poc, 1 ^ list); len += add_sorted(sorted + len, h->short_ref, h->short_ref_count, cur_poc, 0 ^ list); av_assert0(len <= 32); @@ -165,6 +162,7 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) } if (lens[0] == lens[1] && lens[1] > 1) { + int i; for (i = 0; i < lens[0] && sl->ref_list[0][i].parent->f->buf[0]->buffer == sl->ref_list[1][i].parent->f->buf[0]->buffer; i++); @@ -184,14 +182,14 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) memset(&sl->ref_list[0][len], 0, sizeof(H264Ref) * (sl->ref_count[0] - len)); } #ifdef TRACE - for (i = 0; i < sl->ref_count[0]; i++) { + for (int i = 0; i < sl->ref_count[0]; i++) { ff_tlog(h->avctx, "List0: %s fn:%d 0x%p\n", (sl->ref_list[0][i].parent ? (sl->ref_list[0][i].parent->long_ref ? "LT" : "ST") : "??"), sl->ref_list[0][i].pic_id, sl->ref_list[0][i].data[0]); } if (sl->slice_type_nos == AV_PICTURE_TYPE_B) { - for (i = 0; i < sl->ref_count[1]; i++) { + for (int i = 0; i < sl->ref_count[1]; i++) { ff_tlog(h->avctx, "List1: %s fn:%d 0x%p\n", (sl->ref_list[1][i].parent ? (sl->ref_list[1][i].parent->long_ref ? "LT" : "ST") : "??"), sl->ref_list[1][i].pic_id, @@ -200,8 +198,8 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) } #endif - for (j = 0; j<1+(sl->slice_type_nos == AV_PICTURE_TYPE_B); j++) { - for (i = 0; i < sl->ref_count[j]; i++) { + for (int j = 0; j < 1 + (sl->slice_type_nos == AV_PICTURE_TYPE_B); j++) { + for (int i = 0; i < sl->ref_count[j]; i++) { if (sl->ref_list[j][i].parent) { if (mismatches_ref(h, sl->ref_list[j][i].parent)) { av_log(h->avctx, AV_LOG_ERROR, "Discarding mismatching reference\n"); @@ -210,7 +208,7 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) } } } - for (i = 0; i < sl->list_count; i++) + for (int i = 0; i < sl->list_count; i++) h->default_ref[i] = sl->ref_list[i][0]; } @@ -219,10 +217,9 @@ static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) */ static void print_short_term(const H264Context *h) { - uint32_t i; if (h->avctx->debug & FF_DEBUG_MMCO) { av_log(h->avctx, AV_LOG_DEBUG, "short term list:\n"); - for (i = 0; i < h->short_ref_count; i++) { + for (uint32_t i = 0; i < h->short_ref_count; i++) { H264Picture *pic = h->short_ref[i]; av_log(h->avctx, AV_LOG_DEBUG, "%"PRIu32" fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->f->data[0]); @@ -235,10 +232,9 @@ static void print_short_term(const H264Context *h) */ static void print_long_term(const H264Context *h) { - uint32_t i; if (h->avctx->debug & FF_DEBUG_MMCO) { av_log(h->avctx, AV_LOG_DEBUG, "long term list:\n"); - for (i = 0; i < 16; i++) { + for (uint32_t i = 0; i < 16; i++) { H264Picture *pic = h->long_ref[i]; if (pic) { av_log(h->avctx, AV_LOG_DEBUG, "%"PRIu32" fn:%d poc:%d %p\n", @@ -273,22 +269,21 @@ static int pic_num_extract(const H264Context *h, int pic_num, int *structure) static void h264_fill_mbaff_ref_list(H264SliceContext *sl) { - int list, i, j; - for (list = 0; list < sl->list_count; list++) { - for (i = 0; i < sl->ref_count[list]; i++) { + for (int list = 0; list < sl->list_count; list++) { + for (int i = 0; i < sl->ref_count[list]; i++) { const H264Ref *frame = &sl->ref_list[list][i]; H264Ref *field = &sl->ref_list[list][16 + 2 * i]; field[0] = *frame; - for (j = 0; j < 3; j++) + for (int j = 0; j < 3; j++) field[0].linesize[j] <<= 1; field[0].reference = PICT_TOP_FIELD; field[0].poc = field[0].parent->field_poc[0]; field[1] = field[0]; - for (j = 0; j < 3; j++) + for (int j = 0; j < 3; j++) field[1].data[j] += frame->parent->f->linesize[j]; field[1].reference = PICT_BOTTOM_FIELD; field[1].poc = field[1].parent->field_poc[1]; @@ -298,21 +293,19 @@ static void h264_fill_mbaff_ref_list(H264SliceContext *sl) int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl) { - int list, index, pic_structure; - print_short_term(h); print_long_term(h); h264_initialise_ref_list(h, sl); - for (list = 0; list < sl->list_count; list++) { + for (int list = 0; list < sl->list_count; list++) { int pred = sl->curr_pic_num; - for (index = 0; index < sl->nb_ref_modifications[list]; index++) { + for (int index = 0; index < sl->nb_ref_modifications[list]; index++) { unsigned int modification_of_pic_nums_idc = sl->ref_modifications[list][index].op; unsigned int val = sl->ref_modifications[list][index].val; unsigned int pic_id; - int i; + int i, pic_structure; H264Picture *ref = NULL; switch (modification_of_pic_nums_idc) { @@ -396,13 +389,13 @@ int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl) } } } - for (list = 0; list < sl->list_count; list++) { - for (index = 0; index < sl->ref_count[list]; index++) { + for (int list = 0; list < sl->list_count; list++) { + for (int index = 0; index < sl->ref_count[list]; index++) { if ( !sl->ref_list[list][index].parent || (!FIELD_PICTURE(h) && (sl->ref_list[list][index].reference&3) != 3)) { - int i; av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture, default is %d\n", h->default_ref[list].poc); - for (i = 0; i < FF_ARRAY_ELEMS(h->last_pocs); i++) + + for (int i = 0; i < FF_ARRAY_ELEMS(h->last_pocs); i++) h->last_pocs[i] = INT_MIN; if (h->default_ref[list].parent && !(!FIELD_PICTURE(h) && (h->default_ref[list].reference&3) != 3)) @@ -433,16 +426,14 @@ int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl) int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx) { - int list, index; - sl->nb_ref_modifications[0] = 0; sl->nb_ref_modifications[1] = 0; - for (list = 0; list < sl->list_count; list++) { + for (int list = 0; list < sl->list_count; list++) { if (!get_bits1(&sl->gb)) // ref_pic_list_modification_flag_l[01] continue; - for (index = 0; ; index++) { + for (int index = 0; ; index++) { unsigned int op = get_ue_golomb_31(&sl->gb); if (op == 3) @@ -479,11 +470,10 @@ int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx) */ static inline int unreference_pic(H264Context *h, H264Picture *pic, int refmask) { - int i; if (pic->reference &= refmask) { return 0; } else { - for(i = 0; h->delayed_pic[i]; i++) + for (int i = 0; h->delayed_pic[i]; i++) if(pic == h->delayed_pic[i]){ pic->reference = DELAYED_PIC_REF; break; @@ -502,9 +492,7 @@ static inline int unreference_pic(H264Context *h, H264Picture *pic, int refmask) */ static H264Picture *find_short(H264Context *h, int frame_num, int *idx) { - int i; - - for (i = 0; i < h->short_ref_count; i++) { + for (int i = 0; i < h->short_ref_count; i++) { H264Picture *pic = h->short_ref[i]; if (h->avctx->debug & FF_DEBUG_MMCO) av_log(h->avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); @@ -575,11 +563,8 @@ static H264Picture *remove_long(H264Context *h, int i, int ref_mask) void ff_h264_remove_all_refs(H264Context *h) { - int i; - - for (i = 0; i < 16; i++) { + for (int i = 0; i < 16; i++) remove_long(h, i, 0); - } assert(h->long_ref_count == 0); if (h->short_ref_count && !h->last_pic_for_ec.f->data[0]) { @@ -587,7 +572,7 @@ void ff_h264_remove_all_refs(H264Context *h) ff_h264_ref_picture(&h->last_pic_for_ec, h->short_ref[0]); } - for (i = 0; i < h->short_ref_count; i++) { + for (int i = 0; i < h->short_ref_count; i++) { unreference_pic(h, h->short_ref[i], 0); h->short_ref[i] = NULL; } @@ -622,10 +607,8 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) { MMCO *mmco = h->mmco; int mmco_count; - int i, av_uninit(j); int pps_ref_count[2] = {0}; int current_ref_assigned = 0, err = 0; - H264Picture *av_uninit(pic); if (!h->ps.sps) { av_log(h->avctx, AV_LOG_ERROR, "SPS is unset\n"); @@ -640,17 +623,18 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) if ((h->avctx->debug & FF_DEBUG_MMCO) && mmco_count == 0) av_log(h->avctx, AV_LOG_DEBUG, "no mmco here\n"); - for (i = 0; i < mmco_count; i++) { - int av_uninit(structure), av_uninit(frame_num); + for (int i = 0; i < mmco_count; i++) { if (h->avctx->debug & FF_DEBUG_MMCO) av_log(h->avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_pic_num, h->mmco[i].long_arg); switch (mmco[i].opcode) { case MMCO_SHORT2UNUSED: - case MMCO_SHORT2LONG: - frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure); - pic = find_short(h, frame_num, &j); + case MMCO_SHORT2LONG: { + int structure, j; + int frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure); + H264Picture *pic = find_short(h, frame_num, &j); + if (!pic) { if (mmco[i].opcode != MMCO_SHORT2LONG || !h->long_ref[mmco[i].long_arg] || @@ -677,14 +661,16 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) } } break; - case MMCO_LONG2UNUSED: - j = pic_num_extract(h, mmco[i].long_arg, &structure); - pic = h->long_ref[j]; + } + case MMCO_LONG2UNUSED: { + int structure, j = pic_num_extract(h, mmco[i].long_arg, &structure); + H264Picture *pic = h->long_ref[j]; if (pic) { remove_long(h, j, structure ^ PICT_FRAME); } else if (h->avctx->debug & FF_DEBUG_MMCO) av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); break; + } case MMCO_LONG: // Comment below left from previous code as it is an interesting note. /* First field in pair is in short term list or @@ -700,7 +686,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) /* make sure the current picture is not already assigned as a long ref */ if (h->cur_pic_ptr->long_ref) { - for (j = 0; j < FF_ARRAY_ELEMS(h->long_ref); j++) { + for (int j = 0; j < FF_ARRAY_ELEMS(h->long_ref); j++) { if (h->long_ref[j] == h->cur_pic_ptr) { if (j != mmco[i].long_arg) av_log(h->avctx, AV_LOG_ERROR, "mmco: cannot assign current picture to 2 long term references\n"); @@ -724,21 +710,19 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) case MMCO_SET_MAX_LONG: assert(mmco[i].long_arg <= 16); // just remove the long term which index is greater than new max - for (j = mmco[i].long_arg; j < 16; j++) { + for (int j = mmco[i].long_arg; j < 16; j++) remove_long(h, j, 0); - } break; case MMCO_RESET: while (h->short_ref_count) { remove_short(h, h->short_ref[0]->frame_num, 0); } - for (j = 0; j < 16; j++) { + for (int j = 0; j < 16; j++) remove_long(h, j, 0); - } h->poc.frame_num = h->cur_pic_ptr->frame_num = 0; h->mmco_reset = 1; h->cur_pic_ptr->mmco_reset = 1; - for (j = 0; j < FF_ARRAY_ELEMS(h->last_pocs); j++) + for (int j = 0; j < FF_ARRAY_ELEMS(h->last_pocs); j++) h->last_pocs[j] = INT_MIN; break; default: av_assert0(0); @@ -762,7 +746,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) "(first field is long term)\n"); err = AVERROR_INVALIDDATA; } else { - pic = remove_short(h, h->cur_pic_ptr->frame_num, 0); + H264Picture *pic = remove_short(h, h->cur_pic_ptr->frame_num, 0); if (pic) { av_log(h->avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); err = AVERROR_INVALIDDATA; @@ -791,6 +775,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) err = AVERROR_INVALIDDATA; if (h->long_ref_count && !h->short_ref_count) { + int i; for (i = 0; i < 16; ++i) if (h->long_ref[i]) break; @@ -798,13 +783,13 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) assert(i < 16); remove_long(h, i, 0); } else { - pic = h->short_ref[h->short_ref_count - 1]; + H264Picture *pic = h->short_ref[h->short_ref_count - 1]; remove_short(h, pic->frame_num, 0); } } - for (i = 0; ishort_ref_count; i++) { - pic = h->short_ref[i]; + for (int i = 0; i < h->short_ref_count; i++) { + H264Picture *pic = h->short_ref[i]; if (pic->invalid_gap) { int d = av_mod_uintp2(h->cur_pic_ptr->frame_num - pic->frame_num, h->ps.sps->log2_max_frame_num); if (d > h->ps.sps->ref_frame_count) @@ -815,7 +800,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) print_short_term(h); print_long_term(h); - for (i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) { + for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) { if (h->ps.pps_list[i]) { const PPS *pps = h->ps.pps_list[i]; pps_ref_count[0] = FFMAX(pps_ref_count[0], pps->ref_count[0]); @@ -843,7 +828,6 @@ out: int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb, const H2645NAL *nal, void *logctx) { - int i; MMCO *mmco = sl->mmco; int nb_mmco = 0; @@ -858,6 +842,7 @@ int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb, } else { sl->explicit_ref_marking = get_bits1(gb); if (sl->explicit_ref_marking) { + int i; for (i = 0; i < FF_ARRAY_ELEMS(sl->mmco); i++) { MMCOOpcode opcode = get_ue_golomb_31(gb);