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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/common_video/h264/profile_level_id.cc
diff --git a/webrtc/common_video/h264/profile_level_id.cc b/webrtc/common_video/h264/profile_level_id.cc
index 9f9aef9f61d147f72111b6ee3d6f5c79395e00d6..6d8c5c0ce80fa18819759ae4da190da9b79738af 100644
--- a/webrtc/common_video/h264/profile_level_id.cc
+++ b/webrtc/common_video/h264/profile_level_id.cc
@@ -10,6 +10,7 @@
#include "webrtc/common_video/h264/profile_level_id.h"
+#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -128,5 +129,49 @@ rtc::Optional<ProfileLevelId> ParseProfileLevelId(const char* str) {
return rtc::Optional<ProfileLevelId>();
}
+rtc::Optional<std::string> ProfileLevelIdToString(
+ const ProfileLevelId& profile_level_id) {
+ // Handle special case level == 1b.
+ if (profile_level_id.level == kLevel1_b) {
+ switch (profile_level_id.profile) {
+ case kProfileConstrainedBaseline:
+ return rtc::Optional<std::string>("42f00b");
+ case kProfileBaseline:
+ return rtc::Optional<std::string>("42100b");
+ case kProfileMain:
+ return rtc::Optional<std::string>("4D100b");
+ // Level 1b is not allowed for other profiles.
+ default:
+ return rtc::Optional<std::string>();
+ }
+ }
+
+ const char* profile_idc_iop_string;
+ switch (profile_level_id.profile) {
+ case kProfileConstrainedBaseline:
+ profile_idc_iop_string = "42e0";
+ break;
+ case kProfileBaseline:
+ profile_idc_iop_string = "4200";
+ break;
+ case kProfileMain:
+ profile_idc_iop_string = "4D00";
+ break;
+ case kProfileConstrainedHigh:
+ profile_idc_iop_string = "640c";
+ break;
+ case kProfileHigh:
+ profile_idc_iop_string = "6400";
+ break;
+ // Unrecognized profile.
+ default:
+ return rtc::Optional<std::string>();
+ }
+
+ char str[7];
+ snprintf(str, 7u, "%s%02x", profile_idc_iop_string, profile_level_id.level);
+ return rtc::Optional<std::string>(str);
+}
+
} // namespace H264
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698