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/compiler_specific.h"
10 #include "packager/base/memory/ref_counted.h"
11 #include "packager/media/base/byte_queue.h"
12 #include "packager/media/base/media_parser.h"
13 
14 namespace edash_packager {
15 namespace media {
16 
17 class WebMClusterParser;
18 
19 class WebMMediaParser : public MediaParser {
20  public:
22  ~WebMMediaParser() override;
23 
26  void Init(const InitCB& init_cb,
27  const NewSampleCB& new_sample_cb,
28  KeySource* decryption_key_source) override;
29  bool Flush() override WARN_UNUSED_RESULT;
30  bool Parse(const uint8_t* buf, int size) override WARN_UNUSED_RESULT;
32 
33  private:
34  enum State {
35  kWaitingForInit,
36  kParsingHeaders,
37  kParsingClusters,
38  kError
39  };
40 
41  void ChangeState(State new_state);
42 
43  // Parses WebM Header, Info, Tracks elements. It also skips other level 1
44  // elements that are not used right now. Once the Info & Tracks elements have
45  // been parsed, this method will transition the parser from PARSING_HEADERS to
46  // PARSING_CLUSTERS.
47  //
48  // Returns < 0 if the parse fails.
49  // Returns 0 if more data is needed.
50  // Returning > 0 indicates success & the number of bytes parsed.
51  int ParseInfoAndTracks(const uint8_t* data, int size);
52 
53  // Incrementally parses WebM cluster elements. This method also skips
54  // CUES elements if they are encountered since we currently don't use the
55  // data in these elements.
56  //
57  // Returns < 0 if the parse fails.
58  // Returns 0 if more data is needed.
59  // Returning > 0 indicates success & the number of bytes parsed.
60  int ParseCluster(const uint8_t* data, int size);
61 
62  // Fetch keys for the input key ids. Returns true on success, false otherwise.
63  bool FetchKeysIfNecessary(const std::string& audio_encryption_key_id,
64  const std::string& video_encryption_key_id);
65 
66  State state_;
67  InitCB init_cb_;
68  NewSampleCB new_sample_cb_;
69  KeySource* decryption_key_source_;
70  bool ignore_text_tracks_;
71 
72  bool unknown_segment_size_;
73 
74  scoped_ptr<WebMClusterParser> cluster_parser_;
75  ByteQueue byte_queue_;
76 
77  DISALLOW_COPY_AND_ASSIGN(WebMMediaParser);
78 };
79 
80 } // namespace media
81 } // namespace edash_packager
82 
83 #endif // MEDIA_FORMATS_WEBM_WEBM_MEDIA_PARSER_H_
void Init(const InitCB &init_cb, const NewSampleCB &new_sample_cb, KeySource *decryption_key_source) override
base::Callback< bool(uint32_t track_id, const scoped_refptr< MediaSample > &media_sample)> NewSampleCB
Definition: media_parser.h:44
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:35
base::Callback< void(const std::vector< scoped_refptr< StreamInfo > > &stream_info)> InitCB
Definition: media_parser.h:35
bool Parse(const uint8_t *buf, int size) override WARN_UNUSED_RESULT
bool Flush() override WARN_UNUSED_RESULT