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(*streams()[0]);
26 FireOnMediaStartEvent();
30 Status TsMuxer::Finalize() {
31 FireOnMediaEndEvent();
32 return segmenter_->Finalize();
35 Status TsMuxer::AddSample(
size_t stream_id,
const MediaSample& sample) {
36 DCHECK_EQ(stream_id, 0u);
37 return segmenter_->AddSample(sample);
40 Status TsMuxer::FinalizeSegment(
size_t stream_id,
41 const SegmentInfo& segment_info) {
42 DCHECK_EQ(stream_id, 0u);
43 return segment_info.is_subsegment
45 : segmenter_->FinalizeSegment(segment_info.start_timestamp,
46 segment_info.duration);
49 void TsMuxer::FireOnMediaStartEvent() {
50 if (!muxer_listener())
52 muxer_listener()->
OnMediaStart(options(), *streams().front(), kTsTimescale,
53 MuxerListener::kContainerWebM);
56 void TsMuxer::FireOnMediaEndEvent() {
57 if (!muxer_listener())
62 MuxerListener::MediaRanges range;