Commit dbcd1486 authored by Dale Curtis's avatar Dale Curtis Committed by Commit Bot

Fix HDR VP9 in MP4 parsing. Add unit tests.

Finally got around to generating test media for this issue... and
it looks like the original fix was incomplete! We didn't read the
full box header before parsing CoLL and SmDm atoms.

R=cassew

Fixed: 1123430
Test: Updated unittest.
Change-Id: I7aca462f623cd12cb4842c2cfa1b0b9758ba2ab5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518898
Commit-Queue: Will Cassella <cassew@google.com>
Reviewed-by: default avatarWill Cassella <cassew@google.com>
Auto-Submit: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824595}
parent 693cea5c
......@@ -1003,6 +1003,8 @@ bool SMPTE2086MasteringDisplayMetadataBox::Parse(BoxReader* reader) {
constexpr float kLuminanceMaxUnit = 1 << 8;
constexpr float kLuminanceMinUnit = 1 << 14;
RCHECK(reader->ReadFullBoxHeader());
// Technically the color coordinates may be in any order. The spec recommends
// RGB and it is assumed that the color coordinates are in such order.
RCHECK(
......@@ -1034,6 +1036,11 @@ bool ContentLightLevelInformation::Parse(BoxReader* reader) {
reader->Read2(&max_pic_average_light_level);
}
bool ContentLightLevel::Parse(BoxReader* reader) {
RCHECK(reader->ReadFullBoxHeader());
return ContentLightLevelInformation::Parse(reader);
}
FourCC ContentLightLevel::BoxType() const {
return FOURCC_COLL;
}
......
......@@ -310,6 +310,7 @@ struct MEDIA_EXPORT ContentLightLevelInformation : Box {
// Same as ContentLightLevelInformation, but with a different fourcc.
struct MEDIA_EXPORT ContentLightLevel : ContentLightLevelInformation {
bool Parse(BoxReader* reader) override;
FourCC BoxType() const override;
};
......
......@@ -712,8 +712,29 @@ TEST_F(MP4StreamParserTest, Vp9) {
VideoColorSpace::MatrixID::BT2020_NCL,
gfx::ColorSpace::RangeID::LIMITED));
// TODO(crbug.com/1123430): We need a test file that actually has HDR metadata
// to test the SmDm and CoLL parsing.
ASSERT_TRUE(video_decoder_config_.hdr_metadata().has_value());
const auto& hdr_metadata = *video_decoder_config_.hdr_metadata();
EXPECT_EQ(hdr_metadata.max_content_light_level, 1000u);
EXPECT_EQ(hdr_metadata.max_frame_average_light_level, 640u);
const auto& mastering_metadata = hdr_metadata.mastering_metadata;
constexpr float kColorCoordinateUnit = 1 / 16.0f;
EXPECT_NEAR(mastering_metadata.primary_r.x(), 0.68, kColorCoordinateUnit);
EXPECT_NEAR(mastering_metadata.primary_r.y(), 0.31998, kColorCoordinateUnit);
EXPECT_NEAR(mastering_metadata.primary_g.x(), 0.26496, kColorCoordinateUnit);
EXPECT_NEAR(mastering_metadata.primary_g.y(), 0.68998, kColorCoordinateUnit);
EXPECT_NEAR(mastering_metadata.primary_b.x(), 0.15, kColorCoordinateUnit);
EXPECT_NEAR(mastering_metadata.primary_b.y(), 0.05998, kColorCoordinateUnit);
EXPECT_NEAR(mastering_metadata.white_point.x(), 0.314, kColorCoordinateUnit);
EXPECT_NEAR(mastering_metadata.white_point.y(), 0.351, kColorCoordinateUnit);
constexpr float kLuminanceMaxUnit = 1 / 8.0f;
EXPECT_NEAR(mastering_metadata.luminance_max, 1000.0f, kLuminanceMaxUnit);
constexpr float kLuminanceMinUnit = 1 / 14.0;
EXPECT_NEAR(mastering_metadata.luminance_min, 0.01f, kLuminanceMinUnit);
}
TEST_F(MP4StreamParserTest, FourCCToString) {
......
......@@ -289,7 +289,14 @@ VP9 encoded video with profile 2 (10-bit, 4:2:0).
Codec string: vp09.02.10.10.01.02.02.02.00.
#### vp9-hdr-init-segment.mp4
Init segment for a VP9.2 HDR in MP4 file; from https://crbug.com/1102200#c6
Init segment for a VP9.2 HDR in MP4 file; from https://crbug.com/1102200#c6. The
SmDm and CoLL boxes have been added using mp4edit:
mp4edit.exe --insert moov/trak/mdia/minf/stbl/stsd/vp09:smdm.bin \
--insert moov/trak/mdia/minf/stbl/stsd/vp09:coll.bin \
vp9-hdr-init-segment.mp4 fixed.mp4
smdm.bin and coll.bin generated with program from https://crbug.com/1123430#c5.
### AAC test data from MPEG-DASH demoplayer (44100 Hz, stereo)
Duration of each packet is (1024/44100 Hz), approximately 23.22 ms.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment