DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs 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/encryption_modes.h"
16 #include "packager/media/base/status.h"
17 #include "packager/media/formats/mp4/box_definitions.h"
18 
19 namespace edash_packager {
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 
63  Status Initialize(const std::vector<MediaStream*>& streams,
64  MuxerListener* muxer_listener,
65  ProgressListener* progress_listener,
66  KeySource* encryption_key_source,
67  uint32_t max_sd_pixels,
68  double clear_lead_in_seconds,
69  double crypto_period_duration_in_seconds,
70  EncryptionMode encryption_mode);
71 
74  Status Finalize();
75 
81  Status AddSample(const MediaStream* stream,
82  scoped_refptr<MediaSample> sample);
83 
86  virtual bool GetInitRange(size_t* offset, size_t* size) = 0;
87 
90  virtual bool GetIndexRange(size_t* offset, size_t* size) = 0;
91 
92  uint32_t GetReferenceTimeScale() const;
93 
95  double GetDuration() const;
96 
99  uint32_t sample_duration() const { return sample_duration_; }
100 
101  protected:
103  void UpdateProgress(uint64_t progress);
105  void SetComplete();
106 
107  const MuxerOptions& options() const { return options_; }
108  FileType* ftyp() { return ftyp_.get(); }
109  Movie* moov() { return moov_.get(); }
110  BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
111  SegmentIndex* sidx() { return sidx_.get(); }
112  MuxerListener* muxer_listener() { return muxer_listener_; }
113  uint64_t progress_target() { return progress_target_; }
114 
115  void set_progress_target(uint64_t progress_target) {
116  progress_target_ = progress_target;
117  }
118 
119  private:
120  virtual Status DoInitialize() = 0;
121  virtual Status DoFinalize() = 0;
122  virtual Status DoFinalizeSegment() = 0;
123 
124  Status FinalizeSegment();
125  uint32_t GetReferenceStreamId();
126 
127  Status FinalizeFragment(bool finalize_segment, Fragmenter* fragment);
128 
129  const MuxerOptions& options_;
130  scoped_ptr<FileType> ftyp_;
131  scoped_ptr<Movie> moov_;
132  scoped_ptr<MovieFragment> moof_;
133  scoped_ptr<BufferWriter> fragment_buffer_;
134  scoped_ptr<SegmentIndex> sidx_;
135  std::vector<Fragmenter*> fragmenters_;
136  std::vector<uint64_t> segment_durations_;
137  std::map<const MediaStream*, uint32_t> stream_map_;
138  bool end_of_segment_;
139  MuxerListener* muxer_listener_;
140  ProgressListener* progress_listener_;
141  uint64_t progress_target_;
142  uint64_t accumulated_progress_;
143  uint32_t sample_duration_;
144 
145  DISALLOW_COPY_AND_ASSIGN(Segmenter);
146 };
147 
148 } // namespace mp4
149 } // namespace media
150 } // namespace edash_packager
151 
152 #endif // MEDIA_FORMATS_MP4_SEGMENTER_H_
This class listens to progress updates events.
Status AddSample(const MediaStream *stream, scoped_refptr< MediaSample > sample)
Definition: segmenter.cc:268
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, EncryptionMode encryption_mode)
Definition: segmenter.cc:133
virtual bool GetInitRange(size_t *offset, size_t *size)=0
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:31
void UpdateProgress(uint64_t progress)
Update segmentation progress using ProgressListener.
Definition: segmenter.cc:335
virtual bool GetIndexRange(size_t *offset, size_t *size)=0
void SetComplete()
Set progress to 100%.
Definition: segmenter.cc:351
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18