15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file.
490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef MEDIA_FORMATS_WEBM_WEBM_WEBVTT_PARSER_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define MEDIA_FORMATS_WEBM_WEBM_WEBVTT_PARSER_H_
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <string>
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/basictypes.h"
1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "media/base/media_export.h"
1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace media {
1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class MEDIA_EXPORT WebMWebVTTParser {
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public:
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Utility function to parse the WebVTT cue from a byte stream.
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static void Parse(const uint8* payload, int payload_size,
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                    std::string* id,
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                    std::string* settings,
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                    std::string* content);
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private:
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The payload is the embedded WebVTT cue, stored in a WebM block.
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // The parser treats this as a UTF-8 byte stream.
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  WebMWebVTTParser(const uint8* payload, int payload_size);
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Parse the cue identifier, settings, and content from the stream.
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void Parse(std::string* id, std::string* settings, std::string* content);
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Remove a byte from the stream, advancing the stream pointer.
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Returns true if a character was returned; false means "end of stream".
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool GetByte(uint8* byte);
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Backup the stream pointer.
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void UngetByte();
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Parse a line of text from the stream.
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void ParseLine(std::string* line);
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Represents the portion of the stream that has not been consumed yet.
4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const uint8* ptr_;
4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const uint8* const ptr_end_;
4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WebMWebVTTParser);
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace media
4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // MEDIA_FORMATS_WEBM_WEBM_WEBVTT_PARSER_H_
50