2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-08-21 22:40:44 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2015-07-22 23:40:45 +00:00
|
|
|
#include "packager/base/files/file_util.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/strings/string_number_conversions.h"
|
|
|
|
#include "packager/base/strings/stringprintf.h"
|
|
|
|
#include "packager/base/time/clock.h"
|
|
|
|
#include "packager/media/base/demuxer.h"
|
2016-02-19 20:23:37 +00:00
|
|
|
#include "packager/media/base/fixed_key_source.h"
|
2016-04-08 18:41:17 +00:00
|
|
|
#include "packager/media/base/fourccs.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/muxer.h"
|
2016-11-11 23:17:17 +00:00
|
|
|
#include "packager/media/base/muxer_util.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/stream_info.h"
|
2014-10-09 23:33:56 +00:00
|
|
|
#include "packager/media/base/test/status_test_util.h"
|
2017-02-24 01:17:47 +00:00
|
|
|
#include "packager/media/chunking/chunking_handler.h"
|
2017-03-11 02:49:55 +00:00
|
|
|
#include "packager/media/crypto/encryption_handler.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/formats/mp4/mp4_muxer.h"
|
|
|
|
#include "packager/media/test/test_data_util.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2013-11-12 20:37:58 +00:00
|
|
|
using ::testing::ValuesIn;
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-02-28 02:39:52 +00:00
|
|
|
namespace media {
|
2013-10-11 21:44:55 +00:00
|
|
|
namespace {
|
2014-02-28 02:39:52 +00:00
|
|
|
|
2015-09-29 17:13:09 +00:00
|
|
|
const char* kMediaFiles[] = {"bear-640x360.mp4", "bear-640x360-av_frag.mp4",
|
2016-04-28 22:02:55 +00:00
|
|
|
"bear-640x360.ts"};
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2014-01-14 01:38:34 +00:00
|
|
|
// Muxer options.
|
|
|
|
const double kSegmentDurationInSeconds = 1.0;
|
|
|
|
const double kFragmentDurationInSecodns = 0.1;
|
|
|
|
const bool kSegmentSapAligned = true;
|
|
|
|
const bool kFragmentSapAligned = true;
|
|
|
|
const int kNumSubsegmentsPerSidx = 2;
|
2014-02-28 02:39:52 +00:00
|
|
|
|
|
|
|
const char kOutputVideo[] = "output_video";
|
|
|
|
const char kOutputVideo2[] = "output_video_2";
|
|
|
|
const char kOutputAudio[] = "output_audio";
|
|
|
|
const char kOutputAudio2[] = "output_audio_2";
|
|
|
|
const char kOutputNone[] = "";
|
|
|
|
|
2014-01-14 01:38:34 +00:00
|
|
|
const char kSegmentTemplate[] = "template$Number$.m4s";
|
2014-02-28 02:39:52 +00:00
|
|
|
const char kSegmentTemplateOutputPattern[] = "template%d.m4s";
|
|
|
|
|
|
|
|
const bool kSingleSegment = true;
|
|
|
|
const bool kMultipleSegments = false;
|
|
|
|
const bool kEnableEncryption = true;
|
|
|
|
const bool kDisableEncryption = false;
|
2014-01-14 01:38:34 +00:00
|
|
|
|
2013-11-12 20:37:58 +00:00
|
|
|
// Encryption constants.
|
|
|
|
const char kKeyIdHex[] = "e5007e6e9dcd5ac095202ed3758382cd";
|
|
|
|
const char kKeyHex[] = "6fc96fe628a265b13aeddec0bc421f4d";
|
2014-01-14 01:38:34 +00:00
|
|
|
const double kClearLeadInSeconds = 1.5;
|
2014-04-18 18:49:49 +00:00
|
|
|
const double kCryptoDurationInSeconds = 0; // Key rotation is disabled.
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2016-11-11 23:17:17 +00:00
|
|
|
// Track resolution constants.
|
|
|
|
const uint32_t kMaxSDPixels = 640 * 480;
|
|
|
|
const uint32_t kMaxHDPixels = 1920 * 1080;
|
|
|
|
const uint32_t kMaxUHD1Pixels = 4096 * 2160;
|
|
|
|
|
2013-11-12 20:37:58 +00:00
|
|
|
} // namespace
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
class FakeClock : public base::Clock {
|
|
|
|
public:
|
|
|
|
// Fake the clock to return NULL time.
|
2015-07-22 23:40:45 +00:00
|
|
|
base::Time Now() override { return base::Time(); }
|
2014-02-28 02:39:52 +00:00
|
|
|
};
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
class PackagerTestBasic : public ::testing::TestWithParam<const char*> {
|
2013-10-11 21:44:55 +00:00
|
|
|
public:
|
2014-08-25 22:51:19 +00:00
|
|
|
PackagerTestBasic() {}
|
2014-02-28 02:39:52 +00:00
|
|
|
|
2015-07-22 23:40:45 +00:00
|
|
|
void SetUp() override {
|
2014-01-14 01:38:34 +00:00
|
|
|
// Create a test directory for testing, will be deleted after test.
|
2016-08-14 22:28:21 +00:00
|
|
|
ASSERT_TRUE(base::CreateNewTempDirectory(
|
|
|
|
base::FilePath::FromUTF8Unsafe("packager_").value(), &test_directory_));
|
2014-01-14 01:38:34 +00:00
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
// Copy the input to test directory for easy reference.
|
|
|
|
ASSERT_TRUE(base::CopyFile(GetTestDataFilePath(GetParam()),
|
|
|
|
test_directory_.AppendASCII(GetParam())));
|
2013-11-12 20:37:58 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 23:40:45 +00:00
|
|
|
void TearDown() override { base::DeleteFile(test_directory_, true); }
|
2014-01-14 01:38:34 +00:00
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
std::string GetFullPath(const std::string& file_name);
|
|
|
|
// Check if |file1| and |file2| are the same.
|
|
|
|
bool ContentsEqual(const std::string& file1, const std::string file2);
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2017-02-24 01:17:47 +00:00
|
|
|
ChunkingOptions SetupChunkingOptions();
|
2017-03-11 02:49:55 +00:00
|
|
|
EncryptionOptions SetupEncryptionOptions();
|
2017-02-24 01:17:47 +00:00
|
|
|
MuxerOptions SetupMuxerOptions(const std::string& output,
|
|
|
|
bool single_segment);
|
2014-02-28 02:39:52 +00:00
|
|
|
void Remux(const std::string& input,
|
|
|
|
const std::string& video_output,
|
|
|
|
const std::string& audio_output,
|
|
|
|
bool single_segment,
|
2017-02-21 18:36:50 +00:00
|
|
|
bool enable_encryption);
|
2014-01-18 00:03:21 +00:00
|
|
|
|
2014-08-25 22:51:19 +00:00
|
|
|
void Decrypt(const std::string& input,
|
|
|
|
const std::string& video_output,
|
|
|
|
const std::string& audio_output);
|
|
|
|
|
2014-01-14 01:38:34 +00:00
|
|
|
protected:
|
|
|
|
base::FilePath test_directory_;
|
2014-02-28 02:39:52 +00:00
|
|
|
FakeClock fake_clock_;
|
2013-10-11 21:44:55 +00:00
|
|
|
};
|
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
std::string PackagerTestBasic::GetFullPath(const std::string& file_name) {
|
2016-08-14 22:28:21 +00:00
|
|
|
return test_directory_.Append(
|
|
|
|
base::FilePath::FromUTF8Unsafe(file_name)).AsUTF8Unsafe();
|
2014-02-28 02:39:52 +00:00
|
|
|
}
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
bool PackagerTestBasic::ContentsEqual(const std::string& file1,
|
|
|
|
const std::string file2) {
|
|
|
|
return base::ContentsEqual(test_directory_.AppendASCII(file1),
|
|
|
|
test_directory_.AppendASCII(file2));
|
2013-11-12 20:37:58 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 01:17:47 +00:00
|
|
|
MuxerOptions PackagerTestBasic::SetupMuxerOptions(const std::string& output,
|
|
|
|
bool single_segment) {
|
2014-02-28 02:39:52 +00:00
|
|
|
MuxerOptions options;
|
|
|
|
options.num_subsegments_per_sidx = kNumSubsegmentsPerSidx;
|
|
|
|
options.output_file_name = GetFullPath(output);
|
2017-01-07 02:40:37 +00:00
|
|
|
if (!single_segment)
|
|
|
|
options.segment_template = GetFullPath(kSegmentTemplate);
|
2016-08-14 22:28:21 +00:00
|
|
|
options.temp_dir = test_directory_.AsUTF8Unsafe();
|
2014-02-28 02:39:52 +00:00
|
|
|
return options;
|
|
|
|
}
|
2014-01-18 00:03:21 +00:00
|
|
|
|
2017-02-24 01:17:47 +00:00
|
|
|
ChunkingOptions PackagerTestBasic::SetupChunkingOptions() {
|
|
|
|
ChunkingOptions options;
|
|
|
|
options.segment_duration_in_seconds = kSegmentDurationInSeconds;
|
|
|
|
options.subsegment_duration_in_seconds = kFragmentDurationInSecodns;
|
|
|
|
options.segment_sap_aligned = kSegmentSapAligned;
|
|
|
|
options.subsegment_sap_aligned = kFragmentSapAligned;
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2017-03-11 02:49:55 +00:00
|
|
|
EncryptionOptions PackagerTestBasic::SetupEncryptionOptions() {
|
|
|
|
EncryptionOptions options;
|
|
|
|
options.clear_lead_in_seconds = kClearLeadInSeconds;
|
|
|
|
options.protection_scheme = FOURCC_cenc;
|
|
|
|
options.max_sd_pixels = kMaxSDPixels;
|
|
|
|
options.max_hd_pixels = kMaxHDPixels;
|
|
|
|
options.max_uhd1_pixels = kMaxUHD1Pixels;
|
|
|
|
options.crypto_period_duration_in_seconds = kCryptoDurationInSeconds;
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
void PackagerTestBasic::Remux(const std::string& input,
|
|
|
|
const std::string& video_output,
|
|
|
|
const std::string& audio_output,
|
|
|
|
bool single_segment,
|
2017-02-21 18:36:50 +00:00
|
|
|
bool enable_encryption) {
|
2014-02-28 02:39:52 +00:00
|
|
|
CHECK(!video_output.empty() || !audio_output.empty());
|
2014-01-18 00:03:21 +00:00
|
|
|
|
2014-08-25 22:51:19 +00:00
|
|
|
Demuxer demuxer(GetFullPath(input));
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<KeySource> encryption_key_source(
|
2016-02-19 20:23:37 +00:00
|
|
|
FixedKeySource::CreateFromHexStrings(kKeyIdHex, kKeyHex, "", ""));
|
2014-04-16 01:09:32 +00:00
|
|
|
DCHECK(encryption_key_source);
|
2014-02-28 02:39:52 +00:00
|
|
|
|
2017-02-21 18:36:50 +00:00
|
|
|
std::shared_ptr<Muxer> muxer_video;
|
2014-02-28 02:39:52 +00:00
|
|
|
if (!video_output.empty()) {
|
|
|
|
muxer_video.reset(
|
2017-02-24 01:17:47 +00:00
|
|
|
new mp4::MP4Muxer(SetupMuxerOptions(video_output, single_segment)));
|
2014-02-28 02:39:52 +00:00
|
|
|
muxer_video->set_clock(&fake_clock_);
|
|
|
|
|
2017-02-24 01:17:47 +00:00
|
|
|
auto chunking_handler =
|
|
|
|
std::make_shared<ChunkingHandler>(SetupChunkingOptions());
|
|
|
|
ASSERT_OK(demuxer.SetHandler("video", chunking_handler));
|
2017-03-11 02:49:55 +00:00
|
|
|
if (enable_encryption) {
|
|
|
|
auto encryption_handler = std::make_shared<EncryptionHandler>(
|
|
|
|
SetupEncryptionOptions(), encryption_key_source.get());
|
|
|
|
ASSERT_OK(chunking_handler->SetHandler(0, encryption_handler));
|
|
|
|
ASSERT_OK(encryption_handler->SetHandler(0, muxer_video));
|
|
|
|
} else {
|
|
|
|
ASSERT_OK(chunking_handler->SetHandler(0, muxer_video));
|
|
|
|
}
|
2014-02-28 02:39:52 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 18:36:50 +00:00
|
|
|
std::shared_ptr<Muxer> muxer_audio;
|
2014-02-28 02:39:52 +00:00
|
|
|
if (!audio_output.empty()) {
|
|
|
|
muxer_audio.reset(
|
2017-02-24 01:17:47 +00:00
|
|
|
new mp4::MP4Muxer(SetupMuxerOptions(audio_output, single_segment)));
|
2014-02-28 02:39:52 +00:00
|
|
|
muxer_audio->set_clock(&fake_clock_);
|
2014-01-18 00:03:21 +00:00
|
|
|
|
2017-02-24 01:17:47 +00:00
|
|
|
auto chunking_handler =
|
|
|
|
std::make_shared<ChunkingHandler>(SetupChunkingOptions());
|
|
|
|
ASSERT_OK(demuxer.SetHandler("audio", chunking_handler));
|
2017-03-11 02:49:55 +00:00
|
|
|
if (enable_encryption) {
|
|
|
|
auto encryption_handler = std::make_shared<EncryptionHandler>(
|
|
|
|
SetupEncryptionOptions(), encryption_key_source.get());
|
|
|
|
ASSERT_OK(chunking_handler->SetHandler(0, encryption_handler));
|
|
|
|
ASSERT_OK(encryption_handler->SetHandler(0, muxer_audio));
|
|
|
|
} else {
|
|
|
|
ASSERT_OK(chunking_handler->SetHandler(0, muxer_audio));
|
|
|
|
}
|
2014-02-28 02:39:52 +00:00
|
|
|
}
|
2014-01-18 00:03:21 +00:00
|
|
|
|
2017-02-21 18:36:50 +00:00
|
|
|
ASSERT_OK(demuxer.Initialize());
|
2014-01-18 00:03:21 +00:00
|
|
|
// Start remuxing process.
|
|
|
|
ASSERT_OK(demuxer.Run());
|
|
|
|
}
|
|
|
|
|
2014-08-25 22:51:19 +00:00
|
|
|
void PackagerTestBasic::Decrypt(const std::string& input,
|
|
|
|
const std::string& video_output,
|
|
|
|
const std::string& audio_output) {
|
|
|
|
CHECK(!video_output.empty() || !audio_output.empty());
|
|
|
|
|
|
|
|
Demuxer demuxer(GetFullPath(input));
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<KeySource> decryption_key_source(
|
2016-02-19 20:23:37 +00:00
|
|
|
FixedKeySource::CreateFromHexStrings(kKeyIdHex, kKeyHex, "", ""));
|
2014-09-08 18:43:25 +00:00
|
|
|
ASSERT_TRUE(decryption_key_source);
|
2016-08-17 17:41:40 +00:00
|
|
|
demuxer.SetKeySource(std::move(decryption_key_source));
|
2014-08-25 22:51:19 +00:00
|
|
|
|
2017-02-21 18:36:50 +00:00
|
|
|
std::shared_ptr<Muxer> muxer;
|
2014-08-25 22:51:19 +00:00
|
|
|
if (!video_output.empty()) {
|
2017-02-24 01:17:47 +00:00
|
|
|
muxer.reset(new mp4::MP4Muxer(SetupMuxerOptions(video_output, true)));
|
2014-08-25 22:51:19 +00:00
|
|
|
}
|
|
|
|
if (!audio_output.empty()) {
|
2017-02-24 01:17:47 +00:00
|
|
|
muxer.reset(new mp4::MP4Muxer(SetupMuxerOptions(audio_output, true)));
|
2014-08-25 22:51:19 +00:00
|
|
|
}
|
|
|
|
ASSERT_TRUE(muxer);
|
|
|
|
muxer->set_clock(&fake_clock_);
|
|
|
|
|
2017-02-24 01:17:47 +00:00
|
|
|
auto chunking_handler =
|
|
|
|
std::make_shared<ChunkingHandler>(SetupChunkingOptions());
|
|
|
|
ASSERT_OK(demuxer.SetHandler("0", chunking_handler));
|
|
|
|
ASSERT_OK(chunking_handler->SetHandler(0, muxer));
|
|
|
|
|
|
|
|
ASSERT_OK(demuxer.Initialize());
|
2014-08-25 22:51:19 +00:00
|
|
|
ASSERT_OK(demuxer.Run());
|
|
|
|
}
|
|
|
|
|
2014-04-24 19:29:53 +00:00
|
|
|
TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentUnencryptedVideo) {
|
2014-02-28 02:39:52 +00:00
|
|
|
ASSERT_NO_FATAL_FAILURE(Remux(GetParam(),
|
|
|
|
kOutputVideo,
|
|
|
|
kOutputNone,
|
|
|
|
kSingleSegment,
|
2017-02-21 18:36:50 +00:00
|
|
|
kDisableEncryption));
|
2014-02-28 02:39:52 +00:00
|
|
|
}
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-04-24 19:29:53 +00:00
|
|
|
TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentUnencryptedAudio) {
|
|
|
|
ASSERT_NO_FATAL_FAILURE(Remux(GetParam(),
|
|
|
|
kOutputNone,
|
|
|
|
kOutputAudio,
|
|
|
|
kSingleSegment,
|
2017-02-21 18:36:50 +00:00
|
|
|
kDisableEncryption));
|
2014-04-24 19:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentEncryptedVideo) {
|
2014-02-28 02:39:52 +00:00
|
|
|
ASSERT_NO_FATAL_FAILURE(Remux(GetParam(),
|
|
|
|
kOutputVideo,
|
|
|
|
kOutputNone,
|
|
|
|
kSingleSegment,
|
2017-02-21 18:36:50 +00:00
|
|
|
kEnableEncryption));
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-08-25 22:51:19 +00:00
|
|
|
ASSERT_NO_FATAL_FAILURE(Decrypt(kOutputVideo,
|
|
|
|
kOutputVideo2,
|
|
|
|
kOutputNone));
|
2014-01-14 01:38:34 +00:00
|
|
|
}
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-04-24 19:29:53 +00:00
|
|
|
TEST_P(PackagerTestBasic, MP4MuxerSingleSegmentEncryptedAudio) {
|
|
|
|
ASSERT_NO_FATAL_FAILURE(Remux(GetParam(),
|
|
|
|
kOutputNone,
|
|
|
|
kOutputAudio,
|
|
|
|
kSingleSegment,
|
2017-02-21 18:36:50 +00:00
|
|
|
kEnableEncryption));
|
2014-04-24 19:29:53 +00:00
|
|
|
|
2014-08-25 22:51:19 +00:00
|
|
|
ASSERT_NO_FATAL_FAILURE(Decrypt(kOutputAudio,
|
|
|
|
kOutputNone,
|
|
|
|
kOutputAudio2));
|
2014-04-24 19:29:53 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 23:17:17 +00:00
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
class PackagerTest : public PackagerTestBasic {
|
|
|
|
public:
|
2015-07-22 23:40:45 +00:00
|
|
|
void SetUp() override {
|
2014-02-28 02:39:52 +00:00
|
|
|
PackagerTestBasic::SetUp();
|
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(Remux(GetParam(),
|
|
|
|
kOutputVideo,
|
|
|
|
kOutputNone,
|
|
|
|
kSingleSegment,
|
2017-02-21 18:36:50 +00:00
|
|
|
kDisableEncryption));
|
2014-02-28 02:39:52 +00:00
|
|
|
|
|
|
|
ASSERT_NO_FATAL_FAILURE(Remux(GetParam(),
|
|
|
|
kOutputNone,
|
|
|
|
kOutputAudio,
|
|
|
|
kSingleSegment,
|
2017-02-21 18:36:50 +00:00
|
|
|
kDisableEncryption));
|
2014-02-28 02:39:52 +00:00
|
|
|
}
|
|
|
|
};
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-04-24 19:29:53 +00:00
|
|
|
TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedVideoAgain) {
|
2014-02-28 02:39:52 +00:00
|
|
|
// 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,
|
|
|
|
kOutputVideo2,
|
|
|
|
kOutputNone,
|
|
|
|
kSingleSegment,
|
2017-02-21 18:36:50 +00:00
|
|
|
kDisableEncryption));
|
2014-02-28 02:39:52 +00:00
|
|
|
EXPECT_TRUE(ContentsEqual(kOutputVideo, kOutputVideo2));
|
|
|
|
}
|
|
|
|
|
2014-04-24 19:29:53 +00:00
|
|
|
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,
|
2017-02-21 18:36:50 +00:00
|
|
|
kDisableEncryption));
|
2014-04-24 19:29:53 +00:00
|
|
|
EXPECT_TRUE(ContentsEqual(kOutputAudio, kOutputAudio2));
|
|
|
|
}
|
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedSeparateAudioVideo) {
|
|
|
|
ASSERT_NO_FATAL_FAILURE(Remux(GetParam(),
|
|
|
|
kOutputVideo2,
|
|
|
|
kOutputAudio2,
|
|
|
|
kSingleSegment,
|
2017-02-21 18:36:50 +00:00
|
|
|
kDisableEncryption));
|
2014-02-28 02:39:52 +00:00
|
|
|
|
|
|
|
// Compare the output with single muxer output. They should match.
|
|
|
|
EXPECT_TRUE(ContentsEqual(kOutputVideo, kOutputVideo2));
|
|
|
|
EXPECT_TRUE(ContentsEqual(kOutputAudio, kOutputAudio2));
|
|
|
|
}
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-04-24 19:29:53 +00:00
|
|
|
TEST_P(PackagerTest, MP4MuxerMultiSegmentsUnencryptedVideo) {
|
2014-02-28 02:39:52 +00:00
|
|
|
ASSERT_NO_FATAL_FAILURE(Remux(GetParam(),
|
|
|
|
kOutputVideo2,
|
|
|
|
kOutputNone,
|
|
|
|
kMultipleSegments,
|
2017-02-21 18:36:50 +00:00
|
|
|
kDisableEncryption));
|
2014-02-28 02:39:52 +00:00
|
|
|
|
|
|
|
// Find and concatenates the segments.
|
|
|
|
const std::string kOutputVideoSegmentsCombined =
|
|
|
|
std::string(kOutputVideo) + "_combined";
|
|
|
|
base::FilePath output_path =
|
|
|
|
test_directory_.AppendASCII(kOutputVideoSegmentsCombined);
|
|
|
|
ASSERT_TRUE(
|
|
|
|
base::CopyFile(test_directory_.AppendASCII(kOutputVideo2), output_path));
|
|
|
|
|
|
|
|
const int kStartSegmentIndex = 1; // start from one.
|
|
|
|
int segment_index = kStartSegmentIndex;
|
|
|
|
while (true) {
|
|
|
|
base::FilePath segment_path = test_directory_.AppendASCII(
|
|
|
|
base::StringPrintf(kSegmentTemplateOutputPattern, segment_index));
|
|
|
|
if (!base::PathExists(segment_path))
|
|
|
|
break;
|
|
|
|
|
|
|
|
std::string segment_content;
|
2014-03-20 01:57:29 +00:00
|
|
|
ASSERT_TRUE(base::ReadFileToString(segment_path, &segment_content));
|
2015-07-22 23:40:45 +00:00
|
|
|
EXPECT_TRUE(base::AppendToFile(output_path, segment_content.data(),
|
2016-11-09 02:11:13 +00:00
|
|
|
static_cast<int>(segment_content.size())));
|
2014-02-28 02:39:52 +00:00
|
|
|
|
|
|
|
++segment_index;
|
|
|
|
}
|
|
|
|
// We should have at least one segment.
|
|
|
|
ASSERT_LT(kStartSegmentIndex, segment_index);
|
|
|
|
|
|
|
|
// Feed the combined file into muxer again. The new muxer output should be
|
|
|
|
// the same as by just feeding the input to muxer.
|
|
|
|
ASSERT_NO_FATAL_FAILURE(Remux(kOutputVideoSegmentsCombined,
|
|
|
|
kOutputVideo2,
|
|
|
|
kOutputNone,
|
|
|
|
kSingleSegment,
|
2017-02-21 18:36:50 +00:00
|
|
|
kDisableEncryption));
|
2014-02-28 02:39:52 +00:00
|
|
|
EXPECT_TRUE(ContentsEqual(kOutputVideo, kOutputVideo2));
|
2013-10-11 21:44:55 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 23:15:22 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(PackagerEndToEnd,
|
2014-02-28 02:39:52 +00:00
|
|
|
PackagerTestBasic,
|
|
|
|
ValuesIn(kMediaFiles));
|
2014-03-05 23:15:22 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(PackagerEndToEnd, PackagerTest, ValuesIn(kMediaFiles));
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|