DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
segmenter.h
1 // Copyright 2014 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 MEDIA_FORMATS_MP4_SEGMENTER_H_
8 #define MEDIA_FORMATS_MP4_SEGMENTER_H_
9 
10 #include <map>
11 #include <memory>
12 #include <vector>
13 
14 #include "packager/media/base/fourccs.h"
15 #include "packager/media/base/status.h"
16 #include "packager/media/formats/mp4/box_definitions.h"
17 
18 namespace shaka {
19 namespace media {
20 
21 struct EncryptionConfig;
22 struct MuxerOptions;
23 struct SegmentInfo;
24 
25 class BufferWriter;
26 class MediaSample;
27 class MuxerListener;
28 class ProgressListener;
29 class StreamInfo;
30 
31 namespace mp4 {
32 
33 class Fragmenter;
34 
41 class Segmenter {
42  public:
43  Segmenter(const MuxerOptions& options,
44  std::unique_ptr<FileType> ftyp,
45  std::unique_ptr<Movie> moov);
46  virtual ~Segmenter();
47 
55  Status Initialize(const std::vector<std::shared_ptr<StreamInfo>>& streams,
56  MuxerListener* muxer_listener,
57  ProgressListener* progress_listener);
58 
61  Status Finalize();
62 
67  Status AddSample(size_t stream_id, std::shared_ptr<MediaSample> sample);
68 
73  Status FinalizeSegment(size_t stream_id,
74  std::shared_ptr<SegmentInfo> segment_info);
75 
78  virtual bool GetInitRange(size_t* offset, size_t* size) = 0;
79 
82  virtual bool GetIndexRange(size_t* offset, size_t* size) = 0;
83 
84  uint32_t GetReferenceTimeScale() const;
85 
87  double GetDuration() const;
88 
91  uint32_t sample_duration() const { return sample_duration_; }
92 
93  protected:
95  void UpdateProgress(uint64_t progress);
97  void SetComplete();
98 
99  const MuxerOptions& options() const { return options_; }
100  FileType* ftyp() { return ftyp_.get(); }
101  Movie* moov() { return moov_.get(); }
102  BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
103  SegmentIndex* sidx() { return sidx_.get(); }
104  MuxerListener* muxer_listener() { return muxer_listener_; }
105  uint64_t progress_target() { return progress_target_; }
106 
107  void set_progress_target(uint64_t progress_target) {
108  progress_target_ = progress_target;
109  }
110 
111  private:
112  virtual Status DoInitialize() = 0;
113  virtual Status DoFinalize() = 0;
114  virtual Status DoFinalizeSegment() = 0;
115 
116  uint32_t GetReferenceStreamId();
117 
118  void FinalizeFragmentForKeyRotation(
119  size_t stream_id,
120  bool fragment_encrypted,
121  const EncryptionConfig& encryption_config);
122 
123  const MuxerOptions& options_;
124  std::unique_ptr<FileType> ftyp_;
125  std::unique_ptr<Movie> moov_;
126  std::unique_ptr<MovieFragment> moof_;
127  std::unique_ptr<BufferWriter> fragment_buffer_;
128  std::unique_ptr<SegmentIndex> sidx_;
129  std::vector<std::unique_ptr<Fragmenter>> fragmenters_;
130  MuxerListener* muxer_listener_ = nullptr;
131  ProgressListener* progress_listener_ = nullptr;
132  uint64_t progress_target_ = 0u;
133  uint64_t accumulated_progress_ = 0u;
134  uint32_t sample_duration_ = 0u;
135  std::vector<uint64_t> stream_durations_;
136 
137  DISALLOW_COPY_AND_ASSIGN(Segmenter);
138 };
139 
140 } // namespace mp4
141 } // namespace media
142 } // namespace shaka
143 
144 #endif // MEDIA_FORMATS_MP4_SEGMENTER_H_
void UpdateProgress(uint64_t progress)
Update segmentation progress using ProgressListener.
Definition: segmenter.cc:225
void SetComplete()
Set progress to 100%.
Definition: segmenter.cc:241
virtual bool GetInitRange(size_t *offset, size_t *size)=0
Status Initialize(const std::vector< std::shared_ptr< StreamInfo >> &streams, MuxerListener *muxer_listener, ProgressListener *progress_listener)
Definition: segmenter.cc:49
Status AddSample(size_t stream_id, std::shared_ptr< MediaSample > sample)
Definition: segmenter.cc:115
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18
uint32_t sample_duration() const
Definition: segmenter.h:91
This class listens to progress updates events.
Status FinalizeSegment(size_t stream_id, std::shared_ptr< SegmentInfo > segment_info)
Definition: segmenter.cc:140
double GetDuration() const
Definition: segmenter.cc:216
virtual bool GetIndexRange(size_t *offset, size_t *size)=0