FFmpeg
Loading...
Searching...
No Matches
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}
static int out_size
#define NULL
Definition coverity.c:32
static AVFrame * frame
reference-counted frame API
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
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
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:638
@ AV_FRAME_DATA_VIDEO_HINT
Provide encoder-specific hinting information about changed/unchanged portions of a frame.
Definition frame.h:230
Utility Preprocessor macros.
Memory handling functions.
A reference to a data buffer.
Definition buffer.h:82
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
size_t nb_rects
Number of AVVideoRect present.
Definition video_hint.h:50
size_t rect_size
Size in bytes of AVVideoRect.
Definition video_hint.h:61
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
Copyright 2023 Elias Carotti <eliascrt at amazon dot it>
Definition video_hint.h:29
#define av_mallocz(s)
#define av_freep(p)
int size
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 * 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