Chromium Code Reviews| Index: media/webm/webm_parser.h |
| diff --git a/media/webm/webm_parser.h b/media/webm/webm_parser.h |
| index 7d15f9bbb8aac788135707a20b1ba31734966b9e..627a2d45a086330d43bf51b2a90b83a911786815 100644 |
| --- a/media/webm/webm_parser.h |
| +++ b/media/webm/webm_parser.h |
| @@ -6,8 +6,10 @@ |
| #define MEDIA_WEBM_WEBM_PARSER_H_ |
| #include <string> |
| +#include <vector> |
| #include "base/basictypes.h" |
| +#include "media/base/media_export.h" |
| namespace media { |
| @@ -21,7 +23,7 @@ namespace media { |
| // indicates whether the parsed data is valid. If false is returned |
| // then the parse is immediately terminated and an error is reported by the |
| // parser. |
| -class WebMParserClient { |
| +class MEDIA_EXPORT WebMParserClient { |
| public: |
| virtual ~WebMParserClient(); |
| @@ -34,6 +36,104 @@ class WebMParserClient { |
| virtual bool OnSimpleBlock(int track_num, int timecode, |
| int flags, |
| const uint8* data, int size) = 0; |
| + protected: |
| + WebMParserClient(); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebMParserClient); |
| +}; |
| + |
| +struct ListElementInfo; |
| + |
| +// Parses a WebM list element and all of its children. This |
| +// class supports incremental parsing of the list so Parse() |
| +// can be called multiple times with pieces of the list. |
| +// IsParsingComplete() will return true once the entire list has |
| +// been parsed. |
| +class MEDIA_EXPORT WebMListParser { |
| + public: |
| + // |id| - Element ID of the list we intend to parse. |
| + WebMListParser(int id); |
| + ~WebMListParser(); |
| + |
| + // Resets the state of the parser so it can start parsing a new list. |
| + void Reset(); |
| + |
| + // Parses list data contained in |buf|. |
| + // |client| Called as different elements in the list are parsed. |
| + // |
| + // Returns < 0 if the parse fails. |
| + // Returns 0 if more data is needed. |
| + // Returning > 0 indicates success & the number of bytes parsed. |
| + int Parse(const uint8* buf, int size, WebMParserClient* client); |
| + |
| + // Returns true if the entire list has been parsed. |
| + bool IsParsingComplete() const; |
| + |
| + private: |
| + enum State { |
| + NEED_LIST_HEADER, |
| + INSIDE_LIST, |
| + DONE_PARSING_LIST, |
| + PARSE_ERROR, |
| + }; |
| + |
| + struct ListState { |
| + int id_; |
| + int size_; |
| + int bytes_parsed_; |
| + const ListElementInfo* element_info_; |
| + }; |
| + |
| + void ChangeState(State new_state); |
| + |
| + // Parses a single element in the current list. |
| + // |
| + // |header_size| - The size of the element header |
| + // |id| - The ID of the element being parsed. |
| + // |element_size| - The size of the element body. |
| + // |data| - Pointer to the element contents. |
| + // |size| - Number of bytes in |data| |
| + // |client| - Client to pass the parsed data to. |
| + // |
| + // Returns < 0 if the parse fails. |
| + // Returns 0 if more data is needed. |
| + // Returning > 0 indicates success & the number of bytes parsed. |
| + int ParseListElement(int header_size, |
| + int id, int64 element_size, |
| + const uint8* data, int size, |
| + WebMParserClient* client); |
| + |
| + // Called when starting to parse a new list. |
| + // |
| + // |id| - The ID of the new list. |
| + // |size| - The size of the new list. |
| + // |client| - The client object to notify that a new list is being parsed. |
| + // |
| + // Returns true if this list can be started in the current context. False |
| + // if starting this list causes some sort of parse error. |
| + bool OnListStart(int id, int64 size, WebMParserClient* client); |
| + |
| + // Called when the end of the current list has been reached. This may also |
| + // signal the end of the current list's ancestors if the current list happens |
| + // to be at the end of its parent. |
| + // |
| + // |client| - The client to notify about lists ending. |
| + // |
| + // Returns true if no errors occurred while ending this list(s). |
| + bool OnListEnd(WebMParserClient* client); |
| + |
| + State state_; |
| + |
| + // Element ID passed to the constructor. |
| + int root_id_; |
| + |
| + // Element level for |root_id_|. Used to verify that elements appear at |
| + // the correct level. |
| + int root_level_; |
| + |
| + // Stack of state for all the lists currently being parsed. Lists are |
| + // added and removed from this stack as they are parsed. |
| + std::vector<ListState> list_state_stack_; |
| }; |
|
scherkus (not reviewing)
2011/12/09 18:18:04
DISALLOW etc
acolwell GONE FROM CHROMIUM
2011/12/09 19:06:10
Done.
|
| // Parses an element header & returns the ID and element size. |
| @@ -47,15 +147,6 @@ class WebMParserClient { |
| int WebMParseElementHeader(const uint8* buf, int size, |
| int* id, int64* element_size); |
| -// Parses a single list element that matches |id|. This method fails if the |
| -// buffer points to an element that does not match |id|. |
| -// |
| -// Returns -1 if the parse fails. |
| -// Returns 0 if more data is needed. |
| -// Returns the number of bytes parsed on success. |
| -int WebMParseListElement(const uint8* buf, int size, int id, |
| - int level, WebMParserClient* client); |
| - |
| } // namespace media |
| #endif // MEDIA_WEBM_WEBM_PARSER_H_ |