diff mbox series

[FFmpeg-devel,2/2] dnn_backend_openvino.c: parse options in openvino backend

Message ID 1597330050-14203-1-git-send-email-yejun.guo@intel.com
State New
Headers show
Series [FFmpeg-devel,1/2] dnn: fix build issue for tensorflow backend
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Guo, Yejun Aug. 13, 2020, 2:47 p.m. UTC
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
---
 libavfilter/dnn/dnn_backend_openvino.c | 40 +++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index d343bf2..030670b 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -26,8 +26,14 @@ 
 #include "dnn_backend_openvino.h"
 #include "libavformat/avio.h"
 #include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
 #include <c_api/ie_c_api.h>
 
+typedef struct OVOptions{
+    uint32_t batch_size;
+    uint32_t req_num;
+} OVOptions;
+
 typedef struct OVModel{
     ie_core_t *core;
     ie_network_t *network;
@@ -36,6 +42,7 @@  typedef struct OVModel{
     ie_blob_t *input_blob;
     ie_blob_t **output_blobs;
     uint32_t nb_output;
+    OVOptions options;
 } OVModel;
 
 static DNNDataType precision_to_datatype(precision_e precision)
@@ -50,6 +57,32 @@  static DNNDataType precision_to_datatype(precision_e precision)
     }
 }
 
+static int parse_options(OVOptions *to, const char *from)
+{
+    AVDictionary *dict = NULL;
+    AVDictionaryEntry *opt = NULL;
+    int err = av_dict_parse_string(&dict, from, "=", "&", 0);
+    if (err < 0) {
+        av_dict_free(&dict);
+        return err;
+    }
+
+    opt = av_dict_get(dict, "nireq", opt, AV_DICT_MATCH_CASE);
+    if (opt != NULL)
+    {
+        to->req_num = atoi(opt->value);
+    }
+
+    opt = av_dict_get(dict, "batch", opt, AV_DICT_MATCH_CASE);
+    if (opt != NULL)
+    {
+        to->batch_size = atoi(opt->value);
+    }
+
+    av_dict_free(&dict);
+    return 0;
+}
+
 static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input_name)
 {
     OVModel *ov_model = (OVModel *)model;
@@ -171,6 +204,12 @@  DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
     if (!ov_model)
         goto err;
 
+    model->options = options;
+    if (model->options != NULL)
+    {
+        parse_options(&ov_model->options, model->options);
+    }
+
     status = ie_core_create("", &ov_model->core);
     if (status != OK)
         goto err;
@@ -186,7 +225,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;