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

Unified Diff: media/base/video_codecs.cc

Issue 2640113004: Introduce Dolby Vision video codec and Demuxer support (Closed)
Patch Set: fix CQ failure Created 3 years, 10 months 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: media/base/video_codecs.cc
diff --git a/media/base/video_codecs.cc b/media/base/video_codecs.cc
index eb7daa2c21be0f2127073ebab00f74b28c7ee2e9..94d8f57d38bb5afccf8a1b82eaa4b1117f5dd0ae 100644
--- a/media/base/video_codecs.cc
+++ b/media/base/video_codecs.cc
@@ -20,6 +20,8 @@ std::string GetCodecName(VideoCodec codec) {
return "h264";
case kCodecHEVC:
return "hevc";
+ case kCodecDolbyVision:
+ return "dolbyvision";
case kCodecVC1:
return "vc1";
case kCodecMPEG2:
@@ -79,6 +81,14 @@ std::string GetProfileName(VideoCodecProfile profile) {
return "vp9 profile2";
case VP9PROFILE_PROFILE3:
return "vp9 profile3";
+ case DOLBYVISION_PROFILE0:
+ return "dolby vision profile 0";
+ case DOLBYVISION_PROFILE4:
+ return "dolby vision profile 4";
+ case DOLBYVISION_PROFILE5:
+ return "dolby vision profile 5";
+ case DOLBYVISION_PROFILE7:
+ return "dolby vision profile 7";
}
NOTREACHED();
return "";
@@ -419,6 +429,81 @@ bool ParseHEVCCodecId(const std::string& codec_id,
}
#endif
+#if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING)
+// The specification for Dolby Vision codec id strings can be found in Dolby
+// Vision streams within the MPEG-DASH format.
+bool ParseDolbyVisionCodecId(const std::string& codec_id,
+ VideoCodecProfile* profile,
+ uint8_t* level_idc) {
+ if (!base::StartsWith(codec_id, "dvh1.", base::CompareCase::SENSITIVE) &&
+ !base::StartsWith(codec_id, "dvhe.", base::CompareCase::SENSITIVE) &&
+ !base::StartsWith(codec_id, "dva1.", base::CompareCase::SENSITIVE) &&
+ !base::StartsWith(codec_id, "dvav.", base::CompareCase::SENSITIVE)) {
+ return false;
+ }
+
+ const int kMaxDvCodecIdLength = 5 // FOURCC string
+ + 1 // delimiting period
+ + 2 // profile id as 2 digit string
+ + 1 // delimiting period
+ + 2; // level id as 2 digit string.
+
+ if (codec_id.size() > kMaxDvCodecIdLength) {
+ DVLOG(4) << __func__ << ": Codec id is too long (" << codec_id << ")";
+ return false;
+ }
+
+ std::vector<std::string> elem = base::SplitString(
+ codec_id, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ DCHECK(elem[0] == "dvh1" || elem[0] == "dvhe" || elem[0] == "dva1" ||
+ elem[0] == "dvav");
+
+ if (elem.size() != 3) {
+ DVLOG(4) << __func__ << ": invalid dolby vision codec id " << codec_id;
+ return false;
+ }
+
+ unsigned profile_id = 0;
+ if (!base::StringToUint(elem[1], &profile_id) || profile_id > 7) {
+ DVLOG(4) << __func__ << ": invalid profile_id=" << elem[1];
+ return false;
+ }
+
+ // Only profiles 0, 4, 5 and 7 are valid. Profile 0 is encoded based on AVC
+ // while profile 4, 5 and 7 are based on HEVC.
+ switch (profile_id) {
+ case 0:
+ *profile = DOLBYVISION_PROFILE0;
+ break;
+#if BUILDFLAG(ENABLE_HEVC_DEMUXING)
+ case 4:
+ *profile = DOLBYVISION_PROFILE4;
+ break;
+ case 5:
+ *profile = DOLBYVISION_PROFILE5;
+ break;
+ case 7:
+ *profile = DOLBYVISION_PROFILE7;
+ break;
+#endif
+ default:
+ DVLOG(4) << __func__
+ << ": depecrated and not supported profile_id=" << profile_id;
+ return false;
+ }
+
+ unsigned level_id = 0;
+ if (!base::StringToUint(elem[2], &level_id) || level_id > 9 || level_id < 1) {
+ DVLOG(4) << __func__ << ": invalid level_id=" << elem[2];
+ return false;
+ }
+
+ *level_idc = level_id;
+
+ return true;
+}
+#endif
+
VideoCodec StringToVideoCodec(const std::string& codec_id) {
std::vector<std::string> elem = base::SplitString(
codec_id, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
@@ -444,6 +529,10 @@ VideoCodec StringToVideoCodec(const std::string& codec_id) {
if (ParseHEVCCodecId(codec_id, &profile, &level))
return kCodecHEVC;
#endif
+#if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING)
+ if (ParseDolbyVisionCodecId(codec_id, &profile, &level))
+ return kCodecDolbyVision;
+#endif
return kUnknownVideoCodec;
}

Powered by Google App Engine
This is Rietveld 408576698