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 FinalizeSegmentIfPastSegmentDuration();
57  Status OpenNewSegmentIfClosed(uint32_t next_pts);
58 
59  // Writes PES packets (carried in TsPackets) to file(s). This will
60  // segment appropriately. The state of file may be open or closed after
61  // calling this.
62  Status WritePesPacketsToFiles();
63 
64  const MuxerOptions& muxer_options_;
65 
66  // in seconds.
67  double current_segment_duration_ = 0.0;
68 
69  // Used for segment template.
70  uint64_t segment_number_ = 0;
71 
72  scoped_ptr<TsWriter> ts_writer_;
73  // Set to true if TsWriter::NewFile() succeeds, set to false after
74  // TsWriter::FinalizeFile() succeeds.
75  bool ts_writer_file_opened_ = false;
76  scoped_ptr<PesPacketGenerator> pes_packet_generator_;
77 
78  DISALLOW_COPY_AND_ASSIGN(TsSegmenter);
79 };
80 
81 } // namespace mp2t
82 } // namespace media
83 } // namespace edash_packager
84 #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:78
void InjectTsWriterForTesting(scoped_ptr< TsWriter > writer)
Only for testing.
Definition: ts_segmenter.cc:69
Status AddSample(scoped_refptr< MediaSample > sample)
Definition: ts_segmenter.cc:60
void InjectPesPacketGeneratorForTesting(scoped_ptr< PesPacketGenerator > generator)
Only for testing.
Definition: ts_segmenter.cc:73
TsSegmenter(const MuxerOptions &options)
Definition: ts_segmenter.cc:22
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18