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,
36 std::shared_ptr<MediaSample> sample) {
37 DCHECK_EQ(stream_id, 0u);
38 return segmenter_->AddSample(sample);
41 Status TsMuxer::FinalizeSegment(
size_t stream_id,
42 std::shared_ptr<SegmentInfo> segment_info) {
43 DCHECK_EQ(stream_id, 0u);
44 if (segment_info->key_rotation_encryption_config) {
45 NOTIMPLEMENTED() <<
"Key rotation is not implemented for TS.";
46 return Status(error::UNIMPLEMENTED,
47 "Key rotation is not implemented for TS");
49 return segment_info->is_subsegment
51 : segmenter_->FinalizeSegment(segment_info->start_timestamp,
52 segment_info->duration);
55 void TsMuxer::FireOnMediaStartEvent() {
56 if (!muxer_listener())
58 muxer_listener()->
OnMediaStart(options(), *streams().front(), kTsTimescale,
59 MuxerListener::kContainerWebM);
62 void TsMuxer::FireOnMediaEndEvent() {
63 if (!muxer_listener())
68 const bool kHasInitRange =
true;
69 const bool kHasIndexRange =
true;
70 muxer_listener()->
OnMediaEnd(!kHasInitRange, 0, 0, !kHasIndexRange, 0, 0, 0,