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/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 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 
50  void SetKeySource(KeySource* encryption_key_source,
51  uint32_t max_sd_pixels,
52  double clear_lead_in_seconds,
53  double crypto_period_duration_in_seconds,
54  FourCC protection_scheme);
55 
57  void AddStream(MediaStream* stream);
58 
60  Status Run();
61 
64  void Cancel();
65 
68  void SetMuxerListener(scoped_ptr<MuxerListener> muxer_listener);
69 
72  void SetProgressListener(scoped_ptr<ProgressListener> progress_listener);
73 
74  const std::vector<MediaStream*>& streams() const { return streams_; }
75 
82  void set_clock(base::Clock* clock) {
83  clock_ = clock;
84  }
85 
86  protected:
87  const MuxerOptions& options() const { return options_; }
88  KeySource* encryption_key_source() {
89  return encryption_key_source_;
90  }
91  uint32_t max_sd_pixels() const { return max_sd_pixels_; }
92  double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
93  double crypto_period_duration_in_seconds() const {
94  return crypto_period_duration_in_seconds_;
95  }
96  MuxerListener* muxer_listener() { return muxer_listener_.get(); }
97  ProgressListener* progress_listener() { return progress_listener_.get(); }
98  base::Clock* clock() { return clock_; }
99  FourCC protection_scheme() const { return protection_scheme_; }
100 
101  private:
102  friend class MediaStream; // Needed to access AddSample.
103 
104  // Add new media sample.
105  Status AddSample(const MediaStream* stream,
106  scoped_refptr<MediaSample> sample);
107 
108  // Initialize the muxer.
109  virtual Status Initialize() = 0;
110 
111  // Final clean up.
112  virtual Status Finalize() = 0;
113 
114  // AddSample implementation.
115  virtual Status DoAddSample(const MediaStream* stream,
116  scoped_refptr<MediaSample> sample) = 0;
117 
118  MuxerOptions options_;
119  bool initialized_;
120  std::vector<MediaStream*> streams_;
121  KeySource* encryption_key_source_;
122  uint32_t max_sd_pixels_;
123  double clear_lead_in_seconds_;
124  double crypto_period_duration_in_seconds_;
125  FourCC protection_scheme_;
126  bool cancelled_;
127 
128  scoped_ptr<MuxerListener> muxer_listener_;
129  scoped_ptr<ProgressListener> progress_listener_;
130  // An external injected clock, can be NULL.
131  base::Clock* clock_;
132 
133  DISALLOW_COPY_AND_ASSIGN(Muxer);
134 };
135 
136 } // namespace media
137 } // namespace edash_packager
138 
139 #endif // MEDIA_BASE_MUXER_H_
void SetMuxerListener(scoped_ptr< MuxerListener > muxer_listener)
Definition: muxer.cc:86
void SetKeySource(KeySource *encryption_key_source, uint32_t max_sd_pixels, double clear_lead_in_seconds, double crypto_period_duration_in_seconds, FourCC protection_scheme)
Definition: muxer.cc:29
void set_clock(base::Clock *clock)
Definition: muxer.h:82
void SetProgressListener(scoped_ptr< ProgressListener > progress_listener)
Definition: muxer.cc:90
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:31
Status Run()
Drive the remuxing from muxer side (pull).
Definition: muxer.cc:48
void AddStream(MediaStream *stream)
Add video/audio stream.
Definition: muxer.cc:42
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18