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

Guo, Yejun yejun.guo at intel.com
Fri Aug 14 04:49:30 EEST 2020


Signed-off-by: Guo, Yejun <yejun.guo at intel.com>
---
 libavfilter/dnn/dnn_backend_openvino.c | 37 +++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index d343bf2..478e151 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_ov(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);
+    else
+        to->req_num = 1;
+
+    opt = av_dict_get(dict, "batch", opt, AV_DICT_MATCH_CASE);
+    if (opt != NULL)
+        to->batch_size = atoi(opt->value);
+    else
+        to->batch_size = 1;
+
+    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,9 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char *options)
     if (!ov_model)
         goto err;
 
+    model->options = options;
+    parse_options_ov(&ov_model->options, model->options);
+
     status = ie_core_create("", &ov_model->core);
     if (status != OK)
         goto err;
@@ -186,7 +222,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