FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/tests/av1_levels.c
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 1 1 100.0%
Branches: 12 24 50.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2023 Intel Corporation
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 <stddef.h>
22 #include <inttypes.h>
23 #include "libavutil/log.h"
24 #include "libavcodec/av1_levels.h"
25
26 static const struct {
27 int width;
28 int height;
29 float framerate;
30 int level_idx;
31 } test_sizes[] = {
32 { 426, 240, 30.0, 0 },
33 { 640, 360, 30.0, 1 },
34 { 854, 480, 30.0, 4 },
35 { 1280, 720, 30.0, 5 },
36 { 1920, 1080, 30.0, 8 },
37 { 1920, 1080, 60.0, 9 },
38 { 3840, 2160, 30.0, 12 },
39 { 3840, 2160, 60.0, 13 },
40 { 3840, 2160, 120.0, 14 },
41 { 7680, 4320, 30.0, 16 },
42 { 7680, 4320, 60.0, 17 },
43 { 7680, 4320, 120.0, 18 },
44 };
45
46 static const struct {
47 int64_t bitrate;
48 int tier;
49 int level_idx;
50 } test_bitrate[] = {
51 { 1500000, 0, 0 },
52 { 3000000, 0, 1 },
53 { 6000000, 0, 4 },
54 { 10000000, 0, 5 },
55 { 12000000, 0, 8 },
56 { 30000000, 1, 8 },
57 { 20000000, 0, 9 },
58 { 50000000, 1, 9 },
59 { 30000000, 0, 12 },
60 { 100000000, 1, 12 },
61 { 40000000, 0, 13 },
62 { 160000000, 1, 13 },
63 { 60000000, 0, 14 },
64 { 240000000, 1, 14 },
65 { 100000000, 0, 17 },
66 { 480000000, 1, 17 },
67 { 160000000, 0, 18 },
68 { 800000000, 1, 18 },
69 };
70
71 static const struct {
72 int tiles;
73 int tile_cols;
74 int level_idx;
75 } test_tiles[] = {
76 { 8, 4, 0 },
77 { 16, 6, 4 },
78 { 32, 8, 8 },
79 { 64, 8, 12 },
80 { 128, 16, 16 },
81 };
82
83 1 int main(void)
84 {
85 const AV1LevelDescriptor *level;
86 int i;
87
88 #define CHECK(expected, format, ...) do { \
89 if (level ? (level->level_idx != expected) \
90 : !level) { \
91 av_log(NULL, AV_LOG_ERROR, "Incorrect level for " \
92 format ": expected %d, got %d.\n", __VA_ARGS__, \
93 expected, level ? level->level_idx : -1); \
94 return 1; \
95 } \
96 } while (0)
97
98
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
13 for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) {
99 12 level = ff_av1_guess_level(0, 0,
100 12 test_sizes[i].width,
101 12 test_sizes[i].height,
102 12 0, 0, test_sizes[i].framerate);
103
2/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
12 CHECK(test_sizes[i].level_idx, "size %dx%d, framerate %f",
104 test_sizes[i].width, test_sizes[i].height, test_sizes[i].framerate);
105 }
106
107
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
19 for (i = 0; i < FF_ARRAY_ELEMS(test_bitrate); i++) {
108 18 level = ff_av1_guess_level(test_bitrate[i].bitrate,
109 18 test_bitrate[i].tier,
110 0, 0, 0, 0, 0);
111
2/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18 CHECK(test_bitrate[i].level_idx, "bitrate %"PRId64" tier %d",
112 test_bitrate[i].bitrate, test_bitrate[i].tier);
113 }
114
115
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 for (i = 0; i < FF_ARRAY_ELEMS(test_tiles); i++) {
116 5 level = ff_av1_guess_level(0, 0, 0, 0,
117 5 test_tiles[i].tiles,
118 5 test_tiles[i].tile_cols,
119 0);
120
2/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 CHECK(test_tiles[i].level_idx, "tiles %d, tile cols %d",
121 test_tiles[i].tiles,
122 test_tiles[i].tile_cols);
123 }
124
125 1 return 0;
126 }
127