📄 opt.c
字号:
/*
* AVOptions
* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/**
* @file opt.c
* AVOptions
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#include "avcodec.h"
#include "opt.h"
#ifndef M_E
#define M_E 2.718281828
#endif
//FIXME order them and do a bin search
STATIC_FUNC AVOption *find_opt(void *v, const char *name, const char *unit){
AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
AVOption *o= c->option;
for(;o && o->name; o++){
if(!strcmp(o->name, name) && (!unit || !strcmp(o->unit, unit)) )
return o;
}
return NULL;
}
AVOption *av_next_option(void *obj, AVOption *last){
if(last && last[1].name) return ++last;
else if(last) return NULL;
else return (*(AVClass**)obj)->option;
}
STATIC_FUNC AVOption *av_set_number(void *obj, const char *name, int num, int den, int64_t intnum){
AVOption *o= find_opt(obj, name, NULL);
void *dst;
if(!o || o->offset<=0)
return NULL;
if(o->max*den < num*intnum || o->min*den > num*intnum) {
DP_LOG((M_TEXT("Value %lf for parameter '%s' out of range.\n"), num, name));
return NULL;
}
dst= ((uint8_t*)obj) + o->offset;
switch(o->type){
case FF_OPT_TYPE_FLAGS:
case FF_OPT_TYPE_INT: *(int *)dst= (int)(lrintf((num/den))*intnum); break;
default:
return NULL;
}
return o;
}
AVOption *av_set_int(void *obj, const char *name, int64_t n){
return av_set_number(obj, name, 1, 1, n);
}
STATIC_FUNC int av_get_number(void *obj, const char *name, AVOption **o_out, double *num, int *den, int64_t *intnum){
AVOption *o= find_opt(obj, name, NULL);
void *dst;
if(!o || o->offset<=0)
goto error;
dst= ((uint8_t*)obj) + o->offset;
if(o_out) *o_out= o;
switch(o->type){
case FF_OPT_TYPE_FLAGS:
case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0;
}
error:
*den=0;
*intnum=0;
return -1;
}
int64_t av_get_int(void *obj, const char *name, AVOption **o_out){
int64_t intnum=1;
double num=1;
int den=1;
av_get_number(obj, name, o_out, &num, &den, &intnum);
return (int64_t)(num*intnum/den);
}
STATIC_FUNC void opt_list(void *obj, void *av_log_obj, char *unit)
{
AVOption *opt=NULL;
while((opt= av_next_option(obj, opt))){
if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM)))
continue;
/* Don't print CONST's on level one.
* Don't print anything but CONST's on level two.
* Only print items from the requested unit.
*/
if (!unit && opt->type==FF_OPT_TYPE_CONST)
continue;
else if (unit && opt->type!=FF_OPT_TYPE_CONST)
continue;
else if (unit && opt->type==FF_OPT_TYPE_CONST && strcmp(unit, opt->unit))
continue;
else if (unit && opt->type == FF_OPT_TYPE_CONST)
DP_LOG((M_TEXT(" %-15s "), opt->name));
else
DP_LOG((M_TEXT("-%-17s "), opt->name));
switch( opt->type )
{
case FF_OPT_TYPE_FLAGS:
DP_LOG((M_TEXT("%-7s "), "<flags>"));
break;
case FF_OPT_TYPE_INT:
DP_LOG((M_TEXT("%-7s "), "<int>"));
break;
case FF_OPT_TYPE_STRING:
DP_LOG((M_TEXT("%-7s "), "<string>"));
break;
case FF_OPT_TYPE_CONST:
default:
DP_LOG((M_TEXT("%-7s "), ""));
break;
}
DP_LOG((M_TEXT("%c"), (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.'));
DP_LOG((M_TEXT("%c"), (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.'));
DP_LOG((M_TEXT("%c"), (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.'));
DP_LOG((M_TEXT("%c"), (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.'));
DP_LOG((M_TEXT("%c"), (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.'));
if(opt->help)
DP_LOG((M_TEXT(" %s "), opt->help));
DP_LOG((M_TEXT("\n")));
if (opt->unit && opt->type != FF_OPT_TYPE_CONST) {
opt_list(obj, av_log_obj, (char*)opt->unit);
}
}
}
int av_opt_show(void *obj, void *av_log_obj)
{
if(!obj)
return -1;
DP_LOG((M_TEXT("%s AVOptions:\n"), (*(AVClass**)obj)->class_name));
opt_list(obj, av_log_obj, NULL);
return 0;
}
/** Set the values of the AVCodecContext or AVFormatContext structure.
* They are set to the defaults specified in the according AVOption options
* array default_val field.
*
* @param s AVCodecContext or AVFormatContext for which the defaults will be set
*/
void av_opt_set_defaults(void *s)
{
AVOption *opt = NULL;
while ((opt = av_next_option(s, opt)) != NULL) {
switch(opt->type) {
case FF_OPT_TYPE_CONST:
/* Nothing to be done here */
break;
case FF_OPT_TYPE_FLAGS:
case FF_OPT_TYPE_INT: {
int val;
val = (int)(opt->default_val);
av_set_int(s, opt->name, val);
}
break;
case FF_OPT_TYPE_STRING:
/* Cannot set default for string as default_val is of type * double */
break;
default:
DP_LOG((M_TEXT("AVOption type %d of option %s not implemented yet\n"), opt->type, opt->name));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -