opt: Add AV_OPT_TYPE_INT32

Message ID 1338028349-83197-1-git-send-email-martin@martin.st
State New
Headers show

Commit Message

Martin Storsjö May 26, 2012, 10:32 a.m.
This is a safety precaution for options where the variable is
an integer explicitly sized to 32 bit, if we were to be built on
a platform with 64 bit integers.
---
What do people think, is this worthwhile?

 doc/APIchanges     |    3 +++
 libavutil/avutil.h |    2 +-
 libavutil/opt.c    |   10 ++++++++++
 libavutil/opt.h    |    2 ++
 4 files changed, 16 insertions(+), 1 deletion(-)

Comments

Anton Khirnov May 26, 2012, 3:05 p.m. | #1
On Sat, 26 May 2012 13:32:29 +0300, Martin Storsjö <martin@martin.st> wrote:
> This is a safety precaution for options where the variable is
> an integer explicitly sized to 32 bit, if we were to be built on
> a platform with 64 bit integers.
> ---
> What do people think, is this worthwhile?
> 

Fine with me.

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 18105c5..e1f66d5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@  libavutil:     2011-04-18
 
 API changes, most recent first:
 
+2012-05-xx - xxxxxxx - lavu 51.31.0
+  Add AV_OPT_TYPE_INT32 and av_opt_eval_int32
+
 2012-05-xx - xxxxxxx - lavf 54.3.0
   Add AVFMT_TS_NONSTRICT format flag to indicate that a muxer supports
   non-increasing monotone timestamps.
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 3e51357..1c8e076 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -152,7 +152,7 @@ 
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 30
+#define LIBAVUTIL_VERSION_MINOR 31
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 7c53024..00066ae 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -67,6 +67,7 @@  static int read_number(const AVOption *o, void *dst, double *num, int *den, int6
     switch (o->type) {
     case AV_OPT_TYPE_FLAGS:     *intnum = *(unsigned int*)dst;return 0;
     case AV_OPT_TYPE_INT:       *intnum = *(int         *)dst;return 0;
+    case AV_OPT_TYPE_INT32:     *intnum = *(int32_t     *)dst;return 0;
     case AV_OPT_TYPE_INT64:     *intnum = *(int64_t     *)dst;return 0;
     case AV_OPT_TYPE_FLOAT:     *num    = *(float       *)dst;return 0;
     case AV_OPT_TYPE_DOUBLE:    *num    = *(double      *)dst;return 0;
@@ -87,6 +88,7 @@  static int write_number(void *obj, const AVOption *o, void *dst, double num, int
     switch (o->type) {
     case AV_OPT_TYPE_FLAGS:
     case AV_OPT_TYPE_INT:   *(int       *)dst= llrint(num/den)*intnum; break;
+    case AV_OPT_TYPE_INT32: *(int32_t   *)dst= llrint(num/den)*intnum; break;
     case AV_OPT_TYPE_INT64: *(int64_t   *)dst= llrint(num/den)*intnum; break;
     case AV_OPT_TYPE_FLOAT: *(float     *)dst= num*intnum/den;         break;
     case AV_OPT_TYPE_DOUBLE:*(double    *)dst= num*intnum/den;         break;
@@ -237,6 +239,7 @@  int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
     case AV_OPT_TYPE_BINARY:   return set_string_binary(obj, o, val, dst);
     case AV_OPT_TYPE_FLAGS:
     case AV_OPT_TYPE_INT:
+    case AV_OPT_TYPE_INT32:
     case AV_OPT_TYPE_INT64:
     case AV_OPT_TYPE_FLOAT:
     case AV_OPT_TYPE_DOUBLE:
@@ -257,6 +260,7 @@  int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
 
 OPT_EVAL_NUMBER(flags,  AV_OPT_TYPE_FLAGS,    int)
 OPT_EVAL_NUMBER(int,    AV_OPT_TYPE_INT,      int)
+OPT_EVAL_NUMBER(int32,  AV_OPT_TYPE_INT32,    int32_t)
 OPT_EVAL_NUMBER(int64,  AV_OPT_TYPE_INT64,    int64_t)
 OPT_EVAL_NUMBER(float,  AV_OPT_TYPE_FLOAT,    float)
 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE,   double)
@@ -339,6 +343,7 @@  const char *av_get_string(void *obj, const char *name, const AVOption **o_out, c
     switch (o->type) {
     case AV_OPT_TYPE_FLAGS:     snprintf(buf, buf_len, "0x%08X",*(int    *)dst);break;
     case AV_OPT_TYPE_INT:       snprintf(buf, buf_len, "%d" , *(int    *)dst);break;
+    case AV_OPT_TYPE_INT32:     snprintf(buf, buf_len, "%d" , *(int32_t*)dst);break;
     case AV_OPT_TYPE_INT64:     snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break;
     case AV_OPT_TYPE_FLOAT:     snprintf(buf, buf_len, "%f" , *(float  *)dst);break;
     case AV_OPT_TYPE_DOUBLE:    snprintf(buf, buf_len, "%f" , *(double *)dst);break;
@@ -372,6 +377,7 @@  int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
     switch (o->type) {
     case AV_OPT_TYPE_FLAGS:     ret = snprintf(buf, sizeof(buf), "0x%08X",  *(int    *)dst);break;
     case AV_OPT_TYPE_INT:       ret = snprintf(buf, sizeof(buf), "%d" ,     *(int    *)dst);break;
+    case AV_OPT_TYPE_INT32:     ret = snprintf(buf, sizeof(buf), "%d" ,     *(int32_t*)dst);break;
     case AV_OPT_TYPE_INT64:     ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break;
     case AV_OPT_TYPE_FLOAT:     ret = snprintf(buf, sizeof(buf), "%f" ,     *(float  *)dst);break;
     case AV_OPT_TYPE_DOUBLE:    ret = snprintf(buf, sizeof(buf), "%f" ,     *(double *)dst);break;
@@ -543,6 +549,9 @@  static void opt_list(void *obj, void *av_log_obj, const char *unit,
             case AV_OPT_TYPE_INT:
                 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int>");
                 break;
+            case AV_OPT_TYPE_INT32:
+                av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int32>");
+                break;
             case AV_OPT_TYPE_INT64:
                 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int64>");
                 break;
@@ -613,6 +622,7 @@  void av_opt_set_defaults2(void *s, int mask, int flags)
                 /* Nothing to be done here */
             break;
             case AV_OPT_TYPE_FLAGS:
+            case AV_OPT_TYPE_INT32:
             case AV_OPT_TYPE_INT: {
                 int val;
                 val = opt->default_val.dbl;
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 1954940..d754786 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -224,6 +224,7 @@  enum AVOptionType{
     AV_OPT_TYPE_STRING,
     AV_OPT_TYPE_RATIONAL,
     AV_OPT_TYPE_BINARY,  ///< offset must point to a pointer immediately followed by an int for the length
+    AV_OPT_TYPE_INT32,
     AV_OPT_TYPE_CONST = 128,
 #if FF_API_OLD_AVOPTIONS
     FF_OPT_TYPE_FLAGS = 0,
@@ -436,6 +437,7 @@  int av_opt_set_dict(void *obj, struct AVDictionary **options);
  */
 int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int        *flags_out);
 int av_opt_eval_int   (void *obj, const AVOption *o, const char *val, int        *int_out);
+int av_opt_eval_int32 (void *obj, const AVOption *o, const char *val, int32_t    *int_out);
 int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t    *int64_out);
 int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float      *float_out);
 int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double     *double_out);