MPD unit test for encrypted audio

Change-Id: Ib36191803ab9614dffe6221297d4e86243e53fe5
This commit is contained in:
Rintaro Kuroiwa 2014-02-28 14:34:26 -08:00
parent a470d52ee6
commit 895ff32202
6 changed files with 110 additions and 22 deletions

View File

@ -12,37 +12,51 @@
namespace dash_packager { namespace dash_packager {
TEST(MpdBuilderTest, VOD_Video) { class StaticMpdBuilderTest : public ::testing::Test {
MpdBuilder mpd(MpdBuilder::kStatic); 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); MediaInfo video_media_info = GetTestMediaInfo(kFileNameVideoMediaInfo1);
AdaptationSet* video_adaptation_set = mpd.AddAdaptationSet(); AdaptationSet* video_adaptation_set = mpd_.AddAdaptationSet();
ASSERT_TRUE(video_adaptation_set); ASSERT_TRUE(video_adaptation_set);
Representation* video_representation = Representation* video_representation =
video_adaptation_set->AddRepresentation(video_media_info); video_adaptation_set->AddRepresentation(video_media_info);
ASSERT_TRUE(video_adaptation_set); ASSERT_TRUE(video_adaptation_set);
std::string mpd_doc; EXPECT_NO_FATAL_FAILURE(CheckMpd(kFileNameExpectedMpdOutputVideo1));
ASSERT_TRUE(mpd.ToString(&mpd_doc));
ASSERT_TRUE(ValidateMpdSchema(mpd_doc));
EXPECT_NO_FATAL_FAILURE(ExpectMpdToEqualExpectedOutputFile(
mpd_doc, kFileNameExpectedMpdOutputVideo1));
} }
TEST(MpdBuilderTest, VOD_VideoAndAudio) { TEST_F(StaticMpdBuilderTest, VideoAndAudio) {
MpdBuilder mpd(MpdBuilder::kStatic);
MediaInfo video_media_info = GetTestMediaInfo(kFileNameVideoMediaInfo1); MediaInfo video_media_info = GetTestMediaInfo(kFileNameVideoMediaInfo1);
MediaInfo audio_media_info = GetTestMediaInfo(kFileNameAudioMediaInfo1); MediaInfo audio_media_info = GetTestMediaInfo(kFileNameAudioMediaInfo1);
// The order matters here to check against expected output. // The order matters here to check against expected output.
// TODO(rkuroiwa): Investigate if I can deal with IDs and order elements // TODO(rkuroiwa): Investigate if I can deal with IDs and order elements
// deterministically. // deterministically.
AdaptationSet* video_adaptation_set = mpd.AddAdaptationSet(); AdaptationSet* video_adaptation_set = mpd_.AddAdaptationSet();
ASSERT_TRUE(video_adaptation_set); ASSERT_TRUE(video_adaptation_set);
AdaptationSet* audio_adaptation_set = mpd.AddAdaptationSet(); AdaptationSet* audio_adaptation_set = mpd_.AddAdaptationSet();
ASSERT_TRUE(audio_adaptation_set); ASSERT_TRUE(audio_adaptation_set);
Representation* audio_representation = Representation* audio_representation =
@ -53,12 +67,25 @@ TEST(MpdBuilderTest, VOD_VideoAndAudio) {
video_adaptation_set->AddRepresentation(video_media_info); video_adaptation_set->AddRepresentation(video_media_info);
ASSERT_TRUE(video_adaptation_set); ASSERT_TRUE(video_adaptation_set);
std::string mpd_doc; EXPECT_NO_FATAL_FAILURE(CheckMpd(kFileNameExpectedMpdOutputAudio1AndVideo1));
ASSERT_TRUE(mpd.ToString(&mpd_doc)); }
ASSERT_TRUE(ValidateMpdSchema(mpd_doc));
EXPECT_NO_FATAL_FAILURE(ExpectMpdToEqualExpectedOutputFile( // MPD schema has strict ordering. AudioChannelConfiguration must appear before
mpd_doc, kFileNameExpectedMpdOutputAudio1AndVideo1)); // 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 } // namespace dash_packager

View File

@ -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

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns="urn:mpeg:DASH:schema:MPD:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 DASH-MPD.xsd" minBufferTime="PT2S" type="static" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" mediaPresentationDuration="PT24.00943374633789S">
<Period>
<AdaptationSet id="0">
<Representation id="0" bandwidth="195857" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<ContentProtection schemeIdUri="http://foo.com/"/>
<BaseURL>encrypted_audio.mp4</BaseURL>
<SegmentBase indexRange="864-931" timescale="44100">
<Initialization range="0-863"/>
</SegmentBase>
</Representation>
</AdaptationSet>
</Period>
</MPD>

View File

@ -9,6 +9,7 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "mpd/base/media_info.pb.h" #include "mpd/base/media_info.pb.h"
#include "mpd/base/mpd_builder.h"
#include "mpd/base/xml/scoped_xml_ptr.h" #include "mpd/base/xml/scoped_xml_ptr.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/protobuf/src/google/protobuf/text_format.h" #include "third_party/protobuf/src/google/protobuf/text_format.h"

View File

@ -21,6 +21,7 @@ class MediaInfo;
const char kFileNameVideoMediaInfo1[] = "video_media_info1.txt"; const char kFileNameVideoMediaInfo1[] = "video_media_info1.txt";
const char kFileNameVideoMediaInfo2[] = "video_media_info2.txt"; const char kFileNameVideoMediaInfo2[] = "video_media_info2.txt";
const char kFileNameAudioMediaInfo1[] = "audio_media_info1.txt"; const char kFileNameAudioMediaInfo1[] = "audio_media_info1.txt";
const char kFileNameEncytpedAudioMediaInfo[] = "encrypted_audio_media_info.txt";
// These are the expected output files. // These are the expected output files.
const char kFileNameExpectedMpdOutputVideo1[] = const char kFileNameExpectedMpdOutputVideo1[] =
@ -35,6 +36,9 @@ const char kFileNameExpectedMpdOutputAudio1[] =
const char kFileNameExpectedMpdOutputAudio1AndVideo1[] = const char kFileNameExpectedMpdOutputAudio1AndVideo1[] =
"audio_media_info1_video_media_info1_expected_mpd_output.txt"; "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 // Returns the path to test data with |file_name|. Use constants above to get
// path to the test files. // path to the test files.
base::FilePath GetTestDataFilePath(const std::string& file_name); base::FilePath GetTestDataFilePath(const std::string& file_name);

View File

@ -12,7 +12,9 @@
namespace dash_packager { 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; MpdWriter mpd_writer;
base::FilePath media_info_file = GetTestDataFilePath(kFileNameVideoMediaInfo1); base::FilePath media_info_file = GetTestDataFilePath(kFileNameVideoMediaInfo1);
@ -26,7 +28,7 @@ TEST(MpdWriterTest, ReadMediaInfoFile_VideoMediaInfo) {
kFileNameExpectedMpdOutputVideo1)); kFileNameExpectedMpdOutputVideo1));
} }
TEST(MpdWriterTest, ReadMediaInfoFile_TwoVideoMediaInfo) { TEST(MpdWriterTest, TwoVideoMediaInfo) {
MpdWriter mpd_writer; MpdWriter mpd_writer;
base::FilePath media_info_file1 = base::FilePath media_info_file1 =
GetTestDataFilePath(kFileNameVideoMediaInfo1); GetTestDataFilePath(kFileNameVideoMediaInfo1);
@ -45,7 +47,7 @@ TEST(MpdWriterTest, ReadMediaInfoFile_TwoVideoMediaInfo) {
kFileNameExpectedMpdOutputVideo1And2)); kFileNameExpectedMpdOutputVideo1And2));
} }
TEST(MpdWriterTest, ReadMediaInfoFile_AudioMediaInfo) { TEST(MpdWriterTest, AudioMediaInfo) {
MpdWriter mpd_writer; MpdWriter mpd_writer;
base::FilePath media_info_file = GetTestDataFilePath(kFileNameAudioMediaInfo1); base::FilePath media_info_file = GetTestDataFilePath(kFileNameAudioMediaInfo1);
@ -59,7 +61,7 @@ TEST(MpdWriterTest, ReadMediaInfoFile_AudioMediaInfo) {
kFileNameExpectedMpdOutputAudio1)); kFileNameExpectedMpdOutputAudio1));
} }
TEST(MpdWriterTest, ReadMediaInfoFile_VideoAudioMediaInfo) { TEST(MpdWriterTest, VideoAudioMediaInfo) {
MpdWriter mpd_writer; MpdWriter mpd_writer;
base::FilePath audio_media_info = base::FilePath audio_media_info =
GetTestDataFilePath(kFileNameAudioMediaInfo1); GetTestDataFilePath(kFileNameAudioMediaInfo1);
@ -78,4 +80,20 @@ TEST(MpdWriterTest, ReadMediaInfoFile_VideoAudioMediaInfo) {
kFileNameExpectedMpdOutputAudio1AndVideo1)); 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 } // namespace dash_packager