7 #include "packager/media/formats/mp2t/ts_muxer.h"
14 const uint32_t kTsTimescale = 90000;
17 TsMuxer::TsMuxer(
const MuxerOptions& muxer_options) : Muxer(muxer_options) {}
18 TsMuxer::~TsMuxer() {}
20 Status TsMuxer::InitializeMuxer() {
21 if (streams().size() > 1u)
22 return Status(error::MUXER_FAILURE,
"Cannot handle more than one streams.");
24 segmenter_.reset(
new TsSegmenter(options(), muxer_listener()));
25 Status status = segmenter_->Initialize(
26 *streams()[0], encryption_key_source(), max_sd_pixels(), max_hd_pixels(),
27 max_uhd1_pixels(), clear_lead_in_seconds());
28 FireOnMediaStartEvent();
32 Status TsMuxer::Finalize() {
33 FireOnMediaEndEvent();
34 return segmenter_->Finalize();
37 Status TsMuxer::AddSample(
size_t stream_id,
38 std::shared_ptr<MediaSample> sample) {
39 DCHECK_EQ(stream_id, 0u);
40 return segmenter_->AddSample(sample);
43 Status TsMuxer::FinalizeSegment(
size_t stream_id,
44 std::shared_ptr<SegmentInfo> segment_info) {
45 DCHECK_EQ(stream_id, 0u);
46 return segment_info->is_subsegment
48 : segmenter_->FinalizeSegment(segment_info->start_timestamp,
49 segment_info->duration);
52 void TsMuxer::FireOnMediaStartEvent() {
53 if (!muxer_listener())
55 muxer_listener()->
OnMediaStart(options(), *streams().front(), kTsTimescale,
56 MuxerListener::kContainerWebM);
59 void TsMuxer::FireOnMediaEndEvent() {
60 if (!muxer_listener())
65 const bool kHasInitRange =
true;
66 const bool kHasIndexRange =
true;
67 muxer_listener()->
OnMediaEnd(!kHasInitRange, 0, 0, !kHasIndexRange, 0, 0, 0,