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/base/memory/ref_counted.h"
15 #include "packager/media/base/fourccs.h"
16 #include "packager/media/base/status.h"
17 #include "packager/media/formats/mp4/box_definitions.h"
18 
19 namespace shaka {
20 namespace media {
21 
22 struct MuxerOptions;
23 
24 class BufferWriter;
25 class KeySource;
26 class MediaSample;
27 class MediaStream;
28 class MuxerListener;
29 class ProgressListener;
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 
73  Status Initialize(const std::vector<MediaStream*>& streams,
74  MuxerListener* muxer_listener,
75  ProgressListener* progress_listener,
76  KeySource* encryption_key_source,
77  uint32_t max_sd_pixels,
78  uint32_t max_hd_pixels,
79  uint32_t max_uhd1_pixels,
80  double clear_lead_in_seconds,
81  double crypto_period_duration_in_seconds,
82  FourCC protection_scheme);
83 
86  Status Finalize();
87 
93  Status AddSample(const MediaStream* stream,
94  scoped_refptr<MediaSample> sample);
95 
98  virtual bool GetInitRange(size_t* offset, size_t* size) = 0;
99 
102  virtual bool GetIndexRange(size_t* offset, size_t* size) = 0;
103 
104  uint32_t GetReferenceTimeScale() const;
105 
107  double GetDuration() const;
108 
111  uint32_t sample_duration() const { return sample_duration_; }
112 
113  protected:
115  void UpdateProgress(uint64_t progress);
117  void SetComplete();
118 
119  const MuxerOptions& options() const { return options_; }
120  FileType* ftyp() { return ftyp_.get(); }
121  Movie* moov() { return moov_.get(); }
122  BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
123  SegmentIndex* sidx() { return sidx_.get(); }
124  MuxerListener* muxer_listener() { return muxer_listener_; }
125  uint64_t progress_target() { return progress_target_; }
126 
127  void set_progress_target(uint64_t progress_target) {
128  progress_target_ = progress_target;
129  }
130 
131  private:
132  virtual Status DoInitialize() = 0;
133  virtual Status DoFinalize() = 0;
134  virtual Status DoFinalizeSegment() = 0;
135 
136  Status FinalizeSegment();
137  uint32_t GetReferenceStreamId();
138 
139  Status FinalizeFragment(bool finalize_segment, Fragmenter* fragment);
140 
141  const MuxerOptions& options_;
142  std::unique_ptr<FileType> ftyp_;
143  std::unique_ptr<Movie> moov_;
144  std::unique_ptr<MovieFragment> moof_;
145  std::unique_ptr<BufferWriter> fragment_buffer_;
146  std::unique_ptr<SegmentIndex> sidx_;
147  std::vector<std::unique_ptr<Fragmenter>> fragmenters_;
148  std::vector<uint64_t> segment_durations_;
149  std::map<const MediaStream*, uint32_t> stream_map_;
150  MuxerListener* muxer_listener_;
151  ProgressListener* progress_listener_;
152  uint64_t progress_target_;
153  uint64_t accumulated_progress_;
154  uint32_t sample_duration_;
155 
156  DISALLOW_COPY_AND_ASSIGN(Segmenter);
157 };
158 
159 } // namespace mp4
160 } // namespace media
161 } // namespace shaka
162 
163 #endif // MEDIA_FORMATS_MP4_SEGMENTER_H_
void UpdateProgress(uint64_t progress)
Update segmentation progress using ProgressListener.
Definition: segmenter.cc:390
void SetComplete()
Set progress to 100%.
Definition: segmenter.cc:406
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:111
Status AddSample(const MediaStream *stream, scoped_refptr< MediaSample > sample)
Definition: segmenter.cc:323
This class listens to progress updates events.
Status Initialize(const std::vector< MediaStream * > &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:165
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:30
double GetDuration() const
Definition: segmenter.cc:381
virtual bool GetIndexRange(size_t *offset, size_t *size)=0