xref: /aosp_15_r20/external/v4l2_codec2/common/include/v4l2_codec2/common/H264.h (revision 0ec5a0ec62797f775085659156625e7f1bdb369f)
1 // Copyright 2024 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef ANDROID_V4L2_CODEC2_COMMON_H264_H
6 #define ANDROID_V4L2_CODEC2_COMMON_H264_H
7 
8 #include <C2Config.h>
9 
10 #include <ui/Size.h>
11 
12 namespace android {
13 
14 // Table A-1 in spec
15 struct H264LevelLimits {
16     C2Config::level_t level;
17     float maxMBPS;   // max macroblock processing rate in macroblocks per second
18     uint64_t maxFS;  // max frame size in macroblocks
19     uint32_t maxBR;  // max video bitrate in bits per second
20 };
21 
22 constexpr H264LevelLimits kH264Limits[] = {
23         {C2Config::LEVEL_AVC_1, 1485, 99, 64000},
24         {C2Config::LEVEL_AVC_1B, 1485, 99, 128000},
25         {C2Config::LEVEL_AVC_1_1, 3000, 396, 192000},
26         {C2Config::LEVEL_AVC_1_2, 6000, 396, 384000},
27         {C2Config::LEVEL_AVC_1_3, 11880, 396, 768000},
28         {C2Config::LEVEL_AVC_2, 11880, 396, 2000000},
29         {C2Config::LEVEL_AVC_2_1, 19800, 792, 4000000},
30         {C2Config::LEVEL_AVC_2_2, 20250, 1620, 4000000},
31         {C2Config::LEVEL_AVC_3, 40500, 1620, 10000000},
32         {C2Config::LEVEL_AVC_3_1, 108000, 3600, 14000000},
33         {C2Config::LEVEL_AVC_3_2, 216000, 5120, 20000000},
34         {C2Config::LEVEL_AVC_4, 245760, 8192, 20000000},
35         {C2Config::LEVEL_AVC_4_1, 245760, 8192, 50000000},
36         {C2Config::LEVEL_AVC_4_2, 522240, 8704, 50000000},
37         {C2Config::LEVEL_AVC_5, 589824, 22080, 135000000},
38         {C2Config::LEVEL_AVC_5_1, 983040, 36864, 240000000},
39         {C2Config::LEVEL_AVC_5_2, 2073600, 36864, 240000000},
40 };
41 
42 uint32_t maxFramerateForLevelH264(C2Config::level_t level, const ui::Size& videoSize);
43 
isH264Profile(C2Config::profile_t profile)44 inline bool isH264Profile(C2Config::profile_t profile) {
45     return (profile >= C2Config::PROFILE_AVC_BASELINE &&
46             profile <= C2Config::PROFILE_AVC_ENHANCED_MULTIVIEW_DEPTH_HIGH);
47 }
48 
49 }  // namespace android
50 
51 #endif  // ANDROID_V4L2_CODEC2_COMMON_H264_H
52