From c5fa32f0ebf82c2dff331d86eb3aa09dc5ed15d0 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Tue, 20 Nov 2018 16:52:52 -0800 Subject: [PATCH] Return an error when seeing duplicated outputs Fixes #497. Change-Id: Ic3f5352b6774fbd488e6d688df4c8a5053732549 --- packager/packager.cc | 23 +++++++++++++++++++ packager/packager_test.cc | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/packager/packager.cc b/packager/packager.cc index 953d1c8d25..5f9c400364 100644 --- a/packager/packager.cc +++ b/packager/packager.cc @@ -279,6 +279,8 @@ Status ValidateParams(const PackagingParams& packaging_params, // generates multiple segments specified using segment template. const bool on_demand_dash_profile = stream_descriptors.begin()->segment_template.empty(); + std::set outputs; + std::set segment_templates; for (const auto& descriptor : stream_descriptors) { if (on_demand_dash_profile != descriptor.segment_template.empty()) { return Status(error::INVALID_ARGUMENT, @@ -304,6 +306,27 @@ Status ValidateParams(const PackagingParams& packaging_params, // Skip the check for DASH as DASH defaults to 'dynamic' MPD when segment // template is provided. } + + if (!descriptor.output.empty()) { + if (outputs.find(descriptor.output) != outputs.end()) { + return Status( + error::INVALID_ARGUMENT, + "Seeing duplicated outputs '" + descriptor.output + + "' in stream descriptors. Every output must be unique."); + } + outputs.insert(descriptor.output); + } + if (!descriptor.segment_template.empty()) { + if (segment_templates.find(descriptor.segment_template) != + segment_templates.end()) { + return Status(error::INVALID_ARGUMENT, + "Seeing duplicated segment templates '" + + descriptor.segment_template + + "' in stream descriptors. Every segment template " + "must be unique."); + } + segment_templates.insert(descriptor.segment_template); + } } if (packaging_params.output_media_info && !on_demand_dash_profile) { diff --git a/packager/packager_test.cc b/packager/packager_test.cc index 9050388f8d..a776f239ca 100644 --- a/packager/packager_test.cc +++ b/packager/packager_test.cc @@ -10,6 +10,7 @@ #include "packager/packager.h" using testing::_; +using testing::HasSubstr; using testing::Invoke; using testing::MockFunction; using testing::Return; @@ -25,6 +26,7 @@ const char kTestFile[] = "packager/media/test/data/bear-640x360.mp4"; const char kOutputVideo[] = "output_video.mp4"; const char kOutputVideoTemplate[] = "output_video_$Number$.m4s"; const char kOutputAudio[] = "output_audio.mp4"; +const char kOutputAudioTemplate[] = "output_audio_$Number$.m4s"; const char kOutputMpd[] = "output.mpd"; const double kSegmentDurationInSeconds = 1.0; @@ -138,6 +140,51 @@ TEST_F(PackagerTest, MixingSegmentTemplateAndSingleSegment) { ASSERT_EQ(error::INVALID_ARGUMENT, status.error_code()); } +TEST_F(PackagerTest, DuplicatedOutputs) { + std::vector stream_descriptors; + StreamDescriptor stream_descriptor; + + stream_descriptor.input = kTestFile; + stream_descriptor.stream_selector = "video"; + stream_descriptor.output = GetFullPath(kOutputVideo); + stream_descriptor.segment_template = GetFullPath(kOutputVideoTemplate); + stream_descriptors.push_back(stream_descriptor); + + stream_descriptor.input = kTestFile; + stream_descriptor.stream_selector = "audio"; + stream_descriptor.output = GetFullPath(kOutputVideo); + stream_descriptor.segment_template = GetFullPath(kOutputAudioTemplate); + stream_descriptors.push_back(stream_descriptor); + + Packager packager; + auto status = packager.Initialize(SetupPackagingParams(), stream_descriptors); + ASSERT_EQ(error::INVALID_ARGUMENT, status.error_code()); + EXPECT_THAT(status.error_message(), HasSubstr("duplicated outputs")); +} + +TEST_F(PackagerTest, DuplicatedSegmentTemplates) { + std::vector stream_descriptors; + StreamDescriptor stream_descriptor; + + stream_descriptor.input = kTestFile; + stream_descriptor.stream_selector = "video"; + stream_descriptor.output = GetFullPath(kOutputVideo); + stream_descriptor.segment_template = GetFullPath(kOutputVideoTemplate); + stream_descriptors.push_back(stream_descriptor); + + stream_descriptor.input = kTestFile; + stream_descriptor.stream_selector = "audio"; + stream_descriptor.output = GetFullPath(kOutputAudio); + stream_descriptor.segment_template = GetFullPath(kOutputVideoTemplate); + stream_descriptors.push_back(stream_descriptor); + + Packager packager; + auto status = packager.Initialize(SetupPackagingParams(), stream_descriptors); + ASSERT_EQ(error::INVALID_ARGUMENT, status.error_code()); + EXPECT_THAT(status.error_message(), + HasSubstr("duplicated segment templates")); +} + TEST_F(PackagerTest, SegmentAlignedAndSubsegmentNotAligned) { auto packaging_params = SetupPackagingParams(); packaging_params.chunking_params.segment_sap_aligned = true;