[FFmpeg-cvslog] av_opt: add av_opt_ptr() to return a pointer to a field of a object based on

Michael Niedermayer git at videolan.org
Mon Dec 5 05:04:38 CET 2011


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Dec  3 21:16:46 2011 +0100| [dff97be8084594a0bd900782ca91612680c77bbc] | committer: Michael Niedermayer

av_opt: add av_opt_ptr() to return a pointer to a field of a object based on
an AVClass

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dff97be8084594a0bd900782ca91612680c77bbc
---

 libavutil/opt.c |    8 ++++++++
 libavutil/opt.h |   11 +++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 1d7ef38..f0b5deb 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -806,6 +806,14 @@ const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *pre
     return NULL;
 }
 
+void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
+{
+    AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
+    if(!opt)
+        return NULL;
+    return (uint8_t*)obj + opt->offset;
+}
+
 #ifdef TEST
 
 #undef printf
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 5fce09a..2d282b3 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -586,6 +586,17 @@ int av_opt_get_double(void *obj, const char *name, int search_flags, double
 int av_opt_get_q     (void *obj, const char *name, int search_flags, AVRational *out_val);
 /**
  * @}
+ */
+/**
+ * Gets a pointer to the requested field in a struct.
+ * This function allows accessing a struct even when its fields are moved or
+ * renamed since the application making the access has been compiled,
+ *
+ * @returns a pointer to the field, it can be cast to the correct type and read
+ *          or written to.
+ */
+void *av_opt_ptr(const AVClass *class, void *obj, const char *name);
+/**
  * @}
  */
 



More information about the ffmpeg-cvslog mailing list