comparison opt.c @ 8344:844463c05193 libavcodec

Implement the av_set_number2() internal function, which makes possible to distinguish between a not found option failure and a not valid value failure.
author stefano
date Mon, 15 Dec 2008 22:48:10 +0000
parents a6ca9f8642d6
children 0030146fc2ba
comparison
equal deleted inserted replaced
8343:a6ca9f8642d6 8344:844463c05193
45 if(last && last[1].name) return ++last; 45 if(last && last[1].name) return ++last;
46 else if(last) return NULL; 46 else if(last) return NULL;
47 else return (*(AVClass**)obj)->option; 47 else return (*(AVClass**)obj)->option;
48 } 48 }
49 49
50 static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){ 50 static int av_set_number2(void *obj, const char *name, double num, int den, int64_t intnum, const AVOption **o_out){
51 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); 51 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
52 void *dst; 52 void *dst;
53 if(o_out)
54 *o_out= o;
53 if(!o || o->offset<=0) 55 if(!o || o->offset<=0)
54 return NULL; 56 return AVERROR(ENOENT);
55 57
56 if(o->max*den < num*intnum || o->min*den > num*intnum) { 58 if(o->max*den < num*intnum || o->min*den > num*intnum) {
57 av_log(NULL, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range\n", num, name); 59 av_log(NULL, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range\n", num, name);
58 return NULL; 60 return AVERROR(ERANGE);
59 } 61 }
60 62
61 dst= ((uint8_t*)obj) + o->offset; 63 dst= ((uint8_t*)obj) + o->offset;
62 64
63 switch(o->type){ 65 switch(o->type){
69 case FF_OPT_TYPE_RATIONAL: 71 case FF_OPT_TYPE_RATIONAL:
70 if((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den}; 72 if((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
71 else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24); 73 else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
72 break; 74 break;
73 default: 75 default:
76 return AVERROR(EINVAL);
77 }
78 return 0;
79 }
80
81 static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){
82 const AVOption *o = NULL;
83 if (av_set_number2(obj, name, num, den, intnum, &o) < 0)
74 return NULL; 84 return NULL;
75 } 85 else
76 return o; 86 return o;
77 } 87 }
78 88
79 static const double const_values[]={ 89 static const double const_values[]={
80 M_PI, 90 M_PI,
81 M_E, 91 M_E,