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