[FFmpeg-devel] [PATCH V3] dnn_backend_openvino.c: parse options in openvino backend
Guo, Yejun
yejun.guo at intel.com
Tue Aug 18 11:09:21 EEST 2020
Signed-off-by: Guo, Yejun <yejun.guo at intel.com>
---
v3: change to AVOption method
libavfilter/dnn/Makefile | 1 +
libavfilter/dnn/dnn_backend_openvino.c | 35 ++++++++++++++++++++++++++-
libavfilter/dnn/dnn_common.c | 43 ++++++++++++++++++++++++++++++++++
libavfilter/dnn/dnn_common.h | 32 +++++++++++++++++++++++++
4 files changed, 110 insertions(+), 1 deletion(-)
create mode 100644 libavfilter/dnn/dnn_common.c
create mode 100644 libavfilter/dnn/dnn_common.h
diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
index e095707..4b7d10b 100644
--- a/libavfilter/dnn/Makefile
+++ b/libavfilter/dnn/Makefile
@@ -1,4 +1,5 @@
OBJS-$(CONFIG_DNN) += dnn/dnn_interface.o
+OBJS-$(CONFIG_DNN) += dnn/dnn_common.o
OBJS-$(CONFIG_DNN) += dnn/dnn_backend_native.o
OBJS-$(CONFIG_DNN) += dnn/dnn_backend_native_layers.o
OBJS-$(CONFIG_DNN) += dnn/dnn_backend_native_layer_avgpool.o
diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index d343bf2..b8a1b06 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -24,11 +24,40 @@
*/
#include "dnn_backend_openvino.h"
+#include "dnn_common.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;
@@ -171,6 +200,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 +220,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;
diff --git a/libavfilter/dnn/dnn_common.c b/libavfilter/dnn/dnn_common.c
new file mode 100644
index 0000000..be6301f
--- /dev/null
+++ b/libavfilter/dnn/dnn_common.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2020
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * DNN common functions
+ */
+
+#include "dnn_common.h"
+#include "libavutil/opt.h"
+
+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;
+}
diff --git a/libavfilter/dnn/dnn_common.h b/libavfilter/dnn/dnn_common.h
new file mode 100644
index 0000000..dc0f823
--- /dev/null
+++ b/libavfilter/dnn/dnn_common.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2020
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * DNN common functions
+ */
+
+
+#ifndef AVFILTER_DNN_DNN_COMMON_H
+#define AVFILTER_DNN_DNN_COMMON_H
+
+int dnn_parse_options(void *ctx, const char *options);
+
+#endif
--
2.7.4
More information about the ffmpeg-devel
mailing list