Diff
Modified: trunk/LayoutTests/ChangeLog (236264 => 236265)
--- trunk/LayoutTests/ChangeLog 2018-09-20 16:46:58 UTC (rev 236264)
+++ trunk/LayoutTests/ChangeLog 2018-09-20 17:07:03 UTC (rev 236265)
@@ -1,3 +1,15 @@
+2018-09-20 Per Arne Vollan <[email protected]>
+
+ [WebVTT] Update the parser according to the new region syntax.
+ https://bugs.webkit.org/show_bug.cgi?id=189767
+
+ Reviewed by Eric Carlson.
+
+ * media/track/captions-webvtt/captions-regions.vtt:
+ * media/track/captions-webvtt/header-regions.vtt:
+ * media/track/regions-webvtt/vtt-region-parser-expected.txt:
+ * media/track/regions-webvtt/vtt-region-parser.html:
+
2018-09-19 Ryan Haddad <[email protected]>
[macOS Sierra] Layout Test http/wpt/cache-storage/cache-put-keys.https.any.worker.html is a flaky failure
Modified: trunk/LayoutTests/media/track/captions-webvtt/captions-regions.vtt (236264 => 236265)
--- trunk/LayoutTests/media/track/captions-webvtt/captions-regions.vtt 2018-09-20 16:46:58 UTC (rev 236264)
+++ trunk/LayoutTests/media/track/captions-webvtt/captions-regions.vtt 2018-09-20 17:07:03 UTC (rev 236265)
@@ -1,6 +1,12 @@
WEBVTT FILE
-Region: id=fred width=50% height=2 regionanchor=50%,100% viewportanchor=10%,40%
+REGION
+id=fred
+width=50%
+height=2
+regionanchor=50%,100%
+viewportanchor=10%,40%
+
1
00:00:00.000 --> 00:00:01.500 region:fred
We are in New York City
@@ -16,4 +22,4 @@
4
00:00:02.000 --> 00:00:03.000 region:fred
-Fourth cue!
\ No newline at end of file
+Fourth cue!
Modified: trunk/LayoutTests/media/track/captions-webvtt/header-regions.vtt (236264 => 236265)
--- trunk/LayoutTests/media/track/captions-webvtt/header-regions.vtt 2018-09-20 16:46:58 UTC (rev 236264)
+++ trunk/LayoutTests/media/track/captions-webvtt/header-regions.vtt 2018-09-20 17:07:03 UTC (rev 236265)
@@ -1,10 +1,31 @@
WEBVTT FILE
-Region: id=region_without_settings
-Region: id=region_with_all_settings width=32% height=5 regionanchor=41%,20% viewportanchor=31%,84% scroll=up
-Region: id=region_floating_point_anchor regionanchor=41.133%,20.42% viewportanchor=32.33%,32.44%
-Region: id=not_unique_id width=42%
-Region: id=not_unique_id width=67%
-Region: invalid_settings values but region still created
+
+REGION
+id=region_without_settings
+
+REGION
+id=region_with_all_settings
+width=32%
+height=5
+regionanchor=41%,20%
+viewportanchor=31%,84%
+scroll=up
+
+REGION
+id=region_floating_point_anchor
+regionanchor=41.133%,20.42%
+viewportanchor=32.33%,32.44%
+
+REGION
+id=not_unique_id
+width=42%
+
+REGION
+id=not_unique_id
+width=67%
+
+REGION
+invalid_settings values but region still created
: Invalid Header
1
Modified: trunk/LayoutTests/media/track/regions-webvtt/vtt-region-parser-expected.txt (236264 => 236265)
--- trunk/LayoutTests/media/track/regions-webvtt/vtt-region-parser-expected.txt 2018-09-20 16:46:58 UTC (rev 236264)
+++ trunk/LayoutTests/media/track/regions-webvtt/vtt-region-parser-expected.txt 2018-09-20 17:07:03 UTC (rev 236265)
@@ -1,7 +1,7 @@
Tests proper parsing of various regions present in WebVTT header area.
-EXPECTED (video.textTracks[0].regions.length == '5') OK
+EXPECTED (video.textTracks[0].regions.length == '4') OK
EXPECTED (region.id == 'region_without_settings') OK
@@ -23,7 +23,5 @@
EXPECTED (region.id == 'not_unique_id') OK
EXPECTED (region.width == '67') OK
-EXPECTED (region.id == '') OK
-
END OF TEST
Modified: trunk/LayoutTests/media/track/regions-webvtt/vtt-region-parser.html (236264 => 236265)
--- trunk/LayoutTests/media/track/regions-webvtt/vtt-region-parser.html 2018-09-20 16:46:58 UTC (rev 236264)
+++ trunk/LayoutTests/media/track/regions-webvtt/vtt-region-parser.html 2018-09-20 17:07:03 UTC (rev 236265)
@@ -16,7 +16,7 @@
}
findMediaElement();
- testExpected("video.textTracks[0].regions.length", 5);
+ testExpected("video.textTracks[0].regions.length", 4);
consoleWrite("");
region = video.textTracks[0].regions[0];
@@ -47,10 +47,6 @@
testExpected("region.width", 67);
consoleWrite("");
- region = video.textTracks[0].regions[4];
- testExpected("region.id", "");
-
- consoleWrite("");
endTest();
}
Modified: trunk/Source/WebCore/ChangeLog (236264 => 236265)
--- trunk/Source/WebCore/ChangeLog 2018-09-20 16:46:58 UTC (rev 236264)
+++ trunk/Source/WebCore/ChangeLog 2018-09-20 17:07:03 UTC (rev 236265)
@@ -1,3 +1,29 @@
+2018-09-20 Per Arne Vollan <[email protected]>
+
+ [WebVTT] Update the parser according to the new region syntax.
+ https://bugs.webkit.org/show_bug.cgi?id=189767
+
+ Reviewed by Eric Carlson.
+
+ The majority of the code added in this patch is adopted from the Chromium project, which has added
+ support for the new region syntax. The complete parser specification can be found at
+ https://w3c.github.io/webvtt/#file-parsing. One small difference in behavior is that the new parser
+ will not add regions with empty id.
+
+ No new tests, covered by existing tests.
+
+ * html/track/WebVTTParser.cpp:
+ (WebCore::WebVTTParser::getNewRegions):
+ (WebCore::WebVTTParser::parse):
+ (WebCore::WebVTTParser::collectRegionSettings):
+ (WebCore::WebVTTParser::collectWebVTTBlock):
+ (WebCore::WebVTTParser::checkAndRecoverCue):
+ (WebCore::WebVTTParser::checkAndCreateRegion):
+ (WebCore::WebVTTParser::checkAndStoreRegion):
+ (WebCore::WebVTTParser::collectMetadataHeader): Deleted.
+ (WebCore::WebVTTParser::createNewRegion): Deleted.
+ * html/track/WebVTTParser.h:
+
2018-09-20 Alicia Boya GarcĂa <[email protected]>
[GStreamer][MSE] Add a default sample duration
Modified: trunk/Source/WebCore/html/track/WebVTTParser.cpp (236264 => 236265)
--- trunk/Source/WebCore/html/track/WebVTTParser.cpp 2018-09-20 16:46:58 UTC (rev 236264)
+++ trunk/Source/WebCore/html/track/WebVTTParser.cpp 2018-09-20 17:07:03 UTC (rev 236265)
@@ -51,6 +51,7 @@
const double secondsPerMillisecond = 0.001;
const char* fileIdentifier = "WEBVTT";
const unsigned fileIdentifierLength = 6;
+const unsigned regionIdentifierLength = 6;
bool WebVTTParser::parseFloatPercentageValue(VTTScanner& valueScanner, float& percentage)
{
@@ -101,8 +102,7 @@
void WebVTTParser::getNewRegions(Vector<RefPtr<VTTRegion>>& outputRegions)
{
- outputRegions = m_regionList;
- m_regionList.clear();
+ outputRegions = WTFMove(m_regionList);
}
void WebVTTParser::parseFileHeader(String&& data)
@@ -166,20 +166,12 @@
break;
case Header:
- collectMetadataHeader(*line);
+ // Steps 11 - 14 - Collect WebVTT block
+ m_state = collectWebVTTBlock(*line);
+ break;
- if (line->isEmpty()) {
- // Steps 10-14 - Allow a header (comment area) under the WEBVTT line.
- if (m_client && m_regionList.size())
- m_client->newRegionsParsed();
- m_state = Id;
- break;
- }
- // Step 15 - Break out of header loop if the line could be a timestamp line.
- if (line->contains("-->"))
- m_state = recoverCue(*line);
-
- // Step 16 - Line is not the empty string and does not contain "-->".
+ case Region:
+ m_state = collectRegionSettings(*line);
break;
case Id:
@@ -249,28 +241,89 @@
return true;
}
-void WebVTTParser::collectMetadataHeader(const String& line)
+WebVTTParser::ParseState WebVTTParser::collectRegionSettings(const String& line)
{
- // WebVTT header parsing (WebVTT parser algorithm step 12)
- static NeverDestroyed<const AtomicString> regionHeaderName("Region", AtomicString::ConstructFromLiteral);
+ // End of region block
+ if (checkAndStoreRegion(line))
+ return checkAndRecoverCue(line);
+
+ m_currentRegion->setRegionSettings(line);
+ return Region;
+}
- // Step 12.4 If line contains the character ":" (A U+003A COLON), then set metadata's
- // name to the substring of line before the first ":" character and
- // metadata's value to the substring after this character.
- size_t colonPosition = line.find(':');
- if (colonPosition == notFound)
- return;
+WebVTTParser::ParseState WebVTTParser::collectWebVTTBlock(const String& line)
+{
+ // collect a WebVTT block parsing. (WebVTT parser algorithm step 14)
+
+ if (checkAndCreateRegion(line))
+ return Region;
+
+ // Handle cue block.
+ ParseState state = checkAndRecoverCue(line);
+ if (state != Header) {
+ if (m_client && !m_regionList.isEmpty())
+ m_client->newRegionsParsed();
+ if (!m_previousLine.isEmpty() && !m_previousLine.contains("-->"))
+ m_currentId = m_previousLine;
+
+ return state;
+ }
+
+ // store previous line for cue id.
+ // length is more than 1 line clear m_previousLine and ignore line.
+ if (m_previousLine.isEmpty())
+ m_previousLine = line;
+ else
+ m_previousLine = emptyString();
- String headerName = line.substring(0, colonPosition);
+ return state;
+}
- // Step 12.5 If metadata's name equals "Region":
- if (headerName == regionHeaderName) {
- String headerValue = line.substring(colonPosition + 1, line.length() - 1);
- // Steps 12.5.1 - 12.5.11 Region creation: Let region be a new text track region [...]
- createNewRegion(headerValue);
+WebVTTParser::ParseState WebVTTParser::checkAndRecoverCue(const String& line)
+{
+ // parse cue timings and settings
+ if (line.contains("-->")) {
+ ParseState state = recoverCue(line);
+ if (state != BadCue)
+ return state;
}
+ return Header;
}
+bool WebVTTParser::checkAndCreateRegion(const String& line)
+{
+ if (m_previousLine.contains("-->"))
+ return false;
+ // line starts with the substring "REGION" and remaining characters
+ // zero or more U+0020 SPACE characters or U+0009 CHARACTER TABULATION
+ // (tab) characters expected other than these charecters it is invalid.
+ if (line.startsWith("REGION") && line.substring(regionIdentifierLength).isAllSpecialCharacters<isASpace>()) {
+ m_currentRegion = VTTRegion::create(*m_scriptExecutionContext);
+ return true;
+ }
+ return false;
+}
+
+bool WebVTTParser::checkAndStoreRegion(const String& line)
+{
+ if (!line.isEmpty() && !line.contains("-->"))
+ return false;
+
+ if (!m_currentRegion->id().isEmpty()) {
+ // If the text track list of regions regions contains a region
+ // with the same region identifier value as region, remove that region.
+ for (auto region : m_regionList) {
+ if (region->id() == m_currentRegion->id()) {
+ m_regionList.removeFirst(region);
+ break;
+ }
+ }
+ m_regionList.append(m_currentRegion);
+ }
+ m_currentRegion = nullptr;
+ return true;
+}
+
WebVTTParser::ParseState WebVTTParser::collectCueId(const String& line)
{
if (line.contains("-->"))
@@ -422,27 +475,6 @@
m_currentContent.clear();
}
-void WebVTTParser::createNewRegion(const String& headerValue)
-{
- if (headerValue.isEmpty())
- return;
-
- // Steps 12.5.1 - 12.5.9 - Construct and initialize a WebVTT Region object.
- RefPtr<VTTRegion> region = VTTRegion::create(*m_scriptExecutionContext);
- region->setRegionSettings(headerValue);
-
- // Step 12.5.10 If the text track list of regions regions contains a region
- // with the same region identifier value as region, remove that region.
- for (size_t i = 0; i < m_regionList.size(); ++i)
- if (m_regionList[i]->id() == region->id()) {
- m_regionList.remove(i);
- break;
- }
-
- // Step 12.5.11
- m_regionList.append(region);
-}
-
bool WebVTTParser::collectTimeStamp(const String& line, MediaTime& timeStamp)
{
if (line.isEmpty())
Modified: trunk/Source/WebCore/html/track/WebVTTParser.h (236264 => 236265)
--- trunk/Source/WebCore/html/track/WebVTTParser.h 2018-09-20 16:46:58 UTC (rev 236264)
+++ trunk/Source/WebCore/html/track/WebVTTParser.h 2018-09-20 17:07:03 UTC (rev 236265)
@@ -103,6 +103,7 @@
Id,
TimingsAndSettings,
CueText,
+ Region,
BadCue,
Finished
};
@@ -118,6 +119,14 @@
|| tagName == rtTag;
}
+ static inline bool isASpace(UChar c)
+ {
+ // WebVTT space characters are U+0020 SPACE, U+0009 CHARACTER
+ // TABULATION (tab), U+000A LINE FEED (LF), U+000C FORM FEED (FF), and
+ // U+000D CARRIAGE RETURN (CR).
+ return c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r';
+ }
+
static inline bool isValidSettingDelimiter(UChar c)
{
// ... a WebVTT cue consists of zero or more of the following components, in any order, separated from each other by one or more
@@ -157,13 +166,15 @@
ParseState collectCueText(const String&);
ParseState recoverCue(const String&);
ParseState ignoreBadCue(const String&);
-
+ ParseState collectRegionSettings(const String&);
+ ParseState collectWebVTTBlock(const String&);
+ ParseState checkAndRecoverCue(const String& line);
+ bool checkAndCreateRegion(const String& line);
+ bool checkAndStoreRegion(const String& line);
+
void createNewCue();
void resetCueValues();
- void collectMetadataHeader(const String&);
- void createNewRegion(const String& headerValue);
-
static bool collectTimeStamp(VTTScanner& input, MediaTime& timeStamp);
BufferedLineReader m_lineReader;
@@ -172,8 +183,10 @@
MediaTime m_currentStartTime;
MediaTime m_currentEndTime;
StringBuilder m_currentContent;
+ String m_previousLine;
String m_currentSettings;
-
+ RefPtr<VTTRegion> m_currentRegion;
+
WebVTTParserClient* m_client;
Vector<RefPtr<WebVTTCueData>> m_cuelist;