Showing the changes to libavfilter (17 of 24 files). Show all
Unified · Split
| @@ -28,15 +28,26 @@ · 27 unmodified lines | ||
| 28 | 28 | #include "dnn_backend_native_layer_conv2d.h" |
| 29 | 29 | #include "dnn_backend_native_layers.h" |
| 30 | 30 | |
| 31 | +static const AVClass dnn_native_class = { | |
| 32 | + .class_name = "dnn_native", | |
| 33 | + .item_name = av_default_item_name, | |
| 34 | + .option = NULL, | |
| 35 | + .version = LIBAVUTIL_VERSION_INT, | |
| 36 | + .category = AV_CLASS_CATEGORY_FILTER, | |
| 37 | +}; | |
| 38 | + | |
| 31 | 39 | static DNNReturnType get_input_native(void *model, DNNData *input, const char *input_name) |
| 32 | 40 | { |
| 33 | 41 | NativeModel *native_model = (NativeModel *)model; |
| 42 | + NativeContext *ctx = &native_model->ctx; | |
| 34 | 43 | |
| 35 | 44 | for (int i = 0; i < native_model->operands_num; ++i) { |
| 36 | 45 | DnnOperand *oprd = &native_model->operands[i]; |
| 37 | 46 | if (strcmp(oprd->name, input_name) == 0) { |
| 38 | − if (oprd->type != DOT_INPUT) | |
| 47 | + if (oprd->type != DOT_INPUT) { | |
| 48 | + av_log(ctx, AV_LOG_ERROR, "Found \"%s\" in model, but it is not input node\n", input_name); | |
| 39 | 49 | return DNN_ERROR; |
| 50 | + } | |
| 40 | 51 | input->dt = oprd->data_type; |
| 41 | 52 | av_assert0(oprd->dims[0] == 1); |
| 42 | 53 | input->height = oprd->dims[1]; |
| @@ -47,30 +58,37 @@ static DNNReturnType get_input_native(void *model, DNNData *input, const char *i · 4 unmodified lines | ||
| 47 | 58 | } |
| 48 | 59 | |
| 49 | 60 | // do not find the input operand |
| 61 | + av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", input_name); | |
| 50 | 62 | return DNN_ERROR; |
| 51 | 63 | } |
| 52 | 64 | |
| 53 | 65 | static DNNReturnType set_input_native(void *model, DNNData *input, const char *input_name) |
| 54 | 66 | { |
| 55 | 67 | NativeModel *native_model = (NativeModel *)model; |
| 68 | + NativeContext *ctx = &native_model->ctx; | |
| 56 | 69 | DnnOperand *oprd = NULL; |
| 57 | 70 | |
| 58 | − if (native_model->layers_num <= 0 || native_model->operands_num <= 0) | |
| 71 | + if (native_model->layers_num <= 0 || native_model->operands_num <= 0) { | |
| 72 | + av_log(ctx, AV_LOG_ERROR, "No operands or layers in model\n"); | |
| 59 | 73 | return DNN_ERROR; |
| 74 | + } | |
| 60 | 75 | |
| 61 | 76 | /* inputs */ |
| 62 | 77 | for (int i = 0; i < native_model->operands_num; ++i) { |
| 63 | 78 | oprd = &native_model->operands[i]; |
| 64 | 79 | if (strcmp(oprd->name, input_name) == 0) { |
| 65 | − if (oprd->type != DOT_INPUT) | |
| 80 | + if (oprd->type != DOT_INPUT) { | |
| 81 | + av_log(ctx, AV_LOG_ERROR, "Found \"%s\" in model, but it is not input node\n", input_name); | |
| 66 | 82 | return DNN_ERROR; |
| 83 | + } | |
| 67 | 84 | break; |
| 68 | 85 | } |
| 69 | 86 | oprd = NULL; |
| 70 | 87 | } |
| 71 | − | |
| 72 | − if (!oprd) | |
| 88 | + if (!oprd) { | |
| 89 | + av_log(ctx, AV_LOG_ERROR, "Could not find \"%s\" in model\n", input_name); | |
| 73 | 90 | return DNN_ERROR; |
| 91 | + } | |
| 74 | 92 | |
| 75 | 93 | oprd->dims[0] = 1; |
| 76 | 94 | oprd->dims[1] = input->height; |
| @@ -79,11 +97,15 @@ static DNNReturnType set_input_native(void *model, DNNData *input, const char *i · 2 unmodified lines | ||
| 79 | 97 | |
| 80 | 98 | av_freep(&oprd->data); |
| 81 | 99 | oprd->length = calculate_operand_data_length(oprd); |
| 82 | − if (oprd->length <= 0) | |
| 100 | + if (oprd->length <= 0) { | |
| 101 | + av_log(ctx, AV_LOG_ERROR, "The input data length overflow\n"); | |
| 83 | 102 | return DNN_ERROR; |
| 103 | + } | |
| 84 | 104 | oprd->data = av_malloc(oprd->length); |
| 85 | − if (!oprd->data) | |
| 105 | + if (!oprd->data) { | |
| 106 | + av_log(ctx, AV_LOG_ERROR, "Failed to malloc memory for input data\n"); | |
| 86 | 107 | return DNN_ERROR; |
| 108 | + } | |
| 87 | 109 | |
| 88 | 110 | input->data = oprd->data; |
| 89 | 111 | |
| @@ -150,6 +172,8 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, const char *optio · 60 unmodified lines | ||
| 150 | 172 | if (!native_model){ |
| 151 | 173 | goto fail; |
| 152 | 174 | } |
| 175 | + | |
| 176 | + native_model->ctx.class = &dnn_native_class; | |
| 153 | 177 | model->model = (void *)native_model; |
| 154 | 178 | |
| 155 | 179 | avio_seek(model_file_context, file_size - 8, SEEK_SET); |
| @@ -237,19 +261,26 @@ fail: · 81 unmodified lines | ||
| 237 | 261 | DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *outputs, const char **output_names, uint32_t nb_output) |
| 238 | 262 | { |
| 239 | 263 | NativeModel *native_model = (NativeModel *)model->model; |
| 264 | + NativeContext *ctx = &native_model->ctx; | |
| 240 | 265 | int32_t layer; |
| 241 | 266 | |
| 242 | − if (native_model->layers_num <= 0 || native_model->operands_num <= 0) | |
| 267 | + if (native_model->layers_num <= 0 || native_model->operands_num <= 0) { | |
| 268 | + av_log(ctx, AV_LOG_ERROR, "No operands or layers in model\n"); | |
| 243 | 269 | return DNN_ERROR; |
| 244 | − if (!native_model->operands[0].data) | |
| 270 | + } | |
| 271 | + if (!native_model->operands[0].data) { | |
| 272 | + av_log(ctx, AV_LOG_ERROR, "Empty model input data\n"); | |
| 245 | 273 | return DNN_ERROR; |
| 274 | + } | |
| 246 | 275 | |
| 247 | 276 | for (layer = 0; layer < native_model->layers_num; ++layer){ |
| 248 | 277 | DNNLayerType layer_type = native_model->layers[layer].type; |
| 249 | 278 | if (layer_funcs[layer_type].pf_exec(native_model->operands, |
| 250 | 279 | native_model->layers[layer].input_operand_indexes, |
| 251 | 280 | native_model->layers[layer].output_operand_index, |
| 252 | − native_model->layers[layer].params) == DNN_ERROR) { | |
| 281 | + native_model->layers[layer].params, | |
| 282 | + &native_model->ctx) == DNN_ERROR) { | |
| 283 | + av_log(ctx, AV_LOG_ERROR, "Failed to execuet model\n"); | |
| 253 | 284 | return DNN_ERROR; |
| 254 | 285 | } |
| 255 | 286 | } |
| @@ -264,8 +295,10 @@ DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, DNNData *output · 8 unmodified lines | ||
| 264 | 295 | } |
| 265 | 296 | } |
| 266 | 297 | |
| 267 | − if (oprd == NULL) | |
| 298 | + if (oprd == NULL) { | |
| 299 | + av_log(ctx, AV_LOG_ERROR, "Could not find output in model\n"); | |
| 268 | 300 | return DNN_ERROR; |
| 301 | + } | |
| 269 | 302 | |
| 270 | 303 | outputs[i].data = oprd->data; |
| 271 | 304 | outputs[i].height = oprd->dims[1]; |
| @@ -106,8 +106,13 @@ typedef struct InputParams{ · 105 unmodified lines | ||
| 106 | 106 | int height, width, channels; |
| 107 | 107 | } InputParams; |
| 108 | 108 | |
| 109 | +typedef struct NativeContext { | |
| 110 | + const AVClass *class; | |
| 111 | +} NativeContext; | |
| 112 | + | |
| 109 | 113 | // Represents simple feed-forward convolutional network. |
| 110 | 114 | typedef struct NativeModel{ |
| 115 | + NativeContext ctx; | |
| 111 | 116 | Layer *layers; |
| 112 | 117 | int32_t layers_num; |
| 113 | 118 | DnnOperand *operands; |
| @@ -56,7 +56,7 @@ int dnn_load_layer_avg_pool(Layer *layer, AVIOContext *model_file_context, int f · 55 unmodified lines | ||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | int dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 59 | − int32_t output_operand_index, const void *parameters) | |
| 59 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx) | |
| 60 | 60 | { |
| 61 | 61 | float *output; |
| 62 | 62 | int height_end, width_end, height_radius, width_radius, output_height, output_width, kernel_area; |
| @@ -107,9 +107,15 @@ int dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_operan · 44 unmodified lines | ||
| 107 | 107 | output_operand->dims[3] = channel; |
| 108 | 108 | output_operand->data_type = operands[input_operand_index].data_type; |
| 109 | 109 | output_operand->length = calculate_operand_data_length(output_operand); |
| 110 | + if (output_operand->length <= 0) { | |
| 111 | + av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); | |
| 112 | + return DNN_ERROR; | |
| 113 | + } | |
| 110 | 114 | output_operand->data = av_realloc(output_operand->data, output_operand->length); |
| 111 | − if (!output_operand->data) | |
| 115 | + if (!output_operand->data) { | |
| 116 | + av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); | |
| 112 | 117 | return DNN_ERROR; |
| 118 | + } | |
| 113 | 119 | output = output_operand->data; |
| 114 | 120 | |
| 115 | 121 | for (int y = 0; y < height_end; y += kernel_strides) { |
| @@ -35,6 +35,6 @@ typedef struct AvgPoolParams{ · 34 unmodified lines | ||
| 35 | 35 | |
| 36 | 36 | int dnn_load_layer_avg_pool(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num); |
| 37 | 37 | int dnn_execute_layer_avg_pool(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 38 | − int32_t output_operand_index, const void *parameters); | |
| 38 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx); | |
| 39 | 39 | |
| 40 | 40 | #endif |
| @@ -89,7 +89,7 @@ int dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int fil · 88 unmodified lines | ||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | int dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 92 | − int32_t output_operand_index, const void *parameters) | |
| 92 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx) | |
| 93 | 93 | { |
| 94 | 94 | float *output; |
| 95 | 95 | int32_t input_operand_index = input_operand_indexes[0]; |
| @@ -113,11 +113,15 @@ int dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_ · 17 unmodified lines | ||
| 113 | 113 | output_operand->dims[3] = conv_params->output_num; |
| 114 | 114 | output_operand->data_type = operands[input_operand_index].data_type; |
| 115 | 115 | output_operand->length = calculate_operand_data_length(output_operand); |
| 116 | − if (output_operand->length <= 0) | |
| 116 | + if (output_operand->length <= 0) { | |
| 117 | + av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); | |
| 117 | 118 | return DNN_ERROR; |
| 119 | + } | |
| 118 | 120 | output_operand->data = av_realloc(output_operand->data, output_operand->length); |
| 119 | − if (!output_operand->data) | |
| 121 | + if (!output_operand->data) { | |
| 122 | + av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); | |
| 120 | 123 | return DNN_ERROR; |
| 124 | + } | |
| 121 | 125 | output = output_operand->data; |
| 122 | 126 | |
| 123 | 127 | av_assert0(channel == conv_params->input_num); |
| @@ -37,5 +37,5 @@ typedef struct ConvolutionalParams{ · 36 unmodified lines | ||
| 37 | 37 | |
| 38 | 38 | int dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num); |
| 39 | 39 | int dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 40 | − int32_t output_operand_index, const void *parameters); | |
| 40 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx); | |
| 41 | 41 | #endif |
| @@ -50,7 +50,7 @@ int dnn_load_layer_depth2space(Layer *layer, AVIOContext *model_file_context, in · 49 unmodified lines | ||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | int dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 53 | − int32_t output_operand_index, const void *parameters) | |
| 53 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx) | |
| 54 | 54 | { |
| 55 | 55 | float *output; |
| 56 | 56 | const DepthToSpaceParams *params = (const DepthToSpaceParams *)parameters; |
| @@ -75,11 +75,15 @@ int dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_ope · 18 unmodified lines | ||
| 75 | 75 | output_operand->dims[3] = new_channels; |
| 76 | 76 | output_operand->data_type = operands[input_operand_index].data_type; |
| 77 | 77 | output_operand->length = calculate_operand_data_length(output_operand); |
| 78 | − if (output_operand->length <= 0) | |
| 78 | + if (output_operand->length <= 0) { | |
| 79 | + av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); | |
| 79 | 80 | return DNN_ERROR; |
| 81 | + } | |
| 80 | 82 | output_operand->data = av_realloc(output_operand->data, output_operand->length); |
| 81 | − if (!output_operand->data) | |
| 83 | + if (!output_operand->data) { | |
| 84 | + av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); | |
| 82 | 85 | return DNN_ERROR; |
| 86 | + } | |
| 83 | 87 | output = output_operand->data; |
| 84 | 88 | |
| 85 | 89 | for (y = 0; y < height; ++y){ |
| @@ -36,6 +36,6 @@ typedef struct DepthToSpaceParams{ · 35 unmodified lines | ||
| 36 | 36 | |
| 37 | 37 | int dnn_load_layer_depth2space(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num); |
| 38 | 38 | int dnn_execute_layer_depth2space(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 39 | − int32_t output_operand_index, const void *parameters); | |
| 39 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx); | |
| 40 | 40 | |
| 41 | 41 | #endif |
| @@ -149,7 +149,7 @@ int dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, in · 148 unmodified lines | ||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | int dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 152 | − int32_t output_operand_index, const void *parameters) | |
| 152 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx) | |
| 153 | 153 | { |
| 154 | 154 | const DnnOperand *input = &operands[input_operand_indexes[0]]; |
| 155 | 155 | DnnOperand *output = &operands[output_operand_index]; |
| @@ -160,11 +160,15 @@ int dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_ope · 4 unmodified lines | ||
| 160 | 160 | |
| 161 | 161 | output->data_type = input->data_type; |
| 162 | 162 | output->length = calculate_operand_data_length(output); |
| 163 | − if (output->length <= 0) | |
| 163 | + if (output->length <= 0) { | |
| 164 | + av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); | |
| 164 | 165 | return DNN_ERROR; |
| 166 | + } | |
| 165 | 167 | output->data = av_realloc(output->data, output->length); |
| 166 | − if (!output->data) | |
| 168 | + if (!output->data) { | |
| 169 | + av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); | |
| 167 | 170 | return DNN_ERROR; |
| 171 | + } | |
| 168 | 172 | |
| 169 | 173 | switch (params->bin_op) { |
| 170 | 174 | case DMBO_SUB: |
| @@ -186,6 +190,7 @@ int dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_ope · 15 unmodified lines | ||
| 186 | 190 | math_binary_not_commutative(floormod, params, input, output, operands, input_operand_indexes); |
| 187 | 191 | return 0; |
| 188 | 192 | default: |
| 193 | + av_log(ctx, AV_LOG_ERROR, "Unmatch math binary operator\n"); | |
| 189 | 194 | return DNN_ERROR; |
| 190 | 195 | } |
| 191 | 196 | } |
| @@ -49,6 +49,6 @@ typedef struct DnnLayerMathBinaryParams{ · 48 unmodified lines | ||
| 49 | 49 | |
| 50 | 50 | int dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num); |
| 51 | 51 | int dnn_execute_layer_math_binary(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 52 | − int32_t output_operand_index, const void *parameters); | |
| 52 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx); | |
| 53 | 53 | |
| 54 | 54 | #endif |
| @@ -53,7 +53,7 @@ int dnn_load_layer_math_unary(Layer *layer, AVIOContext *model_file_context, int · 52 unmodified lines | ||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 56 | − int32_t output_operand_index, const void *parameters) | |
| 56 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx) | |
| 57 | 57 | { |
| 58 | 58 | const DnnOperand *input = &operands[input_operand_indexes[0]]; |
| 59 | 59 | DnnOperand *output = &operands[output_operand_index]; |
| @@ -67,11 +67,15 @@ int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_oper · 7 unmodified lines | ||
| 67 | 67 | |
| 68 | 68 | output->data_type = input->data_type; |
| 69 | 69 | output->length = calculate_operand_data_length(output); |
| 70 | − if (output->length <= 0) | |
| 70 | + if (output->length <= 0) { | |
| 71 | + av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); | |
| 71 | 72 | return DNN_ERROR; |
| 73 | + } | |
| 72 | 74 | output->data = av_realloc(output->data, output->length); |
| 73 | − if (!output->data) | |
| 75 | + if (!output->data) { | |
| 76 | + av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); | |
| 74 | 77 | return DNN_ERROR; |
| 78 | + } | |
| 75 | 79 | |
| 76 | 80 | dims_count = calculate_operand_dims_count(output); |
| 77 | 81 | src = input->data; |
| @@ -143,6 +147,7 @@ int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_oper · 65 unmodified lines | ||
| 143 | 147 | dst[i] = round(src[i]); |
| 144 | 148 | return 0; |
| 145 | 149 | default: |
| 150 | + av_log(ctx, AV_LOG_ERROR, "Unmatch math unary operator\n"); | |
| 146 | 151 | return DNN_ERROR; |
| 147 | 152 | } |
| 148 | 153 | } |
| @@ -55,6 +55,6 @@ typedef struct DnnLayerMathUnaryParams{ · 54 unmodified lines | ||
| 55 | 55 | |
| 56 | 56 | int dnn_load_layer_math_unary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num); |
| 57 | 57 | int dnn_execute_layer_math_unary(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 58 | − int32_t output_operand_index, const void *parameters); | |
| 58 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx); | |
| 59 | 59 | |
| 60 | 60 | #endif |
| @@ -50,7 +50,7 @@ int dnn_load_layer_maximum(Layer *layer, AVIOContext *model_file_context, int fi · 49 unmodified lines | ||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | int dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 53 | − int32_t output_operand_index, const void *parameters) | |
| 53 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx) | |
| 54 | 54 | { |
| 55 | 55 | const DnnOperand *input = &operands[input_operand_indexes[0]]; |
| 56 | 56 | DnnOperand *output = &operands[output_operand_index]; |
| @@ -64,11 +64,15 @@ int dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand · 7 unmodified lines | ||
| 64 | 64 | |
| 65 | 65 | output->data_type = input->data_type; |
| 66 | 66 | output->length = calculate_operand_data_length(output); |
| 67 | − if (output->length <= 0) | |
| 67 | + if (output->length <= 0) { | |
| 68 | + av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); | |
| 68 | 69 | return DNN_ERROR; |
| 70 | + } | |
| 69 | 71 | output->data = av_realloc(output->data, output->length); |
| 70 | − if (!output->data) | |
| 72 | + if (!output->data) { | |
| 73 | + av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); | |
| 71 | 74 | return DNN_ERROR; |
| 75 | + } | |
| 72 | 76 | |
| 73 | 77 | dims_count = calculate_operand_dims_count(output); |
| 74 | 78 | src = input->data; |
| @@ -39,6 +39,6 @@ typedef struct DnnLayerMaximumParams{ · 38 unmodified lines | ||
| 39 | 39 | |
| 40 | 40 | int dnn_load_layer_maximum(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num); |
| 41 | 41 | int dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 42 | − int32_t output_operand_index, const void *parameters); | |
| 42 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx); | |
| 43 | 43 | |
| 44 | 44 | #endif |
| @@ -76,7 +76,7 @@ static int after_get_buddy(int given, int border, LayerPadModeParam mode) · 75 unmodified lines | ||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | int dnn_execute_layer_pad(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 79 | − int32_t output_operand_index, const void *parameters) | |
| 79 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx) | |
| 80 | 80 | { |
| 81 | 81 | int32_t before_paddings; |
| 82 | 82 | int32_t after_paddings; |
| @@ -111,11 +111,15 @@ int dnn_execute_layer_pad(DnnOperand *operands, const int32_t *input_operand_ind · 28 unmodified lines | ||
| 111 | 111 | output_operand->dims[3] = new_channel; |
| 112 | 112 | output_operand->data_type = operands[input_operand_index].data_type; |
| 113 | 113 | output_operand->length = calculate_operand_data_length(output_operand); |
| 114 | − if (output_operand->length <= 0) | |
| 114 | + if (output_operand->length <= 0) { | |
| 115 | + av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); | |
| 115 | 116 | return DNN_ERROR; |
| 117 | + } | |
| 116 | 118 | output_operand->data = av_realloc(output_operand->data, output_operand->length); |
| 117 | − if (!output_operand->data) | |
| 119 | + if (!output_operand->data) { | |
| 120 | + av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); | |
| 118 | 121 | return DNN_ERROR; |
| 122 | + } | |
| 119 | 123 | output = output_operand->data; |
| 120 | 124 | |
| 121 | 125 | // copy the original data |
| @@ -38,6 +38,6 @@ typedef struct LayerPadParams{ · 37 unmodified lines | ||
| 38 | 38 | |
| 39 | 39 | int dnn_load_layer_pad(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num); |
| 40 | 40 | int dnn_execute_layer_pad(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 41 | − int32_t output_operand_index, const void *parameters); | |
| 41 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx); | |
| 42 | 42 | |
| 43 | 43 | #endif |
| @@ -25,7 +25,7 @@ · 24 unmodified lines | ||
| 25 | 25 | #include "dnn_backend_native.h" |
| 26 | 26 | |
| 27 | 27 | typedef int (*LAYER_EXEC_FUNC)(DnnOperand *operands, const int32_t *input_operand_indexes, |
| 28 | − int32_t output_operand_index, const void *parameters); | |
| 28 | + int32_t output_operand_index, const void *parameters, NativeContext *ctx); | |
| 29 | 29 | typedef int (*LAYER_LOAD_FUNC)(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num); |
| 30 | 30 | |
| 31 | 31 | typedef struct LayerFunc { |