| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/formats/webm/webm_webvtt_parser.h" | 5 #include "media/formats/webm/webm_webvtt_parser.h" |
| 6 | 6 |
| 7 namespace media { | 7 namespace media { |
| 8 | 8 |
| 9 void WebMWebVTTParser::Parse(const uint8* payload, int payload_size, | 9 void WebMWebVTTParser::Parse(const uint8_t* payload, |
| 10 int payload_size, |
| 10 std::string* id, | 11 std::string* id, |
| 11 std::string* settings, | 12 std::string* settings, |
| 12 std::string* content) { | 13 std::string* content) { |
| 13 WebMWebVTTParser parser(payload, payload_size); | 14 WebMWebVTTParser parser(payload, payload_size); |
| 14 parser.Parse(id, settings, content); | 15 parser.Parse(id, settings, content); |
| 15 } | 16 } |
| 16 | 17 |
| 17 WebMWebVTTParser::WebMWebVTTParser(const uint8* payload, int payload_size) | 18 WebMWebVTTParser::WebMWebVTTParser(const uint8_t* payload, int payload_size) |
| 18 : ptr_(payload), | 19 : ptr_(payload), ptr_end_(payload + payload_size) {} |
| 19 ptr_end_(payload + payload_size) { | |
| 20 } | |
| 21 | 20 |
| 22 void WebMWebVTTParser::Parse(std::string* id, | 21 void WebMWebVTTParser::Parse(std::string* id, |
| 23 std::string* settings, | 22 std::string* settings, |
| 24 std::string* content) { | 23 std::string* content) { |
| 25 ParseLine(id); | 24 ParseLine(id); |
| 26 ParseLine(settings); | 25 ParseLine(settings); |
| 27 content->assign(ptr_, ptr_end_); | 26 content->assign(ptr_, ptr_end_); |
| 28 } | 27 } |
| 29 | 28 |
| 30 bool WebMWebVTTParser::GetByte(uint8* byte) { | 29 bool WebMWebVTTParser::GetByte(uint8_t* byte) { |
| 31 if (ptr_ >= ptr_end_) | 30 if (ptr_ >= ptr_end_) |
| 32 return false; // indicates end-of-stream | 31 return false; // indicates end-of-stream |
| 33 | 32 |
| 34 *byte = *ptr_++; | 33 *byte = *ptr_++; |
| 35 return true; | 34 return true; |
| 36 } | 35 } |
| 37 | 36 |
| 38 void WebMWebVTTParser::UngetByte() { | 37 void WebMWebVTTParser::UngetByte() { |
| 39 --ptr_; | 38 --ptr_; |
| 40 } | 39 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 52 | 51 |
| 53 // The spec is here: | 52 // The spec is here: |
| 54 // http://wiki.webmproject.org/webm-metadata/temporal-metadata/webvtt-in-webm | 53 // http://wiki.webmproject.org/webm-metadata/temporal-metadata/webvtt-in-webm |
| 55 | 54 |
| 56 enum { | 55 enum { |
| 57 kLF = '\x0A', | 56 kLF = '\x0A', |
| 58 kCR = '\x0D' | 57 kCR = '\x0D' |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 for (;;) { | 60 for (;;) { |
| 62 uint8 byte; | 61 uint8_t byte; |
| 63 | 62 |
| 64 if (!GetByte(&byte) || byte == kLF) | 63 if (!GetByte(&byte) || byte == kLF) |
| 65 return; | 64 return; |
| 66 | 65 |
| 67 if (byte == kCR) { | 66 if (byte == kCR) { |
| 68 if (GetByte(&byte) && byte != kLF) | 67 if (GetByte(&byte) && byte != kLF) |
| 69 UngetByte(); | 68 UngetByte(); |
| 70 | 69 |
| 71 return; | 70 return; |
| 72 } | 71 } |
| 73 | 72 |
| 74 line->push_back(byte); | 73 line->push_back(byte); |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 | 76 |
| 78 } // namespace media | 77 } // namespace media |
| OLD | NEW |