Tag Parser 12.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
mp4track.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_MP4TRACK_H
2#define TAG_PARSER_MP4TRACK_H
3
4#include "../abstracttrack.h"
5
6#include <memory>
7#include <tuple>
8#include <vector>
9
10namespace TagParser {
11
12class Mp4Atom;
13class Mpeg4Descriptor;
14struct AvcConfiguration;
15struct Av1Configuration;
16struct TrackHeaderInfo;
17struct Mp4Timings;
18
20public:
22
23 std::uint8_t audioObjectType;
25 std::uint32_t sampleFrequency;
35 std::uint16_t coreCoderDelay;
36 std::uint8_t extensionFlag;
37 std::uint8_t layerNr;
38 std::uint8_t numOfSubFrame;
39 std::uint16_t layerLength;
40 std::uint8_t resilienceFlags;
41 std::uint8_t epConfig;
42};
43
45public:
47
48 std::uint8_t profile;
49 std::string userData;
50};
51
53public:
55
56 bool dependencyFlag() const;
57 bool urlFlag() const;
58 bool ocrFlag() const;
59 std::uint8_t priority() const;
60 std::uint8_t streamTypeId() const;
61 bool upstream() const;
62
63 std::uint16_t id;
64 std::uint8_t esDescFlags;
65 std::uint16_t dependsOnId;
66 std::string url;
67 std::uint16_t ocrId;
68 std::uint8_t objectTypeId;
69 std::uint8_t decCfgDescFlags;
70 std::uint32_t bufferSize;
71 std::uint32_t maxBitrate;
72 std::uint32_t averageBitrate;
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}
89
91{
92 return esDescFlags & 0x80;
93}
94
96{
97 return esDescFlags & 0x40;
98}
99
101{
102 return esDescFlags & 0x20;
103}
104
105inline std::uint8_t Mpeg4ElementaryStreamInfo::priority() const
106{
107 return esDescFlags & 0x1F;
108}
109
111{
112 return decCfgDescFlags >> 2;
113}
114
116{
117 return decCfgDescFlags & 0x02;
118}
119
120class TAG_PARSER_EXPORT Mp4Track final : public AbstractTrack {
121public:
122 Mp4Track(Mp4Atom &trakAtom);
123 ~Mp4Track() override;
124 TrackType type() const override;
125
126 // getter methods specific for MP4 tracks
127 Mp4Atom &trakAtom();
128 const std::vector<std::uint32_t> &sampleSizes() const;
129 unsigned int chunkOffsetSize() const;
130 void setChunkOffsetSize(unsigned int chunkOffsetSize);
131 std::uint32_t chunkCount() const;
132 std::uint32_t sampleToChunkEntryCount() const;
133 const Mpeg4ElementaryStreamInfo *mpeg4ElementaryStreamInfo() const;
134 const AvcConfiguration *avcConfiguration() const;
135 const Av1Configuration *av1Configuration() const;
136
137 // methods to parse configuration details from the track header
138 static std::unique_ptr<Mpeg4ElementaryStreamInfo> parseMpeg4ElementaryStreamInfo(
139 CppUtilities::BinaryReader &reader, Mp4Atom *esDescAtom, Diagnostics &diag);
140 static std::unique_ptr<Mpeg4AudioSpecificConfig> parseAudioSpecificConfig(
141 std::istream &stream, std::uint64_t startOffset, std::uint64_t size, Diagnostics &diag);
142 static std::unique_ptr<Mpeg4VideoSpecificConfig> parseVideoSpecificConfig(
143 CppUtilities::BinaryReader &reader, std::uint64_t startOffset, std::uint64_t size, Diagnostics &diag);
144
145 // methods to read the "index" (chunk offsets and sizes)
146 std::vector<std::uint64_t> readChunkOffsets(bool parseFragments, Diagnostics &diag);
147 std::vector<std::tuple<std::uint32_t, std::uint32_t, std::uint32_t>> readSampleToChunkTable(Diagnostics &diag);
148 std::vector<std::uint64_t> readChunkSizes(TagParser::Diagnostics &diag);
149
150 // methods to make the track header
151 void bufferTrackAtoms(Diagnostics &diag);
152 std::uint64_t chunkOffsetAtomSize(Diagnostics &diag) const;
153 std::uint64_t requiredSize(Diagnostics &diag) const;
154 void makeTrack(Diagnostics &diag);
155 void makeTrackHeader(Diagnostics &diag);
156 void makeMedia(Diagnostics &diag);
157 void makeMediaInfo(Diagnostics &diag);
158 void makeSampleTable(Diagnostics &diag);
159
160 // methods to update chunk offsets
161 void updateChunkOffsets(const std::vector<std::int64_t> &oldMdatOffsets, const std::vector<std::int64_t> &newMdatOffsets);
162 void updateChunkOffsets(const std::vector<std::uint64_t> &chunkOffsets);
163 void updateChunkOffset(std::uint32_t chunkIndex, std::uint64_t offset);
164
165 static void addInfo(const AvcConfiguration &avcConfig, AbstractTrack &track);
166 static void addInfo(const Av1Configuration &av1Config, AbstractTrack &track);
167
168protected:
169 void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress) override;
170
171private:
172 // private helper methods
173 std::uint64_t accumulateSampleSizes(std::size_t &sampleIndex, std::size_t count, Diagnostics &diag);
174 void addChunkSizeEntries(
175 std::vector<std::uint64_t> &chunkSizeTable, std::size_t count, std::size_t &sampleIndex, std::uint32_t sampleCount, Diagnostics &diag);
176 const TrackHeaderInfo &verifyPresentTrackHeader() const;
177 Mp4Timings computeTimings() const;
178 std::tuple<std::uint64_t, std::uint64_t> calculateSampleTableSize(Diagnostics &diag) const;
179
180 Mp4Atom *m_trakAtom;
181 Mp4Atom *m_tkhdAtom;
182 Mp4Atom *m_mdiaAtom;
183 Mp4Atom *m_mdhdAtom;
184 Mp4Atom *m_hdlrAtom;
185 Mp4Atom *m_minfAtom;
186 Mp4Atom *m_stblAtom;
187 Mp4Atom *m_stsdAtom;
188 Mp4Atom *m_stscAtom;
189 Mp4Atom *m_stcoAtom;
190 Mp4Atom *m_stszAtom;
191 std::uint32_t m_rawMediaType;
192 std::uint16_t m_framesPerSample;
193 std::vector<std::uint32_t> m_sampleSizes;
194 unsigned int m_chunkOffsetSize;
195 std::uint32_t m_chunkCount;
196 std::uint32_t m_sampleToChunkEntryCount;
197 std::uint64_t m_rawTkhdCreationTime;
198 std::uint64_t m_rawMdhdCreationTime;
199 std::uint64_t m_rawTkhdModificationTime;
200 std::uint64_t m_rawMdhdModificationTime;
201 std::uint64_t m_rawTkhdDuration;
202 std::uint64_t m_rawMdhdDuration;
203 std::unique_ptr<Mpeg4ElementaryStreamInfo> m_esInfo;
204 std::unique_ptr<AvcConfiguration> m_avcConfig;
205 std::unique_ptr<Av1Configuration> m_av1Config;
206 mutable std::unique_ptr<TrackHeaderInfo> m_trackHeaderInfo;
207};
208
213{
214 return *m_trakAtom;
215}
216
224inline const std::vector<std::uint32_t> &Mp4Track::sampleSizes() const
225{
226 return m_sampleSizes;
227}
228
237inline unsigned int Mp4Track::chunkOffsetSize() const
238{
239 return m_chunkOffsetSize;
240}
241
246inline void Mp4Track::setChunkOffsetSize(unsigned int chunkOffsetSize)
247{
248 m_chunkOffsetSize = chunkOffsetSize;
249}
250
254inline std::uint32_t Mp4Track::chunkCount() const
255{
256 return m_chunkCount;
257}
258
262inline std::uint32_t Mp4Track::sampleToChunkEntryCount() const
263{
264 return m_sampleToChunkEntryCount;
265}
266
275{
276 return m_esInfo.get();
277}
278
286{
287 return m_avcConfig.get();
288}
289
297{
298 return m_av1Config.get();
299}
300
301} // namespace TagParser
302
303#endif // TAG_PARSER_MP4TRACK_H
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
The Diagnostics class is a container for DiagMessage.
The Mp4Atom class helps to parse MP4 files.
Implementation of TagParser::AbstractTrack for the MP4 container.
const Av1Configuration * av1Configuration() const
Returns the AV1 configuration.
Definition mp4track.h:296
std::uint32_t chunkCount() const
Returns the number of chunks denoted by the stco/co64 atom.
Definition mp4track.h:254
void setChunkOffsetSize(unsigned int chunkOffsetSize)
Sets the size of a single chunk offset denotation within the stco/co64 atom.
Definition mp4track.h:246
std::uint32_t sampleToChunkEntryCount() const
Returns the number of "sample to chunk" entries within the stsc atom.
Definition mp4track.h:262
const std::vector< std::uint32_t > & sampleSizes() const
Returns the sample size table for the track.
Definition mp4track.h:224
unsigned int chunkOffsetSize() const
Returns the size of a single chunk offset denotation within the stco/co64 atom.
Definition mp4track.h:237
const Mpeg4ElementaryStreamInfo * mpeg4ElementaryStreamInfo() const
Returns information about the MPEG-4 elementary stream.
Definition mp4track.h:274
const AvcConfiguration * avcConfiguration() const
Returns the AVC configuration.
Definition mp4track.h:285
Mp4Atom & trakAtom()
Returns the trak atom for the current instance.
Definition mp4track.h:212
The Mpeg4AudioSpecificConfig class holds MPEG-4 audio specific config parsed using Mp4Track::parseAud...
Definition mp4track.h:19
std::uint8_t extensionChannelConfiguration
Definition mp4track.h:32
std::uint8_t extensionSampleFrequencyIndex
Definition mp4track.h:30
The Mpeg4ElementaryStreamInfo class holds MPEG-4 elementary stream info parsed using Mp4Track::parseM...
Definition mp4track.h:52
std::unique_ptr< Mpeg4AudioSpecificConfig > audioSpecificConfig
Definition mp4track.h:73
std::uint8_t priority() const
Definition mp4track.h:105
std::uint8_t streamTypeId() const
Definition mp4track.h:110
std::unique_ptr< Mpeg4VideoSpecificConfig > videoSpecificConfig
Definition mp4track.h:74
The Mpeg4VideoSpecificConfig class holds MPEG-4 video specific config parsed using Mp4Track::parseVid...
Definition mp4track.h:44
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TrackType
The TrackType enum specifies the underlying file type of a track and the concrete class of the track ...
The Av1Configuration struct provides a parser for AV1 configuration found in ISOBMFF files.
The AvcConfiguration struct provides a parser for AVC configuration.
The Mp4Timings struct holds timing values found in multiple MP4 atoms.
Definition mp4track.cpp:34
The TrackHeaderInfo struct holds information about the present track header (tkhd atom) and informati...
Definition mp4track.cpp:48