diff --git a/packager/media/formats/webvtt/webvtt_parser.cc b/packager/media/formats/webvtt/webvtt_parser.cc index 2e225a82e3..901cc6dccb 100644 --- a/packager/media/formats/webvtt/webvtt_parser.cc +++ b/packager/media/formats/webvtt/webvtt_parser.cc @@ -163,15 +163,14 @@ bool WebVttParser::Parse() { } // CUE with ID - if (block.size() > 2 && MaybeCueId(block[0]) && + if (block.size() >= 2 && MaybeCueId(block[0]) && IsLikelyCueTiming(block[1]) && ParseCueWithId(block)) { saw_cue = true; continue; } // CUE with no ID - if (block.size() > 1 && IsLikelyCueTiming(block[0]) && - ParseCueWithNoId(block)) { + if (IsLikelyCueTiming(block[0]) && ParseCueWithNoId(block)) { saw_cue = true; continue; } diff --git a/packager/media/formats/webvtt/webvtt_parser_unittest.cc b/packager/media/formats/webvtt/webvtt_parser_unittest.cc index a4241a430c..1ed0d1b20c 100644 --- a/packager/media/formats/webvtt/webvtt_parser_unittest.cc +++ b/packager/media/formats/webvtt/webvtt_parser_unittest.cc @@ -214,6 +214,28 @@ TEST_F(WebVttParserTest, ParseOneCue) { ASSERT_OK(parser_->Run()); } +TEST_F(WebVttParserTest, ParseOneEmptyCue) { + const char* text = + "WEBVTT\n" + "\n" + "00:01:00.000 --> 01:00:00.000\n" + "\n"; + + ASSERT_NO_FATAL_FAILURE(SetUpAndInitializeGraph(text)); + + { + testing::InSequence s; + EXPECT_CALL(*Output(kOutputIndex), + OnProcess(IsStreamInfo(_, kTimeScale, !kEncrypted, _))); + EXPECT_CALL( + *Output(kOutputIndex), + OnProcess(IsTextSample(_, kNoId, 60000u, 3600000u, kNoSettings, ""))); + EXPECT_CALL(*Output(kOutputIndex), OnFlush(_)); + } + + ASSERT_OK(parser_->Run()); +} + TEST_F(WebVttParserTest, FailToParseCueWithArrowInId) { const char* text = "WEBVTT\n" @@ -250,6 +272,29 @@ TEST_F(WebVttParserTest, ParseOneCueWithId) { ASSERT_OK(parser_->Run()); } +TEST_F(WebVttParserTest, ParseOneEmptyCueWithId) { + const char* text = + "WEBVTT\n" + "\n" + "id\n" + "00:01:00.000 --> 01:00:00.000\n" + "\n"; + + ASSERT_NO_FATAL_FAILURE(SetUpAndInitializeGraph(text)); + + { + testing::InSequence s; + EXPECT_CALL(*Output(kOutputIndex), + OnProcess(IsStreamInfo(_, kTimeScale, !kEncrypted, _))); + EXPECT_CALL( + *Output(kOutputIndex), + OnProcess(IsTextSample(_, "id", 60000u, 3600000u, kNoSettings, ""))); + EXPECT_CALL(*Output(kOutputIndex), OnFlush(_)); + } + + ASSERT_OK(parser_->Run()); +} + TEST_F(WebVttParserTest, ParseOneCueWithSettings) { const char* text = "WEBVTT\n"