From 895ff3220270044b7520e3653144d231a695f90a Mon Sep 17 00:00:00 2001 From: Rintaro Kuroiwa Date: Fri, 28 Feb 2014 14:34:26 -0800 Subject: [PATCH] MPD unit test for encrypted audio Change-Id: Ib36191803ab9614dffe6221297d4e86243e53fe5 --- mpd/base/mpd_builder_unittest.cc | 63 +++++++++++++------ mpd/test/data/encrypted_audio_media_info.txt | 23 +++++++ ...ypted_audio_media_info_expected_output.txt | 15 +++++ mpd/test/mpd_builder_test_helper.cc | 1 + mpd/test/mpd_builder_test_helper.h | 4 ++ mpd/util/mpd_writer_unittest.cc | 26 ++++++-- 6 files changed, 110 insertions(+), 22 deletions(-) create mode 100644 mpd/test/data/encrypted_audio_media_info.txt create mode 100644 mpd/test/data/encrypted_audio_media_info_expected_output.txt diff --git a/mpd/base/mpd_builder_unittest.cc b/mpd/base/mpd_builder_unittest.cc index 6c15653fa5..dabd0837e1 100644 --- a/mpd/base/mpd_builder_unittest.cc +++ b/mpd/base/mpd_builder_unittest.cc @@ -12,37 +12,51 @@ namespace dash_packager { -TEST(MpdBuilderTest, VOD_Video) { - MpdBuilder mpd(MpdBuilder::kStatic); +class StaticMpdBuilderTest : public ::testing::Test { + public: + StaticMpdBuilderTest() : mpd_(MpdBuilder::kStatic) {} + ~StaticMpdBuilderTest() {} + + void CheckMpd(const std::string& expected_output_file) { + std::string mpd_doc; + ASSERT_TRUE(mpd_.ToString(&mpd_doc)); + ASSERT_TRUE(ValidateMpdSchema(mpd_doc)); + + ASSERT_NO_FATAL_FAILURE( + ExpectMpdToEqualExpectedOutputFile(mpd_doc, expected_output_file)); + } + + protected: + MpdBuilder mpd_; + + private: + DISALLOW_COPY_AND_ASSIGN(StaticMpdBuilderTest); +}; + +TEST_F(StaticMpdBuilderTest, Video) { MediaInfo video_media_info = GetTestMediaInfo(kFileNameVideoMediaInfo1); - AdaptationSet* video_adaptation_set = mpd.AddAdaptationSet(); + AdaptationSet* video_adaptation_set = mpd_.AddAdaptationSet(); ASSERT_TRUE(video_adaptation_set); Representation* video_representation = video_adaptation_set->AddRepresentation(video_media_info); ASSERT_TRUE(video_adaptation_set); - std::string mpd_doc; - ASSERT_TRUE(mpd.ToString(&mpd_doc)); - ASSERT_TRUE(ValidateMpdSchema(mpd_doc)); - - EXPECT_NO_FATAL_FAILURE(ExpectMpdToEqualExpectedOutputFile( - mpd_doc, kFileNameExpectedMpdOutputVideo1)); + EXPECT_NO_FATAL_FAILURE(CheckMpd(kFileNameExpectedMpdOutputVideo1)); } -TEST(MpdBuilderTest, VOD_VideoAndAudio) { - MpdBuilder mpd(MpdBuilder::kStatic); +TEST_F(StaticMpdBuilderTest, VideoAndAudio) { MediaInfo video_media_info = GetTestMediaInfo(kFileNameVideoMediaInfo1); MediaInfo audio_media_info = GetTestMediaInfo(kFileNameAudioMediaInfo1); // The order matters here to check against expected output. // TODO(rkuroiwa): Investigate if I can deal with IDs and order elements // deterministically. - AdaptationSet* video_adaptation_set = mpd.AddAdaptationSet(); + AdaptationSet* video_adaptation_set = mpd_.AddAdaptationSet(); ASSERT_TRUE(video_adaptation_set); - AdaptationSet* audio_adaptation_set = mpd.AddAdaptationSet(); + AdaptationSet* audio_adaptation_set = mpd_.AddAdaptationSet(); ASSERT_TRUE(audio_adaptation_set); Representation* audio_representation = @@ -53,12 +67,25 @@ TEST(MpdBuilderTest, VOD_VideoAndAudio) { video_adaptation_set->AddRepresentation(video_media_info); ASSERT_TRUE(video_adaptation_set); - std::string mpd_doc; - ASSERT_TRUE(mpd.ToString(&mpd_doc)); - ASSERT_TRUE(ValidateMpdSchema(mpd_doc)); + EXPECT_NO_FATAL_FAILURE(CheckMpd(kFileNameExpectedMpdOutputAudio1AndVideo1)); +} - EXPECT_NO_FATAL_FAILURE(ExpectMpdToEqualExpectedOutputFile( - mpd_doc, kFileNameExpectedMpdOutputAudio1AndVideo1)); +// MPD schema has strict ordering. AudioChannelConfiguration must appear before +// ContentProtection. +// TODO(rkuroiwa): Enable this when implemented. +TEST_F(StaticMpdBuilderTest, + DISABLED_AudioChannelConfigurationWithContentProtection) { + MediaInfo encrypted_audio_media_info = + GetTestMediaInfo(kFileNameEncytpedAudioMediaInfo); + + AdaptationSet* audio_adaptation_set = mpd_.AddAdaptationSet(); + ASSERT_TRUE(audio_adaptation_set); + + Representation* audio_representation = + audio_adaptation_set->AddRepresentation(encrypted_audio_media_info); + ASSERT_TRUE(audio_representation); + + EXPECT_NO_FATAL_FAILURE(CheckMpd(kFileNameExpectedMpdOutputEncryptedAudio)); } } // namespace dash_packager diff --git a/mpd/test/data/encrypted_audio_media_info.txt b/mpd/test/data/encrypted_audio_media_info.txt new file mode 100644 index 0000000000..f0de4ddd89 --- /dev/null +++ b/mpd/test/data/encrypted_audio_media_info.txt @@ -0,0 +1,23 @@ +bandwidth: 195857 +audio_info { + codec: "mp4a.40.2" + sampling_frequency: 44100 + time_scale: 44100 + num_channels: 2 + decoder_config: "\022\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000" +} +content_protections { + scheme_id_uri: "http://foo.com/" +} +init_range { + begin: 0 + end: 863 +} +index_range { + begin: 864 + end: 931 +} +media_file_name: "encrypted_audio.mp4" +media_duration_seconds: 24.009434 +reference_time_scale: 44100 +container_type: CONTAINER_MP4 diff --git a/mpd/test/data/encrypted_audio_media_info_expected_output.txt b/mpd/test/data/encrypted_audio_media_info_expected_output.txt new file mode 100644 index 0000000000..1e2bcba7d0 --- /dev/null +++ b/mpd/test/data/encrypted_audio_media_info_expected_output.txt @@ -0,0 +1,15 @@ + + + + + + + + encrypted_audio.mp4 + + + + + + + diff --git a/mpd/test/mpd_builder_test_helper.cc b/mpd/test/mpd_builder_test_helper.cc index aeeda5ff64..0f5e39b364 100644 --- a/mpd/test/mpd_builder_test_helper.cc +++ b/mpd/test/mpd_builder_test_helper.cc @@ -9,6 +9,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "mpd/base/media_info.pb.h" +#include "mpd/base/mpd_builder.h" #include "mpd/base/xml/scoped_xml_ptr.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/protobuf/src/google/protobuf/text_format.h" diff --git a/mpd/test/mpd_builder_test_helper.h b/mpd/test/mpd_builder_test_helper.h index 9d211414f2..46338586f2 100644 --- a/mpd/test/mpd_builder_test_helper.h +++ b/mpd/test/mpd_builder_test_helper.h @@ -21,6 +21,7 @@ class MediaInfo; const char kFileNameVideoMediaInfo1[] = "video_media_info1.txt"; const char kFileNameVideoMediaInfo2[] = "video_media_info2.txt"; const char kFileNameAudioMediaInfo1[] = "audio_media_info1.txt"; +const char kFileNameEncytpedAudioMediaInfo[] = "encrypted_audio_media_info.txt"; // These are the expected output files. const char kFileNameExpectedMpdOutputVideo1[] = @@ -35,6 +36,9 @@ const char kFileNameExpectedMpdOutputAudio1[] = const char kFileNameExpectedMpdOutputAudio1AndVideo1[] = "audio_media_info1_video_media_info1_expected_mpd_output.txt"; +const char kFileNameExpectedMpdOutputEncryptedAudio[] = + "encrypted_audio_media_info_expected_output.txt"; + // Returns the path to test data with |file_name|. Use constants above to get // path to the test files. base::FilePath GetTestDataFilePath(const std::string& file_name); diff --git a/mpd/util/mpd_writer_unittest.cc b/mpd/util/mpd_writer_unittest.cc index 418ebfa13b..2560b34343 100644 --- a/mpd/util/mpd_writer_unittest.cc +++ b/mpd/util/mpd_writer_unittest.cc @@ -12,7 +12,9 @@ namespace dash_packager { -TEST(MpdWriterTest, ReadMediaInfoFile_VideoMediaInfo) { +// Note that these tests look very similar to MpdBuilder tests but these can +// only handle MediaInfos with 1 stream in each file. +TEST(MpdWriterTest, VideoMediaInfo) { MpdWriter mpd_writer; base::FilePath media_info_file = GetTestDataFilePath(kFileNameVideoMediaInfo1); @@ -26,7 +28,7 @@ TEST(MpdWriterTest, ReadMediaInfoFile_VideoMediaInfo) { kFileNameExpectedMpdOutputVideo1)); } -TEST(MpdWriterTest, ReadMediaInfoFile_TwoVideoMediaInfo) { +TEST(MpdWriterTest, TwoVideoMediaInfo) { MpdWriter mpd_writer; base::FilePath media_info_file1 = GetTestDataFilePath(kFileNameVideoMediaInfo1); @@ -45,7 +47,7 @@ TEST(MpdWriterTest, ReadMediaInfoFile_TwoVideoMediaInfo) { kFileNameExpectedMpdOutputVideo1And2)); } -TEST(MpdWriterTest, ReadMediaInfoFile_AudioMediaInfo) { +TEST(MpdWriterTest, AudioMediaInfo) { MpdWriter mpd_writer; base::FilePath media_info_file = GetTestDataFilePath(kFileNameAudioMediaInfo1); @@ -59,7 +61,7 @@ TEST(MpdWriterTest, ReadMediaInfoFile_AudioMediaInfo) { kFileNameExpectedMpdOutputAudio1)); } -TEST(MpdWriterTest, ReadMediaInfoFile_VideoAudioMediaInfo) { +TEST(MpdWriterTest, VideoAudioMediaInfo) { MpdWriter mpd_writer; base::FilePath audio_media_info = GetTestDataFilePath(kFileNameAudioMediaInfo1); @@ -78,4 +80,20 @@ TEST(MpdWriterTest, ReadMediaInfoFile_VideoAudioMediaInfo) { kFileNameExpectedMpdOutputAudio1AndVideo1)); } +// TODO(rkuroiwa): Enable this when implemented. +TEST(MpdWriterTest, DISABLED_EncryptedAudioMediaInfo) { + MpdWriter mpd_writer; + base::FilePath encrypted_audio_media_info = + GetTestDataFilePath(kFileNameEncytpedAudioMediaInfo); + + ASSERT_TRUE(mpd_writer.AddFile(encrypted_audio_media_info.value().c_str())); + + std::string generated_mpd; + ASSERT_TRUE(mpd_writer.WriteMpdToString(&generated_mpd)); + ASSERT_TRUE(ValidateMpdSchema(generated_mpd)); + + ASSERT_NO_FATAL_FAILURE(ExpectMpdToEqualExpectedOutputFile( + generated_mpd, kFileNameExpectedMpdOutputEncryptedAudio)); +} + } // namespace dash_packager