Mercurial > libavcodec.hg
comparison opt.c @ 2874:b6def74f5811 libavcodec
flags and named constants with type checking of course for AVOption
spliting AVOption specific stuff out of avcodec.h into opt.h
author | michael |
---|---|
date | Sun, 11 Sep 2005 14:22:42 +0000 |
parents | 55809f38eb63 |
children | 1021498a5159 |
comparison
equal
deleted
inserted
replaced
2873:55809f38eb63 | 2874:b6def74f5811 |
---|---|
62 return NULL; | 62 return NULL; |
63 | 63 |
64 dst= ((uint8_t*)obj) + o->offset; | 64 dst= ((uint8_t*)obj) + o->offset; |
65 | 65 |
66 switch(o->type){ | 66 switch(o->type){ |
67 case FF_OPT_TYPE_FLAGS: | |
67 case FF_OPT_TYPE_INT: *(int *)dst= lrintf(num/den)*intnum; break; | 68 case FF_OPT_TYPE_INT: *(int *)dst= lrintf(num/den)*intnum; break; |
68 case FF_OPT_TYPE_INT64: *(int64_t *)dst= lrintf(num/den)*intnum; break; | 69 case FF_OPT_TYPE_INT64: *(int64_t *)dst= lrintf(num/den)*intnum; break; |
69 case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break; | 70 case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break; |
70 case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break; | 71 case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break; |
71 case FF_OPT_TYPE_RATIONAL: | 72 case FF_OPT_TYPE_RATIONAL: |
81 AVOption *av_set_string(void *obj, const char *name, const char *val){ | 82 AVOption *av_set_string(void *obj, const char *name, const char *val){ |
82 AVOption *o= find_opt(obj, name); | 83 AVOption *o= find_opt(obj, name); |
83 if(!o || !val || o->offset<=0) | 84 if(!o || !val || o->offset<=0) |
84 return NULL; | 85 return NULL; |
85 if(o->type != FF_OPT_TYPE_STRING){ | 86 if(o->type != FF_OPT_TYPE_STRING){ |
86 double d=0, tmp_d; | |
87 for(;;){ | 87 for(;;){ |
88 int i; | 88 int i; |
89 char buf[256], *tail; | 89 char buf[256], *tail; |
90 | 90 int cmd=0; |
91 for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+'; i++) | 91 double d; |
92 | |
93 if(*val == '+' || *val == '-') | |
94 cmd= *(val++); | |
95 | |
96 for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++) | |
92 buf[i]= val[i]; | 97 buf[i]= val[i]; |
93 buf[i]=0; | 98 buf[i]=0; |
94 val+= i; | 99 val+= i; |
95 | 100 |
96 tmp_d= av_parse_num(buf, &tail); | 101 d= av_parse_num(buf, &tail); |
97 if(tail > buf) | 102 if(tail <= buf){ |
98 d+= tmp_d; | |
99 else{ | |
100 AVOption *o_named= find_opt(obj, buf); | 103 AVOption *o_named= find_opt(obj, buf); |
101 if(o_named && o_named->type == FF_OPT_TYPE_CONST) | 104 if(o_named && o_named->type == FF_OPT_TYPE_CONST && !strcmp(o_named->unit, o->unit)) |
102 d+= o_named->default_val; | 105 d= o_named->default_val; |
103 else if(!strcmp(buf, "default")) d+= o->default_val; | 106 else if(!strcmp(buf, "default")) d= o->default_val; |
104 else if(!strcmp(buf, "max" )) d+= o->max; | 107 else if(!strcmp(buf, "max" )) d= o->max; |
105 else if(!strcmp(buf, "min" )) d+= o->min; | 108 else if(!strcmp(buf, "min" )) d= o->min; |
106 else return NULL; | 109 else return NULL; |
107 } | 110 } |
108 | 111 if(o->type == FF_OPT_TYPE_FLAGS){ |
109 if(*val == '+') val++; | 112 if (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d; |
113 else if(cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d; | |
114 }else if(cmd=='-') | |
115 d= -d; | |
116 | |
117 av_set_number(obj, name, d, 1, 1); | |
110 if(!*val) | 118 if(!*val) |
111 return av_set_number(obj, name, d, 1, 1); | 119 return o; |
112 } | 120 } |
113 return NULL; | 121 return NULL; |
114 } | 122 } |
115 | 123 |
116 memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val)); | 124 memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val)); |
147 | 155 |
148 if(o->type == FF_OPT_TYPE_STRING) | 156 if(o->type == FF_OPT_TYPE_STRING) |
149 return dst; | 157 return dst; |
150 | 158 |
151 switch(o->type){ | 159 switch(o->type){ |
160 case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break; | |
152 case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break; | 161 case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break; |
153 case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%Ld", *(int64_t*)dst);break; | 162 case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%Ld", *(int64_t*)dst);break; |
154 case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; | 163 case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; |
155 case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; | 164 case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; |
156 case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; | 165 case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; |
168 dst= ((uint8_t*)obj) + o->offset; | 177 dst= ((uint8_t*)obj) + o->offset; |
169 | 178 |
170 if(o_out) *o_out= o; | 179 if(o_out) *o_out= o; |
171 | 180 |
172 switch(o->type){ | 181 switch(o->type){ |
182 case FF_OPT_TYPE_FLAGS: | |
173 case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0; | 183 case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0; |
174 case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0; | 184 case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0; |
175 case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0; | 185 case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0; |
176 case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0; | 186 case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0; |
177 case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num; | 187 case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num; |