From 308b92d16e0c0abb660fbb8f35d568a800620041 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Mon, 16 Jul 2018 16:39:41 -0700 Subject: [PATCH] [WebVTT] support cues without payload WebVTT cues without payload may not carry meaningful information, but it is allowed by WebVTT specification [1]. It could also be useful sometimes, e.g. to signal the time progression in live case. Fixes #433. [1] https://www.w3.org/TR/webvtt1/#types-of-webvtt-cue-payload Change-Id: I9e31f4a3789cbdafb7667b64f4019834190ecfc0 --- .../media/formats/webvtt/webvtt_parser.cc | 5 +-- .../formats/webvtt/webvtt_parser_unittest.cc | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) 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"