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"
19 class WebMStreamParser
: public StreamParser
{
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
;
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
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
);
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
77 bool waiting_for_buffers_
;
79 scoped_ptr
<WebMClusterParser
> cluster_parser_
;
80 ByteQueue byte_queue_
;
82 DISALLOW_COPY_AND_ASSIGN(WebMStreamParser
);
87 #endif // MEDIA_WEBM_WEBM_STREAM_PARSER_H_