[FFmpeg-cvslog] fftools/ffmpeg: declare loop indices inside loops

Anton Khirnov git at videolan.org
Sat Feb 24 12:56:54 EET 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Feb 19 10:43:24 2024 +0100| [a2fc86378a18b2c2966ce3438df8f27f646438e5] | committer: Anton Khirnov

fftools/ffmpeg: declare loop indices inside loops

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a2fc86378a18b2c2966ce3438df8f27f646438e5
---

 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,



More information about the ffmpeg-cvslog mailing list