| 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 <inttypes.h> | ||
| 20 | #include <stddef.h> | ||
| 21 | |||
| 22 | #include "libavutil/log.h" | ||
| 23 | #include "libavutil/macros.h" | ||
| 24 | #include "libavcodec/h264_levels.h" | ||
| 25 | |||
| 26 | static const struct { | ||
| 27 | int width; | ||
| 28 | int height; | ||
| 29 | int level_idc; | ||
| 30 | } test_sizes[] = { | ||
| 31 | // First level usable at some standard sizes. | ||
| 32 | // (From H.264 table A-6.) | ||
| 33 | { 176, 144, 10 }, // QCIF | ||
| 34 | { 352, 288, 11 }, // CIF | ||
| 35 | { 640, 480, 22 }, // VGA | ||
| 36 | { 720, 480, 22 }, // NTSC | ||
| 37 | { 720, 576, 22 }, // PAL | ||
| 38 | { 800, 600, 31 }, // SVGA | ||
| 39 | { 1280, 720, 31 }, // 720p | ||
| 40 | { 1280, 1024, 32 }, // SXGA | ||
| 41 | { 1920, 1080, 40 }, // 1080p | ||
| 42 | { 2048, 1080, 42 }, // 2Kx1080 | ||
| 43 | { 2048, 1536, 50 }, // 4XGA | ||
| 44 | { 3840, 2160, 51 }, // 4K | ||
| 45 | { 7680, 4320, 60 }, // 8K | ||
| 46 | |||
| 47 | // Overly wide or tall sizes. | ||
| 48 | { 1, 256, 10 }, | ||
| 49 | { 1, 512, 11 }, | ||
| 50 | { 1, 1024, 21 }, | ||
| 51 | { 1, 1808, 22 }, | ||
| 52 | { 1, 1824, 31 }, | ||
| 53 | { 256, 1, 10 }, | ||
| 54 | { 512, 1, 11 }, | ||
| 55 | { 1024, 1, 21 }, | ||
| 56 | { 1808, 1, 22 }, | ||
| 57 | { 1824, 1, 31 }, | ||
| 58 | { 512, 4096, 40 }, | ||
| 59 | { 256, 4112, 42 }, | ||
| 60 | { 8688, 1024, 51 }, | ||
| 61 | { 8704, 512, 60 }, | ||
| 62 | { 16880, 1, 60 }, | ||
| 63 | { 16896, 1, 0 }, | ||
| 64 | }; | ||
| 65 | |||
| 66 | static const struct { | ||
| 67 | int width; | ||
| 68 | int height; | ||
| 69 | int framerate; | ||
| 70 | int level_idc; | ||
| 71 | } test_framerate[] = { | ||
| 72 | // Some typical sizes and frame rates. | ||
| 73 | // (From H.264 table A-1 and table A-6) | ||
| 74 | { 176, 144, 15, 10 }, | ||
| 75 | { 176, 144, 16, 11 }, | ||
| 76 | { 320, 240, 10, 11 }, | ||
| 77 | { 320, 240, 20, 12 }, | ||
| 78 | { 320, 240, 40, 21 }, | ||
| 79 | { 352, 288, 30, 13 }, | ||
| 80 | { 352, 288, 51, 22 }, | ||
| 81 | { 352, 576, 25, 21 }, | ||
| 82 | { 352, 576, 26, 30 }, | ||
| 83 | { 640, 480, 33, 30 }, | ||
| 84 | { 640, 480, 34, 31 }, | ||
| 85 | { 720, 480, 50, 31 }, | ||
| 86 | { 720, 576, 25, 30 }, | ||
| 87 | { 800, 600, 55, 31 }, | ||
| 88 | { 1024, 768, 35, 31 }, | ||
| 89 | { 1024, 768, 70, 32 }, | ||
| 90 | { 1280, 720, 30, 31 }, | ||
| 91 | { 1280, 720, 31, 32 }, | ||
| 92 | { 1280, 960, 45, 32 }, | ||
| 93 | { 1280, 960, 46, 40 }, | ||
| 94 | { 1280, 1024, 42, 32 }, | ||
| 95 | { 1600, 1200, 32, 40 }, | ||
| 96 | { 1600, 1200, 33, 42 }, | ||
| 97 | { 1920, 1088, 30, 40 }, | ||
| 98 | { 1920, 1088, 55, 42 }, | ||
| 99 | { 2048, 1024, 30, 40 }, | ||
| 100 | { 2048, 1024, 62, 42 }, | ||
| 101 | { 2048, 1088, 60, 42 }, | ||
| 102 | { 3680, 1536, 26, 50 }, | ||
| 103 | { 4096, 2048, 30, 51 }, | ||
| 104 | { 4096, 2048, 59, 52 }, | ||
| 105 | { 4096, 2160, 60, 52 }, | ||
| 106 | }; | ||
| 107 | |||
| 108 | static const struct { | ||
| 109 | int width; | ||
| 110 | int height; | ||
| 111 | int dpb_size; | ||
| 112 | int level_idc; | ||
| 113 | } test_dpb[] = { | ||
| 114 | // First level usable for some DPB sizes. | ||
| 115 | // (From H.264 table A-7.) | ||
| 116 | { 176, 144, 4, 10 }, | ||
| 117 | { 176, 144, 8, 11 }, | ||
| 118 | { 176, 144, 16, 12 }, | ||
| 119 | { 1280, 720, 1, 31 }, | ||
| 120 | { 1280, 720, 5, 31 }, | ||
| 121 | { 1280, 720, 9, 40 }, | ||
| 122 | { 1280, 720, 10, 50 }, | ||
| 123 | { 1920, 1080, 1, 40 }, | ||
| 124 | { 1920, 1080, 5, 50 }, | ||
| 125 | { 1920, 1080, 13, 50 }, | ||
| 126 | { 1920, 1080, 14, 51 }, | ||
| 127 | { 3840, 2160, 5, 51 }, | ||
| 128 | { 3840, 2160, 6, 60 }, | ||
| 129 | { 3840, 2160, 16, 60 }, | ||
| 130 | { 7680, 4320, 5, 60 }, | ||
| 131 | { 7680, 4320, 6, 0 }, | ||
| 132 | }; | ||
| 133 | |||
| 134 | static const struct { | ||
| 135 | int64_t bitrate; | ||
| 136 | int profile_idc; | ||
| 137 | int level_idc; | ||
| 138 | } test_bitrate[] = { | ||
| 139 | // Values where profile affects level at a given bitrate. | ||
| 140 | { 2500000, 77, 21 }, | ||
| 141 | { 2500000, 100, 20 }, | ||
| 142 | { 2500000, 244, 13 }, | ||
| 143 | { 100000000, 77, 50 }, | ||
| 144 | { 100000000, 100, 50 }, | ||
| 145 | { 100000000, 244, 41 }, | ||
| 146 | { 999999999, 77, 0 }, | ||
| 147 | { 999999999, 100, 62 }, | ||
| 148 | // Check level 1b. | ||
| 149 | { 32 * 1200, 66, 10 }, | ||
| 150 | { 32 * 1500, 100, 10 }, | ||
| 151 | { 96 * 1200, 66, 11 }, | ||
| 152 | { 96 * 1500, 100, 9 }, | ||
| 153 | { 144 * 1200, 66, 11 }, | ||
| 154 | { 144 * 1500, 100, 11 }, | ||
| 155 | }; | ||
| 156 | |||
| 157 | static const struct { | ||
| 158 | const char *name; | ||
| 159 | int profile_idc; | ||
| 160 | int64_t bitrate; | ||
| 161 | int width; | ||
| 162 | int height; | ||
| 163 | int dpb_frames; | ||
| 164 | int level_idc; | ||
| 165 | } test_all[] = { | ||
| 166 | { "Bluray 1080p 40Mb/s", 100, 40000000, 1920, 1080, 4, 41 }, | ||
| 167 | { "Bluray 1080p 24Mb/s", 100, 24000000, 1920, 1080, 4, 40 }, | ||
| 168 | { "Bluray 720p 40Mb/s", 100, 40000000, 1280, 720, 6, 41 }, | ||
| 169 | { "Bluray 720p 24Mb/s", 100, 24000000, 1280, 720, 6, 40 }, | ||
| 170 | { "Bluray PAL 40Mb/s", 100, 40000000, 720, 576, 6, 41 }, | ||
| 171 | { "Bluray PAL 24Mb/s", 100, 24000000, 720, 576, 6, 32 }, | ||
| 172 | { "Bluray PAL 16Mb/s", 100, 16800000, 720, 576, 6, 31 }, | ||
| 173 | { "Bluray PAL 12Mb/s", 100, 12000000, 720, 576, 5, 30 }, | ||
| 174 | { "Bluray NTSC 40Mb/s", 100, 40000000, 720, 480, 6, 41 }, | ||
| 175 | { "Bluray NTSC 24Mb/s", 100, 24000000, 720, 480, 6, 32 }, | ||
| 176 | { "Bluray NTSC 16Mb/s", 100, 16800000, 720, 480, 6, 31 }, | ||
| 177 | { "Bluray NTSC 12Mb/s", 100, 12000000, 720, 480, 6, 30 }, | ||
| 178 | }; | ||
| 179 | |||
| 180 | 1 | int main(void) | |
| 181 | { | ||
| 182 | const H264LevelDescriptor *level; | ||
| 183 | int i; | ||
| 184 | |||
| 185 | #define CHECK(expected, format, ...) do { \ | ||
| 186 | if (expected ? (!level || level->level_idc != expected) \ | ||
| 187 | : !!level) { \ | ||
| 188 | av_log(NULL, AV_LOG_ERROR, "Incorrect level for " \ | ||
| 189 | format ": expected %d, got %d.\n", __VA_ARGS__, \ | ||
| 190 | expected, level ? level->level_idc : -1); \ | ||
| 191 | return 1; \ | ||
| 192 | } \ | ||
| 193 | } while (0) | ||
| 194 | |||
| 195 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 1 times.
|
30 | for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) { |
| 196 | 29 | level = ff_h264_guess_level(0, 0, 0, test_sizes[i].width, | |
| 197 | 29 | test_sizes[i].height, 0); | |
| 198 |
5/10✓ Branch 0 taken 28 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 28 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 29 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
29 | CHECK(test_sizes[i].level_idc, "size %dx%d", |
| 199 | test_sizes[i].width, test_sizes[i].height); | ||
| 200 | } | ||
| 201 | |||
| 202 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1 times.
|
33 | for (i = 0; i < FF_ARRAY_ELEMS(test_framerate); i++) { |
| 203 | 32 | level = ff_h264_guess_level(0, 0, test_framerate[i].framerate, | |
| 204 | 32 | test_framerate[i].width, | |
| 205 | 32 | test_framerate[i].height, 0); | |
| 206 |
4/10✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 32 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 32 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
32 | CHECK(test_framerate[i].level_idc, "framerate %d, size %dx%d", |
| 207 | test_framerate[i].framerate, test_framerate[i].width, | ||
| 208 | test_framerate[i].height); | ||
| 209 | } | ||
| 210 | |||
| 211 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 1 times.
|
17 | for (i = 0; i < FF_ARRAY_ELEMS(test_dpb); i++) { |
| 212 | 16 | level = ff_h264_guess_level(0, 0, 0, test_dpb[i].width, | |
| 213 | 16 | test_dpb[i].height, | |
| 214 | 16 | test_dpb[i].dpb_size); | |
| 215 |
5/10✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
16 | CHECK(test_dpb[i].level_idc, "size %dx%d dpb %d", |
| 216 | test_dpb[i].width, test_dpb[i].height, | ||
| 217 | test_dpb[i].dpb_size); | ||
| 218 | } | ||
| 219 | |||
| 220 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1 times.
|
15 | for (i = 0; i < FF_ARRAY_ELEMS(test_bitrate); i++) { |
| 221 | 14 | level = ff_h264_guess_level(test_bitrate[i].profile_idc, | |
| 222 | 14 | test_bitrate[i].bitrate, | |
| 223 | 0, 0, 0, 0); | ||
| 224 |
5/10✓ Branch 0 taken 13 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
14 | CHECK(test_bitrate[i].level_idc, "bitrate %"PRId64" profile %d", |
| 225 | test_bitrate[i].bitrate, test_bitrate[i].profile_idc); | ||
| 226 | } | ||
| 227 | |||
| 228 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1 times.
|
13 | for (i = 0; i < FF_ARRAY_ELEMS(test_all); i++) { |
| 229 | 12 | level = ff_h264_guess_level(test_all[i].profile_idc, | |
| 230 | 12 | test_all[i].bitrate, | |
| 231 | 0, | ||
| 232 | 12 | test_all[i].width, | |
| 233 | 12 | test_all[i].height, | |
| 234 | 12 | test_all[i].dpb_frames); | |
| 235 |
4/10✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
12 | CHECK(test_all[i].level_idc, "%s", test_all[i].name); |
| 236 | } | ||
| 237 | |||
| 238 | 1 | return 0; | |
| 239 | } | ||
| 240 |