FFmpeg
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"
26 #include "libavutil/video_hint.h"
27 
28 int main(void)
29 {
30  AVVideoHint *hint;
32  AVFrame *frame;
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 */
56  rect = av_video_hint_rects(hint);
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++) {
61  rect = av_video_hint_get_rect(hint, 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++) {
71  rect = av_video_hint_get_rect(hint, 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);
97  rect = av_video_hint_get_rect(hint, 0);
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 
118  frame = av_frame_alloc();
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 }
printf
__device__ int printf(const char *,...)
rect
Definition: f_ebur128.c:78
rect::y
int y
Definition: f_ebur128.c:78
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
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
AV_VIDEO_HINT_TYPE_CHANGED
@ AV_VIDEO_HINT_TYPE_CHANGED
Definition: video_hint.h:39
AVVideoHint
Definition: video_hint.h:42
video_hint.h
av_max_alloc
void av_max_alloc(size_t max)
Set the maximum size that may be allocated in one block.
Definition: mem.c:76
macros.h
AV_VIDEO_HINT_TYPE_CONSTANT
@ AV_VIDEO_HINT_TYPE_CONSTANT
Definition: video_hint.h:36
av_video_hint_rects
static av_always_inline AVVideoRect * av_video_hint_rects(const AVVideoHint *hints)
Definition: video_hint.h:67
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
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
limits.h
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
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
size
int size
Definition: twinvq_data.h:10344
frame.h
rect::x
int x
Definition: f_ebur128.c:78
main
int main(void)
Definition: video_hint.c:28
AVVideoHint::type
AVVideoHintType type
Definition: video_hint.h:63
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:265
av_video_hint_get_rect
static av_always_inline AVVideoRect * av_video_hint_get_rect(const AVVideoHint *hints, size_t idx)
Definition: video_hint.h:72
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34