| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef MEDIA_WEBM_WEBM_STREAM_PARSER_H_ | 5 #ifndef MEDIA_WEBM_WEBM_STREAM_PARSER_H_ |
| 6 #define MEDIA_WEBM_WEBM_STREAM_PARSER_H_ | 6 #define MEDIA_WEBM_WEBM_STREAM_PARSER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
| 11 #include "media/base/buffers.h" | 11 #include "media/base/buffers.h" |
| 12 #include "media/base/byte_queue.h" |
| 12 #include "media/base/stream_parser.h" | 13 #include "media/base/stream_parser.h" |
| 13 #include "media/base/video_decoder_config.h" | 14 #include "media/base/video_decoder_config.h" |
| 14 #include "media/webm/webm_cluster_parser.h" | 15 #include "media/webm/webm_cluster_parser.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 class WebMStreamParser : public StreamParser { | 19 class WebMStreamParser : public StreamParser { |
| 19 public: | 20 public: |
| 20 WebMStreamParser(); | 21 WebMStreamParser(); |
| 21 virtual ~WebMStreamParser(); | 22 virtual ~WebMStreamParser(); |
| 22 | 23 |
| 23 // StreamParser implementation. | 24 // StreamParser implementation. |
| 24 virtual void Init(const InitCB& init_cb, StreamParserHost* host) OVERRIDE; | 25 virtual void Init(const InitCB& init_cb, StreamParserHost* host) OVERRIDE; |
| 25 virtual void Flush() OVERRIDE; | 26 virtual void Flush() OVERRIDE; |
| 26 virtual int Parse(const uint8* buf, int size) OVERRIDE; | 27 virtual bool Parse(const uint8* buf, int size) OVERRIDE; |
| 27 | 28 |
| 28 private: | 29 private: |
| 29 enum State { | 30 enum State { |
| 30 WAITING_FOR_INIT, | 31 kWaitingForInit, |
| 31 PARSING_HEADERS, | 32 kParsingHeaders, |
| 32 PARSING_CLUSTERS | 33 kParsingClusters, |
| 34 kError |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 void ChangeState(State new_state); | 37 void ChangeState(State new_state); |
| 36 | 38 |
| 37 // Parses WebM Header, Info, Tracks elements. It also skips other level 1 | 39 // Parses WebM Header, Info, Tracks elements. It also skips other level 1 |
| 38 // elements that are not used right now. Once the Info & Tracks elements have | 40 // elements that are not used right now. Once the Info & Tracks elements have |
| 39 // been parsed, this method will transition the parser from PARSING_HEADERS to | 41 // been parsed, this method will transition the parser from PARSING_HEADERS to |
| 40 // PARSING_CLUSTERS. | 42 // PARSING_CLUSTERS. |
| 41 // | 43 // |
| 42 // Returns < 0 if the parse fails. | 44 // Returns < 0 if the parse fails. |
| 43 // Returns 0 if more data is needed. | 45 // Returns 0 if more data is needed. |
| 44 // Returning > 0 indicates success & the number of bytes parsed. | 46 // Returning > 0 indicates success & the number of bytes parsed. |
| 45 int ParseInfoAndTracks(const uint8* data, int size); | 47 int ParseInfoAndTracks(const uint8* data, int size); |
| 46 | 48 |
| 47 // Incrementally parses WebM cluster elements. This method also skips | 49 // Incrementally parses WebM cluster elements. This method also skips |
| 48 // CUES elements if they are encountered since we currently don't use the | 50 // CUES elements if they are encountered since we currently don't use the |
| 49 // data in these elements. | 51 // data in these elements. |
| 50 // | 52 // |
| 51 // Returns < 0 if the parse fails. | 53 // Returns < 0 if the parse fails. |
| 52 // Returns 0 if more data is needed. | 54 // Returns 0 if more data is needed. |
| 53 // Returning > 0 indicates success & the number of bytes parsed. | 55 // Returning > 0 indicates success & the number of bytes parsed. |
| 54 int ParseCluster(const uint8* data, int size); | 56 int ParseCluster(const uint8* data, int size); |
| 55 | 57 |
| 56 State state_; | 58 State state_; |
| 57 InitCB init_cb_; | 59 InitCB init_cb_; |
| 58 StreamParserHost* host_; | 60 StreamParserHost* host_; |
| 59 | 61 |
| 60 scoped_ptr<WebMClusterParser> cluster_parser_; | 62 scoped_ptr<WebMClusterParser> cluster_parser_; |
| 63 ByteQueue byte_queue_; |
| 61 | 64 |
| 62 DISALLOW_COPY_AND_ASSIGN(WebMStreamParser); | 65 DISALLOW_COPY_AND_ASSIGN(WebMStreamParser); |
| 63 }; | 66 }; |
| 64 | 67 |
| 65 } // namespace media | 68 } // namespace media |
| 66 | 69 |
| 67 #endif // MEDIA_WEBM_WEBM_STREAM_PARSER_H_ | 70 #endif // MEDIA_WEBM_WEBM_STREAM_PARSER_H_ |
| OLD | NEW |