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/memory/ref_counted.h"
16 #include "packager/base/time/clock.h"
17 #include "packager/media/base/fourccs.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 {
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 
70  void AddStream(MediaStream* stream);
71 
73  Status Run();
74 
77  void Cancel();
78 
81  void SetMuxerListener(std::unique_ptr<MuxerListener> muxer_listener);
82 
85  void SetProgressListener(std::unique_ptr<ProgressListener> progress_listener);
86 
87  const std::vector<MediaStream*>& streams() const { return streams_; }
88 
95  void set_clock(base::Clock* clock) {
96  clock_ = clock;
97  }
98 
99  protected:
100  const MuxerOptions& options() const { return options_; }
101  KeySource* encryption_key_source() {
102  return encryption_key_source_;
103  }
104  uint32_t max_sd_pixels() const { return max_sd_pixels_; }
105  uint32_t max_hd_pixels() const { return max_hd_pixels_; }
106  uint32_t max_uhd1_pixels() const { return max_uhd1_pixels_; }
107  double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
108  double crypto_period_duration_in_seconds() const {
109  return crypto_period_duration_in_seconds_;
110  }
111  MuxerListener* muxer_listener() { return muxer_listener_.get(); }
112  ProgressListener* progress_listener() { return progress_listener_.get(); }
113  base::Clock* clock() { return clock_; }
114  FourCC protection_scheme() const { return protection_scheme_; }
115 
116  private:
117  friend class MediaStream; // Needed to access AddSample.
118 
119  // Add new media sample.
120  Status AddSample(const MediaStream* stream,
121  scoped_refptr<MediaSample> sample);
122 
123  // Initialize the muxer.
124  virtual Status Initialize() = 0;
125 
126  // Final clean up.
127  virtual Status Finalize() = 0;
128 
129  // AddSample implementation.
130  virtual Status DoAddSample(const MediaStream* stream,
131  scoped_refptr<MediaSample> sample) = 0;
132 
133  MuxerOptions options_;
134  bool initialized_;
135  std::vector<MediaStream*> streams_;
136  KeySource* encryption_key_source_;
137  uint32_t max_sd_pixels_;
138  uint32_t max_hd_pixels_;
139  uint32_t max_uhd1_pixels_;
140  double clear_lead_in_seconds_;
141  double crypto_period_duration_in_seconds_;
142  FourCC protection_scheme_;
143  bool cancelled_;
144 
145  std::unique_ptr<MuxerListener> muxer_listener_;
146  std::unique_ptr<ProgressListener> progress_listener_;
147  // An external injected clock, can be NULL.
148  base::Clock* clock_;
149 
150  DISALLOW_COPY_AND_ASSIGN(Muxer);
151 };
152 
153 } // namespace media
154 } // namespace shaka
155 
156 #endif // MEDIA_BASE_MUXER_H_
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18
void AddStream(MediaStream *stream)
Add video/audio stream.
Definition: muxer.cc:50
Status Run()
Drive the remuxing from muxer side (pull).
Definition: muxer.cc:56
void SetProgressListener(std::unique_ptr< ProgressListener > progress_listener)
Definition: muxer.cc: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:33
void set_clock(base::Clock *clock)
Definition: muxer.h:95
void SetMuxerListener(std::unique_ptr< MuxerListener > muxer_listener)
Definition: muxer.cc:94