DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
webm_stream_parser.h
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.
4 
5 #ifndef MEDIA_FORMATS_WEBM_WEBM_STREAM_PARSER_H_
6 #define MEDIA_FORMATS_WEBM_WEBM_STREAM_PARSER_H_
7 
8 #include "packager/base/callback_forward.h"
9 #include "packager/base/memory/ref_counted.h"
10 #include "packager/media/base/byte_queue.h"
11 #include "packager/media/base/media_parser.h"
12 
13 namespace edash_packager {
14 namespace media {
15 
16 class WebMClusterParser;
17 
18 class WebMStreamParser : public MediaParser {
19  public:
21  ~WebMStreamParser() override;
22 
23  // StreamParser implementation.
24  void Init(const InitCB& init_cb,
25  const NewSampleCB& new_sample_cb,
26  KeySource* decryption_key_source) override;
27  void Flush() override;
28  bool Parse(const uint8_t* buf, int size) override;
29 
30  private:
31  enum State {
32  kWaitingForInit,
33  kParsingHeaders,
34  kParsingClusters,
35  kError
36  };
37 
38  void ChangeState(State new_state);
39 
40  // Parses WebM Header, Info, Tracks elements. It also skips other level 1
41  // elements that are not used right now. Once the Info & Tracks elements have
42  // been parsed, this method will transition the parser from PARSING_HEADERS to
43  // PARSING_CLUSTERS.
44  //
45  // Returns < 0 if the parse fails.
46  // Returns 0 if more data is needed.
47  // Returning > 0 indicates success & the number of bytes parsed.
48  int ParseInfoAndTracks(const uint8_t* data, int size);
49 
50  // Incrementally parses WebM cluster elements. This method also skips
51  // CUES elements if they are encountered since we currently don't use the
52  // data in these elements.
53  //
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 ParseCluster(const uint8_t* data, int size);
58 
59  // Fire needkey event through the |encrypted_media_init_data_cb_|.
60  void OnEncryptedMediaInitData(const std::string& key_id);
61 
62  State state_;
63  InitCB init_cb_;
64  NewSampleCB new_sample_cb_;
65  KeySource* decryption_key_source_;
66  bool ignore_text_tracks_;
67 
68  bool unknown_segment_size_;
69 
70  scoped_ptr<WebMClusterParser> cluster_parser_;
71  ByteQueue byte_queue_;
72 
73  DISALLOW_COPY_AND_ASSIGN(WebMStreamParser);
74 };
75 
76 } // namespace media
77 } // namespace edash_packager
78 
79 #endif // MEDIA_FORMATS_WEBM_WEBM_STREAM_PARSER_H_
bool Parse(const uint8_t *buf, int size) override
base::Callback< bool(uint32_t track_id, const scoped_refptr< MediaSample > &media_sample)> NewSampleCB
Definition: media_parser.h:43
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:29
base::Callback< void(const std::vector< scoped_refptr< StreamInfo > > &stream_info)> InitCB
Definition: media_parser.h:34
void Init(const InitCB &init_cb, const NewSampleCB &new_sample_cb, KeySource *decryption_key_source) override