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)); }