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),
25 clear_lead_in_seconds_(0),
26 crypto_period_duration_in_seconds_(0),
27 protection_scheme_(FOURCC_NULL),
34 uint32_t max_sd_pixels,
35 uint32_t max_hd_pixels,
36 uint32_t max_uhd1_pixels,
37 double clear_lead_in_seconds,
38 double crypto_period_duration_in_seconds,
39 FourCC protection_scheme) {
40 DCHECK(encryption_key_source);
41 encryption_key_source_ = encryption_key_source;
42 max_sd_pixels_ = max_sd_pixels;
43 max_hd_pixels_ = max_hd_pixels;
44 max_uhd1_pixels_ = max_uhd1_pixels;
45 clear_lead_in_seconds_ = clear_lead_in_seconds;
46 crypto_period_duration_in_seconds_ = crypto_period_duration_in_seconds;
47 protection_scheme_ = protection_scheme;
53 streams_.push_back(stream);
57 DCHECK(!streams_.empty());
61 for (std::vector<MediaStream*>::iterator it = streams_.begin();
64 status = (*it)->Start(MediaStream::kPull);
69 uint32_t current_stream_id = 0;
72 return Status(error::CANCELLED,
"muxer run cancelled");
74 std::shared_ptr<MediaSample> sample;
75 status = streams_[current_stream_id]->PullSample(&sample);
78 status = AddSample(streams_[current_stream_id], sample);
81 if (status.error_code() == error::FRAGMENT_FINALIZED) {
82 current_stream_id = (current_stream_id + 1) % streams_.size();
87 return status.error_code() == error::END_OF_STREAM ? Finalize() : status;
95 muxer_listener_ = std::move(muxer_listener);
99 std::unique_ptr<ProgressListener> progress_listener) {
100 progress_listener_ = std::move(progress_listener);
104 std::shared_ptr<MediaSample> sample) {
105 DCHECK(std::find(streams_.begin(), streams_.end(), stream) != streams_.end());
108 Status status = Initialize();
113 if (sample->end_of_stream()) {
116 DCHECK_EQ(1u, streams_.size());
118 }
else if (sample->is_encrypted()) {
119 LOG(ERROR) <<
"Unable to multiplex encrypted media sample";
120 return Status(error::INTERNAL_ERROR,
"Encrypted media sample.");
122 return DoAddSample(stream, sample);