From patchwork Tue Aug 18 08:09:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Yejun" X-Patchwork-Id: 21698 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 83BEB44992B for ; Tue, 18 Aug 2020 11:14:44 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 603E468B7B6; Tue, 18 Aug 2020 11:14:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CAC8D68B766 for ; Tue, 18 Aug 2020 11:14:37 +0300 (EEST) IronPort-SDR: w72OuhMz59ci0s+TUZQeMYX6DWyitjCm58LXp8RrzissjizFfUgN1W6MYCGYMoi81cofwM2Z7Q f3L5JQ9TUMPg== X-IronPort-AV: E=McAfee;i="6000,8403,9716"; a="154833670" X-IronPort-AV: E=Sophos;i="5.76,326,1592895600"; d="scan'208";a="154833670" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2020 01:14:34 -0700 IronPort-SDR: 3DfI67UAxHRMPU7OMgx4jkQvu9SoDid+Eq5FoRiXEFD6tzoPTZpqKgJwg6n+L37VPnM/N32yI5 P4rTTOAl/omA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,326,1592895600"; d="scan'208";a="320008287" Received: from yguo18-skl-u1604.sh.intel.com ([10.239.159.53]) by fmsmga004.fm.intel.com with ESMTP; 18 Aug 2020 01:14:34 -0700 From: "Guo, Yejun" To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Aug 2020 16:09:21 +0800 Message-Id: <1597738161-5311-1-git-send-email-yejun.guo@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH V3] dnn_backend_openvino.c: parse options in openvino backend X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Guo, Yejun --- 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 +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