Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
acolwell GONE FROM CHROMIUM
2013/05/10 18:41:39
nit: s/2012/2013/
Matthew Heaney (Chromium)
2013/05/11 07:29:13
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/webm/webm_webvtt_parser.h" | |
| 6 | |
| 7 namespace media { | |
| 8 | |
| 9 void WebMWebVTTParser::Parse(const uint8* payload, int payload_size, | |
| 10 std::string* id, | |
| 11 std::string* settings, | |
| 12 std::string* content) { | |
| 13 WebMWebVTTParser parser(payload, payload_size); | |
| 14 parser(id, settings, content); | |
| 15 } | |
| 16 | |
| 17 WebMWebVTTParser::WebMWebVTTParser(const uint8* payload, int payload_size) | |
| 18 : ptr_(payload), | |
| 19 ptr_end_(payload + payload_size) { | |
| 20 } | |
| 21 | |
| 22 void WebMWebVTTParser::operator()(std::string* id, | |
|
acolwell GONE FROM CHROMIUM
2013/05/10 18:41:39
nit: It would be better for readability if this fu
Matthew Heaney (Chromium)
2013/05/11 07:29:13
Done.
| |
| 23 std::string* settings, | |
| 24 std::string* content) { | |
| 25 ParseLine(id); | |
| 26 ParseLine(settings); | |
| 27 content->assign(ptr_, ptr_end_); | |
| 28 } | |
| 29 | |
| 30 bool WebMWebVTTParser::GetByte(uint8* byte) { | |
| 31 if (ptr_ >= ptr_end_) | |
| 32 return false; // indicates end-of-stream | |
| 33 | |
| 34 *byte = *ptr_++; | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 void WebMWebVTTParser::UngetByte() { | |
| 39 --ptr_; | |
| 40 } | |
| 41 | |
| 42 void WebMWebVTTParser::ParseLine(std::string* line_ptr) { | |
| 43 std::string& line = *line_ptr; | |
|
acolwell GONE FROM CHROMIUM
2013/05/10 18:41:39
nit: This isn't really necessary. Just use -> belo
Matthew Heaney (Chromium)
2013/05/11 07:29:13
Done.
| |
| 44 line.clear(); | |
| 45 | |
| 46 // Consume characters from the stream, until we reach end-of-line. | |
| 47 | |
| 48 // The WebVTT spec states that lines may be terminated in any of the following | |
| 49 // three ways: | |
| 50 // LF | |
| 51 // CR | |
| 52 // CR LF | |
| 53 | |
| 54 // The spec is here: | |
| 55 // http://wiki.webmproject.org/webm-metadata/temporal-metadata/webvtt-in-webm | |
| 56 | |
| 57 enum { | |
| 58 kLF = '\x0A', | |
| 59 kCR = '\x0D' | |
| 60 }; | |
| 61 | |
| 62 for (;;) { | |
| 63 uint8 byte; | |
| 64 | |
| 65 if (!GetByte(&byte) || byte == kLF) | |
| 66 return; | |
| 67 | |
| 68 if (byte == kCR) { | |
| 69 if (GetByte(&byte) && byte != kLF) | |
| 70 UngetByte(); | |
| 71 | |
| 72 return; | |
| 73 } | |
| 74 | |
| 75 line.push_back(byte); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 } // namespace media | |
| OLD | NEW |