Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg: declare loop indices inside loops
@ 2024-02-21  9:56 Anton Khirnov
  2024-02-21  9:56 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_sched: simplify failure path in sch_dec_send() Anton Khirnov
  2024-02-21  9:56 ` [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg_sched: remove a triggerable assert in send_to_enc_sq() Anton Khirnov
  0 siblings, 2 replies; 3+ messages in thread
From: Anton Khirnov @ 2024-02-21  9:56 UTC (permalink / raw)
  To: ffmpeg-devel

---
 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,
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_sched: simplify failure path in sch_dec_send()
  2024-02-21  9:56 [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg: declare loop indices inside loops Anton Khirnov
@ 2024-02-21  9:56 ` Anton Khirnov
  2024-02-21  9:56 ` [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg_sched: remove a triggerable assert in send_to_enc_sq() Anton Khirnov
  1 sibling, 0 replies; 3+ messages in thread
From: Anton Khirnov @ 2024-02-21  9:56 UTC (permalink / raw)
  To: ffmpeg-devel

---
 fftools/ffmpeg_sched.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c
index d91968822f..cb9d8c6905 100644
--- a/fftools/ffmpeg_sched.c
+++ b/fftools/ffmpeg_sched.c
@@ -2035,13 +2035,11 @@ int sch_dec_send(Scheduler *sch, unsigned dec_idx, AVFrame *frame)
                 ret = 0;
                 continue;
             }
-            goto finish;
+            return ret;
         }
     }
 
-finish:
-    return ret < 0                  ? ret :
-           (nb_done == dec->nb_dst) ? AVERROR_EOF : 0;
+    return (nb_done == dec->nb_dst) ? AVERROR_EOF : 0;
 }
 
 static int dec_done(Scheduler *sch, unsigned dec_idx)
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg_sched: remove a triggerable assert in send_to_enc_sq()
  2024-02-21  9:56 [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg: declare loop indices inside loops Anton Khirnov
  2024-02-21  9:56 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_sched: simplify failure path in sch_dec_send() Anton Khirnov
@ 2024-02-21  9:56 ` Anton Khirnov
  1 sibling, 0 replies; 3+ messages in thread
From: Anton Khirnov @ 2024-02-21  9:56 UTC (permalink / raw)
  To: ffmpeg-devel

It can be triggered when send_to_enc_thread() returns AVERROR(ENOMEM).
Propagate the error to the caller instead.

Reported-by: Andreas Rheinhardt
---
 fftools/ffmpeg_sched.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c
index cb9d8c6905..1144fce958 100644
--- a/fftools/ffmpeg_sched.c
+++ b/fftools/ffmpeg_sched.c
@@ -1541,31 +1541,34 @@ static int send_to_enc_sq(Scheduler *sch, SchEnc *enc, AVFrame *frame)
         // TODO: the SQ API should be extended to allow returning EOF
         // for individual streams
         ret = sq_receive(sq->sq, -1, SQFRAME(sq->frame));
-        if (ret == AVERROR(EAGAIN)) {
-            ret = 0;
-            goto finish;
-        } else if (ret < 0) {
-            // close all encoders fed from this sync queue
-            for (unsigned i = 0; i < sq->nb_enc_idx; i++) {
-                int err = send_to_enc_thread(sch, &sch->enc[sq->enc_idx[i]], NULL);
-
-                // if the sync queue error is EOF and closing the encoder
-                // produces a more serious error, make sure to pick the latter
-                ret = err_merge((ret == AVERROR_EOF && err < 0) ? 0 : ret, err);
-            }
-            goto finish;
+        if (ret < 0) {
+            ret = (ret == AVERROR(EAGAIN)) ? 0 : ret;
+            break;
         }
 
         enc = &sch->enc[sq->enc_idx[ret]];
         ret = send_to_enc_thread(sch, enc, sq->frame);
         if (ret < 0) {
-            av_assert0(ret == AVERROR_EOF);
             av_frame_unref(sq->frame);
+            if (ret != AVERROR_EOF)
+                break;
+
             sq_send(sq->sq, enc->sq_idx[1], SQFRAME(NULL));
             continue;
         }
     }
 
+    if (ret < 0) {
+        // close all encoders fed from this sync queue
+        for (unsigned i = 0; i < sq->nb_enc_idx; i++) {
+            int err = send_to_enc_thread(sch, &sch->enc[sq->enc_idx[i]], NULL);
+
+            // if the sync queue error is EOF and closing the encoder
+            // produces a more serious error, make sure to pick the latter
+            ret = err_merge((ret == AVERROR_EOF && err < 0) ? 0 : ret, err);
+        }
+    }
+
 finish:
     pthread_mutex_unlock(&sq->lock);
 
-- 
2.42.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-21  9:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-21  9:56 [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg: declare loop indices inside loops Anton Khirnov
2024-02-21  9:56 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_sched: simplify failure path in sch_dec_send() Anton Khirnov
2024-02-21  9:56 ` [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg_sched: remove a triggerable assert in send_to_enc_sq() Anton Khirnov

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git