Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: webrtc/common_video/h264/profile_level_id.cc

Issue 2472693002: Add to-string function for H264 profile level id (Closed)
Patch Set: Return rtc::Optional and remove default ctor Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "webrtc/common_video/h264/profile_level_id.h" 11 #include "webrtc/common_video/h264/profile_level_id.h"
12 12
13 #include <cstdio>
13 #include <cstdlib> 14 #include <cstdlib>
14 #include <cstring> 15 #include <cstring>
15 16
16 namespace { 17 namespace {
17 18
18 // For level_idc=11 and profile_idc=0x42, 0x4D, or 0x58, the constraint set3 19 // For level_idc=11 and profile_idc=0x42, 0x4D, or 0x58, the constraint set3
19 // flag specifies if level 1b or level 1.1 is used. 20 // flag specifies if level 1b or level 1.1 is used.
20 const uint8_t kConstraintSet3Flag = 0x10; 21 const uint8_t kConstraintSet3Flag = 0x10;
21 22
22 // Convert a string of 8 characters into a byte where the positions containing 23 // Convert a string of 8 characters into a byte where the positions containing
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (profile_idc == pattern.profile_idc && 122 if (profile_idc == pattern.profile_idc &&
122 pattern.profile_iop.IsMatch(profile_iop)) { 123 pattern.profile_iop.IsMatch(profile_iop)) {
123 return rtc::Optional<ProfileLevelId>({pattern.profile, level}); 124 return rtc::Optional<ProfileLevelId>({pattern.profile, level});
124 } 125 }
125 } 126 }
126 127
127 // Unrecognized profile_idc/profile_iop combination. 128 // Unrecognized profile_idc/profile_iop combination.
128 return rtc::Optional<ProfileLevelId>(); 129 return rtc::Optional<ProfileLevelId>();
129 } 130 }
130 131
132 rtc::Optional<std::string> ProfileLevelIdToString(
133 const ProfileLevelId& profile_level_id) {
134 // Handle special case level == 1b.
135 if (profile_level_id.level == kLevel1_b) {
136 switch (profile_level_id.profile) {
137 case kProfileConstrainedBaseline:
138 return rtc::Optional<std::string>("42f00b");
139 case kProfileBaseline:
140 return rtc::Optional<std::string>("42100b");
141 case kProfileMain:
142 return rtc::Optional<std::string>("4D100b");
143 // Level 1b is not allowed for other profiles.
144 default:
145 return rtc::Optional<std::string>();
146 }
147 }
148
149 const char* profile_idc_iop_string;
150 switch (profile_level_id.profile) {
151 case kProfileConstrainedBaseline:
152 profile_idc_iop_string = "42e0";
153 break;
154 case kProfileBaseline:
155 profile_idc_iop_string = "4200";
156 break;
157 case kProfileMain:
158 profile_idc_iop_string = "4D00";
159 break;
160 case kProfileConstrainedHigh:
161 profile_idc_iop_string = "640c";
162 break;
163 case kProfileHigh:
164 profile_idc_iop_string = "6400";
165 break;
166 // Unrecognized profile.
167 default:
168 return rtc::Optional<std::string>();
169 }
170
171 char str[7];
172 snprintf(str, 7u, "%s%02x", profile_idc_iop_string, profile_level_id.level);
173 return rtc::Optional<std::string>(str);
174 }
175
131 } // namespace H264 176 } // namespace H264
132 } // namespace webrtc 177 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698