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/muxer_options.h"
18 #include "packager/media/base/status.h"
19 #include "packager/media/event/muxer_listener.h"
20 #include "packager/media/event/progress_listener.h"
21 
22 namespace edash_packager {
23 namespace media {
24 
25 class KeySource;
26 class MediaSample;
27 class MediaStream;
28 
32 class Muxer {
33  public:
34  explicit Muxer(const MuxerOptions& options);
35  virtual ~Muxer();
36 
47  void SetKeySource(KeySource* encryption_key_source,
48  uint32_t max_sd_pixels,
49  double clear_lead_in_seconds,
50  double crypto_period_duration_in_seconds);
51 
53  void AddStream(MediaStream* stream);
54 
56  Status Run();
57 
60  void Cancel();
61 
64  void SetMuxerListener(scoped_ptr<MuxerListener> muxer_listener);
65 
68  void SetProgressListener(scoped_ptr<ProgressListener> progress_listener);
69 
70  const std::vector<MediaStream*>& streams() const { return streams_; }
71 
78  void set_clock(base::Clock* clock) {
79  clock_ = clock;
80  }
81 
82  protected:
83  const MuxerOptions& options() const { return options_; }
84  KeySource* encryption_key_source() {
85  return encryption_key_source_;
86  }
87  uint32_t max_sd_pixels() const { return max_sd_pixels_; }
88  double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
89  double crypto_period_duration_in_seconds() const {
90  return crypto_period_duration_in_seconds_;
91  }
92  MuxerListener* muxer_listener() { return muxer_listener_.get(); }
93  ProgressListener* progress_listener() { return progress_listener_.get(); }
94  base::Clock* clock() { return clock_; }
95 
96  private:
97  friend class MediaStream; // Needed to access AddSample.
98 
99  // Add new media sample.
100  Status AddSample(const MediaStream* stream,
101  scoped_refptr<MediaSample> sample);
102 
103  // Initialize the muxer.
104  virtual Status Initialize() = 0;
105 
106  // Final clean up.
107  virtual Status Finalize() = 0;
108 
109  // AddSample implementation.
110  virtual Status DoAddSample(const MediaStream* stream,
111  scoped_refptr<MediaSample> sample) = 0;
112 
113  MuxerOptions options_;
114  bool initialized_;
115  std::vector<MediaStream*> streams_;
116  KeySource* encryption_key_source_;
117  uint32_t max_sd_pixels_;
118  double clear_lead_in_seconds_;
119  double crypto_period_duration_in_seconds_;
120  bool cancelled_;
121 
122  scoped_ptr<MuxerListener> muxer_listener_;
123  scoped_ptr<ProgressListener> progress_listener_;
124  // An external injected clock, can be NULL.
125  base::Clock* clock_;
126 
127  DISALLOW_COPY_AND_ASSIGN(Muxer);
128 };
129 
130 } // namespace media
131 } // namespace edash_packager
132 
133 #endif // MEDIA_BASE_MUXER_H_
void SetMuxerListener(scoped_ptr< MuxerListener > muxer_listener)
Definition: muxer.cc:82
void set_clock(base::Clock *clock)
Definition: muxer.h:78
void SetProgressListener(scoped_ptr< ProgressListener > progress_listener)
Definition: muxer.cc:86
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:35
Status Run()
Drive the remuxing from muxer side (pull).
Definition: muxer.cc:44
void AddStream(MediaStream *stream)
Add video/audio stream.
Definition: muxer.cc:38
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18
void SetKeySource(KeySource *encryption_key_source, uint32_t max_sd_pixels, double clear_lead_in_seconds, double crypto_period_duration_in_seconds)
Definition: muxer.cc:27