| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "detection_bbox.h" | ||
| 20 | #include "mem.h" | ||
| 21 | |||
| 22 | 8 | AVDetectionBBoxHeader *av_detection_bbox_alloc(uint32_t nb_bboxes, size_t *out_size) | |
| 23 | { | ||
| 24 | size_t size; | ||
| 25 | struct BBoxContext { | ||
| 26 | AVDetectionBBoxHeader header; | ||
| 27 | AVDetectionBBox boxes; | ||
| 28 | }; | ||
| 29 | 8 | const size_t bboxes_offset = offsetof(struct BBoxContext, boxes); | |
| 30 | 8 | const size_t bbox_size = sizeof(AVDetectionBBox); | |
| 31 | AVDetectionBBoxHeader *header; | ||
| 32 | |||
| 33 | 8 | size = bboxes_offset; | |
| 34 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (nb_bboxes > (SIZE_MAX - size) / bbox_size) |
| 35 | ✗ | return NULL; | |
| 36 | 8 | size += bbox_size * nb_bboxes; | |
| 37 | |||
| 38 | 8 | header = av_mallocz(size); | |
| 39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (!header) |
| 40 | ✗ | return NULL; | |
| 41 | |||
| 42 | 8 | header->nb_bboxes = nb_bboxes; | |
| 43 | 8 | header->bbox_size = bbox_size; | |
| 44 | 8 | header->bboxes_offset = bboxes_offset; | |
| 45 | |||
| 46 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | if (out_size) |
| 47 | 4 | *out_size = size; | |
| 48 | |||
| 49 | 8 | return header; | |
| 50 | } | ||
| 51 | |||
| 52 | 1 | AVDetectionBBoxHeader *av_detection_bbox_create_side_data(AVFrame *frame, uint32_t nb_bboxes) | |
| 53 | { | ||
| 54 | AVBufferRef *buf; | ||
| 55 | AVDetectionBBoxHeader *header; | ||
| 56 | size_t size; | ||
| 57 | |||
| 58 | 1 | header = av_detection_bbox_alloc(nb_bboxes, &size); | |
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!header) |
| 60 | ✗ | return NULL; | |
| 61 | 1 | buf = av_buffer_create((uint8_t *)header, size, NULL, NULL, 0); | |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!buf) { |
| 63 | ✗ | av_freep(&header); | |
| 64 | ✗ | return NULL; | |
| 65 | } | ||
| 66 | |||
| 67 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_DETECTION_BBOXES, buf)) { |
| 68 | ✗ | av_buffer_unref(&buf); | |
| 69 | ✗ | return NULL; | |
| 70 | } | ||
| 71 | |||
| 72 | 1 | return header; | |
| 73 | } | ||
| 74 |