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_
10 #include "base/callback_forward.h"
11 #include "base/memory/ref_counted.h"
12 #include "media/base/audio_decoder_config.h"
13 #include "media/base/buffers.h"
14 #include "media/base/byte_queue.h"
15 #include "media/base/stream_parser.h"
16 #include "media/base/video_decoder_config.h"
20 class WebMClusterParser
;
22 class WebMStreamParser
: public StreamParser
{
25 virtual ~WebMStreamParser();
27 // StreamParser implementation.
28 virtual void Init(const InitCB
& init_cb
, const NewConfigCB
& config_cb
,
29 const NewBuffersCB
& new_buffers_cb
,
30 const NewTextBuffersCB
& text_cb
,
31 const NeedKeyCB
& need_key_cb
,
32 const AddTextTrackCB
& add_text_track_cb
,
33 const NewMediaSegmentCB
& new_segment_cb
,
34 const base::Closure
& end_of_segment_cb
,
35 const LogCB
& log_cb
) OVERRIDE
;
36 virtual void Flush() OVERRIDE
;
37 virtual bool Parse(const uint8
* buf
, int size
) OVERRIDE
;
47 void ChangeState(State new_state
);
49 // Parses WebM Header, Info, Tracks elements. It also skips other level 1
50 // elements that are not used right now. Once the Info & Tracks elements have
51 // been parsed, this method will transition the parser from PARSING_HEADERS to
54 // Returns < 0 if the parse fails.
55 // Returns 0 if more data is needed.
56 // Returning > 0 indicates success & the number of bytes parsed.
57 int ParseInfoAndTracks(const uint8
* data
, int size
);
59 // Incrementally parses WebM cluster elements. This method also skips
60 // CUES elements if they are encountered since we currently don't use the
61 // data in these elements.
63 // Returns < 0 if the parse fails.
64 // Returns 0 if more data is needed.
65 // Returning > 0 indicates success & the number of bytes parsed.
66 int ParseCluster(const uint8
* data
, int size
);
68 // Fire needkey event through the |need_key_cb_|.
69 void FireNeedKey(const std::string
& key_id
);
73 NewConfigCB config_cb_
;
74 NewBuffersCB new_buffers_cb_
;
75 NewTextBuffersCB text_cb_
;
76 NeedKeyCB need_key_cb_
;
77 AddTextTrackCB add_text_track_cb_
;
79 typedef std::map
<int, TextTrack
* > TextTrackMap
;
80 TextTrackMap text_track_map_
;
82 NewMediaSegmentCB new_segment_cb_
;
83 base::Closure end_of_segment_cb_
;
86 // True if a new cluster id has been seen, but no audio or video buffers have
88 bool waiting_for_buffers_
;
90 scoped_ptr
<WebMClusterParser
> cluster_parser_
;
91 ByteQueue byte_queue_
;
93 DISALLOW_COPY_AND_ASSIGN(WebMStreamParser
);
98 #endif // MEDIA_WEBM_WEBM_STREAM_PARSER_H_