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

Unified Diff: webrtc/common_video/h264/profile_level_id.cc

Issue 2472693002: Add to-string function for H264 profile level id (Closed)
Patch Set: 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..4b5be2d239efffc59767b10dd102c51c590e8b56 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,48 @@ rtc::Optional<ProfileLevelId> ParseProfileLevelId(const char* str) {
return rtc::Optional<ProfileLevelId>();
}
+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 "42f00b";
+ case kProfileBaseline:
+ return "42100b";
+ case kProfileMain:
+ return "4D100b";
+ // Level 1b is not allowed for other profiles.
+ default:
+ return std::string();
kthelgason 2016/11/03 09:39:05 Maybe we should return an rtc::Optional<std::strin
magjed_webrtc 2016/11/03 12:31:16 You are probably right. It's clearer than returnin
+ }
+ }
+
+ 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 std::string();
kthelgason 2016/11/03 09:39:05 perhaps replace this with a RTC_NOTREACHED() if we
magjed_webrtc 2016/11/03 12:31:16 If we handle some case, then we should not CHECK/N
+ }
+
+ char str[7];
+ snprintf(str, 7u, "%s%02x", profile_idc_iop_string, profile_level_id.level);
+ return str;
+}
+
} // namespace H264
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698