Tag Parser  6.3.0
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<uint64> readChunkOffsetsSupportingFragments(bool parseFragments = false);
143  std::vector<std::tuple<uint32, uint32, uint32> > readSampleToChunkTable();
144  std::vector<uint64> readChunkSizes();
145 
146  // methods to make the track header
147  void makeTrack();
148  uint64 requiredSize() const;
149  void makeTrackHeader();
150  void makeMedia();
151  void makeMediaInfo();
152  void makeSampleTable();
153 
154  // methods to update chunk offsets
155  void updateChunkOffsets(const std::vector<int64> &oldMdatOffsets, const std::vector<int64> &newMdatOffsets);
156  void updateChunkOffsets(const std::vector<uint64> &chunkOffsets);
157  void updateChunkOffset(uint32 chunkIndex, uint64 offset);
158 
159  static void addInfo(const AvcConfiguration &avcConfig, AbstractTrack &track);
160 
161 protected:
162  void internalParseHeader();
163 
164 private:
165  // private helper methods
166  uint64 accumulateSampleSizes(size_t &sampleIndex, size_t count);
167  void addChunkSizeEntries(std::vector<uint64> &chunkSizeTable, size_t count, size_t &sampleIndex, uint32 sampleCount);
168 
169  Mp4Atom *m_trakAtom;
170  Mp4Atom *m_tkhdAtom;
171  Mp4Atom *m_mdiaAtom;
172  Mp4Atom *m_mdhdAtom;
173  Mp4Atom *m_hdlrAtom;
174  Mp4Atom *m_minfAtom;
175  Mp4Atom *m_stblAtom;
176  Mp4Atom *m_stsdAtom;
177  Mp4Atom *m_stscAtom;
178  Mp4Atom *m_stcoAtom;
179  Mp4Atom *m_stszAtom;
180  //Mp4Atom *m_codecConfigAtom;
181  //Mp4Atom *m_esDescAtom;
182  uint16 m_framesPerSample;
183  std::vector<uint32> m_sampleSizes;
184  unsigned int m_chunkOffsetSize;
185  uint32 m_chunkCount;
186  uint32 m_sampleToChunkEntryCount;
187  std::unique_ptr<Mpeg4ElementaryStreamInfo> m_esInfo;
188  std::unique_ptr<AvcConfiguration> m_avcConfig;
189 };
190 
195 {
196  return *m_trakAtom;
197 }
198 
206 inline const std::vector<uint32> &Mp4Track::sampleSizes() const
207 {
208  return m_sampleSizes;
209 }
210 
216 inline unsigned int Mp4Track::chunkOffsetSize() const
217 {
218  return m_chunkOffsetSize;
219 }
220 
224 inline uint32 Mp4Track::chunkCount() const
225 {
226  return m_chunkCount;
227 }
228 
233 {
234  return m_sampleToChunkEntryCount;
235 }
236 
245 {
246  return m_esInfo.get();
247 }
248 
256 {
257  return m_avcConfig.get();
258 }
259 
260 }
261 
262 #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:206
std::unique_ptr< Mpeg4VideoSpecificConfig > videoSpecificConfig
Definition: mp4track.h:74
const AvcConfiguration * avcConfiguration() const
Returns the AVC configuration.
Definition: mp4track.h:255
unsigned int chunkOffsetSize() const
Returns the size of a single chunk offset denotation within the stco atom.
Definition: mp4track.h:216
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:232
uint32 chunkCount() const
Returns the number of chunks denoted by the stco atom.
Definition: mp4track.h:224
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:244
Mp4Atom & trakAtom()
Returns the trak atom for the current instance.
Definition: mp4track.h:194
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.