summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorPanagiotis Issaris <takis.issaris@uhasselt.be>2006-09-14 11:23:41 +0000
committerPanagiotis Issaris <takis.issaris@uhasselt.be>2006-09-14 11:23:41 +0000
commita41e9d6899b7fc81cbf9a3dd7a047d8758d6c6c7 (patch)
treeaa7fd2d8423832b12319018364be678accdee462 /libavcodec
parent7f889a76add819ebdf6469866ff0cd3a6ee117e7 (diff)
Allow parameter values (AVOptions) to use the 'k', 'M', 'G'
and 'B' postfixes. Originally committed as revision 6249 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/opt.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/libavcodec/opt.c b/libavcodec/opt.c
index a17e7ba757..63728f8e0c 100644
--- a/libavcodec/opt.c
+++ b/libavcodec/opt.c
@@ -27,11 +27,38 @@
#include "avcodec.h"
#include "opt.h"
-static double av_parse_num(const char *name, char **tail){
+/**
+ * strtod() function extended with 'k', 'M' and 'B' postfixes.
+ * This allows using kB, MB, k, M and B as a postfix. This function
+ * assumes that the unit of numbers is bits not bytes.
+ */
+static double av_strtod(const char *name, char **tail) {
double d;
d= strtod(name, tail);
+ if(*tail>name && (**tail=='k')) {
+ d*=1000;
+ (*tail)++;
+ }
+ else if(*tail && (**tail=='M')) {
+ d*=1000000;
+ (*tail)++;
+ }
+ else if(*tail && (**tail=='G')) {
+ d*=1000000000;
+ (*tail)++;
+ }
+ if(*tail && (**tail=='B')) {
+ d*=8;
+ (*tail)++;
+ }
+ return d;
+}
+
+static double av_parse_num(const char *name, char **tail){
+ double d;
+ d= av_strtod(name, tail);
if(*tail>name && (**tail=='/' || **tail==':'))
- d/=strtod((*tail)+1, tail);
+ d/=av_strtod((*tail)+1, tail);
return d;
}