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 | #include "libavutil/avassert.h" | 24 | #include "libavutil/avassert.h" |
| 25 | #include "libavutil/detection_bbox.h" | 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 | struct SwsContext *sws_ctx; | 29 | struct SwsContext *sws_ctx; |
| 30 | int bytewidth = av_image_get_linesize(frame->format, frame->width, 0); | 30 | int bytewidth = av_image_get_linesize(frame->format, frame->width, 0); |
| 31 | if (bytewidth < 0) { | 31 | if (bytewidth < 0) { |
| 32 | return DNN_ERROR; | 32 | return AVERROR(EINVAL); |
| 33 | } | 33 | } |
| 34 | if (output->dt != DNN_FLOAT) { | 34 | if (output->dt != DNN_FLOAT) { |
| 35 | avpriv_report_missing_feature(log_ctx, "data type rather than DNN_FLOAT"); | 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 | switch (frame->format) { | 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 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", | 51 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 52 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width * 3, frame->height, | 52 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width * 3, frame->height, |
| 53 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width * 3, frame->height); | 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 | sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0}, | 56 | sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0}, |
| 57 | (const int[4]){frame->width * 3 * sizeof(float), 0, 0, 0}, 0, frame->height, | 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 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", | 82 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 83 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width, frame->height, | 83 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32), frame->width, frame->height, |
| 84 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width, frame->height); | 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 | sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0}, | 87 | sws_scale(sws_ctx, (const uint8_t *[4]){(const uint8_t *)output->data, 0, 0, 0}, |
| 88 | (const int[4]){frame->width * sizeof(float), 0, 0, 0}, 0, frame->height, | 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 | return DNN_SUCCESS; | 91 | return DNN_SUCCESS; |
| 92 | default: | 92 | default: |
| 93 | avpriv_report_missing_feature(log_ctx, "%s", av_get_pix_fmt_name(frame->format)); | 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 | return DNN_SUCCESS; | 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 | struct SwsContext *sws_ctx; | 102 | struct SwsContext *sws_ctx; |
| 103 | int bytewidth = av_image_get_linesize(frame->format, frame->width, 0); | 103 | int bytewidth = av_image_get_linesize(frame->format, frame->width, 0); |
| 104 | if (bytewidth < 0) { | 104 | if (bytewidth < 0) { |
| 105 | return DNN_ERROR; | 105 | return AVERROR(EINVAL); |
| 106 | } | 106 | } |
| 107 | if (input->dt != DNN_FLOAT) { | 107 | if (input->dt != DNN_FLOAT) { |
| 108 | avpriv_report_missing_feature(log_ctx, "data type rather than DNN_FLOAT"); | 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 | switch (frame->format) { | 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 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", | 124 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 125 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width * 3, frame->height, | 125 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width * 3, frame->height, |
| 126 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width * 3, frame->height); | 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 | sws_scale(sws_ctx, (const uint8_t **)frame->data, | 129 | sws_scale(sws_ctx, (const uint8_t **)frame->data, |
| 130 | frame->linesize, 0, frame->height, | 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 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", | 156 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 157 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width, frame->height, | 157 | av_get_pix_fmt_name(AV_PIX_FMT_GRAY8), frame->width, frame->height, |
| 158 | av_get_pix_fmt_name(AV_PIX_FMT_GRAYF32),frame->width, frame->height); | 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 | sws_scale(sws_ctx, (const uint8_t **)frame->data, | 161 | sws_scale(sws_ctx, (const uint8_t **)frame->data, |
| 162 | frame->linesize, 0, frame->height, | 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 | break; | 166 | break; |
| 167 | default: | 167 | default: |
| 168 | avpriv_report_missing_feature(log_ctx, "%s", av_get_pix_fmt_name(frame->format)); | 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 | return DNN_SUCCESS; | 172 | return DNN_SUCCESS; |
| @@ -190,13 +190,14 @@ static enum AVPixelFormat get_pixel_format(DNNData *data) · 17 unmodified lines | |||
| 190 | return AV_PIX_FMT_BGR24; | 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 | const AVPixFmtDescriptor *desc; | 195 | const AVPixFmtDescriptor *desc; |
| 196 | int offsetx[4], offsety[4]; | 196 | int offsetx[4], offsety[4]; |
| 197 | uint8_t *bbox_data[4]; | 197 | uint8_t *bbox_data[4]; |
| 198 | struct SwsContext *sws_ctx; | 198 | struct SwsContext *sws_ctx; |
| 199 | int linesizes[4]; | 199 | int linesizes[4]; |
| 200 | int ret = DNN_SUCCESS; | ||
| 200 | enum AVPixelFormat fmt; | 201 | enum AVPixelFormat fmt; |
| 201 | int left, top, width, height; | 202 | int left, top, width, height; |
| 202 | const AVDetectionBBoxHeader *header; | 203 | const AVDetectionBBoxHeader *header; |
| @@ -221,13 +222,14 @@ DNNReturnType ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t · 18 unmodified lines | |||
| 221 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", | 222 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 222 | av_get_pix_fmt_name(frame->format), width, height, | 223 | av_get_pix_fmt_name(frame->format), width, height, |
| 223 | av_get_pix_fmt_name(fmt), input->width, input->height); | 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 | av_log(log_ctx, AV_LOG_ERROR, "unable to get linesizes with av_image_fill_linesizes"); | 230 | av_log(log_ctx, AV_LOG_ERROR, "unable to get linesizes with av_image_fill_linesizes"); |
| 229 | sws_freeContext(sws_ctx); | 231 | sws_freeContext(sws_ctx); |
| 230 | return DNN_ERROR; | 232 | return ret; |
| 231 | } | 233 | } |
| 232 | 234 | ||
| 233 | desc = av_pix_fmt_desc_get(frame->format); | 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 | sws_freeContext(sws_ctx); | 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 | struct SwsContext *sws_ctx; | 256 | struct SwsContext *sws_ctx; |
| 255 | int linesizes[4]; | 257 | int linesizes[4]; |
| 258 | int ret = DNN_SUCCESS; | ||
| 256 | enum AVPixelFormat fmt = get_pixel_format(input); | 259 | enum AVPixelFormat fmt = get_pixel_format(input); |
| 257 | sws_ctx = sws_getContext(frame->width, frame->height, frame->format, | 260 | sws_ctx = sws_getContext(frame->width, frame->height, frame->format, |
| 258 | input->width, input->height, fmt, | 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 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", | 265 | "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n", |
| 263 | av_get_pix_fmt_name(frame->format), frame->width, frame->height, | 266 | av_get_pix_fmt_name(frame->format), frame->width, frame->height, |
| 264 | av_get_pix_fmt_name(fmt), input->width, input->height); | 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 | av_log(log_ctx, AV_LOG_ERROR, "unable to get linesizes with av_image_fill_linesizes"); | 273 | av_log(log_ctx, AV_LOG_ERROR, "unable to get linesizes with av_image_fill_linesizes"); |
| 270 | sws_freeContext(sws_ctx); | 274 | sws_freeContext(sws_ctx); |
| 271 | return DNN_ERROR; | 275 | return ret; |
| 272 | } | 276 | } |
| 273 | 277 | ||
| 274 | sws_scale(sws_ctx, (const uint8_t *const *)frame->data, frame->linesize, 0, frame->height, | 278 | sws_scale(sws_ctx, (const uint8_t *const *)frame->data, frame->linesize, 0, frame->height, |
| 275 | (uint8_t *const [4]){input->data, 0, 0, 0}, linesizes); | 279 | (uint8_t *const [4]){input->data, 0, 0, 0}, linesizes); |
| 276 | 280 | ||
| 277 | sws_freeContext(sws_ctx); | 281 | sws_freeContext(sws_ctx); |
| 278 | return DNN_SUCCESS; | 282 | return ret; |
| 279 | } | 283 | } |
| @@ -30,9 +30,9 @@ · 29 unmodified lines | |||
| 30 | #include "../dnn_interface.h" | 30 | #include "../dnn_interface.h" |
| 31 | #include "libavutil/frame.h" | 31 | #include "libavutil/frame.h" |
| 32 | 32 | ||
| 33 | DNNReturnType ff_proc_from_frame_to_dnn(AVFrame *frame, DNNData *input, void *log_ctx); | 33 | int 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); | 34 | int 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); | 35 | int 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); | 36 | int ff_frame_to_dnn_classify(AVFrame *frame, DNNData *input, uint32_t bbox_index, void *log_ctx); |
| 37 | 37 | ||
| 38 | #endif | 38 | #endif |