1 // Copyright 2014 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_FORMATS_WEBM_WEBM_STREAM_PARSER_H_
6 #define MEDIA_FORMATS_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"
18 class WebMClusterParser
;
20 class WebMStreamParser
: public StreamParser
{
23 ~WebMStreamParser() override
;
25 // StreamParser implementation.
26 void Init(const InitCB
& init_cb
,
27 const NewConfigCB
& config_cb
,
28 const NewBuffersCB
& new_buffers_cb
,
29 bool ignore_text_tracks
,
30 const EncryptedMediaInitDataCB
& encrypted_media_init_data_cb
,
31 const NewMediaSegmentCB
& new_segment_cb
,
32 const base::Closure
& end_of_segment_cb
,
33 const LogCB
& log_cb
) override
;
34 void Flush() override
;
35 bool Parse(const uint8
* buf
, int size
) override
;
45 void ChangeState(State new_state
);
47 // Parses WebM Header, Info, Tracks elements. It also skips other level 1
48 // elements that are not used right now. Once the Info & Tracks elements have
49 // been parsed, this method will transition the parser from PARSING_HEADERS to
52 // Returns < 0 if the parse fails.
53 // Returns 0 if more data is needed.
54 // Returning > 0 indicates success & the number of bytes parsed.
55 int ParseInfoAndTracks(const uint8
* data
, int size
);
57 // Incrementally parses WebM cluster elements. This method also skips
58 // CUES elements if they are encountered since we currently don't use the
59 // data in these elements.
61 // Returns < 0 if the parse fails.
62 // Returns 0 if more data is needed.
63 // Returning > 0 indicates success & the number of bytes parsed.
64 int ParseCluster(const uint8
* data
, int size
);
66 // Fire needkey event through the |encrypted_media_init_data_cb_|.
67 void OnEncryptedMediaInitData(const std::string
& key_id
);
71 NewConfigCB config_cb_
;
72 NewBuffersCB new_buffers_cb_
;
73 bool ignore_text_tracks_
;
74 EncryptedMediaInitDataCB encrypted_media_init_data_cb_
;
76 NewMediaSegmentCB new_segment_cb_
;
77 base::Closure end_of_segment_cb_
;
80 bool unknown_segment_size_
;
82 scoped_ptr
<WebMClusterParser
> cluster_parser_
;
83 ByteQueue byte_queue_
;
85 DISALLOW_COPY_AND_ASSIGN(WebMStreamParser
);
90 #endif // MEDIA_FORMATS_WEBM_WEBM_STREAM_PARSER_H_