Skip to content

Commit 6de9519

Browse files
quink-blackguoyejun
authored andcommitted
avfilter/dnn: Remove a level of dereference
For code such as 'model->model = ov_model' is confusing. We can just drop the member variable and use cast to get the subclass. Signed-off-by: Zhao Zhili <[email protected]> Reviewed-by: Wenbin Chen <[email protected]> Reviewed-by: Guo Yejun <[email protected]>
1 parent a1fea7e commit 6de9519

File tree

5 files changed

+29
-34
lines changed

5 files changed

+29
-34
lines changed

libavfilter/dnn/dnn_backend_openvino.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ static void dnn_free_model_ov(DNNModel **model)
517517
if (!model || !*model)
518518
return;
519519

520-
ov_model = (*model)->model;
520+
ov_model = (OVModel *)(*model);
521521
while (ff_safe_queue_size(ov_model->request_queue) != 0) {
522522
OVRequestItem *item = ff_safe_queue_pop_front(ov_model->request_queue);
523523
if (item && item->infer_request) {
@@ -1059,9 +1059,9 @@ static int execute_model_ov(OVRequestItem *request, Queue *inferenceq)
10591059
return ret;
10601060
}
10611061

1062-
static int get_input_ov(void *model, DNNData *input, const char *input_name)
1062+
static int get_input_ov(DNNModel *model, DNNData *input, const char *input_name)
10631063
{
1064-
OVModel *ov_model = model;
1064+
OVModel *ov_model = (OVModel *)model;
10651065
DnnContext *ctx = ov_model->ctx;
10661066
int input_resizable = ctx->ov_option.input_resizable;
10671067

@@ -1255,7 +1255,7 @@ static int extract_lltask_from_task(DNNFunctionType func_type, TaskItem *task, Q
12551255
}
12561256
}
12571257

1258-
static int get_output_ov(void *model, const char *input_name, int input_width, int input_height,
1258+
static int get_output_ov(DNNModel *model, const char *input_name, int input_width, int input_height,
12591259
const char *output_name, int *output_width, int *output_height)
12601260
{
12611261
#if HAVE_OPENVINO2
@@ -1268,7 +1268,7 @@ static int get_output_ov(void *model, const char *input_name, int input_width, i
12681268
input_shapes_t input_shapes;
12691269
#endif
12701270
int ret;
1271-
OVModel *ov_model = model;
1271+
OVModel *ov_model = (OVModel *)model;
12721272
DnnContext *ctx = ov_model->ctx;
12731273
TaskItem task;
12741274
OVRequestItem *request;
@@ -1383,7 +1383,6 @@ static DNNModel *dnn_load_model_ov(DnnContext *ctx, DNNFunctionType func_type, A
13831383
return NULL;
13841384
ov_model->ctx = ctx;
13851385
model = &ov_model->model;
1386-
model->model = ov_model;
13871386

13881387
#if HAVE_OPENVINO2
13891388
status = ov_core_create(&core);
@@ -1470,7 +1469,7 @@ static DNNModel *dnn_load_model_ov(DnnContext *ctx, DNNFunctionType func_type, A
14701469

14711470
static int dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_params)
14721471
{
1473-
OVModel *ov_model = model->model;
1472+
OVModel *ov_model = (OVModel *)model;
14741473
DnnContext *ctx = ov_model->ctx;
14751474
OVRequestItem *request;
14761475
TaskItem *task;
@@ -1558,13 +1557,13 @@ static int dnn_execute_model_ov(const DNNModel *model, DNNExecBaseParams *exec_p
15581557

15591558
static DNNAsyncStatusType dnn_get_result_ov(const DNNModel *model, AVFrame **in, AVFrame **out)
15601559
{
1561-
OVModel *ov_model = model->model;
1560+
OVModel *ov_model = (OVModel *)model;
15621561
return ff_dnn_get_result_common(ov_model->task_queue, in, out);
15631562
}
15641563

15651564
static int dnn_flush_ov(const DNNModel *model)
15661565
{
1567-
OVModel *ov_model = model->model;
1566+
OVModel *ov_model = (OVModel *)model;
15681567
DnnContext *ctx = ov_model->ctx;
15691568
OVRequestItem *request;
15701569
#if HAVE_OPENVINO2

libavfilter/dnn/dnn_backend_tf.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ static TF_Tensor *allocate_input_tensor(const DNNData *input)
262262
input_dims[1] * input_dims[2] * input_dims[3] * size);
263263
}
264264

265-
static int get_input_tf(void *model, DNNData *input, const char *input_name)
265+
static int get_input_tf(DNNModel *model, DNNData *input, const char *input_name)
266266
{
267-
TFModel *tf_model = model;
267+
TFModel *tf_model = (TFModel *)model;
268268
DnnContext *ctx = tf_model->ctx;
269269
TF_Status *status;
270270
TF_DataType dt;
@@ -310,11 +310,11 @@ static int get_input_tf(void *model, DNNData *input, const char *input_name)
310310
return 0;
311311
}
312312

313-
static int get_output_tf(void *model, const char *input_name, int input_width, int input_height,
313+
static int get_output_tf(DNNModel *model, const char *input_name, int input_width, int input_height,
314314
const char *output_name, int *output_width, int *output_height)
315315
{
316316
int ret;
317-
TFModel *tf_model = model;
317+
TFModel *tf_model = (TFModel *)model;
318318
DnnContext *ctx = tf_model->ctx;
319319
TaskItem task;
320320
TFRequestItem *request;
@@ -486,7 +486,7 @@ static void dnn_free_model_tf(DNNModel **model)
486486
if (!model || !*model)
487487
return;
488488

489-
tf_model = (*model)->model;
489+
tf_model = (TFModel *)(*model);
490490
while (ff_safe_queue_size(tf_model->request_queue) != 0) {
491491
TFRequestItem *item = ff_safe_queue_pop_front(tf_model->request_queue);
492492
destroy_request_item(&item);
@@ -530,7 +530,6 @@ static DNNModel *dnn_load_model_tf(DnnContext *ctx, DNNFunctionType func_type, A
530530
if (!tf_model)
531531
return NULL;
532532
model = &tf_model->model;
533-
model->model = tf_model;
534533
tf_model->ctx = ctx;
535534

536535
if (load_tf_model(tf_model, ctx->model_filename) != 0){
@@ -611,7 +610,7 @@ static int fill_model_input_tf(TFModel *tf_model, TFRequestItem *request) {
611610
task = lltask->task;
612611
request->lltask = lltask;
613612

614-
ret = get_input_tf(tf_model, &input, task->input_name);
613+
ret = get_input_tf(&tf_model->model, &input, task->input_name);
615614
if (ret != 0) {
616615
goto err;
617616
}
@@ -803,7 +802,7 @@ static int execute_model_tf(TFRequestItem *request, Queue *lltask_queue)
803802

804803
static int dnn_execute_model_tf(const DNNModel *model, DNNExecBaseParams *exec_params)
805804
{
806-
TFModel *tf_model = model->model;
805+
TFModel *tf_model = (TFModel *)model;
807806
DnnContext *ctx = tf_model->ctx;
808807
TaskItem *task;
809808
TFRequestItem *request;
@@ -851,13 +850,13 @@ static int dnn_execute_model_tf(const DNNModel *model, DNNExecBaseParams *exec_p
851850

852851
static DNNAsyncStatusType dnn_get_result_tf(const DNNModel *model, AVFrame **in, AVFrame **out)
853852
{
854-
TFModel *tf_model = model->model;
853+
TFModel *tf_model = (TFModel *)model;
855854
return ff_dnn_get_result_common(tf_model->task_queue, in, out);
856855
}
857856

858857
static int dnn_flush_tf(const DNNModel *model)
859858
{
860-
TFModel *tf_model = model->model;
859+
TFModel *tf_model = (TFModel *)model;
861860
DnnContext *ctx = tf_model->ctx;
862861
TFRequestItem *request;
863862
int ret;

libavfilter/dnn/dnn_backend_torch.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static void dnn_free_model_th(DNNModel **model)
119119
if (!model || !*model)
120120
return;
121121

122-
th_model = (THModel *) (*model)->model;
122+
th_model = (THModel *) (*model);
123123
while (ff_safe_queue_size(th_model->request_queue) != 0) {
124124
THRequestItem *item = (THRequestItem *)ff_safe_queue_pop_front(th_model->request_queue);
125125
destroy_request_item(&item);
@@ -144,7 +144,7 @@ static void dnn_free_model_th(DNNModel **model)
144144
*model = NULL;
145145
}
146146

147-
static int get_input_th(void *model, DNNData *input, const char *input_name)
147+
static int get_input_th(DNNModel *model, DNNData *input, const char *input_name)
148148
{
149149
input->dt = DNN_FLOAT;
150150
input->order = DCO_RGB;
@@ -179,7 +179,7 @@ static int fill_model_input_th(THModel *th_model, THRequestItem *request)
179179
task = lltask->task;
180180
infer_request = request->infer_request;
181181

182-
ret = get_input_th(th_model, &input, NULL);
182+
ret = get_input_th(&th_model->model, &input, NULL);
183183
if ( ret != 0) {
184184
goto err;
185185
}
@@ -356,7 +356,7 @@ static int execute_model_th(THRequestItem *request, Queue *lltask_queue)
356356
return ret;
357357
}
358358

359-
static int get_output_th(void *model, const char *input_name, int input_width, int input_height,
359+
static int get_output_th(DNNModel *model, const char *input_name, int input_width, int input_height,
360360
const char *output_name, int *output_width, int *output_height)
361361
{
362362
int ret = 0;
@@ -421,7 +421,6 @@ static DNNModel *dnn_load_model_th(DnnContext *ctx, DNNFunctionType func_type, A
421421
if (!th_model)
422422
return NULL;
423423
model = &th_model->model;
424-
model->model = th_model;
425424
th_model->ctx = ctx;
426425

427426
c10::Device device = c10::Device(device_name);
@@ -489,7 +488,7 @@ static DNNModel *dnn_load_model_th(DnnContext *ctx, DNNFunctionType func_type, A
489488

490489
static int dnn_execute_model_th(const DNNModel *model, DNNExecBaseParams *exec_params)
491490
{
492-
THModel *th_model = (THModel *)model->model;
491+
THModel *th_model = (THModel *)model;
493492
DnnContext *ctx = th_model->ctx;
494493
TaskItem *task;
495494
THRequestItem *request;
@@ -538,13 +537,13 @@ static int dnn_execute_model_th(const DNNModel *model, DNNExecBaseParams *exec_p
538537

539538
static DNNAsyncStatusType dnn_get_result_th(const DNNModel *model, AVFrame **in, AVFrame **out)
540539
{
541-
THModel *th_model = (THModel *)model->model;
540+
THModel *th_model = (THModel *)model;
542541
return ff_dnn_get_result_common(th_model->task_queue, in, out);
543542
}
544543

545544
static int dnn_flush_th(const DNNModel *model)
546545
{
547-
THModel *th_model = (THModel *)model->model;
546+
THModel *th_model = (THModel *)model;
548547
THRequestItem *request;
549548

550549
if (ff_queue_size(th_model->lltask_queue) == 0)

libavfilter/dnn_filter_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ int ff_dnn_set_classify_post_proc(DnnContext *ctx, ClassifyPostProc post_proc)
157157

158158
int ff_dnn_get_input(DnnContext *ctx, DNNData *input)
159159
{
160-
return ctx->model->get_input(ctx->model->model, input, ctx->model_inputname);
160+
return ctx->model->get_input(ctx->model, input, ctx->model_inputname);
161161
}
162162

163163
int ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height)
164164
{
165165
char * output_name = ctx->model_outputnames && ctx->backend_type != DNN_TH ?
166166
ctx->model_outputnames[0] : NULL;
167-
return ctx->model->get_output(ctx->model->model, ctx->model_inputname, input_width, input_height,
168-
(const char *)output_name, output_width, output_height);
167+
return ctx->model->get_output(ctx->model, ctx->model_inputname, input_width, input_height,
168+
(const char *)output_name, output_width, output_height);
169169
}
170170

171171
int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)

libavfilter/dnn_interface.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,15 @@ typedef int (*DetectPostProc)(AVFrame *frame, DNNData *output, uint32_t nb, AVFi
9595
typedef int (*ClassifyPostProc)(AVFrame *frame, DNNData *output, uint32_t bbox_index, AVFilterContext *filter_ctx);
9696

9797
typedef struct DNNModel{
98-
// Stores model that can be different for different backends.
99-
void *model;
10098
// Stores FilterContext used for the interaction between AVFrame and DNNData
10199
AVFilterContext *filter_ctx;
102100
// Stores function type of the model
103101
DNNFunctionType func_type;
104102
// Gets model input information
105103
// Just reuse struct DNNData here, actually the DNNData.data field is not needed.
106-
int (*get_input)(void *model, DNNData *input, const char *input_name);
104+
int (*get_input)(struct DNNModel *model, DNNData *input, const char *input_name);
107105
// Gets model output width/height with given input w/h
108-
int (*get_output)(void *model, const char *input_name, int input_width, int input_height,
106+
int (*get_output)(struct DNNModel *model, const char *input_name, int input_width, int input_height,
109107
const char *output_name, int *output_width, int *output_height);
110108
// set the pre process to transfer data from AVFrame to DNNData
111109
// the default implementation within DNN is used if it is not provided by the filter

0 commit comments

Comments
 (0)