DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
muxer.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 //
7 // Defines the muxer interface.
8 
9 #ifndef MEDIA_BASE_MUXER_H_
10 #define MEDIA_BASE_MUXER_H_
11 
12 #include <memory>
13 #include <vector>
14 
15 #include "packager/base/time/clock.h"
16 #include "packager/media/base/fourccs.h"
17 #include "packager/media/base/media_handler.h"
18 #include "packager/media/base/muxer_options.h"
19 #include "packager/media/base/status.h"
20 #include "packager/media/event/muxer_listener.h"
21 #include "packager/media/event/progress_listener.h"
22 
23 namespace shaka {
24 namespace media {
25 
26 class KeySource;
27 class MediaSample;
28 class MediaStream;
29 
33 class Muxer : public MediaHandler {
34  public:
35  explicit Muxer(const MuxerOptions& options);
36  virtual ~Muxer();
37 
38  // TODO(kqyang): refactor max_sd_pixels through crypto_period_duration into
39  // an encapsulated EncryptionParams structure.
40 
61  void SetKeySource(KeySource* encryption_key_source,
62  uint32_t max_sd_pixels,
63  uint32_t max_hd_pixels,
64  uint32_t max_uhd1_pixels,
65  double clear_lead_in_seconds,
66  double crypto_period_duration_in_seconds,
67  FourCC protection_scheme);
68 
71  void Cancel();
72 
75  void SetMuxerListener(std::unique_ptr<MuxerListener> muxer_listener);
76 
79  void SetProgressListener(std::unique_ptr<ProgressListener> progress_listener);
80 
81  const std::vector<std::shared_ptr<StreamInfo>>& streams() const {
82  return streams_;
83  }
84 
91  void set_clock(base::Clock* clock) {
92  clock_ = clock;
93  }
94 
95  protected:
98  Status InitializeInternal() override { return Status::OK; }
99  Status Process(std::unique_ptr<StreamData> stream_data) override;
100  Status OnFlushRequest(int input_stream_index) override { return Finalize(); }
102 
103  const MuxerOptions& options() const { return options_; }
104  KeySource* encryption_key_source() {
105  return encryption_key_source_;
106  }
107  uint32_t max_sd_pixels() const { return max_sd_pixels_; }
108  uint32_t max_hd_pixels() const { return max_hd_pixels_; }
109  uint32_t max_uhd1_pixels() const { return max_uhd1_pixels_; }
110  double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
111  double crypto_period_duration_in_seconds() const {
112  return crypto_period_duration_in_seconds_;
113  }
114  MuxerListener* muxer_listener() { return muxer_listener_.get(); }
115  ProgressListener* progress_listener() { return progress_listener_.get(); }
116  base::Clock* clock() { return clock_; }
117  FourCC protection_scheme() const { return protection_scheme_; }
118 
119  private:
120  // Initialize the muxer.
121  virtual Status InitializeMuxer() = 0;
122 
123  // Final clean up.
124  virtual Status Finalize() = 0;
125 
126  // AddSample implementation.
127  virtual Status DoAddSample(std::shared_ptr<MediaSample> sample) = 0;
128 
129  MuxerOptions options_;
130  std::vector<std::shared_ptr<StreamInfo>> streams_;
131  KeySource* encryption_key_source_;
132  uint32_t max_sd_pixels_;
133  uint32_t max_hd_pixels_;
134  uint32_t max_uhd1_pixels_;
135  double clear_lead_in_seconds_;
136  double crypto_period_duration_in_seconds_;
137  FourCC protection_scheme_;
138  bool cancelled_;
139 
140  std::unique_ptr<MuxerListener> muxer_listener_;
141  std::unique_ptr<ProgressListener> progress_listener_;
142  // An external injected clock, can be NULL.
143  base::Clock* clock_;
144 
145  DISALLOW_COPY_AND_ASSIGN(Muxer);
146 };
147 
148 } // namespace media
149 } // namespace shaka
150 
151 #endif // MEDIA_BASE_MUXER_H_
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18
void SetProgressListener(std::unique_ptr< ProgressListener > progress_listener)
Definition: muxer.cc:56
Status InitializeInternal() override
Definition: muxer.h:98
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:30
void SetKeySource(KeySource *encryption_key_source, uint32_t max_sd_pixels, uint32_t max_hd_pixels, uint32_t max_uhd1_pixels, double clear_lead_in_seconds, double crypto_period_duration_in_seconds, FourCC protection_scheme)
Definition: muxer.cc:31
Status Process(std::unique_ptr< StreamData > stream_data) override
Definition: muxer.cc:61
void set_clock(base::Clock *clock)
Definition: muxer.h:91
Status OnFlushRequest(int input_stream_index) override
Event handler for flush request at the specific input stream index.
Definition: muxer.h:100
void SetMuxerListener(std::unique_ptr< MuxerListener > muxer_listener)
Definition: muxer.cc:52