FFmpeg
av1_levels.c
Go to the documentation of this file.
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 {
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 int main(void)
84 {
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  for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) {
100  test_sizes[i].width,
102  0, 0, test_sizes[i].framerate);
103  CHECK(test_sizes[i].level_idx, "size %dx%d, framerate %f",
105  }
106 
107  for (i = 0; i < FF_ARRAY_ELEMS(test_bitrate); i++) {
110  0, 0, 0, 0, 0);
111  CHECK(test_bitrate[i].level_idx, "bitrate %"PRId64" tier %d",
113  }
114 
115  for (i = 0; i < FF_ARRAY_ELEMS(test_tiles); i++) {
116  level = ff_av1_guess_level(0, 0, 0, 0,
117  test_tiles[i].tiles,
119  0);
120  CHECK(test_tiles[i].level_idx, "tiles %d, tile cols %d",
121  test_tiles[i].tiles,
123  }
124 
125  return 0;
126 }
level
uint8_t level
Definition: svq3.c:205
int64_t
long long int64_t
Definition: coverity.c:34
ff_av1_guess_level
const AV1LevelDescriptor * ff_av1_guess_level(int64_t bitrate, int tier, int width, int height, int tiles, int tile_cols, float fps)
Guess the level of a stream from some parameters.
Definition: av1_levels.c:48
height
int height
Definition: av1_levels.c:28
tiles
int tiles
Definition: av1_levels.c:72
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
bitrate
int64_t bitrate
Definition: av1_levels.c:47
tile_cols
int tile_cols
Definition: av1_levels.c:73
tier
int tier
Definition: av1_levels.c:48
framerate
float framerate
Definition: av1_levels.c:29
AV1LevelDescriptor
Definition: av1_levels.h:26
width
int width
Definition: av1_levels.c:27
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
CHECK
#define CHECK(expected, format,...)
test_bitrate
static const struct @222 test_bitrate[]
test_sizes
static const struct @221 test_sizes[]
av1_levels.h
test_tiles
static const struct @223 test_tiles[]
main
int main(void)
Definition: av1_levels.c:83
level_idx
int level_idx
Definition: av1_levels.c:30