comparison opt.c @ 3718:73626972ccbb libavcodec

Allow parameter values (AVOptions) to use the 'k', 'M', 'G' and 'B' postfixes.
author takis
date Thu, 14 Sep 2006 11:23:41 +0000
parents 301d975b69e3
children 8b8773577dd9
comparison
equal deleted inserted replaced
3717:ea9fe1c9d126 3718:73626972ccbb
25 */ 25 */
26 26
27 #include "avcodec.h" 27 #include "avcodec.h"
28 #include "opt.h" 28 #include "opt.h"
29 29
30 /**
31 * strtod() function extended with 'k', 'M' and 'B' postfixes.
32 * This allows using kB, MB, k, M and B as a postfix. This function
33 * assumes that the unit of numbers is bits not bytes.
34 */
35 static double av_strtod(const char *name, char **tail) {
36 double d;
37 d= strtod(name, tail);
38 if(*tail>name && (**tail=='k')) {
39 d*=1000;
40 (*tail)++;
41 }
42 else if(*tail && (**tail=='M')) {
43 d*=1000000;
44 (*tail)++;
45 }
46 else if(*tail && (**tail=='G')) {
47 d*=1000000000;
48 (*tail)++;
49 }
50 if(*tail && (**tail=='B')) {
51 d*=8;
52 (*tail)++;
53 }
54 return d;
55 }
56
30 static double av_parse_num(const char *name, char **tail){ 57 static double av_parse_num(const char *name, char **tail){
31 double d; 58 double d;
32 d= strtod(name, tail); 59 d= av_strtod(name, tail);
33 if(*tail>name && (**tail=='/' || **tail==':')) 60 if(*tail>name && (**tail=='/' || **tail==':'))
34 d/=strtod((*tail)+1, tail); 61 d/=av_strtod((*tail)+1, tail);
35 return d; 62 return d;
36 } 63 }
37 64
38 //FIXME order them and do a bin search 65 //FIXME order them and do a bin search
39 static AVOption *find_opt(void *v, const char *name, const char *unit){ 66 static AVOption *find_opt(void *v, const char *name, const char *unit){