[FFmpeg-devel] [PATCH V4] dnn_backend_openvino.c: parse options in openvino backend

Guo, Yejun yejun.guo at intel.com
Tue Aug 18 18:08:19 EEST 2020


Signed-off-by: Guo, Yejun <yejun.guo at intel.com>
---
v3: use AVOption
v4: don't add new file dnn_common.h/c

 libavfilter/dnn/dnn_backend_openvino.c | 50 +++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index d343bf2..277c313 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -26,9 +26,37 @@
 #include "dnn_backend_openvino.h"
 #include "libavformat/avio.h"
 #include "libavutil/avassert.h"
+#include "libavutil/opt.h"
 #include <c_api/ie_c_api.h>
 
+typedef struct OVOptions{
+    uint32_t batch_size;
+    uint32_t req_num;
+} OVOptions;
+
+typedef struct OvContext {
+    const AVClass *class;
+    OVOptions options;
+} OvContext;
+
+#define OFFSET(x) offsetof(OvContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM
+static const AVOption dnn_ov_options[] = {
+    { "batch",   "batch size",        OFFSET(options.batch_size), AV_OPT_TYPE_INT,  { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS },
+    { "nireq",   "number of request", OFFSET(options.req_num),    AV_OPT_TYPE_INT,  { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS },
+    { NULL },
+};
+
+static const AVClass dnn_ov_class = {
+    .class_name = "dnn_ov",
+    .item_name  = av_default_item_name,
+    .option     = dnn_ov_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+    .category   = AV_CLASS_CATEGORY_FILTER,
+};
+
 typedef struct OVModel{
+    OvContext ctx;
     ie_core_t *core;
     ie_network_t *network;
     ie_executable_network_t *exe_network;
@@ -155,6 +183,22 @@ err:
     return DNN_ERROR;
 }
 
+static int dnn_parse_options(void *ctx, const char *options)
+{
+    AVDictionary *dict = NULL;
+    int err = av_dict_parse_string(&dict, options, "=", "&", 0);
+    if (err < 0) {
+        av_dict_free(&dict);
+        return err;
+    }
+
+    av_opt_set_defaults(ctx);
+    err = av_opt_set_dict(ctx, &dict);
+
+    av_dict_free(&dict);
+    return err;
+}
+
 DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
 {
     DNNModel *model = NULL;
@@ -171,6 +215,11 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
     if (!ov_model)
         goto err;
 
+    ov_model->ctx.class = &dnn_ov_class;
+    model->options = options;
+    if (dnn_parse_options(&ov_model->ctx, model->options) < 0)
+        goto err;
+
     status = ie_core_create("", &ov_model->core);
     if (status != OK)
         goto err;
@@ -186,7 +235,6 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
     model->model = (void *)ov_model;
     model->set_input_output = &set_input_output_ov;
     model->get_input = &get_input_ov;
-    model->options = options;
 
     return model;
 
-- 
2.7.4



More information about the ffmpeg-devel mailing list