Fix iOS build for XCode 4.6.
[chromium-blink-merge.git] / media / webm / webm_stream_parser.h
blobc98805a146f2fd603cf77a011cde7768b439d12f
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,
31 const LogCB& log_cb) OVERRIDE;
32 virtual void Flush() OVERRIDE;
33 virtual bool Parse(const uint8* buf, int size) OVERRIDE;
35 private:
36 enum State {
37 kWaitingForInit,
38 kParsingHeaders,
39 kParsingClusters,
40 kError
43 void ChangeState(State new_state);
45 // Parses WebM Header, Info, Tracks elements. It also skips other level 1
46 // elements that are not used right now. Once the Info & Tracks elements have
47 // been parsed, this method will transition the parser from PARSING_HEADERS to
48 // PARSING_CLUSTERS.
50 // Returns < 0 if the parse fails.
51 // Returns 0 if more data is needed.
52 // Returning > 0 indicates success & the number of bytes parsed.
53 int ParseInfoAndTracks(const uint8* data, int size);
55 // Incrementally parses WebM cluster elements. This method also skips
56 // CUES elements if they are encountered since we currently don't use the
57 // data in these elements.
59 // Returns < 0 if the parse fails.
60 // Returns 0 if more data is needed.
61 // Returning > 0 indicates success & the number of bytes parsed.
62 int ParseCluster(const uint8* data, int size);
64 // Fire needkey event through the |need_key_cb_|.
65 void FireNeedKey(const std::string& key_id);
67 State state_;
68 InitCB init_cb_;
69 NewConfigCB config_cb_;
70 NewBuffersCB audio_cb_;
71 NewBuffersCB video_cb_;
72 NeedKeyCB need_key_cb_;
73 NewMediaSegmentCB new_segment_cb_;
74 base::Closure end_of_segment_cb_;
75 LogCB log_cb_;
77 // True if a new cluster id has been seen, but no audio or video buffers have
78 // been parsed yet.
79 bool waiting_for_buffers_;
81 scoped_ptr<WebMClusterParser> cluster_parser_;
82 ByteQueue byte_queue_;
84 DISALLOW_COPY_AND_ASSIGN(WebMStreamParser);
87 } // namespace media
89 #endif // MEDIA_WEBM_WEBM_STREAM_PARSER_H_