FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/video_hint.c
Date: 2026-09-26 20:14:34
Exec Total Coverage
Lines: 62 66 93.9%
Functions: 1 1 100.0%
Branches: 17 28 60.7%

Line Branch Exec Source
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 1 int main(void)
29 {
30 AVVideoHint *hint;
31 AVVideoRect *rect;
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 1 printf("Testing av_video_hint_alloc()\n");
39
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < FF_ARRAY_ELEMS(alloc_counts); i++) {
40 3 size_t nb = alloc_counts[i];
41 3 hint = av_video_hint_alloc(nb, &size);
42
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (hint) {
43 3 printf("alloc %zu: OK, nb_rects=%zu, size>0=%s\n",
44
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 nb, hint->nb_rects, size > 0 ? "yes" : "no");
45 3 av_free(hint);
46 } else {
47 ✗ printf("alloc %zu: FAIL\n", nb);
48 }
49 }
50
51 /* pointer consistency and write/read back */
52 1 printf("\nTesting av_video_hint_get_rect()\n");
53 1 hint = av_video_hint_alloc(3, &size);
54
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (hint) {
55 /* verify av_video_hint_rects points to first rect */
56 1 rect = av_video_hint_rects(hint);
57
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if ((uint8_t *)rect != (uint8_t *)hint + hint->rect_offset)
58 ✗ printf("rects: pointer inconsistent with rect_offset\n");
59
60
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < 3; i++) {
61 3 rect = av_video_hint_get_rect(hint, i);
62 3 if ((uint8_t *)rect != (uint8_t *)hint + hint->rect_offset +
63
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 (size_t)i * hint->rect_size)
64 ✗ printf("rect %d: pointer inconsistent with rect_offset/rect_size\n", i);
65 3 rect->x = i * 100;
66 3 rect->y = i * 200;
67 3 rect->width = 64 + i;
68 3 rect->height = 48 + i;
69 }
70
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < 3; i++) {
71 3 rect = av_video_hint_get_rect(hint, i);
72 3 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 1 av_free(hint);
77 }
78
79 /* type field */
80 1 printf("\nTesting type field\n");
81 1 hint = av_video_hint_alloc(1, &size);
82
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (hint) {
83 1 hint->type = AV_VIDEO_HINT_TYPE_CONSTANT;
84 1 printf("constant: type=%d\n", hint->type);
85 1 hint->type = AV_VIDEO_HINT_TYPE_CHANGED;
86 1 printf("changed: type=%d\n", hint->type);
87 1 av_free(hint);
88 }
89
90 /* av_video_hint_create_side_data */
91 1 printf("\nTesting av_video_hint_create_side_data()\n");
92 1 frame = av_frame_alloc();
93
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame) {
94 1 hint = av_video_hint_create_side_data(frame, 2);
95
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (hint) {
96 1 printf("side_data: OK, nb_rects=%zu\n", hint->nb_rects);
97 1 rect = av_video_hint_get_rect(hint, 0);
98 1 rect->x = 10;
99 1 rect->y = 20;
100 1 rect->width = 320;
101 1 rect->height = 240;
102 1 rect = av_video_hint_get_rect(hint, 0);
103 1 printf("side_data rect 0: x=%u y=%u\n", rect->x, rect->y);
104 } else {
105 ✗ printf("side_data: FAIL\n");
106 }
107 1 av_frame_free(&frame);
108 }
109
110 /* OOM paths via av_max_alloc */
111 1 printf("\nTesting OOM paths\n");
112 1 av_max_alloc(1);
113 1 hint = av_video_hint_alloc(1, &size);
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("alloc OOM: %s\n", hint ? "FAIL" : "OK");
115 1 av_free(hint);
116 1 av_max_alloc(INT_MAX);
117
118 1 frame = av_frame_alloc();
119
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame) {
120 1 av_max_alloc(1);
121 1 hint = av_video_hint_create_side_data(frame, 1);
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 printf("side_data OOM: %s\n", hint ? "FAIL" : "OK");
123 1 av_max_alloc(INT_MAX);
124 1 av_frame_free(&frame);
125 }
126
127 1 return 0;
128 }
129