Set codec string for webm contents correctly

The new codec strings may not be accepted by old versions of browsers.

Change-Id: Ic1bdde80f204f56674fca1f959a3897146953bcf
This commit is contained in:
KongQun Yang 2016-01-11 13:36:44 -08:00
parent 2909a53568
commit b4e9b5ac2b
2 changed files with 80 additions and 1 deletions

View File

@ -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<xmlNode> 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<xmlNode> 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<xmlNode> node_xml(representation->GetXml());
EXPECT_NO_FATAL_FAILURE(
ExpectAttributeEqString("codecs", "vp9", node_xml.get()));
}
// Make sure RepresentationStateChangeListener::OnNewSegmentForRepresentation()
// is called.
TEST_F(CommonMpdBuilderTest,

View File

@ -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();