From patchwork Fri Aug 27 14:27:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29823 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1514247iov; Fri, 27 Aug 2021 07:30:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxckqZ3DoV/G5oGpC9jrIbB8CVWNy25eFbhUczicJANVxxqzUPNpSzU82CTcXrnWTRwUNYW X-Received: by 2002:aa7:c70c:: with SMTP id i12mr10208459edq.256.1630074647514; Fri, 27 Aug 2021 07:30:47 -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 w11si1386815eds.544.2021.08.27.07.30.47; Fri, 27 Aug 2021 07:30:47 -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=oQ3L5inC; 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 2522068A4DF; Fri, 27 Aug 2021 17:28:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064097.outbound.protection.outlook.com [40.92.64.97]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B3DF268A3E8 for ; Fri, 27 Aug 2021 17:27:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ER2OGV0ynacSMJWI6Y51SwXXCM4dbFnqCh5wAjlPJ+oBcZiubPOjZ9r9ukmuVyei1XOJf2v+0eZTCNVpA6DfM5v6suoDACofDUNBq6RSNJRtCqL62LFqtzff/9sNW12a6Mhd6OBQTRKualia3hBRXC335x+PhUOq4Y8nRvSh0Pn90j8QiBUTGkfZ7TlNKRJIvdJXLwNZmtB3kJBCx1LjLUsZSuZUT8SrrvAI0tbNWdB0lUyDGOFWfN6P7Ur5337LSTiHKWfSKV7B07dlhoPt5FVQIGrl3Y7p9nH1VRs7nqApj7VKFKn8xzUqkZIGB+X9sw2ubsD+ozx56mS2yhg2kA== 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-SenderADCheck; bh=E2iwaKKZU8m+89N6Fn2TBp/AOp6TNnl6JY1wkTMMbpY=; b=QxXSC0EHU8Q5/FQzbfoU8x+4QHj2beUqXAeVJd3W2Yj3xnQ0KleOeKEJInMWiCWnXS250srS0eveGkCBXqyxK2MmmJdbU1PBvaMwAR/uCpE8aFiFvC5iSDSYQLlomPmB3WwOSzIF+ZeTPzDSDGWLzDIqzqqEQP0ViMBTe4aWxKCwMlcsXthOZmMq2nbtxExkN73TNfccBPPMuGzGnp5xcLVIwAYsQBx5Jl5e76NHYXv+VJ1YQbwl4xnXScGAFVbfTH8MOJ3jOGVAch7Vs3Ea6OYCX5isKMrCCPSToDVK2THO0DCa4ijFg8fZ4meGKrs2dAyv0N5NJX6j24L0zR/Deg== 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=E2iwaKKZU8m+89N6Fn2TBp/AOp6TNnl6JY1wkTMMbpY=; b=oQ3L5inC2k0XzFf+YZxSGwx78jRqsO0lrQz/3HpVX6lZqcLXgMvyKOI515SJnDC0QX8AH4fVJVtRu6oRiIKEev2N4h2hOULxlgdmIrMm/D108rRyGCHuLODyq55x1jMVUX4SHYZxDPM9a04cl+jQhchxGNOlhgsrTrs7lELkeJfZGqOSlSyqCJML+5PvnGDuiELsLj99oYacJ0Xbp5XYR7x0FZM0lr7w9Vw6rebrOvyU3XYiuramldds4gtvNOj70J8pvPl6JrhUAedyPODLXDRppcl3exG3H2Cd7f5YOyjh//jyInwnYv6Mv26Rz+M00WNhiIN+k0n7XjZ3TGNULg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4824.eurprd03.prod.outlook.com (2603:10a6:20b:84::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.18; Fri, 27 Aug 2021 14:27:57 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::5574:1fd:cce2:d590%5]) with mapi id 15.20.4436.027; Fri, 27 Aug 2021 14:27:57 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Aug 2021 16:27:18 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [Fj6agcyDfj5IyJMIoFXmpj2btrD1wsGt] X-ClientProxiedBy: FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210827142725.645653-17-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0031.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.10 via Frontend Transport; Fri, 27 Aug 2021 14:27:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5629b083-39d6-4802-ddce-08d96966dd63 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnUOrjuXD0ZUxXZpiaS0/7dsuKrQuTQ3eW4jPAOn+hpL0i+zXbeGFVAPqC/Y94uVHqPIFN+Ou+yWT1xtCJuAth6fOokVVU/uEFwFfFNG0RHV6mxxuduDDwTzLstG6CYkm+fwwEG7Q2pP7T1L7Q3kQHG3YMZ7lZX8y9iCjoCWaei1hU38CnVcNRVf6lJSEhA0M39VUmH4mu8k0/G8VNbHYg8s2iHrw2LR7T/h1nPuiqFi/mvpEiy67/yYiAr02Xcli125mGBOQUigQuF9i/N5RWTD6Qj/09UYiI10hM00TTnYobS/bf5Kz5iNPwlJyG3jdxifveLWy0yfIt+81EHlE1VJPCjIhu+nloMVpMQdMdcsAaqesF0G7XDWO0qg0sYj72n3lmx5mgo3dWifsQdqpWMJf/qUYhI/6ENlzFVCk3UIXQj2Ti+nNQ5EljbxqhWHQT3qNT/dkHNd4Bbon9T1PwqQNKZIwHAEBJPdZ9Ay5I/sJcfwpt7u3ZT0103cA7tNrqyrq3t5NoqjRblEwdwabBLMe4Tv5SP5qUVmjQhovCDcsVXwMJCzOr1E0c65qR8YNItyTSZaYhH7qEFa7dfaTGRUED+BRQuE1bgD496dzpCZU8jVQ5IiQFPrXZIvkeX8XgLlsFccCer0cRltWsPEA8Ny1/W+bARqZcknRTyoe2fQbytz3RdSn69ImOJw0P7gRIeNpLB7nBqaM0wLtk+9c4i0WOOCPsqUULxtRUTdUwYq+5P/AOTsJCR3cxuraeDHE= X-MS-TrafficTypeDiagnostic: AM6PR03MB4824: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SQxbdnNYP/UqGc49WBjqYjTn6TTKxoxAy4wxbSftp84m9xKkkcUlYuIGRA96dvag8fxrv8ehPTBcVxz/3ZgtUvNSJJZjJkybrxBqZ1ImyLp2MH5HZ1WWz8cLBnkKe9jE7QflXLI9UruQfLaaVt7kOvCTfRsbMkMSuU7jWW99htkDqduGGFxKNE5fRYN+gqxLI8sZ+Rqwfx24XC8t8uz4aNMKm3xHv2tMQ7N/iBMH2RzUK07VYKcn0HyqsjWqzG669/qNOfkJfkfjQQ+375F8H3hn1QZQ1Hs/45zYbOurRQrvW3GrXceqEAtCaXvK8z0WMpkFefJ5dtbaGhoHLz7V2nOwM9TsK6IOsKb1muNkRlWSUYX4J5AvJbqOpUexn3HoHmIdZG3yjpsABWNcN2u55gieL5k1IB9VOaIDoPkc7rRKznjWp5PrYOqWKu7hIPos X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pfM9s5xW+Q6N5m8BDZMrgRD5Y0NaH9+ajFDi9GWG3FJSw2BJffVJpNSvueIHDBLuHAkNYj1j0Ey9HvyIwF48AtfqSWR8Vy1rCqEdr6LKhnvAHNrB98RYQucFavZgzY9FWN+TnRIMquORYuiiWL0QfQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5629b083-39d6-4802-ddce-08d96966dd63 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2021 14:27:57.5319 (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: AM6PR03MB4824 Subject: [FFmpeg-devel] [PATCH 18/25] avformat/mux, utils: Use smaller scope for variables 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: yrFRERSlKO9W Signed-off-by: Andreas Rheinhardt --- libavformat/mux.c | 60 ++++------ libavformat/utils.c | 284 +++++++++++++++++++------------------------- 2 files changed, 148 insertions(+), 196 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index b1ad0dd561..a05deb3f0b 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -91,11 +91,10 @@ static void frac_add(FFFrac *f, int64_t incr) AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precision) { AVRational q; - int j; q = st->time_base; - for (j=2; j<14; j+= 1+(j>2)) + for (int j = 2; j < 14; j += 1 + (j > 2)) while (q.den / q.num < min_precision && q.num % j == 0) q.num /= j; while (q.den / q.num < min_precision && q.den < (1<<24)) @@ -193,7 +192,6 @@ error: static int validate_codec_tag(AVFormatContext *s, AVStream *st) { const AVCodecTag *avctag; - int n; enum AVCodecID id = AV_CODEC_ID_NONE; int64_t tag = -1; @@ -203,7 +201,7 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) * If tag is in the table with another id -> FAIL * If id is in the table with another tag -> FAIL unless strict < normal */ - for (n = 0; s->oformat->codec_tag[n]; n++) { + for (int n = 0; s->oformat->codec_tag[n]; n++) { avctag = s->oformat->codec_tag[n]; while (avctag->id != AV_CODEC_ID_NONE) { if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codecpar->codec_tag)) { @@ -226,13 +224,10 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) static int init_muxer(AVFormatContext *s, AVDictionary **options) { - int ret = 0, i; - AVStream *st; AVDictionary *tmp = NULL; - AVCodecParameters *par = NULL; const AVOutputFormat *of = s->oformat; - const AVCodecDescriptor *desc; AVDictionaryEntry *e; + int ret = 0; if (options) av_dict_copy(&tmp, *options, 0); @@ -255,9 +250,10 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) goto fail; } - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; - par = st->codecpar; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; + AVCodecParameters *const par = st->codecpar; + const AVCodecDescriptor *desc; if (!st->time_base.num) { /* fall back on the default timebase values */ @@ -385,13 +381,10 @@ fail: static int init_pts(AVFormatContext *s) { - int i; - AVStream *st; - /* init PTS generation */ - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; int64_t den = AV_NOPTS_VALUE; - st = s->streams[i]; switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: @@ -510,7 +503,6 @@ FF_DISABLE_DEPRECATION_WARNINGS static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { int delay = st->codecpar->video_delay; - int i; int frame_size; if (!s->internal->missing_ts_warning && @@ -546,9 +538,9 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * //calculate dts from pts if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { st->internal->pts_buffer[0] = pkt->pts; - for (i = 1; i < delay + 1 && st->internal->pts_buffer[i] == AV_NOPTS_VALUE; i++) + for (int i = 1; i < delay + 1 && st->internal->pts_buffer[i] == AV_NOPTS_VALUE; i++) st->internal->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration; - for (i = 0; iinternal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) + for (int i = 0; iinternal->pts_buffer[i] > st->internal->pts_buffer[i + 1]; i++) FFSWAP(int64_t, st->internal->pts_buffer[i], st->internal->pts_buffer[i + 1]); pkt->dts = st->internal->pts_buffer[0]; @@ -895,10 +887,9 @@ static int interleave_compare_dts(AVFormatContext *s, const AVPacket *next, int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - PacketList *pktl; int stream_count = 0; int noninterleaved_count = 0; - int i, ret; + int ret; int eof = flush; if (pkt) { @@ -906,7 +897,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, return ret; } - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { if (s->streams[i]->internal->last_in_packet_buffer) { ++stream_count; } else if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT && @@ -930,7 +921,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, s->streams[top_pkt->stream_index]->time_base, AV_TIME_BASE_Q); - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { int64_t last_dts; const PacketList *last = s->streams[i]->internal->last_in_packet_buffer; @@ -965,18 +956,15 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (s->internal->shortest_end != AV_NOPTS_VALUE) { while (s->internal->packet_buffer) { - AVPacket *top_pkt = &s->internal->packet_buffer->pkt; - AVStream *st; - int64_t top_dts = av_rescale_q(top_pkt->dts, - s->streams[top_pkt->stream_index]->time_base, + PacketList *pktl = s->internal->packet_buffer; + AVPacket *const top_pkt = &pktl->pkt; + AVStream *const st = s->streams[top_pkt->stream_index]; + int64_t top_dts = av_rescale_q(top_pkt->dts, st->time_base, AV_TIME_BASE_Q); if (s->internal->shortest_end + 1 >= top_dts) break; - pktl = s->internal->packet_buffer; - st = s->streams[pktl->pkt.stream_index]; - s->internal->packet_buffer = pktl->next; if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; @@ -991,10 +979,10 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } if (stream_count && flush) { - AVStream *st; - pktl = s->internal->packet_buffer; + PacketList *pktl = s->internal->packet_buffer; + AVStream *const st = s->streams[pktl->pkt.stream_index]; + *out = pktl->pkt; - st = s->streams[out->stream_index]; s->internal->packet_buffer = pktl->next; if (!s->internal->packet_buffer) @@ -1236,11 +1224,11 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) int av_write_trailer(AVFormatContext *s) { - int i, ret1, ret = 0; AVPacket *pkt = s->internal->pkt; + int ret1, ret = 0; av_packet_unref(pkt); - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { if (s->streams[i]->internal->bsfc) { ret1 = write_packets_from_bsfs(s, s->streams[i], pkt, 1/*interleaved*/); if (ret1 < 0) @@ -1269,7 +1257,7 @@ int av_write_trailer(AVFormatContext *s) avio_flush(s->pb); if (ret == 0) ret = s->pb ? s->pb->error : 0; - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { av_freep(&s->streams[i]->priv_data); av_freep(&s->streams[i]->internal->index_entries); } diff --git a/libavformat/utils.c b/libavformat/utils.c index b56190d2da..df11dc2517 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -135,9 +135,8 @@ void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type) void av_format_inject_global_side_data(AVFormatContext *s) { - int i; s->internal->inject_global_side_data = 1; - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; st->internal->inject_global_side_data = 1; } @@ -313,12 +312,11 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); if (fmt) { - int i; av_log(s, AV_LOG_DEBUG, "Probe with size=%d, packets=%d detected %s with score=%d\n", pd->buf_size, s->max_probe_packets - st->internal->probe_packets, fmt->name, score); - for (i = 0; fmt_id_type[i].name; i++) { + for (int i = 0; fmt_id_type[i].name; i++) { if (!strcmp(fmt->name, fmt_id_type[i].name)) { if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) @@ -373,8 +371,8 @@ static int init_input(AVFormatContext *s, const char *filename, int avformat_queue_attached_pictures(AVFormatContext *s) { - int i, ret; - for (i = 0; i < s->nb_streams; i++) + int ret; + for (unsigned i = 0; i < s->nb_streams; i++) if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC && s->streams[i]->discard < AVDISCARD_ALL) { if (s->streams[i]->attached_pic.size <= 0) { @@ -431,8 +429,8 @@ fail: static int update_stream_avctx(AVFormatContext *s) { - int i, ret; - for (i = 0; i < s->nb_streams; i++) { + int ret; + for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (!st->internal->need_context_update) @@ -678,7 +676,7 @@ no_packet: static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) { int64_t ref = pkt->dts; - int i, pts_wrap_behavior; + int pts_wrap_behavior; int64_t pts_wrap_reference; AVProgram *first_program; @@ -700,7 +698,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in if (!first_program) { int default_stream_index = av_find_default_stream_index(s); if (s->streams[default_stream_index]->internal->pts_wrap_reference == AV_NOPTS_VALUE) { - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { if (av_find_program_from_stream(s, NULL, i)) continue; s->streams[i]->internal->pts_wrap_reference = pts_wrap_reference; @@ -727,7 +725,7 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in program = first_program; while (program) { if (program->pts_wrap_reference != pts_wrap_reference) { - for (i = 0; inb_stream_indexes; i++) { + for (unsigned i = 0; i < program->nb_stream_indexes; i++) { s->streams[program->stream_index[i]]->internal->pts_wrap_reference = pts_wrap_reference; s->streams[program->stream_index[i]]->internal->pts_wrap_behavior = pts_wrap_behavior; } @@ -743,8 +741,8 @@ static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_in int ff_read_packet(AVFormatContext *s, AVPacket *pkt) { - int err, i; AVStream *st; + int err; #if FF_API_INIT_PACKET FF_DISABLE_DEPRECATION_WARNINGS @@ -784,8 +782,8 @@ FF_ENABLE_DEPRECATION_WARNINGS continue; if (!pktl || err == AVERROR(EAGAIN)) return err; - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; if (st->internal->probe_packets || st->internal->request_probe > 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; @@ -986,7 +984,7 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t } } } else { - for (i = 0; iinternal->pts_reorder_error[i]; @@ -1017,11 +1015,10 @@ static void update_dts_from_pts(AVFormatContext *s, int stream_index, { AVStream *st = s->streams[stream_index]; int delay = st->internal->avctx->has_b_frames; - int i; int64_t pts_buffer[MAX_REORDER_DELAY+1]; - for (i = 0; ipkt.pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) { pts_buffer[0] = pkt_buffer->pkt.pts; - for (i = 0; i pts_buffer[i + 1]; i++) + for (int i = 0; i < delay && pts_buffer[i] > pts_buffer[i + 1]; i++) FFSWAP(int64_t, pts_buffer[i], pts_buffer[i + 1]); pkt_buffer->pkt.dts = select_from_pts_buffer(st, pts_buffer, pkt_buffer->pkt.dts); @@ -1455,7 +1452,7 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts) static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { - int ret, i, got_packet = 0; + int ret, got_packet = 0; AVDictionary *metadata = NULL; while (!got_packet && !s->internal->parse_queue) { @@ -1467,8 +1464,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) if (ret == AVERROR(EAGAIN)) return ret; /* flush the parsers */ - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; if (st->internal->parser && st->internal->need_parsing) parse_packet(s, pkt, st->index, 1); } @@ -1596,7 +1593,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } if (st->internal->inject_global_side_data) { - for (i = 0; i < st->nb_side_data; i++) { + for (int i = 0; i < st->nb_side_data; i++) { AVPacketSideData *src_sd = &st->side_data[i]; uint8_t *dst_data; @@ -1753,16 +1750,14 @@ static void flush_packet_queue(AVFormatContext *s) int av_find_default_stream_index(AVFormatContext *s) { - int i; - AVStream *st; int best_stream = 0; int best_score = INT_MIN; if (s->nb_streams <= 0) return -1; - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { + const AVStream *const st = s->streams[i]; int score = 0; - st = s->streams[i]; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) score -= 400; @@ -1791,14 +1786,12 @@ int av_find_default_stream_index(AVFormatContext *s) /** Flush the frame reader. */ void ff_read_frame_flush(AVFormatContext *s) { - AVStream *st; - int i, j; flush_packet_queue(s); /* Reset read state for each stream. */ - for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; + for (unsigned i = 0; i < s->nb_streams; i++) { + AVStream *const st = s->streams[i]; if (st->internal->parser) { av_parser_close(st->internal->parser); @@ -1814,7 +1807,7 @@ void ff_read_frame_flush(AVFormatContext *s) st->internal->probe_packets = s->max_probe_packets; - for (j = 0; j < MAX_REORDER_DELAY + 1; j++) + for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) st->internal->pts_buffer[j] = AV_NOPTS_VALUE; if (s->internal->inject_global_side_data) @@ -1826,9 +1819,7 @@ void ff_read_frame_flush(AVFormatContext *s) void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp) { - int i; - - for (i = 0; i < s->nb_streams; i++) { + for (unsigned i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; st->internal->cur_dts = @@ -1964,7 +1955,6 @@ int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) { - int ist1, ist2; int64_t pos_delta = 0; int64_t skip = 0; //We could use URLProtocol flags here but as many user applications do not use URLProtocols this would be unreliable @@ -1983,16 +1973,15 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) if (proto && !(strcmp(proto, "file") && strcmp(proto, "pipe") && strcmp(proto, "cache"))) return; - for (ist1 = 0; ist1 < s->nb_streams; ist1++) { + for (unsigned ist1 = 0; ist1 < s->nb_streams; ist1++) { AVStream *st1 = s->streams[ist1]; - for (ist2 = 0; ist2 < s->nb_streams; ist2++) { + for (unsigned ist2 = 0; ist2 < s->nb_streams; ist2++) { AVStream *st2 = s->streams[ist2]; - int i1, i2; if (ist1 == ist2) continue; - for (i1 = i2 = 0; i1 < st1->internal->nb_index_entries; i1++) { + for (int i1 = 0, i2 = 0; i1 < st1->internal->nb_index_entries; i1++) { AVIndexEntry *e1 = &st1->internal->index_entries[i1]; int64_t e1_pts = av_rescale_q(e1->timestamp, st1->time_base, AV_TIME_BASE_Q); @@ -2513,11 +2502,8 @@ int avformat_flush(AVFormatContext *s) */ static int has_duration(AVFormatContext *ic) { - int i; - AVStream *st; - - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; if (st->duration != AV_NOPTS_VALUE) return 1; } @@ -2535,8 +2521,6 @@ static void update_stream_timings(AVFormatContext *ic) { int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text; int64_t duration, duration1, duration_text, filesize; - int i; - AVProgram *p; start_time = INT64_MAX; start_time_text = INT64_MAX; @@ -2545,10 +2529,11 @@ static void update_stream_timings(AVFormatContext *ic) duration = INT64_MIN; duration_text = INT64_MIN; - for (i = 0; i < ic->nb_streams; i++) { + for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *st = ic->streams[i]; int is_text = st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codecpar->codec_type == AVMEDIA_TYPE_DATA; + if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) { start_time1 = av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q); @@ -2566,7 +2551,7 @@ static void update_stream_timings(AVFormatContext *ic) else end_time = FFMAX(end_time, end_time1); } - for (p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) { + for (AVProgram *p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) { if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1) p->start_time = start_time1; if (p->end_time < end_time1) @@ -2601,8 +2586,9 @@ static void update_stream_timings(AVFormatContext *ic) ic->start_time = start_time; if (end_time != INT64_MIN) { if (ic->nb_programs > 1) { - for (i = 0; i < ic->nb_programs; i++) { - p = ic->programs[i]; + for (unsigned i = 0; i < ic->nb_programs; i++) { + AVProgram *const p = ic->programs[i]; + if (p->start_time != AV_NOPTS_VALUE && p->end_time > p->start_time && p->end_time - (uint64_t)p->start_time <= INT64_MAX) @@ -2627,12 +2613,10 @@ static void update_stream_timings(AVFormatContext *ic) static void fill_all_stream_timings(AVFormatContext *ic) { - int i; - AVStream *st; - update_stream_timings(ic); - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + if (st->start_time == AV_NOPTS_VALUE) { if (ic->start_time != AV_NOPTS_VALUE) st->start_time = av_rescale_q(ic->start_time, AV_TIME_BASE_Q, @@ -2646,15 +2630,14 @@ static void fill_all_stream_timings(AVFormatContext *ic) static void estimate_timings_from_bit_rate(AVFormatContext *ic) { - int64_t filesize, duration; - int i, show_warning = 0; - AVStream *st; + int show_warning = 0; /* if bit_rate is already set, we believe it */ if (ic->bit_rate <= 0) { int64_t bit_rate = 0; - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; + if (st->codecpar->bit_rate <= 0 && st->internal->avctx->bit_rate > 0) st->codecpar->bit_rate = st->internal->avctx->bit_rate; if (st->codecpar->bit_rate > 0) { @@ -2676,17 +2659,17 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) /* if duration is already set, we believe it */ if (ic->duration == AV_NOPTS_VALUE && ic->bit_rate != 0) { - filesize = ic->pb ? avio_size(ic->pb) : 0; + int64_t filesize = ic->pb ? avio_size(ic->pb) : 0; if (filesize > ic->internal->data_offset) { filesize -= ic->internal->data_offset; - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + if ( st->time_base.num <= INT64_MAX / ic->bit_rate && st->duration == AV_NOPTS_VALUE) { - duration = av_rescale(filesize, 8LL * st->time_base.den, + st->duration = av_rescale(filesize, 8LL * st->time_base.den, ic->bit_rate * (int64_t) st->time_base.num); - st->duration = duration; show_warning = 1; } } @@ -2704,8 +2687,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) { AVPacket *pkt = ic->internal->pkt; - AVStream *st; - int num, den, read_size, i, ret; + int num, den, read_size, ret; int found_duration = 0; int is_end; int64_t filesize, offset, duration; @@ -2714,8 +2696,9 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) /* flush packet queue */ flush_packet_queue(ic); - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + if (st->start_time == AV_NOPTS_VALUE && st->internal->first_dts == AV_NOPTS_VALUE && st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) @@ -2746,6 +2729,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) avio_seek(ic->pb, offset, SEEK_SET); read_size = 0; for (;;) { + AVStream *st; if (read_size >= DURATION_MAX_READ_SIZE << (FFMAX(retry - 1, 0))) break; @@ -2787,8 +2771,8 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) /* check if all audio/video streams have valid duration */ if (!is_end) { is_end = 1; - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_AUDIO: @@ -2804,8 +2788,9 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) av_opt_set(ic, "skip_changes", "0", AV_OPT_SEARCH_CHILDREN); /* warn about audio/video streams which duration could not be estimated */ - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + const AVStream *const st = ic->streams[i]; + if (st->duration == AV_NOPTS_VALUE) { switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: @@ -2821,14 +2806,13 @@ skip_duration_calc: fill_all_stream_timings(ic); avio_seek(ic->pb, old_offset, SEEK_SET); - for (i = 0; i < ic->nb_streams; i++) { - int j; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; - st = ic->streams[i]; st->internal->cur_dts = st->internal->first_dts; st->internal->last_IP_pts = AV_NOPTS_VALUE; st->internal->last_dts_for_order_check = AV_NOPTS_VALUE; - for (j = 0; j < MAX_REORDER_DELAY + 1; j++) + for (int j = 0; j < MAX_REORDER_DELAY + 1; j++) st->internal->pts_buffer[j] = AV_NOPTS_VALUE; } } @@ -3058,11 +3042,10 @@ unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id) enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag) { - int i; - for (i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) + for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) if (tag == tags[i].tag) return tags[i].id; - for (i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) + for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++) if (avpriv_toupper4(tag) == avpriv_toupper4(tags[i].tag)) return tags[i].id; return AV_CODEC_ID_NONE; @@ -3128,8 +3111,7 @@ unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id) int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id, unsigned int *tag) { - int i; - for (i = 0; tags && tags[i]; i++) { + for (int i = 0; tags && tags[i]; i++) { const AVCodecTag *codec_tags = tags[i]; while (codec_tags->id != AV_CODEC_ID_NONE) { if (codec_tags->id == id) { @@ -3144,8 +3126,7 @@ int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id, enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag) { - int i; - for (i = 0; tags && tags[i]; i++) { + for (int i = 0; tags && tags[i]; i++) { enum AVCodecID id = ff_codec_get_id(tags[i], tag); if (id != AV_CODEC_ID_NONE) return id; @@ -3165,7 +3146,6 @@ static int chapter_start_cmp(const void *p1, const void *p2) static int compute_chapters_end(AVFormatContext *s) { - unsigned int i; int64_t max_time = 0; AVChapter **timetable; @@ -3181,7 +3161,7 @@ static int compute_chapters_end(AVFormatContext *s) return AVERROR(ENOMEM); qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp); - for (i = 0; i < s->nb_chapters; i++) + for (unsigned i = 0; i < s->nb_chapters; i++) if (timetable[i]->end == AV_NOPTS_VALUE) { AVChapter *ch = timetable[i]; int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q, @@ -3276,7 +3256,6 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) { - int i, j; int64_t last = st->internal->info->last_dts; if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last @@ -3291,11 +3270,11 @@ int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) // if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) // av_log(NULL, AV_LOG_ERROR, "%f\n", dts); - for (i = 0; iinternal->info->duration_error[0][1][i] < 1e10) { int framerate = get_std_framerate(i); double sdts = dts*framerate/(1001*12); - for (j= 0; j<2; j++) { + for (int j = 0; j < 2; j++) { int64_t ticks = llrint(sdts+j*0.5); double error= sdts - ticks + j*0.5; st->internal->info->duration_error[j][0][i] += error; @@ -3310,7 +3289,7 @@ int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) if (st->internal->info->duration_count % 10 == 0) { int n = st->internal->info->duration_count; - for (i = 0; iinternal->info->duration_error[0][1][i] < 1e10) { double a0 = st->internal->info->duration_error[0][0][i] / n; double error0 = st->internal->info->duration_error[0][1][i] / n - a0*a0; @@ -3336,9 +3315,7 @@ int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts) void ff_rfps_calculate(AVFormatContext *ic) { - int i, j; - - for (i = 0; i < ic->nb_streams; i++) { + for (unsigned i = 0; i < ic->nb_streams; i++) { AVStream *st = ic->streams[i]; if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) @@ -3355,8 +3332,7 @@ void ff_rfps_calculate(AVFormatContext *ic) double best_error= 0.01; AVRational ref_rate = st->r_frame_rate.num ? st->r_frame_rate : av_inv_q(st->time_base); - for (j= 0; jinternal->info->codec_info_duration && st->internal->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j)) @@ -3367,7 +3343,7 @@ void ff_rfps_calculate(AVFormatContext *ic) if (av_q2d(st->time_base) * st->internal->info->rfps_duration_sum / st->internal->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j)) continue; - for (k= 0; k<2; k++) { + for (int k = 0; k < 2; k++) { int n = st->internal->info->duration_count; double a= st->internal->info->duration_error[k][0][j] / n; double error= st->internal->info->duration_error[k][1][j]/n - a*a; @@ -3509,9 +3485,7 @@ static int extract_extradata(AVFormatContext *s, AVStream *st, const AVPacket *p static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) { - int i; - - for (i = 0; i < avctx->nb_coded_side_data; i++) { + for (int i = 0; i < avctx->nb_coded_side_data; i++) { const AVPacketSideData *sd_src = &avctx->coded_side_data[i]; uint8_t *dst_data; dst_data = av_stream_new_side_data(st, sd_src->type, sd_src->size); @@ -3524,10 +3498,8 @@ static int add_coded_side_data(AVStream *st, AVCodecContext *avctx) int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) { - int i, count = 0, ret = 0, j; + int count = 0, ret = 0; int64_t read_size; - AVStream *st; - AVCodecContext *avctx; AVPacket *pkt1 = ic->internal->pkt; int64_t old_offset = avio_tell(ic->pb); // new streams might appear, no options for those @@ -3562,11 +3534,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, ic->nb_streams); } - for (i = 0; i < ic->nb_streams; i++) { + for (unsigned i = 0; i < ic->nb_streams; i++) { const AVCodec *codec; AVDictionary *thread_opt = NULL; - st = ic->streams[i]; - avctx = st->internal->avctx; + AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; + AVCodecContext *const avctx = sti->avctx; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { @@ -3628,7 +3601,10 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) read_size = 0; for (;;) { const AVPacket *pkt; + AVStream *st; + AVCodecContext *avctx; int analyzed_all_streams; + unsigned i; if (ff_check_interrupt(&ic->interrupt_callback)) { ret = AVERROR_EXIT; av_log(ic, AV_LOG_DEBUG, "interrupted\n"); @@ -3637,10 +3613,10 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* check if one codec still needs to be handled */ for (i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; int fps_analyze_framecount = 20; int count; - st = ic->streams[i]; if (!has_codec_parameters(st, NULL)) break; /* If the timebase is coarse (like the usual millisecond precision @@ -3698,7 +3674,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ret = count; av_log(ic, AV_LOG_DEBUG, "Probe buffer size limit of %"PRId64" bytes reached\n", probesize); - for (i = 0; i < ic->nb_streams; i++) + for (unsigned i = 0; i < ic->nb_streams; i++) if (!ic->streams[i]->r_frame_rate.num && ic->streams[i]->internal->info->duration_count <= 1 && ic->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && @@ -3857,10 +3833,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } if (eof_reached) { - int stream_index; - for (stream_index = 0; stream_index < ic->nb_streams; stream_index++) { - st = ic->streams[stream_index]; - avctx = st->internal->avctx; + for (unsigned stream_index = 0; stream_index < ic->nb_streams; stream_index++) { + AVStream *const st = ic->streams[stream_index]; + AVCodecContext *const avctx = st->internal->avctx; if (!has_codec_parameters(st, NULL)) { const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id); if (codec && !avctx->codec) { @@ -3887,9 +3862,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) int err = 0; av_packet_unref(empty_pkt); - for (i = 0; i < ic->nb_streams; i++) { - - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; /* flush the decoders */ if (st->internal->info->found_decoder == 1) { @@ -3909,9 +3883,11 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ff_rfps_calculate(ic); - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; - avctx = st->internal->avctx; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; + AVStreamInternal *const sti = st->internal; + AVCodecContext *const avctx = sti->avctx; + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) { uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); @@ -3937,7 +3913,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) /* Round guessed framerate to a "standard" framerate if it's * within 1% of the original estimate. */ - for (j = 0; j < MAX_STD_TIMEBASES; j++) { + for (int j = 0; j < MAX_STD_TIMEBASES; j++) { AVRational std_fps = { get_std_framerate(j), 12 * 1001 }; double error = fabs(av_q2d(st->avg_frame_rate) / av_q2d(std_fps) - 1); @@ -4009,9 +3985,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) if (ret >= 0 && ic->nb_streams) /* We could not have all the codec parameters before EOF. */ ret = -1; - for (i = 0; i < ic->nb_streams; i++) { + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; const char *errmsg; - st = ic->streams[i]; /* if no packet was ever seen, update context now for has_codec_parameters */ if (!st->internal->avctx_inited) { @@ -4039,8 +4015,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) goto find_stream_info_err; /* update the stream parameters from the internal codec contexts */ - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; if (st->internal->avctx_inited) { ret = avcodec_parameters_from_context(st->codecpar, st->internal->avctx); @@ -4055,8 +4031,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } find_stream_info_err: - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; + for (unsigned i = 0; i < ic->nb_streams; i++) { + AVStream *const st = ic->streams[i]; if (st->internal->info) av_freep(&st->internal->info->duration_error); avcodec_close(ic->streams[i]->internal->avctx); @@ -4077,14 +4053,12 @@ unref_then_goto_end: AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s) { - int i, j; - - for (i = 0; i < ic->nb_programs; i++) { + for (unsigned i = 0; i < ic->nb_programs; i++) { if (ic->programs[i] == last) { last = NULL; } else { if (!last) - for (j = 0; j < ic->programs[i]->nb_stream_indexes; j++) + for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++) if (ic->programs[i]->stream_index[j] == s) return ic->programs[i]; } @@ -4096,7 +4070,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, const AVCodec **decoder_ret, int flags) { - int i, nb_streams = ic->nb_streams; + int nb_streams = ic->nb_streams; int ret = AVERROR_STREAM_NOT_FOUND; int best_count = -1, best_multiframe = -1, best_disposition = -1; int count, multiframe, disposition; @@ -4112,7 +4086,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, nb_streams = p->nb_stream_indexes; } } - for (i = 0; i < nb_streams; i++) { + for (unsigned i = 0; i < nb_streams; i++) { int real_stream_index = program ? program[i] : i; AVStream *st = ic->streams[real_stream_index]; AVCodecParameters *par = st->codecpar; @@ -4180,7 +4154,7 @@ int av_read_pause(AVFormatContext *s) int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) { - int ret, i; + int ret; dst->id = src->id; dst->time_base = src->time_base; @@ -4200,7 +4174,7 @@ int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) return ret; /* Free existing side data*/ - for (i = 0; i < dst->nb_side_data; i++) + for (int i = 0; i < dst->nb_side_data; i++) av_free(dst->side_data[i].data); av_freep(&dst->side_data); dst->nb_side_data = 0; @@ -4213,7 +4187,7 @@ int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) return AVERROR(ENOMEM); dst->nb_side_data = src->nb_side_data; - for (i = 0; i < src->nb_side_data; i++) { + for (int i = 0; i < src->nb_side_data; i++) { uint8_t *data = av_memdup(src->side_data[i].data, src->side_data[i].size); if (!data) @@ -4230,12 +4204,11 @@ int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src) static void free_stream(AVStream **pst) { AVStream *st = *pst; - int i; if (!st) return; - for (i = 0; i < st->nb_side_data; i++) + for (int i = 0; i < st->nb_side_data; i++) av_freep(&st->side_data[i].data); av_freep(&st->side_data); @@ -4275,8 +4248,6 @@ void ff_free_stream(AVFormatContext *s, AVStream *st) void avformat_free_context(AVFormatContext *s) { - int i; - if (!s) return; @@ -4289,11 +4260,11 @@ void avformat_free_context(AVFormatContext *s) if (s->oformat && s->oformat->priv_class && s->priv_data) av_opt_free(s->priv_data); - for (i = 0; i < s->nb_streams; i++) + for (unsigned i = 0; i < s->nb_streams; i++) free_stream(&s->streams[i]); s->nb_streams = 0; - for (i = 0; i < s->nb_programs; i++) { + for (unsigned i = 0; i < s->nb_programs; i++) { av_dict_free(&s->programs[i]->metadata); av_freep(&s->programs[i]->stream_index); av_freep(&s->programs[i]); @@ -4428,11 +4399,11 @@ fail: AVProgram *av_new_program(AVFormatContext *ac, int id) { AVProgram *program = NULL; - int i, ret; + int ret; av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id); - for (i = 0; i < ac->nb_programs; i++) + for (unsigned i = 0; i < ac->nb_programs; i++) if (ac->programs[i]->id == id) program = ac->programs[i]; @@ -4460,7 +4431,7 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba int64_t start, int64_t end, const char *title) { AVChapter *chapter = NULL; - int i, ret; + int ret; if (end != AV_NOPTS_VALUE && start > end) { av_log(s, AV_LOG_ERROR, "Chapter end time %"PRId64" before start %"PRId64"\n", end, start); @@ -4471,7 +4442,7 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba s->internal->chapter_ids_monotonic = 1; } else if (!s->internal->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) { s->internal->chapter_ids_monotonic = 0; - for (i = 0; i < s->nb_chapters; i++) + for (unsigned i = 0; i < s->nb_chapters; i++) if (s->chapters[i]->id == id) chapter = s->chapters[i]; } @@ -4497,7 +4468,6 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx) { - int i, j; AVProgram *program = NULL; void *tmp; @@ -4506,11 +4476,11 @@ void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx) return; } - for (i = 0; i < ac->nb_programs; i++) { + for (unsigned i = 0; i < ac->nb_programs; i++) { if (ac->programs[i]->id != progid) continue; program = ac->programs[i]; - for (j = 0; j < program->nb_stream_indexes; j++) + for (unsigned j = 0; j < program->nb_stream_indexes; j++) if (program->stream_index[j] == idx) return; @@ -4721,7 +4691,6 @@ int ff_mkdir_p(const char *path) char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase) { - int i; static const char hex_table_uc[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', @@ -4732,7 +4701,7 @@ char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase) 'c', 'd', 'e', 'f' }; const char *hex_table = lowercase ? hex_table_lc : hex_table_uc; - for (i = 0; i < s; i++) { + for (int i = 0; i < s; i++) { buff[i * 2] = hex_table[src[i] >> 4]; buff[i * 2 + 1] = hex_table[src[i] & 0xF]; } @@ -4849,8 +4818,7 @@ void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, int ff_find_stream_index(AVFormatContext *s, int id) { - int i; - for (i = 0; i < s->nb_streams; i++) + for (unsigned i = 0; i < s->nb_streams; i++) if (s->streams[i]->id == id) return i; return -1; @@ -5021,7 +4989,7 @@ static int match_stream_specifier(AVFormatContext *s, AVStream *st, if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC)) match = 0; } else if (*spec == 'p' && *(spec + 1) == ':') { - int prog_id, i, j; + int prog_id; int found = 0; char *endptr; spec += 2; @@ -5031,11 +4999,11 @@ static int match_stream_specifier(AVFormatContext *s, AVStream *st, return AVERROR(EINVAL); spec = endptr; if (match) { - for (i = 0; i < s->nb_programs; i++) { + for (unsigned i = 0; i < s->nb_programs; i++) { if (s->programs[i]->id != prog_id) continue; - for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) { + for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) { if (st->index == s->programs[i]->stream_index[j]) { found = 1; if (p) @@ -5295,9 +5263,7 @@ int ff_generate_avci_extradata(AVStream *st) uint8_t *av_stream_get_side_data(const AVStream *st, enum AVPacketSideDataType type, size_t *size) { - int i; - - for (i = 0; i < st->nb_side_data; i++) { + for (int i = 0; i < st->nb_side_data; i++) { if (st->side_data[i].type == type) { if (size) *size = st->side_data[i].size; @@ -5313,9 +5279,8 @@ int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type, uint8_t *data, size_t size) { AVPacketSideData *sd, *tmp; - int i; - for (i = 0; i < st->nb_side_data; i++) { + for (int i = 0; i < st->nb_side_data; i++) { sd = &st->side_data[i]; if (sd->type == type) { @@ -5475,8 +5440,7 @@ int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t * } if (ret == CONTAINS_PAL) { - int i; - for (i = 0; i < AVPALETTE_COUNT; i++) + for (int i = 0; i < AVPALETTE_COUNT; i++) palette[i] = AV_RL32(pkt->data + pkt->size - AVPALETTE_SIZE + i*4); return 1; }