Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Unified Diff: media/webm/webm_webvtt_parser.cc

Issue 13419002: Media Source dispatches inband text tracks (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: incorporated aaron's comments Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/webm/webm_webvtt_parser.cc
diff --git a/media/webm/webm_webvtt_parser.cc b/media/webm/webm_webvtt_parser.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9c89243f9c7895288e0e7868fe6aa5ae8f669ae3
--- /dev/null
+++ b/media/webm/webm_webvtt_parser.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/webm/webm_webvtt_parser.h"
+
+namespace media {
+
+void WebMWebVTTParser::Parse(const uint8* payload, int payload_size,
+ std::string* id,
+ std::string* settings,
+ std::string* content) {
+ WebMWebVTTParser parser(payload, payload_size);
+ parser.Parse(id, settings, content);
+}
+
+WebMWebVTTParser::WebMWebVTTParser(const uint8* payload, int payload_size)
+ : ptr_(payload),
+ ptr_end_(payload + payload_size) {
+}
+
+void WebMWebVTTParser::Parse(std::string* id,
+ std::string* settings,
+ std::string* content) {
+ ParseLine(id);
+ ParseLine(settings);
+ content->assign(ptr_, ptr_end_);
+}
+
+bool WebMWebVTTParser::GetByte(uint8* byte) {
+ if (ptr_ >= ptr_end_)
+ return false; // indicates end-of-stream
+
+ *byte = *ptr_++;
+ return true;
+}
+
+void WebMWebVTTParser::UngetByte() {
+ --ptr_;
+}
+
+void WebMWebVTTParser::ParseLine(std::string* line) {
+ line->clear();
+
+ // Consume characters from the stream, until we reach end-of-line.
+
+ // The WebVTT spec states that lines may be terminated in any of the following
+ // three ways:
+ // LF
+ // CR
+ // CR LF
+
+ // The spec is here:
+ // http://wiki.webmproject.org/webm-metadata/temporal-metadata/webvtt-in-webm
+
+ enum {
+ kLF = '\x0A',
+ kCR = '\x0D'
+ };
+
+ for (;;) {
+ uint8 byte;
+
+ if (!GetByte(&byte) || byte == kLF)
+ return;
+
+ if (byte == kCR) {
+ if (GetByte(&byte) && byte != kLF)
+ UngetByte();
+
+ return;
+ }
+
+ line->push_back(byte);
+ }
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698