DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
webm_media_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_MEDIA_PARSER_H_
6 #define MEDIA_FORMATS_WEBM_WEBM_MEDIA_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 WebMMediaParser : public MediaParser {
19  public:
21  ~WebMMediaParser() override;
22 
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  // Fetch keys for the input key ids. Returns true on success, false otherwise.
60  bool FetchKeysIfNecessary(const std::string& audio_encryption_key_id,
61  const std::string& video_encryption_key_id);
62 
63  State state_;
64  InitCB init_cb_;
65  NewSampleCB new_sample_cb_;
66  KeySource* decryption_key_source_;
67  bool ignore_text_tracks_;
68 
69  bool unknown_segment_size_;
70 
71  scoped_ptr<WebMClusterParser> cluster_parser_;
72  ByteQueue byte_queue_;
73 
74  DISALLOW_COPY_AND_ASSIGN(WebMMediaParser);
75 };
76 
77 } // namespace media
78 } // namespace edash_packager
79 
80 #endif // MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
bool Parse(const uint8_t *buf, int size) override
void Init(const InitCB &init_cb, const NewSampleCB &new_sample_cb, KeySource *decryption_key_source) override
StreamParser implementation.
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