This commit prepares the filter side to handle specific error codes from the DNN backends instead of current DNN_ERROR.
Unified · Split
| @@ -106,18 +106,18 @@ int ff_dnn_set_classify_post_proc(DnnContext *ctx, ClassifyPostProc post_proc) · 105 unmodified lines | |||
| 106 | return 0; | 106 | return 0; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | DNNReturnType ff_dnn_get_input(DnnContext *ctx, DNNData *input) | 109 | int ff_dnn_get_input(DnnContext *ctx, DNNData *input) |
| 110 | { | 110 | { |
| 111 | return ctx->model->get_input(ctx->model->model, input, ctx->model_inputname); | 111 | return ctx->model->get_input(ctx->model->model, input, ctx->model_inputname); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | DNNReturnType ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height) | 114 | int ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height) |
| 115 | { | 115 | { |
| 116 | return ctx->model->get_output(ctx->model->model, ctx->model_inputname, input_width, input_height, | 116 | return ctx->model->get_output(ctx->model->model, ctx->model_inputname, input_width, input_height, |
| 117 | (const char *)ctx->model_outputnames[0], output_width, output_height); | 117 | (const char *)ctx->model_outputnames[0], output_width, output_height); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | DNNReturnType ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame) | 120 | int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame) |
| 121 | { | 121 | { |
| 122 | DNNExecBaseParams exec_params = { | 122 | DNNExecBaseParams exec_params = { |
| 123 | .input_name = ctx->model_inputname, | 123 | .input_name = ctx->model_inputname, |
| @@ -129,7 +129,7 @@ DNNReturnType ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame * · 5 unmodified lines | |||
| 129 | return (ctx->dnn_module->execute_model)(ctx->model, &exec_params); | 129 | return (ctx->dnn_module->execute_model)(ctx->model, &exec_params); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | DNNReturnType ff_dnn_execute_model_classification(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame, const char *target) | 132 | int ff_dnn_execute_model_classification(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame, const char *target) |
| 133 | { | 133 | { |
| 134 | DNNExecClassificationParams class_params = { | 134 | DNNExecClassificationParams class_params = { |
| 135 | { | 135 | { |
| @@ -149,7 +149,7 @@ DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFram · 13 unmodified lines | |||
| 149 | return (ctx->dnn_module->get_result)(ctx->model, in_frame, out_frame); | 149 | return (ctx->dnn_module->get_result)(ctx->model, in_frame, out_frame); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | DNNReturnType ff_dnn_flush(DnnContext *ctx) | 152 | int ff_dnn_flush(DnnContext *ctx) |
| 153 | { | 153 | { |
| 154 | return (ctx->dnn_module->flush)(ctx->model); | 154 | return (ctx->dnn_module->flush)(ctx->model); |
| 155 | } | 155 | } |
| @@ -53,12 +53,12 @@ int ff_dnn_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *fil · 52 unmodified lines | |||
| 53 | int ff_dnn_set_frame_proc(DnnContext *ctx, FramePrePostProc pre_proc, FramePrePostProc post_proc); | 53 | int ff_dnn_set_frame_proc(DnnContext *ctx, FramePrePostProc pre_proc, FramePrePostProc post_proc); |
| 54 | int ff_dnn_set_detect_post_proc(DnnContext *ctx, DetectPostProc post_proc); | 54 | int ff_dnn_set_detect_post_proc(DnnContext *ctx, DetectPostProc post_proc); |
| 55 | int ff_dnn_set_classify_post_proc(DnnContext *ctx, ClassifyPostProc post_proc); | 55 | int ff_dnn_set_classify_post_proc(DnnContext *ctx, ClassifyPostProc post_proc); |
| 56 | DNNReturnType ff_dnn_get_input(DnnContext *ctx, DNNData *input); | 56 | int ff_dnn_get_input(DnnContext *ctx, DNNData *input); |
| 57 | DNNReturnType ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height); | 57 | int ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height); |
| 58 | DNNReturnType ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame); | 58 | int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame); |
| 59 | DNNReturnType ff_dnn_execute_model_classification(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame, const char *target); | 59 | int ff_dnn_execute_model_classification(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame, const char *target); |
| 60 | DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFrame **out_frame); | 60 | DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFrame **out_frame); |
| 61 | DNNReturnType ff_dnn_flush(DnnContext *ctx); | 61 | int ff_dnn_flush(DnnContext *ctx); |
| 62 | void ff_dnn_uninit(DnnContext *ctx); | 62 | void ff_dnn_uninit(DnnContext *ctx); |
| 63 | 63 | ||
| 64 | #endif | 64 | #endif |
| @@ -62,7 +62,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 61 unmodified lines | |||
| 62 | AVFilterContext *ctx = inlink->dst; | 62 | AVFilterContext *ctx = inlink->dst; |
| 63 | AVFilterLink *outlink = ctx->outputs[0]; | 63 | AVFilterLink *outlink = ctx->outputs[0]; |
| 64 | DRContext *dr_context = ctx->priv; | 64 | DRContext *dr_context = ctx->priv; |
| 65 | DNNReturnType dnn_result; | 65 | int dnn_result; |
| 66 | AVFrame *out; | 66 | AVFrame *out; |
| 67 | 67 | ||
| 68 | out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | 68 | out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
| @@ -77,7 +77,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 8 unmodified lines | |||
| 77 | if (dnn_result != DNN_SUCCESS){ | 77 | if (dnn_result != DNN_SUCCESS){ |
| 78 | av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); | 78 | av_log(ctx, AV_LOG_ERROR, "failed to execute model\n"); |
| 79 | av_frame_free(&in); | 79 | av_frame_free(&in); |
| 80 | return AVERROR(EIO); | 80 | return dnn_result; |
| 81 | } | 81 | } |
| 82 | do { | 82 | do { |
| 83 | async_state = ff_dnn_get_result(&dr_context->dnnctx, &in, &out); | 83 | async_state = ff_dnn_get_result(&dr_context->dnnctx, &in, &out); |
| @@ -134,14 +134,14 @@ static int config_input(AVFilterLink *inlink) · 133 unmodified lines | |||
| 134 | { | 134 | { |
| 135 | AVFilterContext *context = inlink->dst; | 135 | AVFilterContext *context = inlink->dst; |
| 136 | DnnProcessingContext *ctx = context->priv; | 136 | DnnProcessingContext *ctx = context->priv; |
| 137 | DNNReturnType result; | 137 | int result; |
| 138 | DNNData model_input; | 138 | DNNData model_input; |
| 139 | int check; | 139 | int check; |
| 140 | 140 | ||
| 141 | result = ff_dnn_get_input(&ctx->dnnctx, &model_input); | 141 | result = ff_dnn_get_input(&ctx->dnnctx, &model_input); |
| 142 | if (result != DNN_SUCCESS) { | 142 | if (result != DNN_SUCCESS) { |
| 143 | av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n"); | 143 | av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n"); |
| 144 | return AVERROR(EIO); | 144 | return result; |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | check = check_modelinput_inlink(&model_input, inlink); | 147 | check = check_modelinput_inlink(&model_input, inlink); |
| @@ -194,14 +194,14 @@ static int config_output(AVFilterLink *outlink) · 46 unmodified lines | |||
| 194 | { | 194 | { |
| 195 | AVFilterContext *context = outlink->src; | 195 | AVFilterContext *context = outlink->src; |
| 196 | DnnProcessingContext *ctx = context->priv; | 196 | DnnProcessingContext *ctx = context->priv; |
| 197 | DNNReturnType result; | 197 | int result; |
| 198 | AVFilterLink *inlink = context->inputs[0]; | 198 | AVFilterLink *inlink = context->inputs[0]; |
| 199 | 199 | ||
| 200 | // have a try run in case that the dnn model resize the frame | 200 | // have a try run in case that the dnn model resize the frame |
| 201 | result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &outlink->w, &outlink->h); | 201 | result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &outlink->w, &outlink->h); |
| 202 | if (result != DNN_SUCCESS) { | 202 | if (result != DNN_SUCCESS) { |
| 203 | av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n"); | 203 | av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n"); |
| 204 | return AVERROR(EIO); | 204 | return result; |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | prepare_uv_scale(outlink); | 207 | prepare_uv_scale(outlink); |
| @@ -76,7 +76,7 @@ static int config_output(AVFilterLink *outlink) · 75 unmodified lines | |||
| 76 | { | 76 | { |
| 77 | AVFilterContext *context = outlink->src; | 77 | AVFilterContext *context = outlink->src; |
| 78 | SRContext *ctx = context->priv; | 78 | SRContext *ctx = context->priv; |
| 79 | DNNReturnType result; | 79 | int result; |
| 80 | AVFilterLink *inlink = context->inputs[0]; | 80 | AVFilterLink *inlink = context->inputs[0]; |
| 81 | int out_width, out_height; | 81 | int out_width, out_height; |
| 82 | 82 | ||
| @@ -84,7 +84,7 @@ static int config_output(AVFilterLink *outlink) · 1 unmodified line | |||
| 84 | result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &out_width, &out_height); | 84 | result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &out_width, &out_height); |
| 85 | if (result != DNN_SUCCESS) { | 85 | if (result != DNN_SUCCESS) { |
| 86 | av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n"); | 86 | av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n"); |
| 87 | return AVERROR(EIO); | 87 | return result; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | if (inlink->w != out_width || inlink->h != out_height) { | 90 | if (inlink->w != out_width || inlink->h != out_height) { |
| @@ -121,7 +121,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 30 unmodified lines | |||
| 121 | SRContext *ctx = context->priv; | 121 | SRContext *ctx = context->priv; |
| 122 | AVFilterLink *outlink = context->outputs[0]; | 122 | AVFilterLink *outlink = context->outputs[0]; |
| 123 | AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | 123 | AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
| 124 | DNNReturnType dnn_result; | 124 | int dnn_result; |
| 125 | 125 | ||
| 126 | if (!out){ | 126 | if (!out){ |
| 127 | av_log(context, AV_LOG_ERROR, "could not allocate memory for output frame\n"); | 127 | av_log(context, AV_LOG_ERROR, "could not allocate memory for output frame\n"); |
| @@ -143,7 +143,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 15 unmodified lines | |||
| 143 | av_log(ctx, AV_LOG_ERROR, "failed to execute loaded model\n"); | 143 | av_log(ctx, AV_LOG_ERROR, "failed to execute loaded model\n"); |
| 144 | av_frame_free(&in); | 144 | av_frame_free(&in); |
| 145 | av_frame_free(&out); | 145 | av_frame_free(&out); |
| 146 | return AVERROR(EIO); | 146 | return dnn_result; |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | do { | 149 | do { |