[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
This commit is contained in:
KongQun Yang 2018-07-16 16:39:41 -07:00
parent 83f29ff964
commit 308b92d16e
2 changed files with 47 additions and 3 deletions

View File

@ -163,15 +163,14 @@ bool WebVttParser::Parse() {
} }
// CUE with ID // CUE with ID
if (block.size() > 2 && MaybeCueId(block[0]) && if (block.size() >= 2 && MaybeCueId(block[0]) &&
IsLikelyCueTiming(block[1]) && ParseCueWithId(block)) { IsLikelyCueTiming(block[1]) && ParseCueWithId(block)) {
saw_cue = true; saw_cue = true;
continue; continue;
} }
// CUE with no ID // CUE with no ID
if (block.size() > 1 && IsLikelyCueTiming(block[0]) && if (IsLikelyCueTiming(block[0]) && ParseCueWithNoId(block)) {
ParseCueWithNoId(block)) {
saw_cue = true; saw_cue = true;
continue; continue;
} }

View File

@ -214,6 +214,28 @@ TEST_F(WebVttParserTest, ParseOneCue) {
ASSERT_OK(parser_->Run()); 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) { TEST_F(WebVttParserTest, FailToParseCueWithArrowInId) {
const char* text = const char* text =
"WEBVTT\n" "WEBVTT\n"
@ -250,6 +272,29 @@ TEST_F(WebVttParserTest, ParseOneCueWithId) {
ASSERT_OK(parser_->Run()); 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) { TEST_F(WebVttParserTest, ParseOneCueWithSettings) {
const char* text = const char* text =
"WEBVTT\n" "WEBVTT\n"