Improve performance of registering font preferences
[chromium-blink-merge.git] / media / webm / webm_stream_parser.h
blob36401510075340f79380b5cab663d23f8d14aa8c
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_WEBM_WEBM_STREAM_PARSER_H_
6 #define MEDIA_WEBM_WEBM_STREAM_PARSER_H_
8 #include "base/callback_forward.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/base/audio_decoder_config.h"
11 #include "media/base/buffers.h"
12 #include "media/base/byte_queue.h"
13 #include "media/base/stream_parser.h"
14 #include "media/base/video_decoder_config.h"
15 #include "media/webm/webm_cluster_parser.h"
17 namespace media {
19 class WebMStreamParser : public StreamParser {
20 public:
21 WebMStreamParser();
22 virtual ~WebMStreamParser();
24 // StreamParser implementation.
25 virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb,
26 const NewBuffersCB& audio_cb,
27 const NewBuffersCB& video_cb,
28 const NeedKeyCB& need_key_cb,
29 const NewMediaSegmentCB& new_segment_cb,
30 const base::Closure& end_of_segment_cb) OVERRIDE;
31 virtual void Flush() OVERRIDE;
32 virtual bool Parse(const uint8* buf, int size) OVERRIDE;
34 private:
35 enum State {
36 kWaitingForInit,
37 kParsingHeaders,
38 kParsingClusters,
39 kError
42 void ChangeState(State new_state);
44 // Parses WebM Header, Info, Tracks elements. It also skips other level 1
45 // elements that are not used right now. Once the Info & Tracks elements have
46 // been parsed, this method will transition the parser from PARSING_HEADERS to
47 // PARSING_CLUSTERS.
49 // Returns < 0 if the parse fails.
50 // Returns 0 if more data is needed.
51 // Returning > 0 indicates success & the number of bytes parsed.
52 int ParseInfoAndTracks(const uint8* data, int size);
54 // Incrementally parses WebM cluster elements. This method also skips
55 // CUES elements if they are encountered since we currently don't use the
56 // data in these elements.
58 // Returns < 0 if the parse fails.
59 // Returns 0 if more data is needed.
60 // Returning > 0 indicates success & the number of bytes parsed.
61 int ParseCluster(const uint8* data, int size);
63 // Fire needkey event through the |need_key_cb_|.
64 void FireNeedKey(const std::string& key_id);
66 State state_;
67 InitCB init_cb_;
68 NewConfigCB config_cb_;
69 NewBuffersCB audio_cb_;
70 NewBuffersCB video_cb_;
71 NeedKeyCB need_key_cb_;
72 NewMediaSegmentCB new_segment_cb_;
73 base::Closure end_of_segment_cb_;
75 // True if a new cluster id has been seen, but no audio or video buffers have
76 // been parsed yet.
77 bool waiting_for_buffers_;
79 scoped_ptr<WebMClusterParser> cluster_parser_;
80 ByteQueue byte_queue_;
82 DISALLOW_COPY_AND_ASSIGN(WebMStreamParser);
85 } // namespace media
87 #endif // MEDIA_WEBM_WEBM_STREAM_PARSER_H_