FFmpeg
video_hint.c
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <string.h>
22 
23 #include "avstring.h"
24 #include "frame.h"
25 #include "macros.h"
26 #include "mem.h"
27 #include "video_hint.h"
28 
30  size_t *out_size)
31 {
32  struct TestStruct {
33  AVVideoHint hint;
35  };
36  const size_t rect_offset = offsetof(struct TestStruct, rect);
37  size_t size = rect_offset;
38  AVVideoHint *hint;
39 
40  *out_size = 0;
41  if (nb_rects > (SIZE_MAX - size) / sizeof(AVVideoRect))
42  return NULL;
43  size += sizeof(AVVideoRect) * nb_rects;
44 
45  hint = av_mallocz(size);
46  if (!hint)
47  return NULL;
48 
49  hint->nb_rects = nb_rects;
50  hint->rect_offset = rect_offset;
51  hint->rect_size = sizeof(AVVideoRect);
52 
53  *out_size = size;
54 
55  return hint;
56 }
57 
59  size_t nb_rects)
60 {
61  AVVideoHint *hint;
62  AVBufferRef *buf;
63  size_t size = 0;
64 
65  hint = av_video_hint_alloc(nb_rects, &size);
66  if (!hint)
67  return NULL;
68 
69  buf = av_buffer_create((uint8_t *)hint, size, NULL, NULL, 0);
70  if (!buf) {
71  av_freep(&hint);
72  return NULL;
73  }
74 
76  av_buffer_unref(&buf);
77  return NULL;
78  }
79 
80  return hint;
81 }
rect
Definition: f_ebur128.c:77
out_size
int out_size
Definition: movenc.c:56
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
AVVideoRect
Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
Definition: video_hint.h:29
AVVideoHint::nb_rects
size_t nb_rects
Number of AVVideoRect present.
Definition: video_hint.h:50
TestStruct
Definition: audio_fifo.c:29
AVVideoHint
Definition: video_hint.h:42
video_hint.h
macros.h
av_video_hint_alloc
AVVideoHint * av_video_hint_alloc(size_t nb_rects, size_t *out_size)
Allocate memory for the AVVideoHint struct along with an nb_rects-sized arrays of AVVideoRect.
Definition: video_hint.c:29
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:139
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:786
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:55
AVVideoHint::rect_offset
size_t rect_offset
Offset in bytes from the beginning of this structure at which the array of AVVideoRect starts.
Definition: video_hint.h:56
av_video_hint_create_side_data
AVVideoHint * av_video_hint_create_side_data(AVFrame *frame, size_t nb_rects)
Same as av_video_hint_alloc(), except newly-allocated AVVideoHint is attached as side data of type AV...
Definition: video_hint.c:58
AVVideoHint::rect_size
size_t rect_size
Size in bytes of AVVideoRect.
Definition: video_hint.h:61
size
int size
Definition: twinvq_data.h:10344
frame.h
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:256
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
AV_FRAME_DATA_VIDEO_HINT
@ AV_FRAME_DATA_VIDEO_HINT
Provide encoder-specific hinting information about changed/unchanged portions of a frame.
Definition: frame.h:230
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avstring.h