FFmpeg
detection_bbox.c
Go to the documentation of this file.
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 
22 {
23  size_t size;
24  struct {
26  AVDetectionBBox boxes[1];
27  } *ret;
28 
29  size = sizeof(*ret);
30  if (nb_bboxes - 1 > (SIZE_MAX - size) / sizeof(*ret->boxes))
31  return NULL;
32  size += sizeof(*ret->boxes) * (nb_bboxes - 1);
33 
34  ret = av_mallocz(size);
35  if (!ret)
36  return NULL;
37 
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;
41 
42  if (out_size)
43  *out_size = size;
44 
45  return &ret->header;
46 }
47 
49 {
50  AVBufferRef *buf;
52  size_t size;
53 
54  header = av_detection_bbox_alloc(nb_bboxes, &size);
55  if (!header)
56  return NULL;
57  buf = av_buffer_create((uint8_t *)header, size, NULL, NULL, 0);
58  if (!buf) {
59  av_freep(&header);
60  return NULL;
61  }
62 
64  av_buffer_unref(&buf);
65  return NULL;
66  }
67 
68  return header;
69 }
out_size
int out_size
Definition: movenc.c:55
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
NULL
#define NULL
Definition: coverity.c:32
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:125
AVDetectionBBoxHeader
Definition: detection_bbox.h:56
av_frame_new_side_data_from_buf
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
Definition: frame.c:572
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:29
av_detection_bbox_create_side_data
AVDetectionBBoxHeader * av_detection_bbox_create_side_data(AVFrame *frame, uint32_t nb_bboxes)
Allocates memory for AVDetectionBBoxHeader, plus an array of.
Definition: detection_bbox.c:48
size
int size
Definition: twinvq_data.h:10344
header
static const uint8_t header[24]
Definition: sdr2.c:67
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:243
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:84
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AVDetectionBBox
Definition: detection_bbox.h:26
detection_bbox.h
AV_FRAME_DATA_DETECTION_BBOXES
@ AV_FRAME_DATA_DETECTION_BBOXES
Bounding boxes for object detection and classification, as described by AVDetectionBBoxHeader.
Definition: frame.h:189
av_detection_bbox_alloc
AVDetectionBBoxHeader * av_detection_bbox_alloc(uint32_t nb_bboxes, size_t *out_size)
Allocates memory for AVDetectionBBoxHeader, plus an array of.
Definition: detection_bbox.c:21