[02/10] avoptions: Add an av_opt_flag_is_set function for inspecting flag fields

Message ID 1307561599-84211-1-git-send-email-martin@martin.st
State Committed
Commit cb7c11cc9e7e05c819fff487a3f486f11ab4b860
Headers show

Commit Message

Martin Storsjö June 8, 2011, 7:33 p.m.
---
Updated according to Anton's suggestions:
- Using av_opt_ prefix (which appears to be the one settled on)
- Added some doxygen docs
- Checking that the flag avoption is of the right type
- Minor bump + apichanges

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

Comments

Anton Khirnov June 9, 2011, 2:27 p.m. | #1
On Wed,  8 Jun 2011 22:33:19 +0300, Martin Storsjö <martin@martin.st> wrote:
> ---
> Updated according to Anton's suggestions:
> - Using av_opt_ prefix (which appears to be the one settled on)
> - Added some doxygen docs
> - Checking that the flag avoption is of the right type
> - Minor bump + apichanges
> 
>  doc/APIchanges     |    3 +++
>  libavutil/avutil.h |    2 +-
>  libavutil/opt.c    |   10 ++++++++++
>  libavutil/opt.h    |   10 ++++++++++
>  4 files changed, 24 insertions(+), 1 deletions(-)

Look fine.

--
Anton Khirnov

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index b57868d..0ab658d 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@  libavutil:   2011-04-18
 
 API changes, most recent first:
 
+2011-06-xx - xxxxxxx - lavu 51.6.0 - opt.h
+  Add av_opt_flag_is_set().
+
 2011-06-xx - xxxxxxx - lavu 51.5.0 - AVMetadata
   Move AVMetadata from lavf to lavu and rename it to
   AVDictionary -- new installed header dict.h.
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 9c660f3..0299bdf 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -40,7 +40,7 @@ 
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR  5
+#define LIBAVUTIL_VERSION_MINOR  6
 #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 172fcec..7775bb2 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -320,6 +320,16 @@  int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
     return num*intnum/den;
 }
 
+int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
+{
+    const AVOption *field = av_find_opt(obj, field_name, NULL, 0, 0);
+    const AVOption *flag  = av_find_opt(obj, flag_name,  NULL, 0, 0);
+
+    if (!field || !flag || flag->type != FF_OPT_TYPE_CONST)
+        return 0;
+    return av_get_int(obj, field_name, NULL) & (int) flag->default_val.dbl;
+}
+
 static void opt_list(void *obj, void *av_log_obj, const char *unit,
                      int req_flags, int rej_flags)
 {
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 8c3b6c1..46ad8ac 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -181,4 +181,14 @@  int av_set_options_string(void *ctx, const char *opts,
  */
 void av_opt_free(void *obj);
 
+/**
+ * Check whether a particular flag is set in a flags field.
+ *
+ * @param field_name the name of the flag field option
+ * @param flag_name the name of the flag to check
+ * @return non-zero if the flag is set, zero if the flag isn't set,
+ *         isn't of the right type, or the flags field doesn't exist.
+ */
+int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
+
 #endif /* AVUTIL_OPT_H */