Index: media/base/video_codecs.cc |
diff --git a/media/base/video_codecs.cc b/media/base/video_codecs.cc |
index eb7daa2c21be0f2127073ebab00f74b28c7ee2e9..027bfd9218e7eb2f9e113101f4fbffbcb174aaed 100644 |
--- a/media/base/video_codecs.cc |
+++ b/media/base/video_codecs.cc |
@@ -86,21 +86,28 @@ std::string GetProfileName(VideoCodecProfile profile) { |
bool ParseNewStyleVp9CodecID(const std::string& codec_id, |
VideoCodecProfile* profile, |
- uint8_t* level_idc) { |
+ uint8_t* level_idc, |
+ gfx::ColorSpace::TransferID* eotf) { |
+ LOG(ERROR) << __func__ << " 0"; |
servolk
2017/03/02 18:56:36
Nit: don't forget to remove this debug logging.
chcunningham
2017/03/02 23:13:08
Acknowledged.
|
+ |
+ // Initialize optional fields to their defaults. |
+ *eotf = gfx::ColorSpace::TransferID::BT709; |
+ |
std::vector<std::string> fields = base::SplitString( |
codec_id, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
- // TODO(kqyang): The spec specifies 8 fields. We do not allow missing or extra |
- // fields. See crbug.com/667834. |
- if (fields.size() != 8) |
+ // First four fields are mandatory. No more than 9 fields are expected. |
+ if (fields.size() < 4 || fields.size() > 9) |
return false; |
if (fields[0] != "vp09") |
return false; |
+ LOG(ERROR) << __func__ << " 1"; |
+ |
std::vector<int> values; |
for (size_t i = 1; i < fields.size(); ++i) { |
- // Missing value is not allowed. |
+ // Missing value is not allowed. ------------------------------------------ is still this right? |
if (fields[i] == "") |
return false; |
int value; |
@@ -111,6 +118,7 @@ bool ParseNewStyleVp9CodecID(const std::string& codec_id, |
values.push_back(value); |
} |
+ LOG(ERROR) << __func__ << " 2"; |
const int profile_idc = values[0]; |
switch (profile_idc) { |
case 0: |
@@ -129,6 +137,7 @@ bool ParseNewStyleVp9CodecID(const std::string& codec_id, |
return false; |
} |
+ LOG(ERROR) << __func__ << " 3"; |
*level_idc = values[1]; |
// TODO(kqyang): Check if |level_idc| is valid. See crbug.com/667834. |
@@ -136,22 +145,62 @@ bool ParseNewStyleVp9CodecID(const std::string& codec_id, |
if (bit_depth != 8 && bit_depth != 10 && bit_depth != 12) |
return false; |
+ if (values.size() < 4) |
+ return true; |
+ LOG(ERROR) << __func__ << " 4"; |
const int color_space = values[3]; |
- if (color_space > 7) |
+ if (color_space > 9) |
return false; |
- const int chroma_subsampling = values[4]; |
- if (chroma_subsampling > 3) |
- return false; |
+ LOG(ERROR) << __func__ << " 5"; |
+ if (values.size() < 5) |
+ return true; |
+ const int transfer_function = values[4]; |
+ switch (transfer_function) { |
+ case 0: |
servolk
2017/03/02 18:56:36
Are those values taken from https://docs.google.co
chcunningham
2017/03/02 23:13:08
Right, these values are taken from a draft which i
|
+ // "0" bucket denotes one of: |
+ // Rec. ITU-R BT.709-6 |
+ // Rec. ITU-R BT.601-7 525 or 625 |
+ // Rec. ITU-R BT.2020. |
+ // These are all non-HDR, so just grab 709 since they're all treated |
+ // the same from a capabilities standpoint. |
+ *eotf = gfx::ColorSpace::TransferID::BT709; |
+ break; |
+ case 1: |
+ *eotf = gfx::ColorSpace::TransferID::SMPTEST2084; |
+ break; |
+ case 2: |
+ *eotf = gfx::ColorSpace::TransferID::ARIB_STD_B67; // AKA "HLG" |
+ break; |
+ default: |
+ *eotf = gfx::ColorSpace::TransferID::INVALID; |
+ DVLOG(4) << __func__ << ": invalid transfer function id (" |
+ << transfer_function << ")"; |
+ return false; |
+ } |
- const int transfer_function = values[5]; |
- if (transfer_function > 1) |
+ LOG(ERROR) << __func__ << " 6"; |
+ if (values.size() < 6) |
+ return true; |
+ const int matrix_coefficients = values[5]; |
+ if (matrix_coefficients < 0) |
return false; |
+ LOG(ERROR) << __func__ << " 7"; |
+ if (values.size() < 7) |
+ return true; |
const int video_full_range_flag = values[6]; |
- if (video_full_range_flag > 1) |
+ if (video_full_range_flag < 0 || video_full_range_flag > 1) |
return false; |
+ LOG(ERROR) << __func__ << " 8"; |
+ if (values.size() < 8) |
+ return true; |
+ const int chroma_subsampling = values[7]; |
+ if (chroma_subsampling < 0 || chroma_subsampling > 3) |
+ return false; |
+ |
+ LOG(ERROR) << __func__ << " 9"; |
return true; |
} |
@@ -424,11 +473,14 @@ VideoCodec StringToVideoCodec(const std::string& codec_id) { |
codec_id, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
if (elem.empty()) |
return kUnknownVideoCodec; |
+ |
VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
uint8_t level = 0; |
+ gfx::ColorSpace::TransferID eotf = gfx::ColorSpace::TransferID::INVALID; |
+ |
if (codec_id == "vp8" || codec_id == "vp8.0") |
return kCodecVP8; |
- if (ParseNewStyleVp9CodecID(codec_id, &profile, &level) || |
+ if (ParseNewStyleVp9CodecID(codec_id, &profile, &level, &eotf) || |
ParseLegacyVp9CodecID(codec_id, &profile, &level)) { |
return kCodecVP9; |
} |