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