From patchwork Wed Feb 21 09:56:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46410 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1b29:b0:19e:cdac:8cce with SMTP id ch41csp197270pzb; Wed, 21 Feb 2024 01:58:13 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWzhU4cm1FYVu9xyHdA2P0Ugux1y6V+Ws8tN6I1+aKx00cKJQ6B48nt3wAhaBn5O2/awvv800iWqhWuZx63j6cIGoIUvS6YbPNy6w== X-Google-Smtp-Source: AGHT+IH6I50swF92ySD1UpIfiCvIdtVVM7cehuY+c1U4k3cLMz2AOTd+pdHaJQWy9c5UxbwdZacz X-Received: by 2002:a05:6402:2696:b0:564:15b:9f57 with SMTP id w22-20020a056402269600b00564015b9f57mr9620507edd.11.1708509493202; Wed, 21 Feb 2024 01:58:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708509493; cv=none; d=google.com; s=arc-20160816; b=GYWZ+rUC+Blgb9cdtyKTGFcNXTWW4lmN9MIXWfOVEY/H43G4nBC/yuHBwoff5hUN6q mpbouColTEus69v6u6/r7InMtGBcpgDI7KAIYeHjc0xFC2g8QFcWJWMiwEceMhM9KJpu f75eLaHWv35p902PHBdZHyPEp69uE2MnQQ/i1NVxr3PDLT2Kv1VPSv7rZ1NwQHXUaDI7 tMDsUA74A6hfRPizSl4Tpd0lyVIHtyWRH0gP8GI3KPPQH53Q+qmuxpmHjVqQWTpVIGTQ Fs1s4akTsH2eN41La6ie9gVb4Lcm1cj1R6Qp52S0m5TSrDGIF9j6vStiJQUvJ+Q/qbx4 Vetg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=ciyBIeh8IGhUUQ8cxxVKiB4wZxi6BDC1O8SzLpBX8Io=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Ck9Lt6oD/P3cVgQIMxZy/RZLSM7c7b2F+1A44KTkR3N0wzXcdaA9GZSzHJap0CSdCE ebE5A5ZjJcla06Zd7cy2bA3cleOyCv3/5by1LCHdDSPo0F7uteenqrZY750KTWYDzzib xEmMWWPNVwi+EY5SzTOzpL3UFpqm8dbV/d0DKINoxJxcnSjedhJld8zJsYiZ6o7gh0/Z GIXJobnDyclstA8q7R+hMGLHDr/3q1nQisYD11ahgK9XlbGQzuSXU1UtRJym8JNA7kxI Fiv1vnTWqhur2W/Frvwi0/NeEXBjEhjZFDPcLwMw6NbXXz5vCwjn3fezlx3FRTM5cTZZ rWwA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=l26fWwBm; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k2-20020a05640212c200b00563f78799fasi4426350edx.598.2024.02.21.01.58.12; Wed, 21 Feb 2024 01:58:13 -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=@khirnov.net header.s=mail header.b=l26fWwBm; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 01E6668D1A3; Wed, 21 Feb 2024 11:57:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E283B68D0F4 for ; Wed, 21 Feb 2024 11:57:50 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=l26fWwBm; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id EE2294496 for ; Wed, 21 Feb 2024 10:57:49 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id M3hHpAiNHrSE for ; Wed, 21 Feb 2024 10:57:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1708509469; bh=Hh/WWyhB61QVWCzp9RSiF/+olJOYE9b0Emn8RHReZIc=; h=From:To:Subject:Date:From; b=l26fWwBmmcxBo3N1jZQ5vUdcP95mbhIw2jrk3oDaXuPA1lJUjqz0zVhGwFCIeZL5g MdGCQ/ALKH73PgaMZ9cEIH7uB8bomAKDB9JsYt5Td1HNS5M4tmSLXHZUMKV3wSuPkd JcF7msE7uez+IJpOMkwVfGezHFuL9ZwjQX1p6CYvLHhj+bvS9GYzHG7wInMYYZh05V SxQUXPkkYm6GUnR0Odoq+jspAE1hjvsVS0SIESnz5oHvndT59bfVRn6Mzey5ZtHFR0 e/gmqzMUpDp5ZXOfttlU3SndqtHTrGnU0dCZ6PxZ638QQGHX3i6GjYlWQQfTrfbZA/ EglRyJKzqmyyw== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 15625FE1 for ; Wed, 21 Feb 2024 10:57:49 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E4F7F3A0327 for ; Wed, 21 Feb 2024 10:57:48 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Feb 2024 10:56:46 +0100 Message-ID: <20240221095648.5175-1-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg: declare loop indices inside loops 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vNI31WwGcUtf --- fftools/ffmpeg.c | 12 +++++------- fftools/ffmpeg_dec.c | 11 ++++------- fftools/ffmpeg_enc.c | 6 ++---- fftools/ffmpeg_filter.c | 24 ++++++++++-------------- fftools/ffmpeg_mux.c | 3 +-- fftools/ffmpeg_mux_init.c | 9 +++------ 6 files changed, 25 insertions(+), 40 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 3ee7b26d26..2f01a01e2d 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -325,21 +325,19 @@ const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL }; static void ffmpeg_cleanup(int ret) { - int i; - if (do_benchmark) { int maxrss = getmaxrss() / 1024; av_log(NULL, AV_LOG_INFO, "bench: maxrss=%iKiB\n", maxrss); } - for (i = 0; i < nb_filtergraphs; i++) + for (int i = 0; i < nb_filtergraphs; i++) fg_free(&filtergraphs[i]); av_freep(&filtergraphs); - for (i = 0; i < nb_output_files; i++) + for (int i = 0; i < nb_output_files; i++) of_free(&output_files[i]); - for (i = 0; i < nb_input_files; i++) + for (int i = 0; i < nb_input_files; i++) ifile_close(&input_files[i]); if (vstats_file) { @@ -792,7 +790,7 @@ static int check_keyboard_interaction(int64_t cur_time) */ static int transcode(Scheduler *sch) { - int ret = 0, i; + int ret = 0; int64_t timer_start, transcode_ts = 0; print_stream_maps(); @@ -824,7 +822,7 @@ static int transcode(Scheduler *sch) ret = sch_stop(sch, &transcode_ts); /* write the trailer if needed */ - for (i = 0; i < nb_output_files; i++) { + for (int i = 0; i < nb_output_files; i++) { int err = of_write_trailer(output_files[i]); ret = err_merge(ret, err); } diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 769ae36296..8c92b27cc1 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -871,14 +871,13 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(*p); const AVCodecHWConfig *config = NULL; - int i; if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) break; if (dp->hwaccel_id == HWACCEL_GENERIC || dp->hwaccel_id == HWACCEL_AUTO) { - for (i = 0;; i++) { + for (int i = 0;; i++) { config = avcodec_get_hw_config(s->codec, i); if (!config) break; @@ -902,8 +901,7 @@ static HWDevice *hw_device_match_by_codec(const AVCodec *codec) { const AVCodecHWConfig *config; HWDevice *dev; - int i; - for (i = 0;; i++) { + for (int i = 0;; i++) { config = avcodec_get_hw_config(codec, i); if (!config) return NULL; @@ -981,12 +979,11 @@ static int hw_device_setup_for_decode(DecoderPriv *dp, } if (auto_device) { - int i; if (!avcodec_get_hw_config(codec, 0)) { // Decoder does not support any hardware devices. return 0; } - for (i = 0; !dev; i++) { + for (int i = 0; !dev; i++) { config = avcodec_get_hw_config(codec, i); if (!config) break; @@ -998,7 +995,7 @@ static int hw_device_setup_for_decode(DecoderPriv *dp, av_hwdevice_get_type_name(type), dev->name); } } - for (i = 0; !dev; i++) { + for (int i = 0; !dev; i++) { config = avcodec_get_hw_config(codec, i); if (!config) break; diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index e66f8e6183..bdba50df03 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -93,7 +93,6 @@ static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref { const AVCodecHWConfig *config; HWDevice *dev = NULL; - int i; if (frames_ref && ((AVHWFramesContext*)frames_ref->data)->format == @@ -103,7 +102,7 @@ static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref frames_ref = NULL; } - for (i = 0;; i++) { + for (int i = 0;; i++) { config = avcodec_get_hw_config(ost->enc_ctx->codec, i); if (!config) break; @@ -353,8 +352,7 @@ int enc_open(void *opaque, const AVFrame *frame) * global side data. */ if (ist) { - int i; - for (i = 0; i < ist->st->codecpar->nb_coded_side_data; i++) { + for (int i = 0; i < ist->st->codecpar->nb_coded_side_data; i++) { AVPacketSideData *sd_src = &ist->st->codecpar->coded_side_data[i]; if (sd_src->type != AV_PKT_DATA_CPB_PROPERTIES) { AVPacketSideData *sd_dst = av_packet_side_data_new(&ost->par_in->coded_side_data, diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 79cc101fb6..4731c78ba0 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -330,7 +330,7 @@ static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts, AVFrame *frame = ifp->sub2video.frame; int8_t *dst; int dst_linesize; - int num_rects, i; + int num_rects; int64_t pts, end_pts; if (sub) { @@ -356,7 +356,7 @@ static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts, } dst = frame->data [0]; dst_linesize = frame->linesize[0]; - for (i = 0; i < num_rects; i++) + for (int i = 0; i < num_rects; i++) sub2video_copy_rect(dst, dst_linesize, frame->width, frame->height, sub->rects[i]); sub2video_push_ref(ifp, pts); ifp->sub2video.end_pts = end_pts; @@ -617,8 +617,7 @@ fail: // Filters can be configured only if the formats of all inputs are known. static int ifilter_has_all_input_formats(FilterGraph *fg) { - int i; - for (i = 0; i < fg->nb_inputs; i++) { + for (int i = 0; i < fg->nb_inputs; i++) { InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); if (ifp->format < 0) return 0; @@ -1368,10 +1367,9 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, #if FFMPEG_OPT_MAP_CHANNEL if (ost->audio_channels_mapped) { AVChannelLayout mapped_layout = { 0 }; - int i; av_channel_layout_default(&mapped_layout, ost->audio_channels_mapped); av_channel_layout_describe_bprint(&mapped_layout, &args); - for (i = 0; i < ost->audio_channels_mapped; i++) + for (int i = 0; i < ost->audio_channels_mapped; i++) if (ost->audio_channels_map[i] != -1) av_bprintf(&args, "|c%d=c%d", i, ost->audio_channels_map[i]); @@ -1450,8 +1448,7 @@ static int configure_output_filter(FilterGraph *fg, AVFilterGraph *graph, int check_filter_outputs(void) { - int i; - for (i = 0; i < nb_filtergraphs; i++) { + for (int i = 0; i < nb_filtergraphs; i++) { int n; for (n = 0; n < filtergraphs[i]->nb_outputs; n++) { OutputFilter *output = filtergraphs[i]->outputs[n]; @@ -1636,10 +1633,9 @@ static int configure_input_filter(FilterGraph *fg, AVFilterGraph *graph, static void cleanup_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) { - int i; - for (i = 0; i < fg->nb_outputs; i++) + for (int i = 0; i < fg->nb_outputs; i++) ofp_from_ofilter(fg->outputs[i])->filter = NULL; - for (i = 0; i < fg->nb_inputs; i++) + for (int i = 0; i < fg->nb_inputs; i++) ifp_from_ifilter(fg->inputs[i])->filter = NULL; avfilter_graph_free(&fgt->graph); } @@ -1749,7 +1745,7 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) /* limit the lists of allowed formats to the ones selected, to * make sure they stay the same if the filtergraph is reconfigured later */ - for (i = 0; i < fg->nb_outputs; i++) { + for (int i = 0; i < fg->nb_outputs; i++) { OutputFilter *ofilter = fg->outputs[i]; OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); AVFilterContext *sink = ofp->filter; @@ -1778,7 +1774,7 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) goto fail; } - for (i = 0; i < fg->nb_inputs; i++) { + for (int i = 0; i < fg->nb_inputs; i++) { InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); AVFrame *tmp; while (av_fifo_read(ifp->frame_queue, &tmp, 1) >= 0) { @@ -1794,7 +1790,7 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt) } /* send the EOFs for the finished inputs */ - for (i = 0; i < fg->nb_inputs; i++) { + for (int i = 0; i < fg->nb_inputs; i++) { InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); if (fgt->eof_in[i]) { ret = av_buffersrc_add_frame(ifp->filter, NULL); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 5a648c0568..2c01aec665 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -506,7 +506,6 @@ int print_sdp(const char *filename); int print_sdp(const char *filename) { char sdp[16384]; - int i; int j, ret; AVIOContext *sdp_pb; AVFormatContext **avc; @@ -514,7 +513,7 @@ int print_sdp(const char *filename) avc = av_malloc_array(nb_output_files, sizeof(*avc)); if (!avc) return AVERROR(ENOMEM); - for (i = 0, j = 0; i < nb_output_files; i++) { + for (int i = 0, j = 0; i < nb_output_files; i++) { if (!strcmp(output_files[i]->format->name, "rtp")) { avc[j] = mux_from_of(output_files[i])->fc; j++; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 1abbb2d945..4e2e2ab1d8 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -485,9 +485,8 @@ static int ost_get_filters(const OptionsContext *o, AVFormatContext *oc, static int parse_matrix_coeffs(void *logctx, uint16_t *dest, const char *str) { - int i; const char *p = str; - for (i = 0;; i++) { + for (int i = 0;; i++) { dest[i] = atoi(p); if (i == 63) break; @@ -1108,7 +1107,6 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, const char *bsfs = NULL, *time_base = NULL; char *filters = NULL, *next, *codec_tag = NULL; double qscale = -1; - int i; st = avformat_new_stream(oc, NULL); if (!st) @@ -1350,7 +1348,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, ms->max_frames = INT64_MAX; MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st); - for (i = 0; i < o->max_frames.nb_opt; i++) { + for (int i = 0; i < o->max_frames.nb_opt; i++) { char *p = o->max_frames.opt[i].specifier; if (!*p && type != AVMEDIA_TYPE_VIDEO) { av_log(ost, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n"); @@ -2541,14 +2539,13 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *o { AVFormatContext *is = ifile->ctx; AVChapter **tmp; - int i; tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters)); if (!tmp) return AVERROR(ENOMEM); os->chapters = tmp; - for (i = 0; i < is->nb_chapters; i++) { + for (int i = 0; i < is->nb_chapters; i++) { AVChapter *in_ch = is->chapters[i], *out_ch; int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time; int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,