DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
ts_muxer.cc
1 // Copyright 2016 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include "packager/media/formats/mp2t/ts_muxer.h"
8 
9 namespace shaka {
10 namespace media {
11 namespace mp2t {
12 
13 namespace {
14 const uint32_t kTsTimescale = 90000;
15 } // namespace
16 
17 TsMuxer::TsMuxer(const MuxerOptions& muxer_options) : Muxer(muxer_options) {}
18 TsMuxer::~TsMuxer() {}
19 
20 Status TsMuxer::InitializeMuxer() {
21  if (streams().size() > 1u)
22  return Status(error::MUXER_FAILURE, "Cannot handle more than one streams.");
23 
24  segmenter_.reset(new TsSegmenter(options(), muxer_listener()));
25  Status status = segmenter_->Initialize(*streams()[0]);
26  FireOnMediaStartEvent();
27  return status;
28 }
29 
30 Status TsMuxer::Finalize() {
31  FireOnMediaEndEvent();
32  return segmenter_->Finalize();
33 }
34 
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);
39 }
40 
41 Status TsMuxer::FinalizeSegment(size_t stream_id,
42  std::shared_ptr<SegmentInfo> segment_info) {
43  DCHECK_EQ(stream_id, 0u);
44  return segment_info->is_subsegment
45  ? Status::OK
46  : segmenter_->FinalizeSegment(segment_info->start_timestamp,
47  segment_info->duration);
48 }
49 
50 void TsMuxer::FireOnMediaStartEvent() {
51  if (!muxer_listener())
52  return;
53  muxer_listener()->OnMediaStart(options(), *streams().front(), kTsTimescale,
54  MuxerListener::kContainerWebM);
55 }
56 
57 void TsMuxer::FireOnMediaEndEvent() {
58  if (!muxer_listener())
59  return;
60 
61  // For now, there is no single file TS segmenter. So all the values passed
62  // here are left empty.
63  MuxerListener::MediaRanges range;
64  muxer_listener()->OnMediaEnd(range, 0);
65 }
66 
67 } // namespace mp2t
68 } // namespace media
69 } // namespace shaka
virtual void OnMediaEnd(const MediaRanges &media_ranges, float duration_seconds)=0
virtual void OnMediaStart(const MuxerOptions &muxer_options, const StreamInfo &stream_info, uint32_t time_scale, ContainerType container_type)=0