DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs 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 <vector>
13 
14 #include "packager/base/memory/ref_counted.h"
15 #include "packager/base/memory/scoped_ptr.h"
16 #include "packager/base/time/clock.h"
17 #include "packager/media/base/encryption_modes.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 edash_packager {
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 
48  void SetKeySource(KeySource* encryption_key_source,
49  uint32_t max_sd_pixels,
50  double clear_lead_in_seconds,
51  double crypto_period_duration_in_seconds,
52  EncryptionMode encryption_mode);
53 
55  void AddStream(MediaStream* stream);
56 
58  Status Run();
59 
62  void Cancel();
63 
66  void SetMuxerListener(scoped_ptr<MuxerListener> muxer_listener);
67 
70  void SetProgressListener(scoped_ptr<ProgressListener> progress_listener);
71 
72  const std::vector<MediaStream*>& streams() const { return streams_; }
73 
80  void set_clock(base::Clock* clock) {
81  clock_ = clock;
82  }
83 
84  protected:
85  const MuxerOptions& options() const { return options_; }
86  KeySource* encryption_key_source() {
87  return encryption_key_source_;
88  }
89  uint32_t max_sd_pixels() const { return max_sd_pixels_; }
90  double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
91  double crypto_period_duration_in_seconds() const {
92  return crypto_period_duration_in_seconds_;
93  }
94  MuxerListener* muxer_listener() { return muxer_listener_.get(); }
95  ProgressListener* progress_listener() { return progress_listener_.get(); }
96  base::Clock* clock() { return clock_; }
97  EncryptionMode encryption_mode() const { return encryption_mode_; }
98 
99  private:
100  friend class MediaStream; // Needed to access AddSample.
101 
102  // Add new media sample.
103  Status AddSample(const MediaStream* stream,
104  scoped_refptr<MediaSample> sample);
105 
106  // Initialize the muxer.
107  virtual Status Initialize() = 0;
108 
109  // Final clean up.
110  virtual Status Finalize() = 0;
111 
112  // AddSample implementation.
113  virtual Status DoAddSample(const MediaStream* stream,
114  scoped_refptr<MediaSample> sample) = 0;
115 
116  MuxerOptions options_;
117  bool initialized_;
118  std::vector<MediaStream*> streams_;
119  KeySource* encryption_key_source_;
120  uint32_t max_sd_pixels_;
121  double clear_lead_in_seconds_;
122  double crypto_period_duration_in_seconds_;
123  EncryptionMode encryption_mode_;
124  bool cancelled_;
125 
126  scoped_ptr<MuxerListener> muxer_listener_;
127  scoped_ptr<ProgressListener> progress_listener_;
128  // An external injected clock, can be NULL.
129  base::Clock* clock_;
130 
131  DISALLOW_COPY_AND_ASSIGN(Muxer);
132 };
133 
134 } // namespace media
135 } // namespace edash_packager
136 
137 #endif // MEDIA_BASE_MUXER_H_
void SetMuxerListener(scoped_ptr< MuxerListener > muxer_listener)
Definition: muxer.cc:85
void set_clock(base::Clock *clock)
Definition: muxer.h:80
void SetProgressListener(scoped_ptr< ProgressListener > progress_listener)
Definition: muxer.cc:89
void SetKeySource(KeySource *encryption_key_source, uint32_t max_sd_pixels, double clear_lead_in_seconds, double crypto_period_duration_in_seconds, EncryptionMode encryption_mode)
Definition: muxer.cc:28
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:31
Status Run()
Drive the remuxing from muxer side (pull).
Definition: muxer.cc:47
void AddStream(MediaStream *stream)
Add video/audio stream.
Definition: muxer.cc:41
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18