DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
fragmenter.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_FRAGMENTER_H_
8 #define MEDIA_FORMATS_MP4_FRAGMENTER_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "packager/base/logging.h"
14 #include "packager/base/memory/ref_counted.h"
15 #include "packager/media/base/status.h"
16 
17 namespace shaka {
18 namespace media {
19 
20 class BufferWriter;
21 class MediaSample;
22 class StreamInfo;
23 
24 namespace mp4 {
25 
26 struct SegmentReference;
27 struct TrackFragment;
28 
31 class Fragmenter {
32  public:
35  Fragmenter(scoped_refptr<StreamInfo> info, TrackFragment* traf);
36 
37  virtual ~Fragmenter();
38 
42  virtual Status AddSample(scoped_refptr<MediaSample> sample);
43 
48  virtual Status InitializeFragment(int64_t first_sample_dts);
49 
51  virtual void FinalizeFragment();
52 
55 
56  uint64_t fragment_duration() const { return fragment_duration_; }
57  uint64_t first_sap_time() const { return first_sap_time_; }
58  uint64_t earliest_presentation_time() const {
59  return earliest_presentation_time_;
60  }
61  bool fragment_initialized() const { return fragment_initialized_; }
62  bool fragment_finalized() const { return fragment_finalized_; }
63  BufferWriter* data() { return data_.get(); }
64 
70  bool use_decoding_timestamp_in_timeline) {
71  use_decoding_timestamp_in_timeline_ = use_decoding_timestamp_in_timeline;
72  }
73 
74  protected:
75  TrackFragment* traf() { return traf_; }
76 
80  template <typename T>
81  bool OptimizeSampleEntries(std::vector<T>* entries, T* default_value);
82 
83  private:
84  // Check if the current fragment starts with SAP.
85  bool StartsWithSAP();
86 
87  bool use_decoding_timestamp_in_timeline_;
88  TrackFragment* traf_;
89  uint64_t seek_preroll_;
90  bool fragment_initialized_;
91  bool fragment_finalized_;
92  uint64_t fragment_duration_;
93  int64_t earliest_presentation_time_;
94  int64_t first_sap_time_;
95  std::unique_ptr<BufferWriter> data_;
96 
97  DISALLOW_COPY_AND_ASSIGN(Fragmenter);
98 };
99 
100 template <typename T>
101 bool Fragmenter::OptimizeSampleEntries(std::vector<T>* entries,
102  T* default_value) {
103  DCHECK(entries);
104  DCHECK(default_value);
105  DCHECK(!entries->empty());
106 
107  typename std::vector<T>::const_iterator it = entries->begin();
108  T value = *it;
109  for (; it < entries->end(); ++it)
110  if (value != *it)
111  return false;
112 
113  // Clear |entries| if it contains only one value.
114  entries->clear();
115  *default_value = value;
116  return true;
117 }
118 
119 } // namespace mp4
120 } // namespace media
121 } // namespace shaka
122 
123 #endif // MEDIA_FORMATS_MP4_FRAGMENTER_H_
void set_use_decoding_timestamp_in_timeline(bool use_decoding_timestamp_in_timeline)
Definition: fragmenter.h:69
Fragmenter(scoped_refptr< StreamInfo > info, TrackFragment *traf)
Definition: fragmenter.cc:32
virtual Status AddSample(scoped_refptr< MediaSample > sample)
Definition: fragmenter.cc:46
virtual Status InitializeFragment(int64_t first_sample_dts)
Definition: fragmenter.cc:91
virtual void FinalizeFragment()
Finalize and optimize the fragment.
Definition: fragmenter.cc:110
void GenerateSegmentReference(SegmentReference *reference)
Fill reference with current fragment information.
Definition: fragmenter.cc:167
bool OptimizeSampleEntries(std::vector< T > *entries, T *default_value)
Definition: fragmenter.h:101