This commit returns specific error codes from the functions in the dnn_io_proc instead of DNN_ERROR.
Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -24,16 +24,16 @@ · 23 unmodified lines | ||
| 24 | 24 | #include "libavutil/avassert.h" |
| 25 | 25 | #include "libavutil/detection_bbox.h" |
| 26 | 26 | |
| 27 | −DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx) | |
| 27 | +int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx) | |
| 28 | 28 | { |
| 29 | 29 | struct SwsContext *sws_ctx; |
| 30 | 30 | int bytewidth = av_image_get_linesize(frame->format, frame->width, 0); |
| 31 | 31 | if (bytewidth < 0) { |
| 32 | − return DNN_ERROR; | |
| 32 | + return AVERROR(EINVAL); | |
| 33 | 33 | } |
| 34 | 34 | if (output->dt != DNN_FLOAT) { |
| 35 | 35 | avpriv_report_missing_feature(log_ctx, "data type rather than DNN_FLOAT"); |
| 36 | − return DNN_ERROR; | |
| 36 | + return AVERROR(ENOSYS); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | switch (frame->format) { |
| @@ -51,7 +51,7 @@ DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *l · 11 unmodified lines | ||
| 51 | 51 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 52 | 52 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width * 3, frame->height, |
| 53 | 53 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width * 3, frame->height); |
| 54 | − return DNN_ERROR; | |
| 54 | + return AVERROR(EINVAL); | |
| 55 | 55 | } |
| 56 | 56 | sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0}, |
| 57 | 57 | (const int[4]){frame->width * 3 * sizeof(float), 0, 0, 0}, 0, frame->height, |
| @@ -82,7 +82,7 @@ DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *l · 24 unmodified lines | ||
| 82 | 82 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 83 | 83 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width, frame->height, |
| 84 | 84 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width, frame->height); |
| 85 | − return DNN_ERROR; | |
| 85 | + return AVERROR(EINVAL); | |
| 86 | 86 | } |
| 87 | 87 | sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0}, |
| 88 | 88 | (const int[4]){frame->width * sizeof(float), 0, 0, 0}, 0, frame->height, |
| @@ -91,22 +91,22 @@ DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *l · 2 unmodified lines | ||
| 91 | 91 | return DNN_SUCCESS; |
| 92 | 92 | default: |
| 93 | 93 | avpriv_report_missing_feature(log_ctx, "%s", av_get_pix_fmt_name(frame->format)); |
| 94 | − return DNN_ERROR; | |
| 94 | + return AVERROR(ENOSYS); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return DNN_SUCCESS; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | −DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx) | |
| 100 | +int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx) | |
| 101 | 101 | { |
| 102 | 102 | struct SwsContext *sws_ctx; |
| 103 | 103 | int bytewidth = av_image_get_linesize(frame->format, frame->width, 0); |
| 104 | 104 | if (bytewidth < 0) { |
| 105 | − return DNN_ERROR; | |
| 105 | + return AVERROR(EINVAL); | |
| 106 | 106 | } |
| 107 | 107 | if (input->dt != DNN_FLOAT) { |
| 108 | 108 | avpriv_report_missing_feature(log_ctx, "data type rather than DNN_FLOAT"); |
| 109 | − return DNN_ERROR; | |
| 109 | + return AVERROR(ENOSYS); | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | switch (frame->format) { |
| @@ -124,7 +124,7 @@ DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *lo · 11 unmodified lines | ||
| 124 | 124 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 125 | 125 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width * 3, frame->height, |
| 126 | 126 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width * 3, frame->height); |
| 127 | − return DNN_ERROR; | |
| 127 | + return AVERROR(EINVAL); | |
| 128 | 128 | } |
| 129 | 129 | sws_scale(sws_ctx, (const uint8_t **)frame->data, |
| 130 | 130 | frame->linesize, 0, frame->height, |
| @@ -156,7 +156,7 @@ DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *lo · 25 unmodified lines | ||
| 156 | 156 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 157 | 157 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width, frame->height, |
| 158 | 158 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width, frame->height); |
| 159 | − return DNN_ERROR; | |
| 159 | + return AVERROR(EINVAL); | |
| 160 | 160 | } |
| 161 | 161 | sws_scale(sws_ctx, (const uint8_t **)frame->data, |
| 162 | 162 | frame->linesize, 0, frame->height, |
| @@ -166,7 +166,7 @@ DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *lo · 3 unmodified lines | ||
| 166 | 166 | break; |
| 167 | 167 | default: |
| 168 | 168 | avpriv_report_missing_feature(log_ctx, "%s", av_get_pix_fmt_name(frame->format)); |
| 169 | − return DNN_ERROR; | |
| 169 | + return AVERROR(ENOSYS); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | return DNN_SUCCESS; |
| @@ -190,13 +190,14 @@ static enum AVPixelFormat get_pixel_format(DNNData *data) · 17 unmodified lines | ||
| 190 | 190 | return AV_PIX_FMT_BGR24; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | −DNNReturnType ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index, void *log_ctx) | |
| 193 | +int ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index, void *log_ctx) | |
| 194 | 194 | { |
| 195 | 195 | const AVPixFmtDescriptor *desc; |
| 196 | 196 | int offsetx[4], offsety[4]; |
| 197 | 197 | uint8_t *bbox_data[4]; |
| 198 | 198 | struct SwsContext *sws_ctx; |
| 199 | 199 | int linesizes[4]; |
| 200 | + int ret = DNN_SUCCESS; | |
| 200 | 201 | enum AVPixelFormat fmt; |
| 201 | 202 | int left, top, width, height; |
| 202 | 203 | const AVDetectionBBoxHeader *header; |
| @@ -221,13 +222,14 @@ DNNReturnType ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t · 18 unmodified lines | ||
| 221 | 222 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 222 | 223 | av_get_pix_fmt_name(frame->format), width, height, |
| 223 | 224 | av_get_pix_fmt_name(fmt), input->width, input->height); |
| 224 | − return DNN_ERROR; | |
| 225 | + return AVERROR(EINVAL); | |
| 225 | 226 | } |
| 226 | 227 | |
| 227 | − if (av_image_fill_linesizes(linesizes, fmt, input->width) < 0) { | |
| 228 | + ret = av_image_fill_linesizes(linesizes, fmt, input->width); | |
| 229 | + if (ret < 0) { | |
| 228 | 230 | av_log(log_ctx, AV_LOG_ERROR, "unable to get linesizes with av_image_fill_linesizes"); |
| 229 | 231 | sws_freeContext(sws_ctx); |
| 230 | − return DNN_ERROR; | |
| 232 | + return ret; | |
| 231 | 233 | } |
| 232 | 234 | |
| 233 | 235 | desc = av_pix_fmt_desc_get(frame->format); |
| @@ -246,13 +248,14 @@ DNNReturnType ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t · 12 unmodified lines | ||
| 246 | 248 | |
| 247 | 249 | sws_freeContext(sws_ctx); |
| 248 | 250 | |
| 249 | − return DNN_SUCCESS; | |
| 251 | + return ret; | |
| 250 | 252 | } |
| 251 | 253 | |
| 252 | −DNNReturnType ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx) | |
| 254 | +int ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx) | |
| 253 | 255 | { |
| 254 | 256 | struct SwsContext *sws_ctx; |
| 255 | 257 | int linesizes[4]; |
| 258 | + int ret = DNN_SUCCESS; | |
| 256 | 259 | enum AVPixelFormat fmt = get_pixel_format(input); |
| 257 | 260 | sws_ctx = sws_getContext(frame->width, frame->height, frame->format, |
| 258 | 261 | input->width, input->height, fmt, |
| @@ -262,18 +265,19 @@ DNNReturnType ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_c · 3 unmodified lines | ||
| 262 | 265 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 263 | 266 | av_get_pix_fmt_name(frame->format), frame->width, frame->height, |
| 264 | 267 | av_get_pix_fmt_name(fmt), input->width, input->height); |
| 265 | − return DNN_ERROR; | |
| 268 | + return AVERROR(EINVAL); | |
| 266 | 269 | } |
| 267 | 270 | |
| 268 | − if (av_image_fill_linesizes(linesizes, fmt, input->width) < 0) { | |
| 271 | + ret = av_image_fill_linesizes(linesizes, fmt, input->width); | |
| 272 | + if (ret < 0) { | |
| 269 | 273 | av_log(log_ctx, AV_LOG_ERROR, "unable to get linesizes with av_image_fill_linesizes"); |
| 270 | 274 | sws_freeContext(sws_ctx); |
| 271 | − return DNN_ERROR; | |
| 275 | + return ret; | |
| 272 | 276 | } |
| 273 | 277 | |
| 274 | 278 | sws_scale(sws_ctx, (const uint8_t *const *)frame->data, frame->linesize, 0, frame->height, |
| 275 | 279 | (uint8_t *const [4]){input->data, 0, 0, 0}, linesizes); |
| 276 | 280 | |
| 277 | 281 | sws_freeContext(sws_ctx); |
| 278 | − return DNN_SUCCESS; | |
| 282 | + return ret; | |
| 279 | 283 | } |
| @@ -30,9 +30,9 @@ · 29 unmodified lines | ||
| 30 | 30 | #include "../dnn_interface.h" |
| 31 | 31 | #include "libavutil/frame.h" |
| 32 | 32 | |
| 33 | −DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx); | |
| 34 | −DNNReturnType ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx); | |
| 35 | −DNNReturnType ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx); | |
| 36 | −DNNReturnType ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index, void *log_ctx); | |
| 33 | +int ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx); | |
| 34 | +int ff_proc_from_dnn_to_frame(AVFrame *frame, DNNData *output, void *log_ctx); | |
| 35 | +int ff_frame_to_dnn_detect(AVFrame *frame, DNNData *input, void *log_ctx); | |
| 36 | +int ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index, void *log_ctx); | |
| 37 | 37 | |
| 38 | 38 | #endif |