From b4e9b5ac2b7b5e35ed6420b833c6cf201994c1eb Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Mon, 11 Jan 2016 13:36:44 -0800 Subject: [PATCH] Set codec string for webm contents correctly The new codec strings may not be accepted by old versions of browsers. Change-Id: Ic1bdde80f204f56674fca1f959a3897146953bcf --- packager/mpd/base/mpd_builder_unittest.cc | 67 +++++++++++++++++++++++ packager/mpd/base/mpd_utils.cc | 14 ++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/packager/mpd/base/mpd_builder_unittest.cc b/packager/mpd/base/mpd_builder_unittest.cc index 4932ea3c8a..fc36d6c9e4 100644 --- a/packager/mpd/base/mpd_builder_unittest.cc +++ b/packager/mpd/base/mpd_builder_unittest.cc @@ -501,6 +501,73 @@ TEST_F(CommonMpdBuilderTest, CheckVideoInfoReflectedInXml) { ExpectAttributeEqString("frameRate", "10/10", node_xml.get())); } +TEST_F(CommonMpdBuilderTest, CheckVideoInfoVp8CodecInMp4) { + const char kTestMediaInfoCodecVp8[] = + "video_info {\n" + " codec: 'vp08.00.00.08.01.01.00.00'\n" + " width: 1280\n" + " height: 720\n" + " time_scale: 10\n" + " frame_duration: 10\n" + " pixel_width: 1\n" + " pixel_height: 1\n" + "}\n" + "container_type: 1\n"; + auto representation = + CreateRepresentation(ConvertToMediaInfo(kTestMediaInfoCodecVp8), + MpdOptions(), kAnyRepresentationId, NoListener()); + EXPECT_TRUE(representation->Init()); + xml::scoped_xml_ptr node_xml(representation->GetXml()); + EXPECT_NO_FATAL_FAILURE( + ExpectAttributeEqString("codecs", "vp08.00.00.08.01.01.00.00", node_xml.get())); +} + +// Check that vp8 codec string will be updated for backward compatibility +// support in webm. +TEST_F(CommonMpdBuilderTest, CheckVideoInfoVp8CodecInWebm) { + const char kTestMediaInfoCodecVp8[] = + "video_info {\n" + " codec: 'vp08.00.00.08.01.01.00.00'\n" + " width: 1280\n" + " height: 720\n" + " time_scale: 10\n" + " frame_duration: 10\n" + " pixel_width: 1\n" + " pixel_height: 1\n" + "}\n" + "container_type: 3\n"; + auto representation = + CreateRepresentation(ConvertToMediaInfo(kTestMediaInfoCodecVp8), + MpdOptions(), kAnyRepresentationId, NoListener()); + EXPECT_TRUE(representation->Init()); + xml::scoped_xml_ptr node_xml(representation->GetXml()); + EXPECT_NO_FATAL_FAILURE( + ExpectAttributeEqString("codecs", "vp8", node_xml.get())); +} + +// Check that vp9 codec string will be updated for backward compatibility +// support in webm. +TEST_F(CommonMpdBuilderTest, CheckVideoInfoVp9CodecInWebm) { + const char kTestMediaInfoCodecVp9[] = + "video_info {\n" + " codec: 'vp09.00.00.08.01.01.00.00'\n" + " width: 1280\n" + " height: 720\n" + " time_scale: 10\n" + " frame_duration: 10\n" + " pixel_width: 1\n" + " pixel_height: 1\n" + "}\n" + "container_type: 3\n"; + auto representation = + CreateRepresentation(ConvertToMediaInfo(kTestMediaInfoCodecVp9), + MpdOptions(), kAnyRepresentationId, NoListener()); + EXPECT_TRUE(representation->Init()); + xml::scoped_xml_ptr node_xml(representation->GetXml()); + EXPECT_NO_FATAL_FAILURE( + ExpectAttributeEqString("codecs", "vp9", node_xml.get())); +} + // Make sure RepresentationStateChangeListener::OnNewSegmentForRepresentation() // is called. TEST_F(CommonMpdBuilderTest, diff --git a/packager/mpd/base/mpd_utils.cc b/packager/mpd/base/mpd_utils.cc index bc1049588c..2369969051 100644 --- a/packager/mpd/base/mpd_utils.cc +++ b/packager/mpd/base/mpd_utils.cc @@ -61,8 +61,20 @@ std::string GetCodecs(const MediaInfo& media_info) { CHECK(OnlyOneTrue(media_info.has_video_info(), media_info.has_audio_info(), media_info.has_text_info())); - if (media_info.has_video_info()) + if (media_info.has_video_info()) { + if (media_info.container_type() == MediaInfo::CONTAINER_WEBM) { + std::string codec = media_info.video_info().codec().substr(0, 4); + // media_info.video_info().codec() contains new revised codec string + // specified by "VPx in ISO BMFF" document, which is not compatible to + // old codec strings in WebM. Hack it here before all browsers support + // new codec strings. + if (codec == "vp08") + return "vp8"; + if (codec == "vp09") + return "vp9"; + } return media_info.video_info().codec(); + } if (media_info.has_audio_info()) return media_info.audio_info().codec();