History

fftools/cmdutils: add error handling to filter_codec_opts()

Anton Khirnov committed 3 years ago

Commit 87f03331 parent 6b8cf256 files · +56 −23Browse files

Unified · Split

6 files
  1. fftools/cmdutils.c +28 −13
  2. fftools/cmdutils.h +5 −3
  3. fftools/ffmpeg_demux.c +4 −1
  4. fftools/ffmpeg_mux_init.c +8 −3
  5. fftools/ffplay.c +5 −1
  6. fftools/ffprobe.c +6 −2
fftools/cmdutils.c+28−13
@@ -943,8 +943,9 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) · 942 unmodified lines
943943 return ret;
944944 }
945945
946−AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
947− AVFormatContext *s, AVStream *st, const AVCodec *codec)
946+int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
947+ AVFormatContext *s, AVStream *st, const AVCodec *codec,
948+ AVDictionary **dst)
948949 {
949950 AVDictionary *ret = NULL;
950951 const AVDictionaryEntry *t = NULL;
@@ -977,12 +978,16 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i · 26 unmodified lines
977978 char *p = strchr(t->key, ':');
978979
979980 /* check stream specification in opt name */
980− if (p)
981− switch (check_stream_specifier(s, st, p + 1)) {
982− case 1: *p = 0; break;
983− case 0: continue;
984− default: exit_program(1);
985− }
981+ if (p) {
982+ int err = check_stream_specifier(s, st, p + 1);
983+ if (err < 0) {
984+ av_dict_free(&ret);
985+ return err;
986+ } else if (!err)
987+ continue;
988+
989+ *p = 0;
990+ }
986991
987992 if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
988993 !codec ||
@@ -998,14 +1003,16 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i · 9 unmodified lines
9981003 if (p)
9991004 *p = ':';
10001005 }
1001− return ret;
1006+
1007+ *dst = ret;
1008+ return 0;
10021009 }
10031010
10041011 int setup_find_stream_info_opts(AVFormatContext *s,
10051012 AVDictionary *codec_opts,
10061013 AVDictionary ***dst)
10071014 {
1008− int i;
1015+ int ret;
10091016 AVDictionary **opts;
10101017
10111018 *dst = NULL;
@@ -1017,11 +1024,19 @@ int setup_find_stream_info_opts(AVFormatContext *s, · 5 unmodified lines
10171024 if (!opts)
10181025 return AVERROR(ENOMEM);
10191026
1020− for (i = 0; i < s->nb_streams; i++)
1021− opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
1022− s, s->streams[i], NULL);
1027+ for (int i = 0; i < s->nb_streams; i++) {
1028+ ret = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
1029+ s, s->streams[i], NULL, &opts[i]);
1030+ if (ret < 0)
1031+ goto fail;
1032+ }
10231033 *dst = opts;
10241034 return 0;
1035+fail:
1036+ for (int i = 0; i < s->nb_streams; i++)
1037+ av_dict_free(&opts[i]);
1038+ av_freep(&opts);
1039+ return ret;
10251040 }
10261041
10271042 int grow_array(void **array, int elem_size, int *size, int new_size)
fftools/cmdutils.h+5−3
@@ -333,10 +333,12 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec); · 332 unmodified lines
333333 * @param st A stream from s for which the options should be filtered.
334334 * @param codec The particular codec for which the options should be filtered.
335335 * If null, the default one is looked up according to the codec id.
336− * @return a pointer to the created dictionary
336+ * @param dst a pointer to the created dictionary
337+ * @return a non-negative number on success, a negative error code on failure
337338 */
338−AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
339− AVFormatContext *s, AVStream *st, const AVCodec *codec);
339+int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
340+ AVFormatContext *s, AVStream *st, const AVCodec *codec,
341+ AVDictionary **dst);
340342
341343 /**
342344 * Setup AVCodecContext options for avformat_find_stream_info().
fftools/ffmpeg_demux.c+4−1
@@ -1176,7 +1176,10 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) · 1175 unmodified lines
11761176 if (ret < 0)
11771177 return ret;
11781178
1179− ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
1179+ ret = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id,
1180+ ic, st, ist->dec, &ist->decoder_opts);
1181+ if (ret < 0)
1182+ return ret;
11801183
11811184 ist->reinit_filters = -1;
11821185 MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
fftools/ffmpeg_mux_init.c+8−3
@@ -1206,8 +1206,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 1205 unmodified lines
12061206 const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL;
12071207 const char *enc_time_base = NULL;
12081208
1209− ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id,
1210− oc, st, enc->codec);
1209+ ret = filter_codec_opts(o->g->codec_opts, enc->codec_id,
1210+ oc, st, enc->codec, &ost->encoder_opts);
1211+ if (ret < 0)
1212+ return ret;
12111213
12121214 MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
12131215 ost->autoscale = 1;
@@ -1305,7 +1307,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 91 unmodified lines
13051307 ost->enc_timebase = q;
13061308 }
13071309 } else {
1308− ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
1310+ ret = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st,
1311+ NULL, &ost->encoder_opts);
1312+ if (ret < 0)
1313+ return ret;
13091314 }
13101315
13111316
fftools/ffplay.c+5−1
@@ -2584,7 +2584,11 @@ static int stream_component_open(VideoState *is, int stream_index) · 2583 unmodified lines
25842584 if (fast)
25852585 avctx->flags2 |= AV_CODEC_FLAG2_FAST;
25862586
2587− opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index], codec);
2587+ ret = filter_codec_opts(codec_opts, avctx->codec_id, ic,
2588+ ic->streams[stream_index], codec, &opts);
2589+ if (ret < 0)
2590+ goto fail;
2591+
25882592 if (!av_dict_get(opts, "threads", NULL, 0))
25892593 av_dict_set(&opts, "threads", "auto", 0);
25902594 if (stream_lowres)
fftools/ffprobe.c+6−2
@@ -3421,8 +3421,12 @@ static int open_input_file(InputFile *ifile, const char *filename, · 3420 unmodified lines
34213421 continue;
34223422 }
34233423 {
3424− AVDictionary *opts = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
3425− fmt_ctx, stream, codec);
3424+ AVDictionary *opts;
3425+
3426+ err = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
3427+ fmt_ctx, stream, codec, &opts);
3428+ if (err < 0)
3429+ exit(1);
34263430
34273431 ist->dec_ctx = avcodec_alloc_context3(codec);
34283432 if (!ist->dec_ctx)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t