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-03-11 02:49:55 +00:00
|
|
|
Status status = segmenter_->Initialize(*streams()[0]);
|
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-09-12 17:24:24 +00:00
|
|
|
Status TsMuxer::AddSample(size_t stream_id, const MediaSample& sample) {
|
2017-03-03 00:10:30 +00:00
|
|
|
DCHECK_EQ(stream_id, 0u);
|
2016-04-16 22:58:47 +00:00
|
|
|
return segmenter_->AddSample(sample);
|
|
|
|
}
|
|
|
|
|
2017-03-03 00:10:30 +00:00
|
|
|
Status TsMuxer::FinalizeSegment(size_t stream_id,
|
2017-09-12 17:24:24 +00:00
|
|
|
const SegmentInfo& segment_info) {
|
2017-03-03 00:10:30 +00:00
|
|
|
DCHECK_EQ(stream_id, 0u);
|
2017-09-12 17:24:24 +00:00
|
|
|
return segment_info.is_subsegment
|
2017-02-24 01:17:47 +00:00
|
|
|
? Status::OK
|
2017-09-12 17:24:24 +00:00
|
|
|
: segmenter_->FinalizeSegment(segment_info.start_timestamp,
|
|
|
|
segment_info.duration);
|
2017-02-24 01:17:47 +00:00
|
|
|
}
|
|
|
|
|
2016-04-16 22:58:47 +00:00
|
|
|
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
|
2017-05-01 23:17:09 +00:00
|
|
|
// here are left empty.
|
|
|
|
MuxerListener::MediaRanges range;
|
2017-07-18 19:23:42 +00:00
|
|
|
muxer_listener()->OnMediaEnd(range, 0);
|
2016-03-21 23:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mp2t
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|