7 #include "packager/media/base/muxer.h"
9 #include "packager/media/base/media_sample.h"
10 #include "packager/media/base/media_stream.h"
12 namespace edash_packager {
15 Muxer::Muxer(
const MuxerOptions& options)
18 encryption_key_source_(NULL),
20 clear_lead_in_seconds_(0),
21 crypto_period_duration_in_seconds_(0),
22 encryption_mode_(kEncryptionModeUnknown),
29 uint32_t max_sd_pixels,
30 double clear_lead_in_seconds,
31 double crypto_period_duration_in_seconds,
32 EncryptionMode encryption_mode) {
33 DCHECK(encryption_key_source);
34 encryption_key_source_ = encryption_key_source;
35 max_sd_pixels_ = max_sd_pixels;
36 clear_lead_in_seconds_ = clear_lead_in_seconds;
37 crypto_period_duration_in_seconds_ = crypto_period_duration_in_seconds;
38 encryption_mode_ = encryption_mode;
44 streams_.push_back(stream);
48 DCHECK(!streams_.empty());
52 for (std::vector<MediaStream*>::iterator it = streams_.begin();
55 status = (*it)->Start(MediaStream::kPull);
60 uint32_t current_stream_id = 0;
63 return Status(error::CANCELLED,
"muxer run cancelled");
65 scoped_refptr<MediaSample> sample;
66 status = streams_[current_stream_id]->PullSample(&sample);
69 status = AddSample(streams_[current_stream_id], sample);
72 if (status.error_code() == error::FRAGMENT_FINALIZED) {
73 current_stream_id = (current_stream_id + 1) % streams_.size();
78 return status.error_code() == error::END_OF_STREAM ? Finalize() : status;
86 muxer_listener_ = muxer_listener.Pass();
90 scoped_ptr<ProgressListener> progress_listener) {
91 progress_listener_ = progress_listener.Pass();
95 scoped_refptr<MediaSample> sample) {
96 DCHECK(std::find(streams_.begin(), streams_.end(), stream) != streams_.end());
99 Status status = Initialize();
104 if (sample->end_of_stream()) {
107 DCHECK_EQ(1u, streams_.size());
109 }
else if (sample->is_encrypted()) {
110 LOG(ERROR) <<
"Unable to multiplex encrypted media sample";
111 return Status(error::INTERNAL_ERROR,
"Encrypted media sample.");
113 return DoAddSample(stream, sample);