Go to the documentation of this file.
32 #include "../internal.h"
35 #include <c_api/ie_c_api.h>
80 #define APPEND_STRING(generated_string, iterate_string) \
81 generated_string = generated_string ? av_asprintf("%s %s", generated_string, iterate_string) : \
82 av_asprintf("%s", iterate_string);
84 #define OFFSET(x) offsetof(OVContext, x)
85 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM
115 return sizeof(float);
127 precision_e precision;
128 ie_blob_buffer_t blob_buffer;
132 ie_blob_t *input_blob =
NULL;
141 status |= ie_blob_get_dims(input_blob, &dims);
142 status |= ie_blob_get_precision(input_blob, &precision);
144 ie_blob_free(&input_blob);
149 status = ie_blob_get_buffer(input_blob, &blob_buffer);
151 ie_blob_free(&input_blob);
156 input.height = dims.dims[2];
157 input.width = dims.dims[3];
158 input.channels = dims.dims[1];
159 input.data = blob_buffer.buffer;
178 ie_blob_free(&input_blob);
186 precision_e precision;
191 ie_blob_t *output_blob =
NULL;
192 ie_blob_buffer_t blob_buffer;
199 char *model_output_name =
NULL;
200 char *all_output_names =
NULL;
201 size_t model_output_count = 0;
204 for (
size_t i = 0;
i < model_output_count;
i++) {
209 "output \"%s\" may not correct, all output(s) are: \"%s\"\n",
214 status = ie_blob_get_buffer(output_blob, &blob_buffer);
216 ie_blob_free(&output_blob);
221 status |= ie_blob_get_dims(output_blob, &dims);
222 status |= ie_blob_get_precision(output_blob, &precision);
224 ie_blob_free(&output_blob);
229 output.channels = dims.dims[1];
230 output.height = dims.dims[2];
231 output.width = dims.dims[3];
233 output.data = blob_buffer.buffer;
253 ie_blob_free(&output_blob);
269 ie_available_devices_t a_dev;
271 char *all_dev_names =
NULL;
274 if (
ctx->options.batch_size <= 0) {
275 ctx->options.batch_size = 1;
278 if (
ctx->options.batch_size > 1) {
279 input_shapes_t input_shapes;
280 status = ie_network_get_input_shapes(ov_model->
network, &input_shapes);
283 for (
int i = 0;
i < input_shapes.shape_num;
i++)
284 input_shapes.shapes[
i].shape.dims[0] =
ctx->options.batch_size;
285 status = ie_network_reshape(ov_model->
network, input_shapes);
286 ie_network_input_shapes_free(&input_shapes);
293 status = ie_network_set_input_layout(ov_model->
network, input_name, NHWC);
298 status = ie_network_set_output_layout(ov_model->
network, output_name, NHWC);
311 status = ie_network_set_input_precision(ov_model->
network, input_name, U8);
321 status = ie_core_get_available_devices(ov_model->
core, &a_dev);
326 for (
int i = 0;
i < a_dev.num_devices;
i++) {
330 ctx->options.device_type, all_dev_names);
340 if (
ctx->options.nireq <= 0) {
350 for (
int i = 0;
i <
ctx->options.nireq;
i++) {
436 char *model_input_name =
NULL;
437 char *all_input_names =
NULL;
439 size_t model_input_count = 0;
441 precision_e precision;
442 int input_resizable =
ctx->options.input_resizable;
444 status = ie_network_get_inputs_number(ov_model->
network, &model_input_count);
450 for (
size_t i = 0;
i < model_input_count;
i++) {
451 status = ie_network_get_input_name(ov_model->
network,
i, &model_input_name);
456 if (strcmp(model_input_name, input_name) == 0) {
457 ie_network_name_free(&model_input_name);
458 status |= ie_network_get_input_dims(ov_model->
network, input_name, &dims);
459 status |= ie_network_get_input_precision(ov_model->
network, input_name, &precision);
465 input->channels = dims.dims[1];
466 input->height = input_resizable ? -1 : dims.dims[2];
467 input->width = input_resizable ? -1 : dims.dims[3];
475 ie_network_name_free(&model_input_name);
478 av_log(
ctx,
AV_LOG_ERROR,
"Could not find \"%s\" in model, all input(s) are: \"%s\"\n", input_name, all_input_names);
483 const char *output_name,
int *output_width,
int *output_height)
494 input_shapes_t input_shapes;
496 if (
ctx->options.input_resizable) {
497 status = ie_network_get_input_shapes(ov_model->
network, &input_shapes);
498 input_shapes.shapes->shape.dims[2] = input_height;
499 input_shapes.shapes->shape.dims[3] = input_width;
500 status |= ie_network_reshape(ov_model->
network, input_shapes);
501 ie_network_input_shapes_free(&input_shapes);
520 in_frame->
width = input_width;
521 in_frame->
height = input_height;
541 request.
tasks = &ptask;
544 *output_width = out_frame->
width;
545 *output_height = out_frame->
height;
569 model->
model = ov_model;
570 ov_model->
model = model;
571 ov_model->
ctx.
class = &dnn_openvino_class;
588 ver = ie_c_api_version();
590 "Please check if the model version matches the runtime OpenVINO %s\n",
591 model_filename, ver.api_version);
592 ie_version_free(&ver);
610 const char **output_names, uint32_t nb_output,
AVFrame *out_frame)
628 if (nb_output != 1) {
635 if (
ctx->options.batch_size > 1) {
658 request.
tasks = &ptask;
664 const char **output_names, uint32_t nb_output,
AVFrame *out_frame)
808 ie_network_free(&ov_model->
network);
810 ie_core_free(&ov_model->
core);
static DNNReturnType execute_model_ov(RequestItem *request)
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
static FilteringContext * filter_ctx
ie_complete_call_back_t callback
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
void * ff_safe_queue_pop_front(SafeQueue *sq)
ie_executable_network_t * exe_network
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
void * ff_queue_pop_front(Queue *q)
size_t ff_queue_size(Queue *q)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
AVFILTER_DEFINE_CLASS(dnn_openvino)
DNNModel * ff_dnn_load_model_ov(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx)
int ff_safe_queue_push_front(SafeQueue *sq, void *v)
static DNNReturnType get_input_ov(void *model, DNNData *input, const char *input_name)
AVFilterContext * filter_ctx
Queue * ff_queue_create(void)
DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx)
DNNReturnType ff_dnn_execute_model_async_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame, const char **output_names, uint32_t nb_output, AVFrame *out_frame)
DNNReturnType(* get_output)(void *model, const char *input_name, int input_width, int input_height, const char *output_name, int *output_width, int *output_height)
static DNNReturnType init_model_ov(OVModel *ov_model, const char *input_name, const char *output_name)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int ff_queue_push_back(Queue *q, void *v)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define APPEND_STRING(generated_string, iterate_string)
void ff_queue_destroy(Queue *q)
void ff_dnn_free_model_ov(DNNModel **model)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
DNNReturnType(* get_input)(void *model, DNNData *input, const char *input_name)
size_t ff_safe_queue_size(SafeQueue *sq)
Describe the class of an AVClass context structure.
static DNNReturnType fill_model_input_ov(OVModel *ov_model, RequestItem *request)
int(* pre_proc)(AVFrame *frame_in, DNNData *model_input, AVFilterContext *filter_ctx)
SafeQueue * ff_safe_queue_create(void)
int av_opt_set_from_string(void *ctx, const char *opts, const char *const *shorthand, const char *key_val_sep, const char *pairs_sep)
Parse the key-value pairs list in opts.
ie_infer_request_t * infer_request
static int get_datatype_size(DNNDataType dt)
const OptionDef options[]
int(* post_proc)(AVFrame *frame_out, DNNData *model_output, AVFilterContext *filter_ctx)
DNNFunctionType func_type
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void ff_safe_queue_destroy(SafeQueue *sq)
static DNNReturnType get_output_ov(void *model, const char *input_name, int input_width, int input_height, const char *output_name, int *output_width, int *output_height)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
DNNReturnType ff_dnn_flush_ov(const DNNModel *model)
DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, DNNFunctionType func_type, void *log_ctx)
int ff_safe_queue_push_back(SafeQueue *sq, void *v)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static const AVOption dnn_openvino_options[]
static void infer_completion_callback(void *args)
DNNAsyncStatusType ff_dnn_get_async_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out)
#define av_malloc_array(a, b)
static DNNDataType precision_to_datatype(precision_e precision)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
SafeQueue * request_queue
void * ff_queue_peek_front(Queue *q)
DNNReturnType ff_dnn_execute_model_ov(const DNNModel *model, const char *input_name, AVFrame *in_frame, const char **output_names, uint32_t nb_output, AVFrame *out_frame)
ie_infer_request_t * infer_request