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