From 53287e5fe78ee29c02d900bed4af1ecd71fd11d6 Mon Sep 17 00:00:00 2001 From: Kongqun Yang Date: Thu, 24 Apr 2014 12:29:53 -0700 Subject: [PATCH] Add m2ts and audio tests in packager_test Change-Id: I11cc65a2baa69bc5e3bc022027bca6712f810f1a --- media/formats/mp4/fragmenter.cc | 2 +- media/test/packager_test.cc | 48 +++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/media/formats/mp4/fragmenter.cc b/media/formats/mp4/fragmenter.cc index 72cd559d65..c659d9686b 100644 --- a/media/formats/mp4/fragmenter.cc +++ b/media/formats/mp4/fragmenter.cc @@ -116,7 +116,7 @@ Status Fragmenter::AddSample(scoped_refptr sample) { } else { // Can we safely assume the first sample in the media has the earliest // presentation timestamp? - DCHECK_GT(pts, presentation_start_time_); + DCHECK_GE(pts, presentation_start_time_); pts -= presentation_start_time_; } } diff --git a/media/test/packager_test.cc b/media/test/packager_test.cc index 5b4fa0c055..693e77b5b6 100644 --- a/media/test/packager_test.cc +++ b/media/test/packager_test.cc @@ -23,7 +23,8 @@ using ::testing::ValuesIn; namespace media { namespace { -const char* kMediaFiles[] = {"bear-1280x720.mp4", "bear-1280x720-av_frag.mp4"}; +const char* kMediaFiles[] = {"bear-1280x720.mp4", "bear-1280x720-av_frag.mp4", + "bear-1280x720.ts"}; // Muxer options. const double kSegmentDurationInSeconds = 1.0; @@ -131,6 +132,10 @@ MuxerOptions PackagerTestBasic::SetupOptions(const std::string& output, options.fragment_duration = kFragmentDurationInSecodns; options.segment_sap_aligned = kSegmentSapAligned; options.fragment_sap_aligned = kFragmentSapAligned; + // The mp4 muxer does not generate EditList, so the starting timestamp in the + // source is not carried over. Normalize the PTS so a second parse of the + // muxed output generates the same output. + options.normalize_presentation_timestamp = true; options.num_subsegments_per_sidx = kNumSubsegmentsPerSidx; options.output_file_name = GetFullPath(output); @@ -190,7 +195,7 @@ void PackagerTestBasic::Remux(const std::string& input, ASSERT_OK(demuxer.Run()); } -TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentUnencrypted) { +TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentUnencryptedVideo) { ASSERT_NO_FATAL_FAILURE(Remux(GetParam(), kOutputVideo, kOutputNone, @@ -198,7 +203,15 @@ TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentUnencrypted) { kDisableEncryption)); } -TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentEncrypted) { +TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentUnencryptedAudio) { + ASSERT_NO_FATAL_FAILURE(Remux(GetParam(), + kOutputNone, + kOutputAudio, + kSingleSegment, + kDisableEncryption)); +} + +TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentEncryptedVideo) { ASSERT_NO_FATAL_FAILURE(Remux(GetParam(), kOutputVideo, kOutputNone, @@ -212,6 +225,20 @@ TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentEncrypted) { EXPECT_TRUE(demuxer.streams()[0]->info()->is_encrypted()); } +TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentEncryptedAudio) { + ASSERT_NO_FATAL_FAILURE(Remux(GetParam(), + kOutputNone, + kOutputAudio, + kSingleSegment, + kEnableEncryption)); + + // Expect the output to be encrypted. + Demuxer demuxer(GetFullPath(kOutputAudio), decryptor_source_); + ASSERT_OK(demuxer.Initialize()); + ASSERT_EQ(1u, demuxer.streams().size()); + EXPECT_TRUE(demuxer.streams()[0]->info()->is_encrypted()); +} + class PackagerTest : public PackagerTestBasic { public: virtual void SetUp() OVERRIDE { @@ -231,7 +258,7 @@ class PackagerTest : public PackagerTestBasic { } }; -TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedAgain) { +TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedVideoAgain) { // Take the muxer output and feed into muxer again. The new muxer output // should contain the same contents as the previous muxer output. ASSERT_NO_FATAL_FAILURE(Remux(kOutputVideo, @@ -242,6 +269,17 @@ TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedAgain) { EXPECT_TRUE(ContentsEqual(kOutputVideo, kOutputVideo2)); } +TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedAudioAgain) { + // Take the muxer output and feed into muxer again. The new muxer output + // should contain the same contents as the previous muxer output. + ASSERT_NO_FATAL_FAILURE(Remux(kOutputAudio, + kOutputNone, + kOutputAudio2, + kSingleSegment, + kDisableEncryption)); + EXPECT_TRUE(ContentsEqual(kOutputAudio, kOutputAudio2)); +} + TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedSeparateAudioVideo) { ASSERT_NO_FATAL_FAILURE(Remux(GetParam(), kOutputVideo2, @@ -254,7 +292,7 @@ TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedSeparateAudioVideo) { EXPECT_TRUE(ContentsEqual(kOutputAudio, kOutputAudio2)); } -TEST_P(PackagerTest, MP4MuxerMultiSegmentsUnencrypted) { +TEST_P(PackagerTest, MP4MuxerMultiSegmentsUnencryptedVideo) { ASSERT_NO_FATAL_FAILURE(Remux(GetParam(), kOutputVideo2, kOutputNone,