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"
22 AVDetectionBBoxHeader
*av_detection_bbox_alloc(uint32_t nb_bboxes
, size_t *out_size
)
26 AVDetectionBBoxHeader header
;
27 AVDetectionBBox boxes
;
29 const size_t bboxes_offset
= offsetof(struct BBoxContext
, boxes
);
30 const size_t bbox_size
= sizeof(AVDetectionBBox
);
31 AVDetectionBBoxHeader
*header
;
34 if (nb_bboxes
> (SIZE_MAX
- size
) / bbox_size
)
36 size
+= bbox_size
* nb_bboxes
;
38 header
= av_mallocz(size
);
42 header
->nb_bboxes
= nb_bboxes
;
43 header
->bbox_size
= bbox_size
;
44 header
->bboxes_offset
= bboxes_offset
;
52 AVDetectionBBoxHeader
*av_detection_bbox_create_side_data(AVFrame
*frame
, uint32_t nb_bboxes
)
55 AVDetectionBBoxHeader
*header
;
58 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
);