2015-10-08 21:48:07 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
|
|
|
#ifndef MEDIA_FORMATS_WEBM_WEBM_WEBVTT_PARSER_H_
|
|
|
|
#define MEDIA_FORMATS_WEBM_WEBM_WEBVTT_PARSER_H_
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2015-10-08 21:48:07 +00:00
|
|
|
#include <string>
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
#include "packager/base/macros.h"
|
2015-10-08 21:48:07 +00:00
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
namespace edash_packager {
|
2015-10-08 21:48:07 +00:00
|
|
|
namespace media {
|
|
|
|
|
2015-10-14 22:46:23 +00:00
|
|
|
class WebMWebVTTParser {
|
2015-10-08 21:48:07 +00:00
|
|
|
public:
|
2015-10-15 22:39:16 +00:00
|
|
|
/// Utility function to parse the WebVTT cue from a byte stream.
|
2015-10-14 22:46:23 +00:00
|
|
|
static void Parse(const uint8_t* payload,
|
|
|
|
int payload_size,
|
2015-10-08 21:48:07 +00:00
|
|
|
std::string* id,
|
|
|
|
std::string* settings,
|
|
|
|
std::string* content);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// The payload is the embedded WebVTT cue, stored in a WebM block.
|
|
|
|
// The parser treats this as a UTF-8 byte stream.
|
2015-10-14 22:46:23 +00:00
|
|
|
WebMWebVTTParser(const uint8_t* payload, int payload_size);
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
// Parse the cue identifier, settings, and content from the stream.
|
|
|
|
void Parse(std::string* id, std::string* settings, std::string* content);
|
|
|
|
// Remove a byte from the stream, advancing the stream pointer.
|
|
|
|
// Returns true if a character was returned; false means "end of stream".
|
2015-10-14 22:46:23 +00:00
|
|
|
bool GetByte(uint8_t* byte);
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
// Backup the stream pointer.
|
|
|
|
void UngetByte();
|
|
|
|
|
|
|
|
// Parse a line of text from the stream.
|
|
|
|
void ParseLine(std::string* line);
|
|
|
|
|
|
|
|
// Represents the portion of the stream that has not been consumed yet.
|
2015-10-14 22:46:23 +00:00
|
|
|
const uint8_t* ptr_;
|
|
|
|
const uint8_t* const ptr_end_;
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebMWebVTTParser);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2015-10-14 22:46:23 +00:00
|
|
|
} // namespace edash_packager
|
2015-10-08 21:48:07 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_FORMATS_WEBM_WEBM_WEBVTT_PARSER_H_
|