2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/muxer.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2016-04-08 18:41:17 +00:00
|
|
|
#include "packager/media/base/fourccs.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/media_sample.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-10-11 21:44:55 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-01-14 01:38:34 +00:00
|
|
|
Muxer::Muxer(const MuxerOptions& options)
|
2013-12-12 23:49:31 +00:00
|
|
|
: options_(options),
|
2014-04-18 18:49:49 +00:00
|
|
|
encryption_key_source_(NULL),
|
2014-04-24 21:32:18 +00:00
|
|
|
max_sd_pixels_(0),
|
2016-11-11 23:17:17 +00:00
|
|
|
max_hd_pixels_(0),
|
|
|
|
max_uhd1_pixels_(0),
|
2013-12-12 23:49:31 +00:00
|
|
|
clear_lead_in_seconds_(0),
|
2014-04-18 18:49:49 +00:00
|
|
|
crypto_period_duration_in_seconds_(0),
|
2016-04-08 18:41:17 +00:00
|
|
|
protection_scheme_(FOURCC_NULL),
|
2015-02-09 18:22:28 +00:00
|
|
|
cancelled_(false),
|
2014-02-28 02:39:52 +00:00
|
|
|
clock_(NULL) {}
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
Muxer::~Muxer() {}
|
|
|
|
|
2014-08-20 23:51:15 +00:00
|
|
|
void Muxer::SetKeySource(KeySource* encryption_key_source,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t max_sd_pixels,
|
2016-11-11 23:17:17 +00:00
|
|
|
uint32_t max_hd_pixels,
|
|
|
|
uint32_t max_uhd1_pixels,
|
2014-08-20 23:51:15 +00:00
|
|
|
double clear_lead_in_seconds,
|
2016-03-17 17:03:19 +00:00
|
|
|
double crypto_period_duration_in_seconds,
|
2016-04-08 18:41:17 +00:00
|
|
|
FourCC protection_scheme) {
|
2014-04-18 18:49:49 +00:00
|
|
|
DCHECK(encryption_key_source);
|
2014-04-16 01:09:32 +00:00
|
|
|
encryption_key_source_ = encryption_key_source;
|
2014-04-24 21:32:18 +00:00
|
|
|
max_sd_pixels_ = max_sd_pixels;
|
2016-11-11 23:17:17 +00:00
|
|
|
max_hd_pixels_ = max_hd_pixels;
|
|
|
|
max_uhd1_pixels_ = max_uhd1_pixels;
|
2014-01-14 01:38:34 +00:00
|
|
|
clear_lead_in_seconds_ = clear_lead_in_seconds;
|
2014-04-18 18:49:49 +00:00
|
|
|
crypto_period_duration_in_seconds_ = crypto_period_duration_in_seconds;
|
2016-04-08 18:41:17 +00:00
|
|
|
protection_scheme_ = protection_scheme;
|
2014-01-14 01:38:34 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 18:22:28 +00:00
|
|
|
void Muxer::Cancel() {
|
|
|
|
cancelled_ = true;
|
|
|
|
}
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
void Muxer::SetMuxerListener(std::unique_ptr<MuxerListener> muxer_listener) {
|
|
|
|
muxer_listener_ = std::move(muxer_listener);
|
2013-12-12 23:49:31 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 21:07:10 +00:00
|
|
|
void Muxer::SetProgressListener(
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<ProgressListener> progress_listener) {
|
|
|
|
progress_listener_ = std::move(progress_listener);
|
2015-05-11 21:07:10 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 18:36:50 +00:00
|
|
|
Status Muxer::Process(std::unique_ptr<StreamData> stream_data) {
|
|
|
|
Status status;
|
|
|
|
switch (stream_data->stream_data_type) {
|
|
|
|
case StreamDataType::kStreamInfo:
|
|
|
|
streams_.push_back(std::move(stream_data->stream_info));
|
|
|
|
return InitializeMuxer();
|
|
|
|
case StreamDataType::kMediaSample:
|
|
|
|
return DoAddSample(stream_data->media_sample);
|
|
|
|
default:
|
|
|
|
VLOG(3) << "Stream data type "
|
|
|
|
<< static_cast<int>(stream_data->stream_data_type) << " ignored.";
|
|
|
|
break;
|
2014-04-09 17:34:55 +00:00
|
|
|
}
|
2017-02-21 18:36:50 +00:00
|
|
|
// No dispatch for muxer.
|
|
|
|
return Status::OK;
|
2014-04-09 17:34:55 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|