OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_COMMON_VIDEO_H264_PROFILE_LEVEL_ID_H_ | 11 #ifndef WEBRTC_COMMON_VIDEO_H264_PROFILE_LEVEL_ID_H_ |
12 #define WEBRTC_COMMON_VIDEO_H264_PROFILE_LEVEL_ID_H_ | 12 #define WEBRTC_COMMON_VIDEO_H264_PROFILE_LEVEL_ID_H_ |
13 | 13 |
| 14 #include <map> |
14 #include <string> | 15 #include <string> |
15 | 16 |
16 #include "webrtc/base/optional.h" | 17 #include "webrtc/base/optional.h" |
17 | 18 |
18 namespace webrtc { | 19 namespace webrtc { |
19 namespace H264 { | 20 namespace H264 { |
20 | 21 |
| 22 // Map containting SDP codec parameters. |
| 23 typedef std::map<std::string, std::string> CodecParameterMap; |
| 24 |
21 enum Profile { | 25 enum Profile { |
22 kProfileConstrainedBaseline, | 26 kProfileConstrainedBaseline, |
23 kProfileBaseline, | 27 kProfileBaseline, |
24 kProfileMain, | 28 kProfileMain, |
25 kProfileConstrainedHigh, | 29 kProfileConstrainedHigh, |
26 kProfileHigh, | 30 kProfileHigh, |
27 }; | 31 }; |
28 | 32 |
29 // All values are equal to ten times the level number, except level 1b which is | 33 // All values are equal to ten times the level number, except level 1b which is |
30 // special. | 34 // special. |
(...skipping 22 matching lines...) Expand all Loading... |
53 : profile(profile), level(level) {} | 57 : profile(profile), level(level) {} |
54 Profile profile; | 58 Profile profile; |
55 Level level; | 59 Level level; |
56 }; | 60 }; |
57 | 61 |
58 // Parse profile level id that is represented as a string of 3 hex bytes. | 62 // Parse profile level id that is represented as a string of 3 hex bytes. |
59 // Nothing will be returned if the string is not a recognized H264 | 63 // Nothing will be returned if the string is not a recognized H264 |
60 // profile level id. | 64 // profile level id. |
61 rtc::Optional<ProfileLevelId> ParseProfileLevelId(const char* str); | 65 rtc::Optional<ProfileLevelId> ParseProfileLevelId(const char* str); |
62 | 66 |
| 67 // Parse profile level id that is represented as a string of 3 hex bytes |
| 68 // contained in an SDP key-value map. A default profile level id will be |
| 69 // returned if the profile-level-id key is missing. Nothing will be returned if |
| 70 // the key is present but the string is invalid. |
| 71 rtc::Optional<ProfileLevelId> ParseSdpProfileLevelId( |
| 72 const CodecParameterMap& params); |
| 73 |
63 // Given that a decoder supports up to a given frame size (in pixels) at up to a | 74 // Given that a decoder supports up to a given frame size (in pixels) at up to a |
64 // given number of frames per second, return the highest H.264 level where it | 75 // given number of frames per second, return the highest H.264 level where it |
65 // can guarantee that it will be able to support all valid encoded streams that | 76 // can guarantee that it will be able to support all valid encoded streams that |
66 // are within that level. | 77 // are within that level. |
67 rtc::Optional<Level> SupportedLevel(int max_frame_pixel_count, float max_fps); | 78 rtc::Optional<Level> SupportedLevel(int max_frame_pixel_count, float max_fps); |
68 | 79 |
69 // Returns canonical string representation as three hex bytes of the profile | 80 // Returns canonical string representation as three hex bytes of the profile |
70 // level id, or returns nothing for invalid profile level ids. | 81 // level id, or returns nothing for invalid profile level ids. |
71 rtc::Optional<std::string> ProfileLevelIdToString( | 82 rtc::Optional<std::string> ProfileLevelIdToString( |
72 const ProfileLevelId& profile_level_id); | 83 const ProfileLevelId& profile_level_id); |
73 | 84 |
| 85 // Generate codec parameters that will be used as answer in an SDP negotiation |
| 86 // based on local supported parameters and remote offered parameters. Both |
| 87 // |local_supported_params|, |remote_offered_params|, and |answer_params| |
| 88 // represent sendrecv media descriptions, i.e they are a mix of both encode and |
| 89 // decode capabilities. In theory, when the profile in |local_supported_params| |
| 90 // represent a strict superset of the profile in |remote_offered_params|, we |
| 91 // could limit the profile in |answer_params| to the profile in |
| 92 // |remote_offered_params|. However, to simplify the code, each supported H264 |
| 93 // profile should be listed explicitly in the list of local supported codecs, |
| 94 // even if they are redundant. Then each local codec in the list should be |
| 95 // tested one at a time against the remote codec, and only when the profiles are |
| 96 // equal should this function be called. Therefore, this function does not need |
| 97 // to handle profile intersection, and the profile of |local_supported_params| |
| 98 // and |remote_offered_params| must be equal before calling this function. The |
| 99 // parameters that are used when negotiating are the level part of |
| 100 // profile-level-id and level-asymmetry-allowed. |
| 101 void GenerateProfileLevelIdForAnswer( |
| 102 const CodecParameterMap& local_supported_params, |
| 103 const CodecParameterMap& remote_offered_params, |
| 104 CodecParameterMap* answer_params); |
| 105 |
74 } // namespace H264 | 106 } // namespace H264 |
75 } // namespace webrtc | 107 } // namespace webrtc |
76 | 108 |
77 #endif // WEBRTC_COMMON_VIDEO_H264_PROFILE_LEVEL_ID_H_ | 109 #endif // WEBRTC_COMMON_VIDEO_H264_PROFILE_LEVEL_ID_H_ |
OLD | NEW |