FFmpeg
Loading...
Searching...
No Matches
video_hint.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 <limits.h>
20#include <stdint.h>
21#include <stdio.h>
22
23#include "libavutil/frame.h"
24#include "libavutil/macros.h"
25#include "libavutil/mem.h"
27
28int main(void)
29{
30 AVVideoHint *hint;
33 size_t size;
34
35 static const size_t alloc_counts[] = { 0, 1, 4 };
36
37 /* av_video_hint_alloc - various counts */
38 printf("Testing av_video_hint_alloc()\n");
39 for (int i = 0; i < FF_ARRAY_ELEMS(alloc_counts); i++) {
40 size_t nb = alloc_counts[i];
41 hint = av_video_hint_alloc(nb, &size);
42 if (hint) {
43 printf("alloc %zu: OK, nb_rects=%zu, size>0=%s\n",
44 nb, hint->nb_rects, size > 0 ? "yes" : "no");
45 av_free(hint);
46 } else {
47 printf("alloc %zu: FAIL\n", nb);
48 }
49 }
50
51 /* pointer consistency and write/read back */
52 printf("\nTesting av_video_hint_get_rect()\n");
53 hint = av_video_hint_alloc(3, &size);
54 if (hint) {
55 /* verify av_video_hint_rects points to first rect */
57 if ((uint8_t *)rect != (uint8_t *)hint + hint->rect_offset)
58 printf("rects: pointer inconsistent with rect_offset\n");
59
60 for (int i = 0; i < 3; i++) {
62 if ((uint8_t *)rect != (uint8_t *)hint + hint->rect_offset +
63 (size_t)i * hint->rect_size)
64 printf("rect %d: pointer inconsistent with rect_offset/rect_size\n", i);
65 rect->x = i * 100;
66 rect->y = i * 200;
67 rect->width = 64 + i;
68 rect->height = 48 + i;
69 }
70 for (int i = 0; i < 3; i++) {
72 printf("rect %d: x=%u y=%u w=%u h=%u\n",
73 i, rect->x, rect->y, rect->width, rect->height);
74 }
75
76 av_free(hint);
77 }
78
79 /* type field */
80 printf("\nTesting type field\n");
81 hint = av_video_hint_alloc(1, &size);
82 if (hint) {
84 printf("constant: type=%d\n", hint->type);
86 printf("changed: type=%d\n", hint->type);
87 av_free(hint);
88 }
89
90 /* av_video_hint_create_side_data */
91 printf("\nTesting av_video_hint_create_side_data()\n");
93 if (frame) {
95 if (hint) {
96 printf("side_data: OK, nb_rects=%zu\n", hint->nb_rects);
98 rect->x = 10;
99 rect->y = 20;
100 rect->width = 320;
101 rect->height = 240;
102 rect = av_video_hint_get_rect(hint, 0);
103 printf("side_data rect 0: x=%u y=%u\n", rect->x, rect->y);
104 } else {
105 printf("side_data: FAIL\n");
106 }
108 }
109
110 /* OOM paths via av_max_alloc */
111 printf("\nTesting OOM paths\n");
112 av_max_alloc(1);
113 hint = av_video_hint_alloc(1, &size);
114 printf("alloc OOM: %s\n", hint ? "FAIL" : "OK");
115 av_free(hint);
116 av_max_alloc(INT_MAX);
117
119 if (frame) {
120 av_max_alloc(1);
122 printf("side_data OOM: %s\n", hint ? "FAIL" : "OK");
123 av_max_alloc(INT_MAX);
125 }
126
127 return 0;
128}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
__device__ int printf(const char *,...)
static AVFrame * frame
reference-counted frame API
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
void av_max_alloc(size_t max)
Set the maximum size that may be allocated in one block.
Definition mem.c:76
Utility Preprocessor macros.
Memory handling functions.
#define FF_ARRAY_ELEMS(a)
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
AVVideoHintType type
Definition video_hint.h:63
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
int y
Definition f_ebur128.c:78
int x
Definition f_ebur128.c:78
#define av_free(p)
int main(void)
Definition video_hint.c:28
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
@ AV_VIDEO_HINT_TYPE_CONSTANT
Definition video_hint.h:36
@ AV_VIDEO_HINT_TYPE_CHANGED
Definition video_hint.h:39
static av_always_inline AVVideoRect * av_video_hint_get_rect(const AVVideoHint *hints, size_t idx)
Definition video_hint.h:72
static av_always_inline AVVideoRect * av_video_hint_rects(const AVVideoHint *hints)
Definition video_hint.h:67