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),
28 uint32_t max_sd_pixels,
29 double clear_lead_in_seconds,
30 double crypto_period_duration_in_seconds) {
31 DCHECK(encryption_key_source);
32 encryption_key_source_ = encryption_key_source;
33 max_sd_pixels_ = max_sd_pixels;
34 clear_lead_in_seconds_ = clear_lead_in_seconds;
35 crypto_period_duration_in_seconds_ = crypto_period_duration_in_seconds;
41 streams_.push_back(stream);
45 DCHECK(!streams_.empty());
49 for (std::vector<MediaStream*>::iterator it = streams_.begin();
52 status = (*it)->Start(MediaStream::kPull);
57 uint32_t current_stream_id = 0;
60 return Status(error::CANCELLED,
"muxer run cancelled");
62 scoped_refptr<MediaSample> sample;
63 status = streams_[current_stream_id]->PullSample(&sample);
66 status = AddSample(streams_[current_stream_id], sample);
69 if (status.error_code() == error::FRAGMENT_FINALIZED) {
70 current_stream_id = (current_stream_id + 1) % streams_.size();
75 return status.error_code() == error::END_OF_STREAM ? Finalize() : status;
83 muxer_listener_ = muxer_listener.Pass();
87 scoped_ptr<ProgressListener> progress_listener) {
88 progress_listener_ = progress_listener.Pass();
92 scoped_refptr<MediaSample> sample) {
93 DCHECK(std::find(streams_.begin(), streams_.end(), stream) != streams_.end());
96 Status status = Initialize();
101 if (sample->end_of_stream()) {
104 DCHECK_EQ(1u, streams_.size());
106 }
else if (sample->is_encrypted()) {
107 LOG(ERROR) <<
"Unable to multiplex encrypted media sample";
108 return Status(error::INTERNAL_ERROR,
"Encrypted media sample.");
110 return DoAddSample(stream, sample);