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 MuxerOptions;
22 
23 class BufferWriter;
24 class KeySource;
25 class MediaSample;
26 class MuxerListener;
27 class ProgressListener;
28 class StreamInfo;
29 
30 namespace mp4 {
31 
32 class Fragmenter;
33 
40 class Segmenter {
41  public:
42  Segmenter(const MuxerOptions& options,
43  std::unique_ptr<FileType> ftyp,
44  std::unique_ptr<Movie> moov);
45  virtual ~Segmenter();
46 
72  Status Initialize(const std::vector<std::shared_ptr<StreamInfo>>& streams,
73  MuxerListener* muxer_listener,
74  ProgressListener* progress_listener,
75  KeySource* encryption_key_source,
76  uint32_t max_sd_pixels,
77  uint32_t max_hd_pixels,
78  uint32_t max_uhd1_pixels,
79  double clear_lead_in_seconds,
80  double crypto_period_duration_in_seconds,
81  FourCC protection_scheme);
82 
85  Status Finalize();
86 
90  Status AddSample(const StreamInfo& stream_Info,
91  std::shared_ptr<MediaSample> sample);
92 
95  virtual bool GetInitRange(size_t* offset, size_t* size) = 0;
96 
99  virtual bool GetIndexRange(size_t* offset, size_t* size) = 0;
100 
101  uint32_t GetReferenceTimeScale() const;
102 
104  double GetDuration() const;
105 
108  uint32_t sample_duration() const { return sample_duration_; }
109 
110  protected:
112  void UpdateProgress(uint64_t progress);
114  void SetComplete();
115 
116  const MuxerOptions& options() const { return options_; }
117  FileType* ftyp() { return ftyp_.get(); }
118  Movie* moov() { return moov_.get(); }
119  BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
120  SegmentIndex* sidx() { return sidx_.get(); }
121  MuxerListener* muxer_listener() { return muxer_listener_; }
122  uint64_t progress_target() { return progress_target_; }
123 
124  void set_progress_target(uint64_t progress_target) {
125  progress_target_ = progress_target;
126  }
127 
128  private:
129  virtual Status DoInitialize() = 0;
130  virtual Status DoFinalize() = 0;
131  virtual Status DoFinalizeSegment() = 0;
132 
133  Status FinalizeSegment();
134  uint32_t GetReferenceStreamId();
135 
136  Status FinalizeFragment(bool finalize_segment, Fragmenter* fragment);
137 
138  const MuxerOptions& options_;
139  std::unique_ptr<FileType> ftyp_;
140  std::unique_ptr<Movie> moov_;
141  std::unique_ptr<MovieFragment> moof_;
142  std::unique_ptr<BufferWriter> fragment_buffer_;
143  std::unique_ptr<SegmentIndex> sidx_;
144  std::vector<std::unique_ptr<Fragmenter>> fragmenters_;
145  std::vector<uint64_t> segment_durations_;
146  MuxerListener* muxer_listener_;
147  ProgressListener* progress_listener_;
148  uint64_t progress_target_;
149  uint64_t accumulated_progress_;
150  uint32_t sample_duration_;
151 
152  DISALLOW_COPY_AND_ASSIGN(Segmenter);
153 };
154 
155 } // namespace mp4
156 } // namespace media
157 } // namespace shaka
158 
159 #endif // MEDIA_FORMATS_MP4_SEGMENTER_H_
Abstract class holds stream information.
Definition: stream_info.h:58
Status AddSample(const StreamInfo &stream_Info, std::shared_ptr< MediaSample > sample)
Definition: segmenter.cc:318
void UpdateProgress(uint64_t progress)
Update segmentation progress using ProgressListener.
Definition: segmenter.cc:383
void SetComplete()
Set progress to 100%.
Definition: segmenter.cc:399
virtual bool GetInitRange(size_t *offset, size_t *size)=0
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18
uint32_t sample_duration() const
Definition: segmenter.h:108
This class listens to progress updates events.
Status Initialize(const std::vector< std::shared_ptr< StreamInfo >> &streams, MuxerListener *muxer_listener, ProgressListener *progress_listener, KeySource *encryption_key_source, uint32_t max_sd_pixels, uint32_t max_hd_pixels, uint32_t max_uhd1_pixels, double clear_lead_in_seconds, double crypto_period_duration_in_seconds, FourCC protection_scheme)
Definition: segmenter.cc:164
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:30
double GetDuration() const
Definition: segmenter.cc:374
virtual bool GetIndexRange(size_t *offset, size_t *size)=0