aboutsummaryrefslogtreecommitdiffstats
path: root/fftools/ffmpeg_demux.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2024-08-06 11:11:41 +0200
committerAnton Khirnov <anton@khirnov.net>2024-08-13 10:28:54 +0200
commite218bde9f9e3b41d89921ed475065da88b5c0b83 (patch)
tree980673bab7299aee20f9548f00d7180e84cec165 /fftools/ffmpeg_demux.c
parent82085a3e0a5a2d167dc51628678f7374dc53060e (diff)
downloadffmpeg-e218bde9f9e3b41d89921ed475065da88b5c0b83.tar.gz
fftools/ffmpeg: replace MATCH_PER_STREAM_OPT(.., str, ..) with a function
This has multiple advantages: * The macro has multiple parameters that often have similar or identical values, yet very different meanings (one is the name of the OptionsContext member where the parsed options are stored, the other the name of the variable into which the result is written); this change makes each of these explicit. * The macro returns on failure, which may cause leaks - this was the reason for adding MATCH_PER_STREAM_OPT_CLEAN(), also ost_add() currently leaks encoder_opts. The new function returns failure to its caller, which decides how to deal with it. While that adds a lot of error checks/forwards for now, those will be reduced in following commits. * new code is type- and const- correct Invocations of MATCH_PER_STREAM_OPT() with other types will be converted in following commits.
Diffstat (limited to 'fftools/ffmpeg_demux.c')
-rw-r--r--fftools/ffmpeg_demux.c74
1 files changed, 51 insertions, 23 deletions
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 6f7d78c896..0c92d31c10 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1077,14 +1077,19 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
return ds->sch_idx_dec;
}
-static int choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
+static int choose_decoder(const OptionsContext *o, void *logctx,
+ AVFormatContext *s, AVStream *st,
enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
const AVCodec **pcodec)
{
- char *codec_name = NULL;
+ const char *codec_name = NULL;
+ int ret;
+
+ ret = opt_match_per_stream_str(logctx, &o->codec_names, s, st, &codec_name);
+ if (ret < 0)
+ return ret;
- MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
if (codec_name) {
int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
if (ret < 0)
@@ -1226,14 +1231,14 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
AVCodecParameters *par = st->codecpar;
DemuxStream *ds;
InputStream *ist;
- char *framerate = NULL, *hwaccel_device = NULL;
+ const char *framerate = NULL, *hwaccel_device = NULL;
const char *hwaccel = NULL;
const char *apply_cropping = NULL;
- char *hwaccel_output_format = NULL;
- char *codec_tag = NULL;
- char *bsfs = NULL;
+ const char *hwaccel_output_format = NULL;
+ const char *codec_tag = NULL;
+ const char *bsfs = NULL;
char *next;
- char *discard_str = NULL;
+ const char *discard_str = NULL;
int ret;
ds = demux_stream_alloc(d, st);
@@ -1256,7 +1261,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
ds->apply_cropping = CROP_ALL;
- MATCH_PER_STREAM_OPT(apply_cropping, str, apply_cropping, ic, st);
+ ret = opt_match_per_stream_str(ist, &o->apply_cropping, ic, st, &apply_cropping);
+ if (ret < 0)
+ return ret;
if (apply_cropping) {
const AVOption opts[] = {
{ "apply_cropping", NULL, 0, AV_OPT_TYPE_INT,
@@ -1282,7 +1289,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
}
}
- MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
+ ret = opt_match_per_stream_str(ist, &o->codec_tags, ic, st, &codec_tag);
+ if (ret < 0)
+ return ret;
if (codec_tag) {
uint32_t tag = strtol(codec_tag, &next, 0);
if (*next) {
@@ -1299,9 +1308,14 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
if (ret < 0)
return ret;
- MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
- MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
- hwaccel_output_format, ic, st);
+ ret = opt_match_per_stream_str(ist, &o->hwaccels, ic, st, &hwaccel);
+ if (ret < 0)
+ return ret;
+
+ ret = opt_match_per_stream_str(ist, &o->hwaccel_output_formats, ic, st,
+ &hwaccel_output_format);
+ if (ret < 0)
+ return ret;
if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
av_log(ist, AV_LOG_WARNING,
@@ -1360,7 +1374,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
}
}
- MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
+ ret = opt_match_per_stream_str(ist, &o->hwaccel_devices, ic, st, &hwaccel_device);
+ if (ret < 0)
+ return ret;
if (hwaccel_device) {
ds->dec_opts.hwaccel_device = av_strdup(hwaccel_device);
if (!ds->dec_opts.hwaccel_device)
@@ -1368,7 +1384,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
}
}
- ret = choose_decoder(o, ic, st, ds->dec_opts.hwaccel_id,
+ ret = choose_decoder(o, ist, ic, st, ds->dec_opts.hwaccel_id,
ds->dec_opts.hwaccel_device_type, &ist->dec);
if (ret < 0)
return ret;
@@ -1391,7 +1407,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
(o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
ist->user_set_discard = AVDISCARD_ALL;
- MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
+ ret = opt_match_per_stream_str(ist, &o->discard, ic, st, &discard_str);
+ if (ret < 0)
+ return ret;
if (discard_str) {
ret = av_opt_set(ist->st, "discard", discard_str, 0);
if (ret < 0) {
@@ -1413,7 +1431,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
switch (par->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
+ ret = opt_match_per_stream_str(ist, &o->frame_rates, ic, st, &framerate);
+ if (ret < 0)
+ return ret;
if (framerate) {
ret = av_parse_video_rate(&ist->framerate, framerate);
if (ret < 0) {
@@ -1430,8 +1450,11 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
break;
case AVMEDIA_TYPE_AUDIO: {
- char *ch_layout_str = NULL;
- MATCH_PER_STREAM_OPT(audio_ch_layouts, str, ch_layout_str, ic, st);
+ const char *ch_layout_str = NULL;
+
+ ret = opt_match_per_stream_str(ist, &o->audio_ch_layouts, ic, st, &ch_layout_str);
+ if (ret < 0)
+ return ret;
if (ch_layout_str) {
AVChannelLayout ch_layout;
ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);
@@ -1458,9 +1481,12 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
}
case AVMEDIA_TYPE_DATA:
case AVMEDIA_TYPE_SUBTITLE: {
- char *canvas_size = NULL;
+ const char *canvas_size = NULL;
MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
- MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
+
+ ret = opt_match_per_stream_str(ist, &o->canvas_sizes, ic, st, &canvas_size);
+ if (ret < 0)
+ return ret;
if (canvas_size) {
ret = av_parse_video_size(&par->width, &par->height,
canvas_size);
@@ -1490,7 +1516,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
if (ist->st->sample_aspect_ratio.num)
ist->par->sample_aspect_ratio = ist->st->sample_aspect_ratio;
- MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, ic, st);
+ ret = opt_match_per_stream_str(ist, &o->bitstream_filters, ic, st, &bsfs);
+ if (ret < 0)
+ return ret;
if (bsfs) {
ret = av_bsf_list_parse_str(bsfs, &ds->bsf);
if (ret < 0) {
@@ -1752,7 +1780,7 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
/* apply forced codec ids */
for (i = 0; i < ic->nb_streams; i++) {
const AVCodec *dummy;
- ret = choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE,
+ ret = choose_decoder(o, f, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE,
&dummy);
if (ret < 0)
return ret;