From 30b189cb991745938253e9b94be5f955ac083fdf Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Wed, 6 Jun 2018 11:41:21 -0700 Subject: [PATCH] Make Test Util 'GetTextStreamInfo' require Time Scale Make the text stream info factory method in media_handler_test_base require the caller to specify the time scale. Issue: #399 Change-Id: Ibdfb183e0aa3f4ff50edf6b58c4e9b966006c6d2 --- .../media/base/media_handler_test_base.cc | 8 ++--- packager/media/base/media_handler_test_base.h | 2 +- .../cue_alignment_handler_unittest.cc | 10 +++--- .../media/chunking/text_chunker_unittest.cc | 33 ++++++++++--------- .../webvtt_text_output_handler_unittest.cc | 16 +++++---- .../webvtt/webvtt_to_mp4_handler_unittest.cc | 4 ++- 6 files changed, 39 insertions(+), 34 deletions(-) diff --git a/packager/media/base/media_handler_test_base.cc b/packager/media/base/media_handler_test_base.cc index d6ec24127a..0940225a78 100644 --- a/packager/media/base/media_handler_test_base.cc +++ b/packager/media/base/media_handler_test_base.cc @@ -194,14 +194,12 @@ std::unique_ptr MediaHandlerTestBase::GetSegmentInfo( return info; } -std::unique_ptr MediaHandlerTestBase::GetTextStreamInfo() const { - // Assume that text will use milliseconds. - const uint64_t kTimeScaleMs = 1000; - +std::unique_ptr MediaHandlerTestBase::GetTextStreamInfo( + uint32_t timescale) const { // None of this information is actually used by the text out handler. // The stream info is just needed to signal the start of the stream. return std::unique_ptr( - new TextStreamInfo(0, kTimeScaleMs, 0, kUnknownCodec, "", "", 0, 0, "")); + new TextStreamInfo(0, timescale, 0, kUnknownCodec, "", "", 0, 0, "")); } std::unique_ptr MediaHandlerTestBase::GetTextSample( diff --git a/packager/media/base/media_handler_test_base.h b/packager/media/base/media_handler_test_base.h index aea5898a27..bd5923a5fe 100644 --- a/packager/media/base/media_handler_test_base.h +++ b/packager/media/base/media_handler_test_base.h @@ -231,7 +231,7 @@ class MediaHandlerTestBase : public ::testing::Test { int64_t duration, bool is_subsegment) const; - std::unique_ptr GetTextStreamInfo() const; + std::unique_ptr GetTextStreamInfo(uint32_t timescale) const; std::unique_ptr GetTextSample(const std::string& id, int64_t start, diff --git a/packager/media/chunking/cue_alignment_handler_unittest.cc b/packager/media/chunking/cue_alignment_handler_unittest.cc index cc0dcfb54e..5b688cddbc 100644 --- a/packager/media/chunking/cue_alignment_handler_unittest.cc +++ b/packager/media/chunking/cue_alignment_handler_unittest.cc @@ -192,7 +192,7 @@ TEST_F(CueAlignmentHandlerTest, TextInputWithNoCues) { EXPECT_CALL(*Output(kTextStream), OnFlush(kParent)); } - auto stream_info = GetTextStreamInfo(); + auto stream_info = GetTextStreamInfo(kMsTimeScale); auto sample_0 = GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload); auto sample_1 = GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload); auto sample_2 = GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload); @@ -277,7 +277,7 @@ TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithNoCues) { } // Text samples - auto text_stream_info = GetTextStreamInfo(); + auto text_stream_info = GetTextStreamInfo(kMsTimeScale); auto text_sample_0 = GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload); auto text_sample_1 = @@ -480,7 +480,7 @@ TEST_F(CueAlignmentHandlerTest, TextInputWithCues) { EXPECT_CALL(*Output(kTextStream), OnFlush(kParent)); } - auto stream_info = GetTextStreamInfo(); + auto stream_info = GetTextStreamInfo(kMsTimeScale); auto sample_0 = GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload); auto sample_1 = GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload); auto sample_2 = GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload); @@ -539,7 +539,7 @@ TEST_F(CueAlignmentHandlerTest, TextInputWithCueAfterLastStart) { EXPECT_CALL(*Output(kTextStream), OnFlush(kParent)); } - auto stream_info = GetTextStreamInfo(); + auto stream_info = GetTextStreamInfo(kMsTimeScale); auto sample_0 = GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload); auto sample_1 = GetTextSample(kNoId, kSample1Start, kSample1End, kNoPayload); auto sample_2 = GetTextSample(kNoId, kSample2Start, kSample2End, kNoPayload); @@ -639,7 +639,7 @@ TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithCues) { } // Text samples - auto text_stream_info = GetTextStreamInfo(); + auto text_stream_info = GetTextStreamInfo(kMsTimeScale); auto text_sample_0 = GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload); auto text_sample_1 = diff --git a/packager/media/chunking/text_chunker_unittest.cc b/packager/media/chunking/text_chunker_unittest.cc index 83b773c035..92be56dc90 100644 --- a/packager/media/chunking/text_chunker_unittest.cc +++ b/packager/media/chunking/text_chunker_unittest.cc @@ -16,6 +16,7 @@ namespace media { namespace { const uint64_t kStreamIndex = 0; +const uint64_t kMsTimeScale = 1000u; const size_t kInputs = 1; const size_t kOutputs = 1; @@ -70,8 +71,8 @@ TEST_F(TextChunkerTest, SampleEndingOnSegmentStart) { EXPECT_CALL(*Output(kOutput), OnFlush(kStreamIndex)); } - ASSERT_OK(Input(kInput)->Dispatch( - StreamData::FromStreamInfo(kStreamIndex, GetTextStreamInfo()))); + ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromTextSample( kStreamIndex, GetTextSample(kNoId, kSampleStart, kSampleEnd, kNoPayload)))); @@ -124,8 +125,8 @@ TEST_F(TextChunkerTest, CreatesSegmentsForSamples) { EXPECT_CALL(*Output(kOutput), OnFlush(kStreamIndex)); } - ASSERT_OK(Input(kInput)->Dispatch( - StreamData::FromStreamInfo(kStreamIndex, GetTextStreamInfo()))); + ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromTextSample( kStreamIndex, GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload)))); @@ -188,8 +189,8 @@ TEST_F(TextChunkerTest, OutputsEmptySegments) { EXPECT_CALL(*Output(kOutput), OnFlush(kStreamIndex)); } - ASSERT_OK(Input(kInput)->Dispatch( - StreamData::FromStreamInfo(kStreamIndex, GetTextStreamInfo()))); + ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromTextSample( kStreamIndex, GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload)))); @@ -240,8 +241,8 @@ TEST_F(TextChunkerTest, SampleCrossesSegments) { EXPECT_CALL(*Output(kOutput), OnFlush(kStreamIndex)); } - ASSERT_OK(Input(kInput)->Dispatch( - StreamData::FromStreamInfo(kStreamIndex, GetTextStreamInfo()))); + ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromTextSample( kStreamIndex, GetTextSample(kNoId, kSampleStart, kSampleEnd, kNoPayload)))); @@ -326,8 +327,8 @@ TEST_F(TextChunkerTest, PreservesOrder) { EXPECT_CALL(*Output(kOutput), OnFlush(kStreamIndex)); } - ASSERT_OK(Input(kInput)->Dispatch( - StreamData::FromStreamInfo(kStreamIndex, GetTextStreamInfo()))); + ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromTextSample( kStreamIndex, GetTextSample(kSample0Id, kSample0Start, kSample0End, kNoPayload)))); @@ -426,8 +427,8 @@ TEST_F(TextChunkerTest, NestedSamples) { EXPECT_CALL(*Output(kOutput), OnFlush(kStreamIndex)); } - ASSERT_OK(Input(kInput)->Dispatch( - StreamData::FromStreamInfo(kStreamIndex, GetTextStreamInfo()))); + ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromTextSample( kStreamIndex, GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload)))); @@ -493,8 +494,8 @@ TEST_F(TextChunkerTest, SecondSampleStartsAfterMultiSegmentSampleEnds) { EXPECT_CALL(*Output(kOutput), OnFlush(kStreamIndex)); } - ASSERT_OK(Input(kInput)->Dispatch( - StreamData::FromStreamInfo(kStreamIndex, GetTextStreamInfo()))); + ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromTextSample( kStreamIndex, GetTextSample(kNoId, kSample0Start, kSample0End, kNoPayload)))); @@ -569,8 +570,8 @@ TEST_F(TextChunkerTest, SampleSpanningMultipleCues) { !kSubSegment, !kEncrypted))); } - ASSERT_OK(Input(kInput)->Dispatch( - StreamData::FromStreamInfo(kStreamIndex, GetTextStreamInfo()))); + ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK(Input(kInput)->Dispatch(StreamData::FromTextSample( kStreamIndex, GetTextSample(kNoId, kSampleStart, kSampleEnd, kNoPayload)))); diff --git a/packager/media/formats/webvtt/webvtt_text_output_handler_unittest.cc b/packager/media/formats/webvtt/webvtt_text_output_handler_unittest.cc index 916f4d5776..cde1afa78d 100644 --- a/packager/media/formats/webvtt/webvtt_text_output_handler_unittest.cc +++ b/packager/media/formats/webvtt/webvtt_text_output_handler_unittest.cc @@ -28,6 +28,8 @@ const size_t kStreamIndex = 0; const bool kEncrypted = true; const char* kNoId = ""; +const uint64_t kMsTimeScale = 1000u; + const char* kSegmentedFileTemplate = "memory://output/template-$Number$.vtt"; const char* kSegmentedFileOutput1 = "memory://output/template-1.vtt"; const char* kSegmentedFileOutput2 = "memory://output/template-2.vtt"; @@ -72,8 +74,8 @@ TEST_F(WebVttSegmentedOutputTest, WithNoSegmentAndWithNoSamples) { } ASSERT_OK(Input(kInputIndex) - ->Dispatch(StreamData::FromStreamInfo(kStreamIndex, - GetTextStreamInfo()))); + ->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK(Input(kInputIndex)->FlushAllDownstreams()); } @@ -100,8 +102,8 @@ TEST_F(WebVttSegmentedOutputTest, WithOneSegmentAndWithOneSample) { } ASSERT_OK(Input(kInputIndex) - ->Dispatch(StreamData::FromStreamInfo(kStreamIndex, - GetTextStreamInfo()))); + ->Dispatch(StreamData::FromStreamInfo( + kStreamIndex, GetTextStreamInfo(kMsTimeScale)))); ASSERT_OK( Input(kInputIndex) ->Dispatch(StreamData::FromTextSample( @@ -150,7 +152,8 @@ TEST_F(WebVttSegmentedOutputTest, WithTwoSegmentAndWithOneSample) { } ASSERT_OK(Input(kInputIndex) - ->Dispatch(StreamData::FromStreamInfo(0, GetTextStreamInfo()))); + ->Dispatch(StreamData::FromStreamInfo( + 0, GetTextStreamInfo(kMsTimeScale)))); // Segment One ASSERT_OK( @@ -209,7 +212,8 @@ TEST_F(WebVttSegmentedOutputTest, WithAnEmptySegment) { } ASSERT_OK(Input(kInputIndex) - ->Dispatch(StreamData::FromStreamInfo(0, GetTextStreamInfo()))); + ->Dispatch(StreamData::FromStreamInfo( + 0, GetTextStreamInfo(kMsTimeScale)))); // Segment One ASSERT_OK( Input(kInputIndex) diff --git a/packager/media/formats/webvtt/webvtt_to_mp4_handler_unittest.cc b/packager/media/formats/webvtt/webvtt_to_mp4_handler_unittest.cc index 624d47e167..88dcd1df4a 100644 --- a/packager/media/formats/webvtt/webvtt_to_mp4_handler_unittest.cc +++ b/packager/media/formats/webvtt/webvtt_to_mp4_handler_unittest.cc @@ -70,7 +70,9 @@ class WebVttToMp4HandlerTest : public MediaHandlerTestBase { } Status DispatchStream() { - auto info = GetTextStreamInfo(); + const uint64_t kMsTimeScale = 1000u; + + auto info = GetTextStreamInfo(kMsTimeScale); return In()->Dispatch( StreamData::FromStreamInfo(kStreamIndex, std::move(info))); }