diff --git a/media/mp4/mp4_vod_segmenter.cc b/media/mp4/mp4_vod_segmenter.cc index de58078c6d..b09b4d42f6 100644 --- a/media/mp4/mp4_vod_segmenter.cc +++ b/media/mp4/mp4_vod_segmenter.cc @@ -35,13 +35,15 @@ Status MP4VODSegmenter::Initialize(EncryptorSource* encryptor_source, } Status MP4VODSegmenter::Finalize() { - DCHECK(temp_file_ != NULL && ftyp() != NULL && moov() != NULL && - vod_sidx_ != NULL); - Status status = MP4Segmenter::Finalize(); if (!status.ok()) return status; + DCHECK(temp_file_); + DCHECK(ftyp()); + DCHECK(moov()); + DCHECK(vod_sidx_); + // Close the temp file to prepare for reading later. if (!temp_file_.release()->Close()) { return Status(error::FILE_FAILURE, diff --git a/media/test/packager_test.cc b/media/test/packager_test.cc index 3d3c007fc8..ae4ab10db5 100644 --- a/media/test/packager_test.cc +++ b/media/test/packager_test.cc @@ -30,6 +30,7 @@ const char kOutputFileName2[] = "output_file2"; const char kSegmentTemplate[] = "template$Number$.m4s"; const char kSegmentTemplateOutputFile[] = "template1.m4s"; const char kTempFileName[] = "temp_file"; +const char kTempFileName2[] = "temp_file2"; // Encryption constants. const char kKeyIdHex[] = "e5007e6e9dcd5ac095202ed3758382cd"; @@ -82,11 +83,17 @@ class PackagerTest : public ::testing::TestWithParam { ASSERT_OK(muxer->AddStream(demuxer.streams()[0])); ASSERT_OK(muxer->Initialize()); - // Starts remuxing process. + // Start remuxing process. ASSERT_OK(demuxer.Run()); ASSERT_OK(muxer->Finalize()); } + // Check |input_file| is a valid media file and can be initialized by Demuxer. + void CheckMediaFile(const std::string input_file) { + Demuxer demuxer(input_file, NULL); + ASSERT_OK(demuxer.Initialize()); + } + protected: base::FilePath test_directory_; MuxerOptions options_; @@ -107,10 +114,48 @@ TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencrypted) { muxer.reset(new mp4::MP4Muxer(options_)); ASSERT_NO_FATAL_FAILURE(Remux(new_input_media_file, muxer.get())); + // TODO(kqyang): This comparison might be flaky due to timestamp difference. + // Compare data beyond moov box only? EXPECT_TRUE(base::ContentsEqual(base::FilePath(new_input_media_file), base::FilePath(options_.output_file_name))); } +TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedSeparateAudioVideo) { + options_.single_segment = true; + + const std::string input_media_file = GetTestDataFilePath(GetParam()).value(); + + Demuxer demuxer(input_media_file, NULL); + ASSERT_OK(demuxer.Initialize()); + ASSERT_EQ(2, demuxer.streams().size()); + + // Create and initialize the first muxer. + scoped_ptr muxer(new mp4::MP4Muxer(options_)); + ASSERT_OK(muxer->AddStream(demuxer.streams()[0])); + ASSERT_OK(muxer->Initialize()); + + // Create and initialize the second muxer. + MuxerOptions options2 = options_; + options2.output_file_name = + test_directory_.AppendASCII(kOutputFileName2).value(); + options2.temp_file_name = + test_directory_.AppendASCII(kTempFileName2).value(); + scoped_ptr muxer2(new mp4::MP4Muxer(options2)); + + ASSERT_OK(muxer2->AddStream(demuxer.streams()[1])); + ASSERT_OK(muxer2->Initialize()); + + // Start remuxing process. + ASSERT_OK(demuxer.Run()); + ASSERT_OK(muxer->Finalize()); + ASSERT_OK(muxer2->Finalize()); + + // Check output file is valid. + // TODO(kqyang): Compare the output with a known good output. + ASSERT_NO_FATAL_FAILURE(CheckMediaFile(options_.output_file_name)); + ASSERT_NO_FATAL_FAILURE(CheckMediaFile(options2.output_file_name)); +} + TEST_P(PackagerTest, MP4MuxerSingleSegmentEncrypted) { options_.single_segment = true;