FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/av1_levels.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 22 26 84.6%
Functions: 1 1 100.0%
Branches: 16 20 80.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 "libavutil/macros.h"
23 #include "av1_levels.h"
24
25 /** ignore entries which named in spec but no details. Like level 2.2 and 7.0. */
26 static const AV1LevelDescriptor av1_levels[] = {
27 // Name MaxVSize MainMbps MaxTiles
28 // | level_idx | MaxDisplayRate | HighMbps | MaxTileCols
29 // | | MaxPicSize | | MaxDecodeRate | | MainCR | |
30 // | | | MaxHSize | | | MaxHeaderRate | | | HighCR| |
31 // | | | | | | | | | | | | | |
32 { "2.0", 0, 147456, 2048, 1152, 4423680, 5529600, 150, 1.5, 0, 2, 0, 8, 4 },
33 { "2.1", 1, 278784, 2816, 1584, 8363520, 10454400, 150, 3.0, 0, 2, 0, 8, 4 },
34 { "3.0", 4, 665856, 4352, 2448, 19975680, 24969600, 150, 6.0, 0, 2, 0, 16, 6 },
35 { "3.1", 5, 1065024, 5504, 3096, 31950720, 39938400, 150, 10.0, 0, 2, 0, 16, 6 },
36 { "4.0", 8, 2359296, 6144, 3456, 70778880, 77856768, 300, 12.0, 30.0, 4, 4, 32, 8 },
37 { "4.1", 9, 2359296, 6144, 3456, 141557760, 155713536, 300, 20.0, 50.0, 4, 4, 32, 8 },
38 { "5.0", 12, 8912896, 8192, 4352, 267386880, 273715200, 300, 30.0, 100.0, 6, 4, 64, 8 },
39 { "5.1", 13, 8912896, 8192, 4352, 534773760, 547430400, 300, 40.0, 160.0, 8, 4, 64, 8 },
40 { "5.2", 14, 8912896, 8192, 4352, 1069547520, 1094860800, 300, 60.0, 240.0, 8, 4, 64, 8 },
41 { "5.3", 15, 8912896, 8192, 4352, 1069547520, 1176502272, 300, 60.0, 240.0, 8, 4, 64, 8 },
42 { "6.0", 16, 35651584, 16384, 8704, 1069547520, 1176502272, 300, 60.0, 240.0, 8, 4, 128, 16 },
43 { "6.1", 17, 35651584, 16384, 8704, 2139095040, 2189721600, 300, 100.0, 480.0, 8, 4, 128, 16 },
44 { "6.2", 18, 35651584, 16384, 8704, 4278190080, 4379443200, 300, 160.0, 800.0, 8, 4, 128, 16 },
45 { "6.3", 19, 35651584, 16384, 8704, 4278190080, 4706009088, 300, 160.0, 800.0, 8, 4, 128, 16 },
46 };
47
48 35 const AV1LevelDescriptor *ff_av1_guess_level(int64_t bitrate,
49 int tier,
50 int width,
51 int height,
52 int tiles,
53 int tile_cols,
54 float fps)
55 {
56 int pic_size;
57 uint64_t display_rate;
58 float max_br;
59
60 35 pic_size = width * height;
61 35 display_rate = (uint64_t)pic_size * fps;
62
63
1/2
✓ Branch 0 taken 238 times.
✗ Branch 1 not taken.
238 for (int i = 0; i < FF_ARRAY_ELEMS(av1_levels); i++) {
64 238 const AV1LevelDescriptor *level = &av1_levels[i];
65 // Limitation: decode rate, header rate, compress rate, etc. are not considered.
66
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 176 times.
238 if (pic_size > level->max_pic_size)
67 62 continue;
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 176 times.
176 if (width > level->max_h_size)
69 continue;
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 176 times.
176 if (height > level->max_v_size)
71 continue;
72
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 169 times.
176 if (display_rate > level->max_display_rate)
73 7 continue;
74
75
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 109 times.
169 if (tier)
76 60 max_br = level->high_mbps;
77 else
78 109 max_br = level->main_mbps;
79
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 141 times.
169 if (!max_br)
80 28 continue;
81
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 57 times.
141 if (bitrate > (int64_t)(1000000.0 * max_br))
82 84 continue;
83
84
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 35 times.
57 if (tiles > level->max_tiles)
85 22 continue;
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if (tile_cols > level->max_tile_cols)
87 continue;
88 35 return level;
89 }
90
91 return NULL;
92 }
93