2 * This file is part of FFmpeg.
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.
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.
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
19 #include "detection_bbox.h"
21 AVDetectionBBoxHeader *av_detection_bbox_alloc(uint32_t nb_bboxes, size_t *out_size)
25 AVDetectionBBoxHeader header;
26 AVDetectionBBox boxes[1];
30 if (nb_bboxes - 1 > (SIZE_MAX - size) / sizeof(*ret->boxes))
32 size += sizeof(*ret->boxes) * (nb_bboxes - 1);
34 ret = av_mallocz(size);
38 ret->header.nb_bboxes = nb_bboxes;
39 ret->header.bbox_size = sizeof(*ret->boxes);
40 ret->header.bboxes_offset = (char *)&ret->boxes - (char *)&ret->header;
48 AVDetectionBBoxHeader *av_detection_bbox_create_side_data(AVFrame *frame, uint32_t nb_bboxes)
51 AVDetectionBBoxHeader *header;
54 header = av_detection_bbox_alloc(nb_bboxes, &size);
61 buf = av_buffer_create((uint8_t *)header, size, NULL, NULL, 0);
67 if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_DETECTION_BBOXES, buf)) {
68 av_buffer_unref(&buf);