blob: 51d025cd7bdb1eef42f079c61b23e4a6b6f08bde [file] [log] [blame]
Johannes Kronc3fcee72021-04-19 09:09:26 +02001/*
2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef API_VIDEO_CODECS_H264_PROFILE_LEVEL_ID_H_
12#define API_VIDEO_CODECS_H264_PROFILE_LEVEL_ID_H_
13
14#include <string>
15
16#include "absl/types/optional.h"
17#include "api/video_codecs/sdp_video_format.h"
18#include "rtc_base/system/rtc_export.h"
19
20namespace webrtc {
21
22enum class H264Profile {
23 kProfileConstrainedBaseline,
24 kProfileBaseline,
25 kProfileMain,
26 kProfileConstrainedHigh,
27 kProfileHigh,
28};
29
30// All values are equal to ten times the level number, except level 1b which is
31// special.
32enum class H264Level {
33 kLevel1_b = 0,
34 kLevel1 = 10,
35 kLevel1_1 = 11,
36 kLevel1_2 = 12,
37 kLevel1_3 = 13,
38 kLevel2 = 20,
39 kLevel2_1 = 21,
40 kLevel2_2 = 22,
41 kLevel3 = 30,
42 kLevel3_1 = 31,
43 kLevel3_2 = 32,
44 kLevel4 = 40,
45 kLevel4_1 = 41,
46 kLevel4_2 = 42,
47 kLevel5 = 50,
48 kLevel5_1 = 51,
49 kLevel5_2 = 52
50};
51
52struct H264ProfileLevelId {
53 constexpr H264ProfileLevelId(H264Profile profile, H264Level level)
54 : profile(profile), level(level) {}
55 H264Profile profile;
56 H264Level level;
57};
58
59// Parse profile level id that is represented as a string of 3 hex bytes.
60// Nothing will be returned if the string is not a recognized H264
61// profile level id.
62absl::optional<H264ProfileLevelId> ParseH264ProfileLevelId(const char* str);
63
64// Parse profile level id that is represented as a string of 3 hex bytes
65// contained in an SDP key-value map. A default profile level id will be
66// returned if the profile-level-id key is missing. Nothing will be returned if
67// the key is present but the string is invalid.
68RTC_EXPORT absl::optional<H264ProfileLevelId> ParseSdpForH264ProfileLevelId(
69 const SdpVideoFormat::Parameters& params);
70
71// Given that a decoder supports up to a given frame size (in pixels) at up to a
72// given number of frames per second, return the highest H.264 level where it
73// can guarantee that it will be able to support all valid encoded streams that
74// are within that level.
75RTC_EXPORT absl::optional<H264Level> H264SupportedLevel(
76 int max_frame_pixel_count,
77 float max_fps);
78
79// Returns canonical string representation as three hex bytes of the profile
80// level id, or returns nothing for invalid profile level ids.
81RTC_EXPORT absl::optional<std::string> H264ProfileLevelIdToString(
82 const H264ProfileLevelId& profile_level_id);
83
84// Returns true if the parameters have the same H264 profile (Baseline, High,
85// etc).
86RTC_EXPORT bool H264IsSameProfile(const SdpVideoFormat::Parameters& params1,
87 const SdpVideoFormat::Parameters& params2);
88
89} // namespace webrtc
90
91#endif // API_VIDEO_CODECS_H264_PROFILE_LEVEL_ID_H_