mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-21 10:55:51 +02:00
fftools/ffmpeg: change the MATCH_PER_TYPE_OPT macro into a function
There is no reason for it to be a macro anymore, this makes the code using it cleaner and simpler.
This commit is contained in:
parent
0ba70a6792
commit
148fac277a
@ -239,14 +239,15 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
|
|||||||
* a global var*/
|
* a global var*/
|
||||||
void *dst = po->flags & OPT_FLAG_OFFSET ?
|
void *dst = po->flags & OPT_FLAG_OFFSET ?
|
||||||
(uint8_t *)optctx + po->u.off : po->u.dst_ptr;
|
(uint8_t *)optctx + po->u.off : po->u.dst_ptr;
|
||||||
|
SpecifierOptList *sol = NULL;
|
||||||
double num;
|
double num;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (po->flags & OPT_FLAG_SPEC) {
|
if (po->flags & OPT_FLAG_SPEC) {
|
||||||
SpecifierOptList *sol = dst;
|
|
||||||
char *p = strchr(opt, ':');
|
char *p = strchr(opt, ':');
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
|
sol = dst;
|
||||||
ret = GROW_ARRAY(sol->opt, sol->nb_opt);
|
ret = GROW_ARRAY(sol->opt, sol->nb_opt);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
@ -312,6 +313,9 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
|
|||||||
if (po->flags & OPT_EXIT)
|
if (po->flags & OPT_EXIT)
|
||||||
return AVERROR_EXIT;
|
return AVERROR_EXIT;
|
||||||
|
|
||||||
|
if (sol)
|
||||||
|
sol->type = po->type;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +117,8 @@ typedef struct SpecifierOpt {
|
|||||||
typedef struct SpecifierOptList {
|
typedef struct SpecifierOptList {
|
||||||
SpecifierOpt *opt;
|
SpecifierOpt *opt;
|
||||||
int nb_opt;
|
int nb_opt;
|
||||||
|
|
||||||
|
enum OptionType type;
|
||||||
} SpecifierOptList;
|
} SpecifierOptList;
|
||||||
|
|
||||||
typedef struct OptionDef {
|
typedef struct OptionDef {
|
||||||
|
@ -803,15 +803,8 @@ void update_benchmark(const char *fmt, ...);
|
|||||||
WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
|
WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
|
const char *opt_match_per_type_str(const SpecifierOptList *sol,
|
||||||
{\
|
char mediatype);
|
||||||
int i;\
|
|
||||||
for (i = 0; i < o->name.nb_opt; i++) {\
|
|
||||||
char *spec = o->name.opt[i].specifier;\
|
|
||||||
if (!strcmp(spec, mediatype))\
|
|
||||||
outvar = o->name.opt[i].u.type;\
|
|
||||||
}\
|
|
||||||
}
|
|
||||||
|
|
||||||
extern const char * const opt_name_codec_names[];
|
extern const char * const opt_name_codec_names[];
|
||||||
extern const char * const opt_name_codec_tags[];
|
extern const char * const opt_name_codec_tags[];
|
||||||
|
@ -1333,10 +1333,10 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
|
|||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
AVDictionary *unused_opts = NULL;
|
AVDictionary *unused_opts = NULL;
|
||||||
const AVDictionaryEntry *e = NULL;
|
const AVDictionaryEntry *e = NULL;
|
||||||
char * video_codec_name = NULL;
|
const char* video_codec_name = NULL;
|
||||||
char * audio_codec_name = NULL;
|
const char* audio_codec_name = NULL;
|
||||||
char *subtitle_codec_name = NULL;
|
const char* subtitle_codec_name = NULL;
|
||||||
char * data_codec_name = NULL;
|
const char* data_codec_name = NULL;
|
||||||
int scan_all_pmts_set = 0;
|
int scan_all_pmts_set = 0;
|
||||||
|
|
||||||
int64_t start_time = o->start_time;
|
int64_t start_time = o->start_time;
|
||||||
@ -1426,10 +1426,10 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
|
|||||||
if (o->frame_pix_fmts.nb_opt)
|
if (o->frame_pix_fmts.nb_opt)
|
||||||
av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts.opt[o->frame_pix_fmts.nb_opt - 1].u.str, 0);
|
av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts.opt[o->frame_pix_fmts.nb_opt - 1].u.str, 0);
|
||||||
|
|
||||||
MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
|
video_codec_name = opt_match_per_type_str(&o->codec_names, 'v');
|
||||||
MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
|
audio_codec_name = opt_match_per_type_str(&o->codec_names, 'a');
|
||||||
MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
|
subtitle_codec_name = opt_match_per_type_str(&o->codec_names, 's');
|
||||||
MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
|
data_codec_name = opt_match_per_type_str(&o->codec_names, 'd');
|
||||||
|
|
||||||
if (video_codec_name)
|
if (video_codec_name)
|
||||||
ret = err_merge(ret, find_codec(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0,
|
ret = err_merge(ret, find_codec(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0,
|
||||||
|
@ -1612,10 +1612,10 @@ static int map_auto_audio(Muxer *mux, const OptionsContext *o)
|
|||||||
static int map_auto_subtitle(Muxer *mux, const OptionsContext *o)
|
static int map_auto_subtitle(Muxer *mux, const OptionsContext *o)
|
||||||
{
|
{
|
||||||
AVFormatContext *oc = mux->fc;
|
AVFormatContext *oc = mux->fc;
|
||||||
char *subtitle_codec_name = NULL;
|
const char *subtitle_codec_name = NULL;
|
||||||
|
|
||||||
/* subtitles: pick first */
|
/* subtitles: pick first */
|
||||||
MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
|
subtitle_codec_name = opt_match_per_type_str(&o->codec_names, 's');
|
||||||
if (!avcodec_find_encoder(oc->oformat->subtitle_codec) && !subtitle_codec_name)
|
if (!avcodec_find_encoder(oc->oformat->subtitle_codec) && !subtitle_codec_name)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -182,6 +182,19 @@ AVDictionary *strip_specifiers(const AVDictionary *dict)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *opt_match_per_type_str(const SpecifierOptList *sol,
|
||||||
|
char mediatype)
|
||||||
|
{
|
||||||
|
av_assert0(!sol->nb_opt || sol->type == OPT_TYPE_STRING);
|
||||||
|
|
||||||
|
for (int i = 0; i < sol->nb_opt; i++) {
|
||||||
|
const char *spec = sol->opt[i].specifier;
|
||||||
|
if (spec[0] == mediatype && !spec[1])
|
||||||
|
return sol->opt[i].u.str;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
|
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
|
||||||
{
|
{
|
||||||
if (!av_strcasecmp(arg, "cfr")) *vsync_var = VSYNC_CFR;
|
if (!av_strcasecmp(arg, "cfr")) *vsync_var = VSYNC_CFR;
|
||||||
@ -1019,9 +1032,7 @@ static int opt_preset(void *optctx, const char *opt, const char *arg)
|
|||||||
const char *codec_name = NULL;
|
const char *codec_name = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
tmp_line[0] = *opt;
|
codec_name = opt_match_per_type_str(&o->codec_names, *opt);
|
||||||
tmp_line[1] = 0;
|
|
||||||
MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line);
|
|
||||||
|
|
||||||
if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
|
if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
|
||||||
if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
|
if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
|
||||||
|
Loading…
Reference in New Issue
Block a user