7 #include "packager/media/base/muxer.h"
9 #include "packager/media/base/fourccs.h"
10 #include "packager/media/base/media_sample.h"
11 #include "packager/media/base/media_stream.h"
13 namespace edash_packager {
16 Muxer::Muxer(
const MuxerOptions& options)
19 encryption_key_source_(NULL),
21 clear_lead_in_seconds_(0),
22 crypto_period_duration_in_seconds_(0),
23 protection_scheme_(FOURCC_NULL),
30 uint32_t max_sd_pixels,
31 double clear_lead_in_seconds,
32 double crypto_period_duration_in_seconds,
33 FourCC protection_scheme) {
34 DCHECK(encryption_key_source);
35 encryption_key_source_ = encryption_key_source;
36 max_sd_pixels_ = max_sd_pixels;
37 clear_lead_in_seconds_ = clear_lead_in_seconds;
38 crypto_period_duration_in_seconds_ = crypto_period_duration_in_seconds;
39 protection_scheme_ = protection_scheme;
45 streams_.push_back(stream);
49 DCHECK(!streams_.empty());
53 for (std::vector<MediaStream*>::iterator it = streams_.begin();
56 status = (*it)->Start(MediaStream::kPull);
61 uint32_t current_stream_id = 0;
64 return Status(error::CANCELLED,
"muxer run cancelled");
66 scoped_refptr<MediaSample> sample;
67 status = streams_[current_stream_id]->PullSample(&sample);
70 status = AddSample(streams_[current_stream_id], sample);
73 if (status.error_code() == error::FRAGMENT_FINALIZED) {
74 current_stream_id = (current_stream_id + 1) % streams_.size();
79 return status.error_code() == error::END_OF_STREAM ? Finalize() : status;
87 muxer_listener_ = muxer_listener.Pass();
91 scoped_ptr<ProgressListener> progress_listener) {
92 progress_listener_ = progress_listener.Pass();
96 scoped_refptr<MediaSample> sample) {
97 DCHECK(std::find(streams_.begin(), streams_.end(), stream) != streams_.end());
100 Status status = Initialize();
105 if (sample->end_of_stream()) {
108 DCHECK_EQ(1u, streams_.size());
110 }
else if (sample->is_encrypted()) {
111 LOG(ERROR) <<
"Unable to multiplex encrypted media sample";
112 return Status(error::INTERNAL_ERROR,
"Encrypted media sample.");
114 return DoAddSample(stream, sample);