DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
ts_segmenter.h
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 #ifndef PACKAGER_MEDIA_FORMATS_MP2T_TS_SEGMENTER_H_
8 #define PACKAGER_MEDIA_FORMATS_MP2T_TS_SEGMENTER_H_
9 
10 #include "packager/base/memory/scoped_ptr.h"
11 #include "packager/media/base/media_stream.h"
12 #include "packager/media/base/muxer_options.h"
13 #include "packager/media/base/status.h"
14 #include "packager/media/file/file.h"
15 #include "packager/media/formats/mp2t/pes_packet_generator.h"
16 #include "packager/media/formats/mp2t/ts_writer.h"
17 
18 namespace edash_packager {
19 namespace media {
20 namespace mp2t {
21 
22 // TODO(rkuroiwa): For now, this implements multifile segmenter. Like other
23 // make this an abstract super class and implement multifile and single file
24 // segmenters.
25 class TsSegmenter {
26  public:
29  explicit TsSegmenter(const MuxerOptions& options);
30  ~TsSegmenter();
31 
35  Status Initialize(const StreamInfo& stream_info);
36 
39  Status Finalize();
40 
43  Status AddSample(scoped_refptr<MediaSample> sample);
44 
46  void InjectTsWriterForTesting(scoped_ptr<TsWriter> writer);
47 
50  scoped_ptr<PesPacketGenerator> generator);
51 
53  void SetTsWriterFileOpenedForTesting(bool value);
54 
55  private:
56  Status OpenNewSegmentIfClosed(uint32_t next_pts);
57 
58  // Writes PES packets (carried in TsPackets) to a file. If a file is not open,
59  // it will open one. This will not close the file.
60  Status WritePesPacketsToFile();
61 
62  // Flush all the samples that are (possibly) buffered and write them to the
63  // current segment, this will close the file. If a file is not already opened
64  // before calling this, this will open one and write them to file.
65  Status Flush();
66 
67  const MuxerOptions& muxer_options_;
68 
69  // in seconds.
70  double current_segment_total_sample_duration_ = 0.0;
71 
72  // Used for segment template.
73  uint64_t segment_number_ = 0;
74 
75  scoped_ptr<TsWriter> ts_writer_;
76  // Set to true if TsWriter::NewFile() succeeds, set to false after
77  // TsWriter::FinalizeFile() succeeds.
78  bool ts_writer_file_opened_ = false;
79  scoped_ptr<PesPacketGenerator> pes_packet_generator_;
80 
81  DISALLOW_COPY_AND_ASSIGN(TsSegmenter);
82 };
83 
84 } // namespace mp2t
85 } // namespace media
86 } // namespace edash_packager
87 #endif // PACKAGER_MEDIA_FORMATS_MP2T_TS_SEGMENTER_H_
Status Initialize(const StreamInfo &stream_info)
Definition: ts_segmenter.cc:28
Abstract class holds stream information.
Definition: stream_info.h:26
void SetTsWriterFileOpenedForTesting(bool value)
Only for testing.
Definition: ts_segmenter.cc:79
void InjectTsWriterForTesting(scoped_ptr< TsWriter > writer)
Only for testing.
Definition: ts_segmenter.cc:70
Status AddSample(scoped_refptr< MediaSample > sample)
Definition: ts_segmenter.cc:48
void InjectPesPacketGeneratorForTesting(scoped_ptr< PesPacketGenerator > generator)
Only for testing.
Definition: ts_segmenter.cc:74
TsSegmenter(const MuxerOptions &options)
Definition: ts_segmenter.cc:22
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18