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/status.h"
16 #include "packager/media/formats/mp4/box_definitions.h"
17 
18 namespace edash_packager {
19 namespace media {
20 
21 struct MuxerOptions;
22 
23 class BufferWriter;
24 class KeySource;
25 class MediaSample;
26 class MediaStream;
27 class MuxerListener;
28 class ProgressListener;
29 
30 namespace mp4 {
31 
32 class Fragmenter;
33 
40 class Segmenter {
41  public:
42  Segmenter(const MuxerOptions& options,
43  scoped_ptr<FileType> ftyp,
44  scoped_ptr<Movie> moov);
45  virtual ~Segmenter();
46 
62  Status Initialize(const std::vector<MediaStream*>& streams,
63  MuxerListener* muxer_listener,
64  ProgressListener* progress_listener,
65  KeySource* encryption_key_source,
66  uint32_t max_sd_pixels,
67  double clear_lead_in_seconds,
68  double crypto_period_duration_in_seconds);
69 
72  Status Finalize();
73 
79  Status AddSample(const MediaStream* stream,
80  scoped_refptr<MediaSample> sample);
81 
84  virtual bool GetInitRange(size_t* offset, size_t* size) = 0;
85 
88  virtual bool GetIndexRange(size_t* offset, size_t* size) = 0;
89 
90  uint32_t GetReferenceTimeScale() const;
91 
93  double GetDuration() const;
94 
97  uint32_t sample_duration() const { return sample_duration_; }
98 
99  protected:
101  void UpdateProgress(uint64_t progress);
103  void SetComplete();
104 
105  const MuxerOptions& options() const { return options_; }
106  FileType* ftyp() { return ftyp_.get(); }
107  Movie* moov() { return moov_.get(); }
108  BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
109  SegmentIndex* sidx() { return sidx_.get(); }
110  MuxerListener* muxer_listener() { return muxer_listener_; }
111  uint64_t progress_target() { return progress_target_; }
112 
113  void set_progress_target(uint64_t progress_target) {
114  progress_target_ = progress_target;
115  }
116 
117  private:
118  virtual Status DoInitialize() = 0;
119  virtual Status DoFinalize() = 0;
120  virtual Status DoFinalizeSegment() = 0;
121 
122  Status FinalizeSegment();
123  uint32_t GetReferenceStreamId();
124 
125  Status FinalizeFragment(bool finalize_segment, Fragmenter* fragment);
126 
127  const MuxerOptions& options_;
128  scoped_ptr<FileType> ftyp_;
129  scoped_ptr<Movie> moov_;
130  scoped_ptr<MovieFragment> moof_;
131  scoped_ptr<BufferWriter> fragment_buffer_;
132  scoped_ptr<SegmentIndex> sidx_;
133  std::vector<Fragmenter*> fragmenters_;
134  std::vector<uint64_t> segment_durations_;
135  std::map<const MediaStream*, uint32_t> stream_map_;
136  bool end_of_segment_;
137  MuxerListener* muxer_listener_;
138  ProgressListener* progress_listener_;
139  uint64_t progress_target_;
140  uint64_t accumulated_progress_;
141  uint32_t sample_duration_;
142 
143  DISALLOW_COPY_AND_ASSIGN(Segmenter);
144 };
145 
146 } // namespace mp4
147 } // namespace media
148 } // namespace edash_packager
149 
150 #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:258
virtual bool GetInitRange(size_t *offset, size_t *size)=0
KeySource is responsible for encryption key acquisition.
Definition: key_source.h:35
void UpdateProgress(uint64_t progress)
Update segmentation progress using ProgressListener.
Definition: segmenter.cc:325
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)
Definition: segmenter.cc:124
virtual bool GetIndexRange(size_t *offset, size_t *size)=0
void SetComplete()
Set progress to 100%.
Definition: segmenter.cc:341
This structure contains the list of configuration options for Muxer.
Definition: muxer_options.h:18