1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

libavfilter: Prepare to handle specific error codes in DNN Filters

This commit prepares the filter side to handle specific error codes
from the DNN backends instead of current DNN_ERROR.

Signed-off-by: Shubhanshu Saxena <shubhanshu.e01@gmail.com>
This commit is contained in:
Shubhanshu Saxena 2022-03-02 23:35:49 +05:30 committed by Guo Yejun
parent e7caa18b4a
commit e5ce6a6070
5 changed files with 20 additions and 20 deletions

View File

@ -106,18 +106,18 @@ int ff_dnn_set_classify_post_proc(DnnContext *ctx, ClassifyPostProc post_proc)
return 0;
}
DNNReturnType ff_dnn_get_input(DnnContext *ctx, DNNData *input)
int ff_dnn_get_input(DnnContext *ctx, DNNData *input)
{
return ctx->model->get_input(ctx->model->model, input, ctx->model_inputname);
}
DNNReturnType ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height)
int ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height)
{
return ctx->model->get_output(ctx->model->model, ctx->model_inputname, input_width, input_height,
(const char *)ctx->model_outputnames[0], output_width, output_height);
}
DNNReturnType ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)
int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame)
{
DNNExecBaseParams exec_params = {
.input_name = ctx->model_inputname,
@ -129,7 +129,7 @@ DNNReturnType ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *
return (ctx->dnn_module->execute_model)(ctx->model, &exec_params);
}
DNNReturnType ff_dnn_execute_model_classification(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame, const char *target)
int ff_dnn_execute_model_classification(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame, const char *target)
{
DNNExecClassificationParams class_params = {
{
@ -149,7 +149,7 @@ DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFram
return (ctx->dnn_module->get_result)(ctx->model, in_frame, out_frame);
}
DNNReturnType ff_dnn_flush(DnnContext *ctx)
int ff_dnn_flush(DnnContext *ctx)
{
return (ctx->dnn_module->flush)(ctx->model);
}

View File

@ -53,12 +53,12 @@ int ff_dnn_init(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *fil
int ff_dnn_set_frame_proc(DnnContext *ctx, FramePrePostProc pre_proc, FramePrePostProc post_proc);
int ff_dnn_set_detect_post_proc(DnnContext *ctx, DetectPostProc post_proc);
int ff_dnn_set_classify_post_proc(DnnContext *ctx, ClassifyPostProc post_proc);
DNNReturnType ff_dnn_get_input(DnnContext *ctx, DNNData *input);
DNNReturnType ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height);
DNNReturnType ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame);
DNNReturnType ff_dnn_execute_model_classification(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame, const char *target);
int ff_dnn_get_input(DnnContext *ctx, DNNData *input);
int ff_dnn_get_output(DnnContext *ctx, int input_width, int input_height, int *output_width, int *output_height);
int ff_dnn_execute_model(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame);
int ff_dnn_execute_model_classification(DnnContext *ctx, AVFrame *in_frame, AVFrame *out_frame, const char *target);
DNNAsyncStatusType ff_dnn_get_result(DnnContext *ctx, AVFrame **in_frame, AVFrame **out_frame);
DNNReturnType ff_dnn_flush(DnnContext *ctx);
int ff_dnn_flush(DnnContext *ctx);
void ff_dnn_uninit(DnnContext *ctx);
#endif

View File

@ -62,7 +62,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0];
DRContext *dr_context = ctx->priv;
DNNReturnType dnn_result;
int dnn_result;
AVFrame *out;
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
@ -77,7 +77,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
if (dnn_result != DNN_SUCCESS){
av_log(ctx, AV_LOG_ERROR, "failed to execute model\n");
av_frame_free(&in);
return AVERROR(EIO);
return dnn_result;
}
do {
async_state = ff_dnn_get_result(&dr_context->dnnctx, &in, &out);

View File

@ -134,14 +134,14 @@ static int config_input(AVFilterLink *inlink)
{
AVFilterContext *context = inlink->dst;
DnnProcessingContext *ctx = context->priv;
DNNReturnType result;
int result;
DNNData model_input;
int check;
result = ff_dnn_get_input(&ctx->dnnctx, &model_input);
if (result != DNN_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n");
return AVERROR(EIO);
return result;
}
check = check_modelinput_inlink(&model_input, inlink);
@ -194,14 +194,14 @@ static int config_output(AVFilterLink *outlink)
{
AVFilterContext *context = outlink->src;
DnnProcessingContext *ctx = context->priv;
DNNReturnType result;
int result;
AVFilterLink *inlink = context->inputs[0];
// have a try run in case that the dnn model resize the frame
result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &outlink->w, &outlink->h);
if (result != DNN_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n");
return AVERROR(EIO);
return result;
}
prepare_uv_scale(outlink);

View File

@ -76,7 +76,7 @@ static int config_output(AVFilterLink *outlink)
{
AVFilterContext *context = outlink->src;
SRContext *ctx = context->priv;
DNNReturnType result;
int result;
AVFilterLink *inlink = context->inputs[0];
int out_width, out_height;
@ -84,7 +84,7 @@ static int config_output(AVFilterLink *outlink)
result = ff_dnn_get_output(&ctx->dnnctx, inlink->w, inlink->h, &out_width, &out_height);
if (result != DNN_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "could not get output from the model\n");
return AVERROR(EIO);
return result;
}
if (inlink->w != out_width || inlink->h != out_height) {
@ -121,7 +121,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
SRContext *ctx = context->priv;
AVFilterLink *outlink = context->outputs[0];
AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
DNNReturnType dnn_result;
int dnn_result;
if (!out){
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)
av_log(ctx, AV_LOG_ERROR, "failed to execute loaded model\n");
av_frame_free(&in);
av_frame_free(&out);
return AVERROR(EIO);
return dnn_result;
}
do {