DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
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/memory/ref_counted.h"
13 #include "packager/base/memory/scoped_ptr.h"
14 #include "packager/media/base/status.h"
15 
16 namespace edash_packager {
17 namespace media {
18 
19 class BufferWriter;
20 class MediaSample;
21 
22 namespace mp4 {
23 
24 struct SegmentReference;
25 struct TrackFragment;
26 
29 class Fragmenter {
30  public:
33 
34  virtual ~Fragmenter();
35 
39  virtual Status AddSample(scoped_refptr<MediaSample> sample);
40 
45  virtual Status InitializeFragment(int64_t first_sample_dts);
46 
48  virtual void FinalizeFragment();
49 
52 
53  uint64_t fragment_duration() const { return fragment_duration_; }
54  uint64_t first_sap_time() const { return first_sap_time_; }
55  uint64_t earliest_presentation_time() const {
56  return earliest_presentation_time_;
57  }
58  bool fragment_initialized() const { return fragment_initialized_; }
59  bool fragment_finalized() const { return fragment_finalized_; }
60  BufferWriter* data() { return data_.get(); }
61  BufferWriter* aux_data() { return aux_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  scoped_ptr<BufferWriter> aux_data_;
85 
86  DISALLOW_COPY_AND_ASSIGN(Fragmenter);
87 };
88 
89 template <typename T>
90 bool Fragmenter::OptimizeSampleEntries(std::vector<T>* entries,
91  T* default_value) {
92  DCHECK(entries);
93  DCHECK(default_value);
94  DCHECK(!entries->empty());
95 
96  typename std::vector<T>::const_iterator it = entries->begin();
97  T value = *it;
98  for (; it < entries->end(); ++it)
99  if (value != *it)
100  return false;
101 
102  // Clear |entries| if it contains only one value.
103  entries->clear();
104  *default_value = value;
105  return true;
106 }
107 
108 } // namespace mp4
109 } // namespace media
110 } // namespace edash_packager
111 
112 #endif // MEDIA_FORMATS_MP4_FRAGMENTER_H_
void GenerateSegmentReference(SegmentReference *reference)
Fill reference with current fragment information.
Definition: fragmenter.cc:118
virtual Status InitializeFragment(int64_t first_sample_dts)
Definition: fragmenter.cc:73
virtual Status AddSample(scoped_refptr< MediaSample > sample)
Definition: fragmenter.cc:36
bool OptimizeSampleEntries(std::vector< T > *entries, T *default_value)
Definition: fragmenter.h:90
virtual void FinalizeFragment()
Finalize and optimize the fragment.
Definition: fragmenter.cc:91