diff --git a/packager/mpd/base/mpd_builder.cc b/packager/mpd/base/mpd_builder.cc index b790b85c48..b5e809097b 100644 --- a/packager/mpd/base/mpd_builder.cc +++ b/packager/mpd/base/mpd_builder.cc @@ -538,6 +538,12 @@ Representation* AdaptationSet::AddRepresentation(const MediaInfo& media_info) { } } + if (media_info.has_video_info()) { + content_type_ = "video"; + } else if (media_info.has_audio_info()) { + content_type_ = "audio"; + } + representations_.push_back(representation.get()); return representation.release(); } @@ -570,6 +576,7 @@ xml::ScopedXmlPtr::type AdaptationSet::GetXml() { } adaptation_set.SetId(id_); + adaptation_set.SetStringAttribute("contentType", content_type_); if (!lang_.empty() && lang_ != "und") { adaptation_set.SetStringAttribute("lang", LanguageToShortestForm(lang_)); } diff --git a/packager/mpd/base/mpd_builder.h b/packager/mpd/base/mpd_builder.h index 81bc912d2b..110bf4f621 100644 --- a/packager/mpd/base/mpd_builder.h +++ b/packager/mpd/base/mpd_builder.h @@ -181,6 +181,12 @@ class AdaptationSet { private: friend class MpdBuilder; FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, CheckAdaptationSetId); + FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, + CheckAdaptationSetVideoContentType); + FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, + CheckAdaptationSetAudioContentType); + FRIEND_TEST_ALL_PREFIXES(CommonMpdBuilderTest, + CheckAdaptationSetTextContentType); /// @param adaptation_set_id is an ID number for this AdaptationSet. /// @param representation_counter is a Counter for assigning ID numbers to @@ -220,6 +226,10 @@ class AdaptationSet { // So, key == CalculatedValue(value) std::map video_frame_rates_; + // contentType attribute of AdaptationSet. + // Determined by examining the MediaInfo passed to AddRepresentation(). + std::string content_type_; + DISALLOW_COPY_AND_ASSIGN(AdaptationSet); }; diff --git a/packager/mpd/base/mpd_builder_unittest.cc b/packager/mpd/base/mpd_builder_unittest.cc index 525d4d997d..d70a1429bc 100644 --- a/packager/mpd/base/mpd_builder_unittest.cc +++ b/packager/mpd/base/mpd_builder_unittest.cc @@ -25,9 +25,10 @@ namespace edash_packager { using base::FilePath; namespace { -// Any number for RepresentationId. Required to create a Representation but -// not checked in test. +// Any number for {AdaptationSet,Representation} ID. Required to create +// either objects. Not checked in test. const uint32_t kAnyRepresentationId = 1; +const uint32_t kAnyAdaptationSetId = 1; const char kSElementTemplate[] = "\n"; const char kSElementTemplateWithoutR[] = @@ -135,7 +136,7 @@ class DynamicMpdBuilderTest : public MpdBuilderTest { std::string GetDefaultMediaInfo() { const char kMediaInfo[] = "video_info {\n" - " codec: \"avc1.010101\"\n" + " codec: 'avc1.010101'\n" " width: 720\n" " height: 480\n" " time_scale: 10\n" @@ -145,8 +146,8 @@ class DynamicMpdBuilderTest : public MpdBuilderTest { "}\n" "reference_time_scale: %u\n" "container_type: 1\n" - "init_segment_name: \"init.mp4\"\n" - "segment_template: \"$Time$.mp4\"\n"; + "init_segment_name: 'init.mp4'\n" + "segment_template: '$Time$.mp4'\n"; return base::StringPrintf(kMediaInfo, DefaultTimeScale()); } @@ -208,7 +209,7 @@ class SegmentTemplateTest : public DynamicMpdBuilderTest { "type=\"dynamic\" profiles=\"urn:mpeg:dash:profile:isoff-live:2011\">\n" " \n" " \n" + " frameRate=\"10/5\" contentType=\"video\">\n" " \n" @@ -258,7 +259,7 @@ class TimeShiftBufferDepthTest : public SegmentTemplateTest { // $Number$ for segment template. const char kMediaInfo[] = "video_info {\n" - " codec: \"avc1.010101\"\n" + " codec: 'avc1.010101'\n" " width: 720\n" " height: 480\n" " time_scale: 10\n" @@ -268,8 +269,8 @@ class TimeShiftBufferDepthTest : public SegmentTemplateTest { "}\n" "reference_time_scale: %u\n" "container_type: 1\n" - "init_segment_name: \"init.mp4\"\n" - "segment_template: \"$Number$.mp4\"\n"; + "init_segment_name: 'init.mp4'\n" + "segment_template: '$Number$.mp4'\n"; const std::string& number_template_media_info = base::StringPrintf(kMediaInfo, DefaultTimeScale()); @@ -291,7 +292,7 @@ class TimeShiftBufferDepthTest : public SegmentTemplateTest { "timeShiftBufferDepth=\"PT%dS\">\n" " \n" " \n" + " frameRate=\"10/2\" contentType=\"video\">\n" " \n" @@ -327,7 +328,7 @@ class TimeShiftBufferDepthTest : public SegmentTemplateTest { TEST_F(CommonMpdBuilderTest, ValidMediaInfo) { const char kTestMediaInfo[] = "video_info {\n" - " codec: \"avc1\"\n" + " codec: 'avc1'\n" " width: 720\n" " height: 480\n" " time_scale: 10\n" @@ -346,7 +347,7 @@ TEST_F(CommonMpdBuilderTest, InvalidMediaInfo) { // Missing width. const char kTestMediaInfo[] = "video_info {\n" - " codec: \"avc1\"\n" + " codec: 'avc1'\n" " height: 480\n" " time_scale: 10\n" " frame_duration: 10\n" @@ -363,7 +364,7 @@ TEST_F(CommonMpdBuilderTest, InvalidMediaInfo) { TEST_F(CommonMpdBuilderTest, CheckVideoInfoReflectedInXml) { const char kTestMediaInfo[] = "video_info {\n" - " codec: \"avc1\"\n" + " codec: 'avc1'\n" " width: 1280\n" " height: 720\n" " time_scale: 10\n" @@ -388,6 +389,76 @@ TEST_F(CommonMpdBuilderTest, CheckVideoInfoReflectedInXml) { ExpectAttributeEqString("frameRate", "10/10", node_xml.get())); } +// Verify that content type is set correctly if video info is present in +// MediaInfo. +TEST_F(CommonMpdBuilderTest, CheckAdaptationSetVideoContentType) { + base::AtomicSequenceNumber sequence_counter; + const char kVideoMediaInfo[] = + "video_info {\n" + " codec: 'avc1'\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"; + + AdaptationSet adaptation_set( + kAnyAdaptationSetId, "", MpdOptions(), &sequence_counter); + adaptation_set.AddRepresentation(ConvertToMediaInfo(kVideoMediaInfo)); + + xml::ScopedXmlPtr::type node_xml(adaptation_set.GetXml()); + EXPECT_NO_FATAL_FAILURE( + ExpectAttributeEqString("contentType", "video", node_xml.get())); +} + +// Verify that content type is set correctly if audio info is present in +// MediaInfo. +TEST_F(CommonMpdBuilderTest, CheckAdaptationSetAudioContentType) { + base::AtomicSequenceNumber sequence_counter; + const char kAudioMediaInfo[] = + "audio_info {\n" + " codec: 'mp4a.40.2'\n" + " sampling_frequency: 44100\n" + " time_scale: 1200\n" + " num_channels: 2\n" + "}\n" + "container_type: 1\n"; + + AdaptationSet adaptation_set( + kAnyAdaptationSetId, "", MpdOptions(), &sequence_counter); + adaptation_set.AddRepresentation(ConvertToMediaInfo(kAudioMediaInfo)); + + xml::ScopedXmlPtr::type node_xml(adaptation_set.GetXml()); + EXPECT_NO_FATAL_FAILURE( + ExpectAttributeEqString("contentType", "audio", node_xml.get())); +} + +// Verify that content type is set correctly if text info is present in +// MediaInfo. +// TODO(rkuroiwa): Enable this once text support is implemented. +// This fails because it fails to get the codec, therefore Representation +// creation fails. +TEST_F(CommonMpdBuilderTest, DISABLED_CheckAdaptationSetTextContentType) { + base::AtomicSequenceNumber sequence_counter; + const char kTextMediaInfo[] = + "text_info {\n" + " format: 'ttml'\n" + " language: 'en'\n" + "}\n" + "container_type: 1\n"; + + AdaptationSet adaptation_set( + kAnyAdaptationSetId, "", MpdOptions(), &sequence_counter); + adaptation_set.AddRepresentation(ConvertToMediaInfo(kTextMediaInfo)); + + xml::ScopedXmlPtr::type node_xml(adaptation_set.GetXml()); + EXPECT_NO_FATAL_FAILURE( + ExpectAttributeEqString("contentType", "text", node_xml.get())); +} + TEST_F(CommonMpdBuilderTest, CheckAdaptationSetId) { base::AtomicSequenceNumber sequence_counter; const uint32_t kAdaptationSetId = 42; diff --git a/packager/mpd/test/data/audio_media_info1_expected_mpd_output.txt b/packager/mpd/test/data/audio_media_info1_expected_mpd_output.txt index 197e6121bc..63b0f8903c 100644 --- a/packager/mpd/test/data/audio_media_info1_expected_mpd_output.txt +++ b/packager/mpd/test/data/audio_media_info1_expected_mpd_output.txt @@ -1,7 +1,7 @@ - + test_output_file_name_audio1.mp4 diff --git a/packager/mpd/test/data/audio_media_info1_video_media_info1_expected_mpd_output.txt b/packager/mpd/test/data/audio_media_info1_video_media_info1_expected_mpd_output.txt index d47680bd82..5ca173fe99 100644 --- a/packager/mpd/test/data/audio_media_info1_video_media_info1_expected_mpd_output.txt +++ b/packager/mpd/test/data/audio_media_info1_video_media_info1_expected_mpd_output.txt @@ -1,7 +1,7 @@ - + test_output_file_name1.mp4 @@ -9,7 +9,7 @@ - + test_output_file_name_audio1.mp4 diff --git a/packager/mpd/test/data/dynamic_normal_mpd.txt b/packager/mpd/test/data/dynamic_normal_mpd.txt index c369ede3a0..86fc4402c1 100644 --- a/packager/mpd/test/data/dynamic_normal_mpd.txt +++ b/packager/mpd/test/data/dynamic_normal_mpd.txt @@ -1,7 +1,7 @@ - + diff --git a/packager/mpd/test/data/encrypted_audio_media_info_expected_output.txt b/packager/mpd/test/data/encrypted_audio_media_info_expected_output.txt index 1e2bcba7d0..27990319da 100644 --- a/packager/mpd/test/data/encrypted_audio_media_info_expected_output.txt +++ b/packager/mpd/test/data/encrypted_audio_media_info_expected_output.txt @@ -1,7 +1,7 @@ - + diff --git a/packager/mpd/test/data/language_audio_media_info_expected_output.txt b/packager/mpd/test/data/language_audio_media_info_expected_output.txt index bcd7fc6b01..98c7be5a13 100644 --- a/packager/mpd/test/data/language_audio_media_info_expected_output.txt +++ b/packager/mpd/test/data/language_audio_media_info_expected_output.txt @@ -1,7 +1,7 @@ - + test_output_file_name1.mp4 @@ -9,7 +9,7 @@ - + test_output_file_name_audio_eng1.mp4 @@ -25,7 +25,7 @@ - + test_output_file_name_audio_ger1.mp4 diff --git a/packager/mpd/test/data/video_media_info1_expected_mpd_output.txt b/packager/mpd/test/data/video_media_info1_expected_mpd_output.txt index f6e69b444f..50239a3174 100644 --- a/packager/mpd/test/data/video_media_info1_expected_mpd_output.txt +++ b/packager/mpd/test/data/video_media_info1_expected_mpd_output.txt @@ -1,7 +1,7 @@ - + test_output_file_name1.mp4 diff --git a/packager/mpd/test/data/video_media_info1and2_expected_mpd_output.txt b/packager/mpd/test/data/video_media_info1and2_expected_mpd_output.txt index 8a9e9edee1..54f0e2b9f7 100644 --- a/packager/mpd/test/data/video_media_info1and2_expected_mpd_output.txt +++ b/packager/mpd/test/data/video_media_info1and2_expected_mpd_output.txt @@ -1,7 +1,7 @@ - + test_output_file_name1.mp4