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 <vector>
11 
12 #include "packager/base/logging.h"
13 #include "packager/base/memory/ref_counted.h"
14 #include "packager/base/memory/scoped_ptr.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 presentation_start_time_;
94  int64_t earliest_presentation_time_;
95  int64_t first_sap_time_;
96  scoped_ptr<BufferWriter> data_;
97 
98  DISALLOW_COPY_AND_ASSIGN(Fragmenter);
99 };
100 
101 template <typename T>
102 bool Fragmenter::OptimizeSampleEntries(std::vector<T>* entries,
103  T* default_value) {
104  DCHECK(entries);
105  DCHECK(default_value);
106  DCHECK(!entries->empty());
107 
108  typename std::vector<T>::const_iterator it = entries->begin();
109  T value = *it;
110  for (; it < entries->end(); ++it)
111  if (value != *it)
112  return false;
113 
114  // Clear |entries| if it contains only one value.
115  entries->clear();
116  *default_value = value;
117  return true;
118 }
119 
120 } // namespace mp4
121 } // namespace media
122 } // namespace shaka
123 
124 #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:47
virtual Status InitializeFragment(int64_t first_sample_dts)
Definition: fragmenter.cc:92
virtual void FinalizeFragment()
Finalize and optimize the fragment.
Definition: fragmenter.cc:111
void GenerateSegmentReference(SegmentReference *reference)
Fill reference with current fragment information.
Definition: fragmenter.cc:168
bool OptimizeSampleEntries(std::vector< T > *entries, T *default_value)
Definition: fragmenter.h:102