Mercurial > libavcodec.hg
comparison opt.c @ 6034:72bb141d9c05 libavcodec
Add FF_OPT_TYPE_BINARY and use it to add a cryptokey option
author | reimar |
---|---|
date | Mon, 17 Dec 2007 17:41:24 +0000 |
parents | bb4f24c580f5 |
children | 42a3c36e3303 |
comparison
equal
deleted
inserted
replaced
6033:bd7600c7a061 | 6034:72bb141d9c05 |
---|---|
106 "E", | 106 "E", |
107 "QP2LAMBDA", | 107 "QP2LAMBDA", |
108 0 | 108 0 |
109 }; | 109 }; |
110 | 110 |
111 static int hexchar2int(char c) { | |
112 if (c >= '0' && c <= '9') return c - '0'; | |
113 if (c >= 'a' && c <= 'f') return c - 'a' + 10; | |
114 if (c >= 'A' && c <= 'F') return c - 'A' + 10; | |
115 return -1; | |
116 } | |
117 | |
111 const AVOption *av_set_string(void *obj, const char *name, const char *val){ | 118 const AVOption *av_set_string(void *obj, const char *name, const char *val){ |
112 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); | 119 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); |
113 if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){ | 120 if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){ |
114 return set_all_opt(obj, o->unit, o->default_val); | 121 return set_all_opt(obj, o->unit, o->default_val); |
115 } | 122 } |
116 if(!o || !val || o->offset<=0) | 123 if(!o || !val || o->offset<=0) |
117 return NULL; | 124 return NULL; |
125 if(o->type == FF_OPT_TYPE_BINARY){ | |
126 uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset); | |
127 int *lendst = (int *)(dst + 1); | |
128 uint8_t *bin, *ptr; | |
129 int len = strlen(val); | |
130 av_freep(dst); | |
131 *lendst = 0; | |
132 if (len & 1) return NULL; | |
133 len /= 2; | |
134 ptr = bin = av_malloc(len); | |
135 while (*val) { | |
136 int a = hexchar2int(*val++); | |
137 int b = hexchar2int(*val++); | |
138 if (a < 0 || b < 0) { | |
139 av_free(bin); | |
140 return NULL; | |
141 } | |
142 *ptr++ = (a << 4) | b; | |
143 } | |
144 *dst = bin; | |
145 *lendst = len; | |
146 return o; | |
147 } | |
118 if(o->type != FF_OPT_TYPE_STRING){ | 148 if(o->type != FF_OPT_TYPE_STRING){ |
119 for(;;){ | 149 for(;;){ |
120 int i; | 150 int i; |
121 char buf[256]; | 151 char buf[256]; |
122 int cmd=0; | 152 int cmd=0; |
182 * @param buf_len allocated length in bytes of buf | 212 * @param buf_len allocated length in bytes of buf |
183 */ | 213 */ |
184 const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){ | 214 const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){ |
185 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); | 215 const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); |
186 void *dst; | 216 void *dst; |
217 uint8_t *bin; | |
218 int len, i; | |
187 if(!o || o->offset<=0) | 219 if(!o || o->offset<=0) |
188 return NULL; | 220 return NULL; |
189 if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) | 221 if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) |
190 return NULL; | 222 return NULL; |
191 | 223 |
198 case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break; | 230 case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break; |
199 case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; | 231 case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; |
200 case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; | 232 case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; |
201 case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; | 233 case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; |
202 case FF_OPT_TYPE_STRING: return *(void**)dst; | 234 case FF_OPT_TYPE_STRING: return *(void**)dst; |
235 case FF_OPT_TYPE_BINARY: | |
236 len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *)); | |
237 if(len >= (buf_len + 1)/2) return NULL; | |
238 bin = *(uint8_t**)dst; | |
239 for(i = 0; i < len; i++) snprintf(buf + i*2, 3, "%02X", bin[i]); | |
240 break; | |
203 default: return NULL; | 241 default: return NULL; |
204 } | 242 } |
205 return buf; | 243 return buf; |
206 } | 244 } |
207 | 245 |
303 case FF_OPT_TYPE_STRING: | 341 case FF_OPT_TYPE_STRING: |
304 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<string>" ); | 342 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<string>" ); |
305 break; | 343 break; |
306 case FF_OPT_TYPE_RATIONAL: | 344 case FF_OPT_TYPE_RATIONAL: |
307 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>" ); | 345 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>" ); |
346 break; | |
347 case FF_OPT_TYPE_BINARY: | |
348 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "<binary>" ); | |
308 break; | 349 break; |
309 case FF_OPT_TYPE_CONST: | 350 case FF_OPT_TYPE_CONST: |
310 default: | 351 default: |
311 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "" ); | 352 av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "" ); |
312 break; | 353 break; |
371 val = av_d2q(opt->default_val, INT_MAX); | 412 val = av_d2q(opt->default_val, INT_MAX); |
372 av_set_q(s, opt->name, val); | 413 av_set_q(s, opt->name, val); |
373 } | 414 } |
374 break; | 415 break; |
375 case FF_OPT_TYPE_STRING: | 416 case FF_OPT_TYPE_STRING: |
417 case FF_OPT_TYPE_BINARY: | |
376 /* Cannot set default for string as default_val is of type * double */ | 418 /* Cannot set default for string as default_val is of type * double */ |
377 break; | 419 break; |
378 default: | 420 default: |
379 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name); | 421 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name); |
380 } | 422 } |