Tag Parser  6.2.2
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
mp4track.h
Go to the documentation of this file.
1 #ifndef MP4TRACK_H
2 #define MP4TRACK_H
3 
4 #include "../abstracttrack.h"
5 
6 #include <vector>
7 #include <memory>
8 
9 namespace Media
10 {
11 
12 class Mp4Atom;
13 class Mpeg4Descriptor;
14 class AvcConfiguration;
15 
17 {
18 public:
20 
26  bool sbrPresent;
27  bool psPresent;
35  byte layerNr;
37  uint16 layerLength;
39  byte epConfig;
40 };
41 
43 {
44 public:
46 
47  byte profile;
48  std::string userData;
49 };
50 
52 {
53 public:
55 
56  bool dependencyFlag() const;
57  bool urlFlag() const;
58  bool ocrFlag() const;
59  byte priority() const;
60  byte streamTypeId() const;
61  bool upstream() const;
62 
63  uint16 id;
65  uint16 dependsOnId;
66  std::string url;
67  uint16 ocrId;
70  uint32 bufferSize;
71  uint32 maxBitrate;
73  std::unique_ptr<Mpeg4AudioSpecificConfig> audioSpecificConfig;
74  std::unique_ptr<Mpeg4VideoSpecificConfig> videoSpecificConfig;
75 };
76 
78  id(0),
79  esDescFlags(0),
80  dependsOnId(0),
81  ocrId(0),
82  objectTypeId(0),
83  decCfgDescFlags(0),
84  bufferSize(0),
85  maxBitrate(0),
86  averageBitrate(0)
87 {}
88 
90 {
91  return esDescFlags & 0x80;
92 }
93 
95 {
96  return esDescFlags & 0x40;
97 }
98 
100 {
101  return esDescFlags & 0x20;
102 }
103 
105 {
106  return esDescFlags & 0x1F;
107 }
108 
110 {
111  return decCfgDescFlags >> 2;
112 }
113 
115 {
116  return decCfgDescFlags & 0x02;
117 }
118 
120 {
121 public:
122  Mp4Track(Mp4Atom &trakAtom);
123  ~Mp4Track();
124  TrackType type() const;
125 
126  // getter methods specific for MP4 tracks
127  Mp4Atom &trakAtom();
128  const std::vector<uint32> &sampleSizes() const;
129  unsigned int chunkOffsetSize() const;
130  uint32 chunkCount() const;
131  uint32 sampleToChunkEntryCount() const;
132  const Mpeg4ElementaryStreamInfo *mpeg4ElementaryStreamInfo() const;
133  const AvcConfiguration *avcConfiguration() const;
134 
135  // methods to parse configuration details from the track header
136  static std::unique_ptr<Mpeg4ElementaryStreamInfo> parseMpeg4ElementaryStreamInfo(StatusProvider &statusProvider, IoUtilities::BinaryReader &reader, Mp4Atom *esDescAtom);
137  static std::unique_ptr<Mpeg4AudioSpecificConfig> parseAudioSpecificConfig(StatusProvider &statusProvider, std::istream &stream, uint64 startOffset, uint64 size);
138  static std::unique_ptr<Mpeg4VideoSpecificConfig> parseVideoSpecificConfig(StatusProvider &statusProvider, IoUtilities::BinaryReader &reader, uint64 startOffset, uint64 size);
139 
140  // methods to read the "index" (chunk offsets and sizes)
141  std::vector<uint64> readChunkOffsets();
142  std::vector<std::tuple<uint32, uint32, uint32> > readSampleToChunkTable();
143  std::vector<uint64> readChunkSizes();
144 
145  // methods to make the track header
146  void makeTrack();
147  uint64 requiredSize() const;
148  void makeTrackHeader();
149  void makeMedia();
150  void makeMediaInfo();
151  void makeSampleTable();
152 
153  // methods to update chunk offsets
154  void updateChunkOffsets(const std::vector<int64> &oldMdatOffsets, const std::vector<int64> &newMdatOffsets);
155  void updateChunkOffsets(const std::vector<uint64> &chunkOffsets);
156  void updateChunkOffset(uint32 chunkIndex, uint64 offset);
157 
158  static void addInfo(const AvcConfiguration &avcConfig, AbstractTrack &track);
159 
160 protected:
161  void internalParseHeader();
162 
163 private:
164  // private helper methods
165  uint64 accumulateSampleSizes(size_t &sampleIndex, size_t count);
166  void addChunkSizeEntries(std::vector<uint64> &chunkSizeTable, size_t count, size_t &sampleIndex, uint32 sampleCount);
167 
168  Mp4Atom *m_trakAtom;
169  Mp4Atom *m_tkhdAtom;
170  Mp4Atom *m_mdiaAtom;
171  Mp4Atom *m_mdhdAtom;
172  Mp4Atom *m_hdlrAtom;
173  Mp4Atom *m_minfAtom;
174  Mp4Atom *m_stblAtom;
175  Mp4Atom *m_stsdAtom;
176  Mp4Atom *m_stscAtom;
177  Mp4Atom *m_stcoAtom;
178  Mp4Atom *m_stszAtom;
179  //Mp4Atom *m_codecConfigAtom;
180  //Mp4Atom *m_esDescAtom;
181  uint16 m_framesPerSample;
182  std::vector<uint32> m_sampleSizes;
183  unsigned int m_chunkOffsetSize;
184  uint32 m_chunkCount;
185  uint32 m_sampleToChunkEntryCount;
186  std::unique_ptr<Mpeg4ElementaryStreamInfo> m_esInfo;
187  std::unique_ptr<AvcConfiguration> m_avcConfig;
188 };
189 
194 {
195  return *m_trakAtom;
196 }
197 
205 inline const std::vector<uint32> &Mp4Track::sampleSizes() const
206 {
207  return m_sampleSizes;
208 }
209 
215 inline unsigned int Mp4Track::chunkOffsetSize() const
216 {
217  return m_chunkOffsetSize;
218 }
219 
223 inline uint32 Mp4Track::chunkCount() const
224 {
225  return m_chunkCount;
226 }
227 
232 {
233  return m_sampleToChunkEntryCount;
234 }
235 
244 {
245  return m_esInfo.get();
246 }
247 
255 {
256  return m_avcConfig.get();
257 }
258 
259 }
260 
261 #endif // MP4TRACK_H
Implementation of Media::AbstractTrack for the MP4 container.
Definition: mp4track.h:119
The Mpeg4ElementaryStreamInfo class holds MPEG-4 elementary stream info parsed using Mp4Track::parseM...
Definition: mp4track.h:51
TrackType
Specifies the track type.
Definition: abstracttrack.h:28
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
Definition: abstracttrack.h:40
const std::vector< uint32 > & sampleSizes() const
Returns the sample size table for the track.
Definition: mp4track.h:205
std::unique_ptr< Mpeg4VideoSpecificConfig > videoSpecificConfig
Definition: mp4track.h:74
const AvcConfiguration * avcConfiguration() const
Returns the AVC configuration.
Definition: mp4track.h:254
unsigned int chunkOffsetSize() const
Returns the size of a single chunk offset denotation within the stco atom.
Definition: mp4track.h:215
The Mpeg4AudioSpecificConfig class holds MPEG-4 audio specific config parsed using Mp4Track::parseAud...
Definition: mp4track.h:16
The AvcConfiguration struct provides a parser for AVC configuration.
std::unique_ptr< Mpeg4AudioSpecificConfig > audioSpecificConfig
Definition: mp4track.h:73
uint32 sampleToChunkEntryCount() const
Returns the number of "sample to chunk" entries within the stsc atom.
Definition: mp4track.h:231
uint32 chunkCount() const
Returns the number of chunks denoted by the stco atom.
Definition: mp4track.h:223
The Mp4Atom class helps to parse MP4 files.
Definition: mp4atom.h:57
The Mpeg4VideoSpecificConfig class holds MPEG-4 video specific config parsed using Mp4Track::parseVid...
Definition: mp4track.h:42
const Mpeg4ElementaryStreamInfo * mpeg4ElementaryStreamInfo() const
Returns information about the MPEG-4 elementary stream.
Definition: mp4track.h:243
Mp4Atom & trakAtom()
Returns the trak atom for the current instance.
Definition: mp4track.h:193
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
The StatusProvider class acts as a base class for objects providing status information.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.