From b0edec8c4025ffed9416c19a6ba4b11786de6b4b Mon Sep 17 00:00:00 2001 From: Aaron Vaage Date: Tue, 2 Jan 2018 13:58:47 -0800 Subject: [PATCH] Changed Text Segmenter to output segment info last To better align with the Chunking Handler, the Text Segmenter now outputs the SegmentInfo at the end of the segment rather than the start. Change-Id: If69ab951947d00779b4b63a52c4b6662bbdc4c0d --- .../media/formats/webvtt/webvtt_segmenter.cc | 16 +++--- .../webvtt/webvtt_segmenter_unittest.cc | 53 +++++++++---------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/packager/media/formats/webvtt/webvtt_segmenter.cc b/packager/media/formats/webvtt/webvtt_segmenter.cc index 4612341d32..c1bbca89bc 100644 --- a/packager/media/formats/webvtt/webvtt_segmenter.cc +++ b/packager/media/formats/webvtt/webvtt_segmenter.cc @@ -85,18 +85,22 @@ Status WebVttSegmenter::OnSegmentEnd() { const uint64_t segment = samples_.top().segment; - std::shared_ptr info = std::make_shared(); - info->start_timestamp = segment * segment_duration_ms_; - info->duration = segment_duration_ms_; - - Status status = DispatchSegmentInfo(kStreamIndex, std::move(info)); - + Status status; while (status.ok() && samples_.size() && samples_.top().segment == segment) { status.Update( DispatchTextSample(kStreamIndex, std::move(samples_.top().sample))); samples_.pop(); } + // Only send the segment info if all the samples were accepted. + if (status.ok()) { + std::shared_ptr info = std::make_shared(); + info->start_timestamp = segment * segment_duration_ms_; + info->duration = segment_duration_ms_; + + status.Update(DispatchSegmentInfo(kStreamIndex, std::move(info))); + } + return status; } } // namespace media diff --git a/packager/media/formats/webvtt/webvtt_segmenter_unittest.cc b/packager/media/formats/webvtt/webvtt_segmenter_unittest.cc index 4c7df1beeb..d56933a89d 100644 --- a/packager/media/formats/webvtt/webvtt_segmenter_unittest.cc +++ b/packager/media/formats/webvtt/webvtt_segmenter_unittest.cc @@ -58,15 +58,14 @@ TEST_F(WebVttSegmenterTest, CueEndingOnSegmentStart) { EXPECT_CALL(*Output(kOutputIndex), OnProcess(IsStreamInfo(kStreamIndex))); // Segment One - EXPECT_CALL( - *Output(kOutputIndex), - OnProcess(IsSegmentInfo(kStreamIndex, kStartTimeSigned, - kSegmentDuration, !kSubSegment, !kEncrypted))); EXPECT_CALL( *Output(kOutputIndex), OnProcess(IsTextSample(kId[0], kStartTime, kStartTime + kSampleDuration, kNoSettings, kPayload[0]))); - + EXPECT_CALL( + *Output(kOutputIndex), + OnProcess(IsSegmentInfo(kStreamIndex, kStartTimeSigned, + kSegmentDuration, !kSubSegment, !kEncrypted))); EXPECT_CALL(*Output(kOutputIndex), OnFlush(kStreamIndex)); } @@ -98,25 +97,25 @@ TEST_F(WebVttSegmenterTest, CreatesSegmentsForCues) { EXPECT_CALL(*Output(kOutputIndex), OnProcess(IsStreamInfo(kStreamIndex))); // Segment One - EXPECT_CALL( - *Output(kOutputIndex), - OnProcess(IsSegmentInfo(kStreamIndex, kStartTimeSigned, - kSegmentDuration, !kSubSegment, !kEncrypted))); EXPECT_CALL( *Output(kOutputIndex), OnProcess(IsTextSample(kId[0], kStartTime, kStartTime + kSampleDuration, kNoSettings, kPayload[0]))); + EXPECT_CALL( + *Output(kOutputIndex), + OnProcess(IsSegmentInfo(kStreamIndex, kStartTimeSigned, + kSegmentDuration, !kSubSegment, !kEncrypted))); // Segment Two - EXPECT_CALL(*Output(kOutputIndex), - OnProcess(IsSegmentInfo( - kStreamIndex, kStartTimeSigned + kSegmentDuration, - kSegmentDuration, !kSubSegment, !kEncrypted))); EXPECT_CALL( *Output(kOutputIndex), OnProcess(IsTextSample(kId[1], kStartTime + kSegmentDuration, kStartTime + kSegmentDuration + kSampleDuration, kNoSettings, kPayload[1]))); + EXPECT_CALL(*Output(kOutputIndex), + OnProcess(IsSegmentInfo( + kStreamIndex, kStartTimeSigned + kSegmentDuration, + kSegmentDuration, !kSubSegment, !kEncrypted))); EXPECT_CALL(*Output(kOutputIndex), OnFlush(kStreamIndex)); } @@ -152,27 +151,27 @@ TEST_F(WebVttSegmenterTest, SkipsEmptySegments) { EXPECT_CALL(*Output(kOutputIndex), OnProcess(IsStreamInfo(kStreamIndex))); // Segment One - EXPECT_CALL( - *Output(kOutputIndex), - OnProcess(IsSegmentInfo(kStreamIndex, kStartTimeSigned, - kSegmentDuration, !kSubSegment, !kEncrypted))); EXPECT_CALL( *Output(kOutputIndex), OnProcess(IsTextSample(kId[0], kStartTime, kStartTime + kSampleDuration, kNoSettings, kPayload[0]))); + EXPECT_CALL( + *Output(kOutputIndex), + OnProcess(IsSegmentInfo(kStreamIndex, kStartTimeSigned, + kSegmentDuration, !kSubSegment, !kEncrypted))); // There is no segment two // Segment Three - EXPECT_CALL(*Output(kOutputIndex), - OnProcess(IsSegmentInfo( - kStreamIndex, kStartTimeSigned + 2 * kSegmentDuration, - kSegmentDuration, !kSubSegment, !kEncrypted))); EXPECT_CALL(*Output(kOutputIndex), OnProcess(IsTextSample( kId[1], kStartTime + 2 * kSegmentDuration, kStartTime + 2 * kSegmentDuration + kSampleDuration, kNoSettings, kPayload[1]))); + EXPECT_CALL(*Output(kOutputIndex), + OnProcess(IsSegmentInfo( + kStreamIndex, kStartTimeSigned + 2 * kSegmentDuration, + kSegmentDuration, !kSubSegment, !kEncrypted))); EXPECT_CALL(*Output(kOutputIndex), OnFlush(kStreamIndex)); } @@ -209,24 +208,24 @@ TEST_F(WebVttSegmenterTest, CueCrossesSegments) { EXPECT_CALL(*Output(kOutputIndex), OnProcess(IsStreamInfo(kStreamIndex))); // Segment One + EXPECT_CALL( + *Output(kOutputIndex), + OnProcess(IsTextSample(kId[0], kStartTime, kStartTime + kSampleDuration, + kNoSettings, kPayload[0]))); EXPECT_CALL( *Output(kOutputIndex), OnProcess(IsSegmentInfo(kStreamIndex, kStartTimeSigned, kSegmentDuration, !kSubSegment, !kEncrypted))); + + // Segment Two EXPECT_CALL( *Output(kOutputIndex), OnProcess(IsTextSample(kId[0], kStartTime, kStartTime + kSampleDuration, kNoSettings, kPayload[0]))); - - // Segment Two EXPECT_CALL(*Output(kOutputIndex), OnProcess(IsSegmentInfo( kStreamIndex, kStartTimeSigned + kSegmentDuration, kSegmentDuration, !kSubSegment, !kEncrypted))); - EXPECT_CALL( - *Output(kOutputIndex), - OnProcess(IsTextSample(kId[0], kStartTime, kStartTime + kSampleDuration, - kNoSettings, kPayload[0]))); EXPECT_CALL(*Output(kOutputIndex), OnFlush(kStreamIndex)); }