From 47f20031dd06ff76fbe5de25ebc43668a6adf646 Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Fri, 1 Jun 2018 10:29:44 -0700 Subject: [PATCH] WebVtt Text to MP4 - Test That No Payloads Becomes Gaps Text Samples with no payload should be ignored, so this adds a test to check that samples with no payload get treated the same as a gap. As long as this case is true, using gaps in our other tests should functionally be the same as using samples with no payload. Change-Id: Ic16b240c43eda2514b537a2d938d4135638adc4e --- .../webvtt/webvtt_to_mp4_handler_unittest.cc | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) 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 bbd35c2c0e..624d47e167 100644 --- a/packager/media/formats/webvtt/webvtt_to_mp4_handler_unittest.cc +++ b/packager/media/formats/webvtt/webvtt_to_mp4_handler_unittest.cc @@ -26,6 +26,7 @@ const char* kId2 = "sample-id-2"; const char* kId3 = "sample-id-3"; const char* kSimplePayload = "simple-payload-that-has-some-text"; +const char* kEmptyPayload = ""; } // namespace MATCHER_P(MediaSampleContainsId, id, "") { @@ -97,6 +98,51 @@ class WebVttToMp4HandlerTest : public MediaHandlerTestBase { Status Flush() { return In()->FlushAllDownstreams(); } }; +// Verify that samples with no payload are ignored and act as gaps. +// +// |[-- SEGMENT ------------------]| +// | [--- EMPTY SAMPLE ---]| +// |[- GAP -] | +// +TEST_F(WebVttToMp4HandlerTest, IngoresEmptyPayloadSamples) { + const int64_t kSegmentStart = 0; + const int64_t kSegmentEnd = 10000; + const int64_t kSegmentDuration = kSegmentEnd - kSegmentStart; + + const int64_t kGapStart = kSegmentStart; + const int64_t kGapEnd = kGapStart + 200; + + const int64_t kSampleStart = kGapEnd; + const int64_t kSampleEnd = kSegmentEnd; + + ASSERT_OK(SetUpTestGraph()); + + { + testing::InSequence s; + + EXPECT_CALL(*Out(), OnProcess(IsStreamInfo(kStreamIndex))); + + // Gap - The gap and sample should be combines into a new gap that spans + // the while segment. + EXPECT_CALL(*Out(), + OnProcess(IsMediaSample(kStreamIndex, kSegmentStart, + kSegmentDuration, !kEncrypted))); + // Segment + EXPECT_CALL(*Out(), OnProcess(IsSegmentInfo(kStreamIndex, kSegmentStart, + kSegmentDuration, !kSubSegment, + !kEncrypted))); + + EXPECT_CALL(*Out(), OnFlush(kStreamIndex)); + } + + ASSERT_OK(DispatchStream()); + // Even if the sample has an id, it should still get ignored if it has no + // payload. + ASSERT_OK(DispatchText(kId1, kEmptyPayload, kSampleStart, kSampleEnd)); + ASSERT_OK(DispatchSegment(kSegmentStart, kSegmentEnd)); + ASSERT_OK(Flush()); +} + // Verify that when the stream starts at a non-zero value, the gap at the // start will be filled. //