7 #include "packager/media/base/muxer.h"
11 #include "packager/media/base/fourccs.h"
12 #include "packager/media/base/media_sample.h"
13 #include "packager/media/base/media_stream.h"
18 Muxer::Muxer(
const MuxerOptions& options)
21 encryption_key_source_(NULL),
23 clear_lead_in_seconds_(0),
24 crypto_period_duration_in_seconds_(0),
25 protection_scheme_(FOURCC_NULL),
32 uint32_t max_sd_pixels,
33 double clear_lead_in_seconds,
34 double crypto_period_duration_in_seconds,
35 FourCC protection_scheme) {
36 DCHECK(encryption_key_source);
37 encryption_key_source_ = encryption_key_source;
38 max_sd_pixels_ = max_sd_pixels;
39 clear_lead_in_seconds_ = clear_lead_in_seconds;
40 crypto_period_duration_in_seconds_ = crypto_period_duration_in_seconds;
41 protection_scheme_ = protection_scheme;
47 streams_.push_back(stream);
51 DCHECK(!streams_.empty());
55 for (std::vector<MediaStream*>::iterator it = streams_.begin();
58 status = (*it)->Start(MediaStream::kPull);
63 uint32_t current_stream_id = 0;
66 return Status(error::CANCELLED,
"muxer run cancelled");
68 scoped_refptr<MediaSample> sample;
69 status = streams_[current_stream_id]->PullSample(&sample);
72 status = AddSample(streams_[current_stream_id], sample);
75 if (status.error_code() == error::FRAGMENT_FINALIZED) {
76 current_stream_id = (current_stream_id + 1) % streams_.size();
81 return status.error_code() == error::END_OF_STREAM ? Finalize() : status;
89 muxer_listener_ = std::move(muxer_listener);
93 std::unique_ptr<ProgressListener> progress_listener) {
94 progress_listener_ = std::move(progress_listener);
98 scoped_refptr<MediaSample> sample) {
99 DCHECK(std::find(streams_.begin(), streams_.end(), stream) != streams_.end());
102 Status status = Initialize();
107 if (sample->end_of_stream()) {
110 DCHECK_EQ(1u, streams_.size());
112 }
else if (sample->is_encrypted()) {
113 LOG(ERROR) <<
"Unable to multiplex encrypted media sample";
114 return Status(error::INTERNAL_ERROR,
"Encrypted media sample.");
116 return DoAddSample(stream, sample);