2018-05-25 17:31:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Sergey Lavrushkin
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Implements DNN module initialization with specified backend.
|
|
|
|
*/
|
|
|
|
|
2019-07-16 05:55:45 +00:00
|
|
|
#include "../dnn_interface.h"
|
2018-05-25 17:31:04 +00:00
|
|
|
#include "dnn_backend_native.h"
|
2018-06-03 17:22:50 +00:00
|
|
|
#include "dnn_backend_tf.h"
|
2020-05-25 07:38:09 +00:00
|
|
|
#include "dnn_backend_openvino.h"
|
2018-05-25 17:31:04 +00:00
|
|
|
#include "libavutil/mem.h"
|
|
|
|
|
2018-07-27 16:34:02 +00:00
|
|
|
DNNModule *ff_get_dnn_module(DNNBackendType backend_type)
|
2018-05-25 17:31:04 +00:00
|
|
|
{
|
2018-07-27 16:34:02 +00:00
|
|
|
DNNModule *dnn_module;
|
2018-05-25 17:31:04 +00:00
|
|
|
|
2020-11-18 06:28:06 +00:00
|
|
|
dnn_module = av_mallocz(sizeof(DNNModule));
|
2018-05-25 17:31:04 +00:00
|
|
|
if(!dnn_module){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(backend_type){
|
|
|
|
case DNN_NATIVE:
|
|
|
|
dnn_module->load_model = &ff_dnn_load_model_native;
|
|
|
|
dnn_module->execute_model = &ff_dnn_execute_model_native;
|
2021-08-25 21:10:45 +00:00
|
|
|
dnn_module->get_result = &ff_dnn_get_result_native;
|
|
|
|
dnn_module->flush = &ff_dnn_flush_native;
|
2018-05-25 17:31:04 +00:00
|
|
|
dnn_module->free_model = &ff_dnn_free_model_native;
|
2018-06-03 17:22:50 +00:00
|
|
|
break;
|
|
|
|
case DNN_TF:
|
|
|
|
#if (CONFIG_LIBTENSORFLOW == 1)
|
|
|
|
dnn_module->load_model = &ff_dnn_load_model_tf;
|
|
|
|
dnn_module->execute_model = &ff_dnn_execute_model_tf;
|
2021-08-25 21:10:45 +00:00
|
|
|
dnn_module->get_result = &ff_dnn_get_result_tf;
|
2021-08-08 10:55:34 +00:00
|
|
|
dnn_module->flush = &ff_dnn_flush_tf;
|
2018-06-03 17:22:50 +00:00
|
|
|
dnn_module->free_model = &ff_dnn_free_model_tf;
|
|
|
|
#else
|
2018-06-07 15:22:22 +00:00
|
|
|
av_freep(&dnn_module);
|
2018-06-03 17:22:50 +00:00
|
|
|
return NULL;
|
|
|
|
#endif
|
2018-09-24 14:02:54 +00:00
|
|
|
break;
|
2020-05-25 07:38:09 +00:00
|
|
|
case DNN_OV:
|
|
|
|
#if (CONFIG_LIBOPENVINO == 1)
|
|
|
|
dnn_module->load_model = &ff_dnn_load_model_ov;
|
|
|
|
dnn_module->execute_model = &ff_dnn_execute_model_ov;
|
2021-08-25 21:10:45 +00:00
|
|
|
dnn_module->get_result = &ff_dnn_get_result_ov;
|
2021-01-07 03:14:10 +00:00
|
|
|
dnn_module->flush = &ff_dnn_flush_ov;
|
2020-05-25 07:38:09 +00:00
|
|
|
dnn_module->free_model = &ff_dnn_free_model_ov;
|
|
|
|
#else
|
|
|
|
av_freep(&dnn_module);
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
break;
|
2018-09-24 14:02:54 +00:00
|
|
|
default:
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Module backend_type is not native or tensorflow\n");
|
|
|
|
av_freep(&dnn_module);
|
|
|
|
return NULL;
|
2018-05-25 17:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dnn_module;
|
|
|
|
}
|