Shaka Packager SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
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, const MediaSample& sample) {
36  DCHECK_EQ(stream_id, 0u);
37  return segmenter_->AddSample(sample);
38 }
39 
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
44  ? Status::OK
45  : segmenter_->FinalizeSegment(segment_info.start_timestamp,
46  segment_info.duration);
47 }
48 
49 void TsMuxer::FireOnMediaStartEvent() {
50  if (!muxer_listener())
51  return;
52  muxer_listener()->OnMediaStart(options(), *streams().front(), kTsTimescale,
53  MuxerListener::kContainerWebM);
54 }
55 
56 void TsMuxer::FireOnMediaEndEvent() {
57  if (!muxer_listener())
58  return;
59 
60  // For now, there is no single file TS segmenter. So all the values passed
61  // here are left empty.
62  MuxerListener::MediaRanges range;
63  muxer_listener()->OnMediaEnd(range, 0);
64 }
65 
66 } // namespace mp2t
67 } // namespace media
68 } // 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