2016-03-21 23:33:00 +00:00
|
|
|
// Copyright 2016 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
|
|
|
|
|
|
|
|
#include "packager/media/formats/mp2t/ts_muxer.h"
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-03-21 23:33:00 +00:00
|
|
|
namespace media {
|
|
|
|
namespace mp2t {
|
|
|
|
|
2016-04-16 22:58:47 +00:00
|
|
|
namespace {
|
|
|
|
const uint32_t kTsTimescale = 90000;
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TsMuxer::TsMuxer(const MuxerOptions& muxer_options) : Muxer(muxer_options) {}
|
2016-03-21 23:33:00 +00:00
|
|
|
TsMuxer::~TsMuxer() {}
|
|
|
|
|
2017-02-21 18:36:50 +00:00
|
|
|
Status TsMuxer::InitializeMuxer() {
|
2016-03-21 23:33:00 +00:00
|
|
|
if (streams().size() > 1u)
|
|
|
|
return Status(error::MUXER_FAILURE, "Cannot handle more than one streams.");
|
2016-04-16 22:58:47 +00:00
|
|
|
|
|
|
|
segmenter_.reset(new TsSegmenter(options(), muxer_listener()));
|
2017-02-21 18:36:50 +00:00
|
|
|
Status status = segmenter_->Initialize(
|
|
|
|
*streams()[0], encryption_key_source(), max_sd_pixels(), max_hd_pixels(),
|
|
|
|
max_uhd1_pixels(), clear_lead_in_seconds());
|
2016-04-16 22:58:47 +00:00
|
|
|
FireOnMediaStartEvent();
|
|
|
|
return status;
|
2016-03-21 23:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status TsMuxer::Finalize() {
|
2016-04-16 22:58:47 +00:00
|
|
|
FireOnMediaEndEvent();
|
|
|
|
return segmenter_->Finalize();
|
2016-03-21 23:33:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 18:36:50 +00:00
|
|
|
Status TsMuxer::DoAddSample(std::shared_ptr<MediaSample> sample) {
|
2016-04-16 22:58:47 +00:00
|
|
|
return segmenter_->AddSample(sample);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TsMuxer::FireOnMediaStartEvent() {
|
|
|
|
if (!muxer_listener())
|
|
|
|
return;
|
2017-02-21 18:36:50 +00:00
|
|
|
muxer_listener()->OnMediaStart(options(), *streams().front(), kTsTimescale,
|
|
|
|
MuxerListener::kContainerWebM);
|
2016-04-16 22:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TsMuxer::FireOnMediaEndEvent() {
|
|
|
|
if (!muxer_listener())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// For now, there is no single file TS segmenter. So all the values passed
|
|
|
|
// here are false and 0. Called just to notify the MuxerListener.
|
|
|
|
const bool kHasInitRange = true;
|
|
|
|
const bool kHasIndexRange = true;
|
|
|
|
muxer_listener()->OnMediaEnd(!kHasInitRange, 0, 0, !kHasIndexRange, 0, 0, 0,
|
|
|
|
0);
|
2016-03-21 23:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mp2t
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|