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 <vector>
12 
13 #include "packager/base/memory/ref_counted.h"
14 #include "packager/base/memory/scoped_ptr.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  scoped_ptr<FileType> ftyp,
45  scoped_ptr<Movie> moov);
46  virtual ~Segmenter();
47 
65  Status Initialize(const std::vector<MediaStream*>& streams,
66  MuxerListener* muxer_listener,
67  ProgressListener* progress_listener,
68  KeySource* encryption_key_source,
69  uint32_t max_sd_pixels,
70  double clear_lead_in_seconds,
71  double crypto_period_duration_in_seconds,
72  FourCC protection_scheme);
73 
76  Status Finalize();
77 
83  Status AddSample(const MediaStream* stream,
84  scoped_refptr<MediaSample> sample);
85 
88  virtual bool GetInitRange(size_t* offset, size_t* size) = 0;
89 
92  virtual bool GetIndexRange(size_t* offset, size_t* size) = 0;
93 
94  uint32_t GetReferenceTimeScale() const;
95 
97  double GetDuration() const;
98 
101  uint32_t sample_duration() const { return sample_duration_; }
102 
103  protected:
105  void UpdateProgress(uint64_t progress);
107  void SetComplete();
108 
109  const MuxerOptions& options() const { return options_; }
110  FileType* ftyp() { return ftyp_.get(); }
111  Movie* moov() { return moov_.get(); }
112  BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
113  SegmentIndex* sidx() { return sidx_.get(); }
114  MuxerListener* muxer_listener() { return muxer_listener_; }
115  uint64_t progress_target() { return progress_target_; }
116 
117  void set_progress_target(uint64_t progress_target) {
118  progress_target_ = progress_target;
119  }
120 
121  private:
122  virtual Status DoInitialize() = 0;
123  virtual Status DoFinalize() = 0;
124  virtual Status DoFinalizeSegment() = 0;
125 
126  Status FinalizeSegment();
127  uint32_t GetReferenceStreamId();
128 
129  Status FinalizeFragment(bool finalize_segment, Fragmenter* fragment);
130 
131  const MuxerOptions& options_;
132  scoped_ptr<FileType> ftyp_;
133  scoped_ptr<Movie> moov_;
134  scoped_ptr<MovieFragment> moof_;
135  scoped_ptr<BufferWriter> fragment_buffer_;
136  scoped_ptr<SegmentIndex> sidx_;
137  std::vector<Fragmenter*> fragmenters_;
138  std::vector<uint64_t> segment_durations_;
139  std::map<const MediaStream*, uint32_t> stream_map_;
140  bool end_of_segment_;
141  MuxerListener* muxer_listener_;
142  ProgressListener* progress_listener_;
143  uint64_t progress_target_;
144  uint64_t accumulated_progress_;
145  uint32_t sample_duration_;
146 
147  DISALLOW_COPY_AND_ASSIGN(Segmenter);
148 };
149 
150 } // namespace mp4
151 } // namespace media
152 } // namespace shaka
153 
154 #endif // MEDIA_FORMATS_MP4_SEGMENTER_H_
Status Initialize(const std::vector< MediaStream * > &streams, MuxerListener *muxer_listener, ProgressListener *progress_listener, KeySource *encryption_key_source, uint32_t max_sd_pixels, double clear_lead_in_seconds, double crypto_period_duration_in_seconds, FourCC protection_scheme)
Definition: segmenter.cc:166
void UpdateProgress(uint64_t progress)
Update segmentation progress using ProgressListener.
Definition: segmenter.cc:389
void SetComplete()
Set progress to 100%.
Definition: segmenter.cc:405
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:101
Status AddSample(const MediaStream *stream, scoped_refptr< MediaSample > sample)
Definition: segmenter.cc:322
This class listens to progress updates events.
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:31
double GetDuration() const
Definition: segmenter.cc:380
virtual bool GetIndexRange(size_t *offset, size_t *size)=0