Tag Parser 11.3.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
abstracttrack.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_ABSTRACTTRACK_H
2#define TAG_PARSER_ABSTRACTTRACK_H
3
4#include "./aspectratio.h"
5#include "./diagnostics.h"
6#include "./localehelper.h"
7#include "./margin.h"
8#include "./mediaformat.h"
9#include "./size.h"
10
11#include <c++utilities/chrono/datetime.h>
12#include <c++utilities/chrono/timespan.h>
13#include <c++utilities/io/binaryreader.h>
14#include <c++utilities/io/binarywriter.h>
15#include <c++utilities/misc/flagenumclass.h>
16
17#include <iosfwd>
18#include <string>
19#include <string_view>
20
21namespace TagParser {
22
23class AbortableProgressFeedback;
25class WaveAudioStream;
26class Mp4Track;
27
31enum class TrackType {
35 Mp4Track,
37 OggStream,
40 IvfStream,
41};
42
46enum class TrackFlags : std::uint64_t {
47 None = 0,
48 HeaderValid = (1 << 0),
49 Enabled = (1 << 2),
50 Default = (1 << 3),
51 Forced = (1 << 4),
52 Lacing = (1 << 5),
53 Encrypted = (1 << 6),
54 UsedInPresentation = (1 << 7),
55 UsedWhenPreviewing = (1 << 8),
56 Interlaced = (1 << 9),
57};
58
62enum class FieldOrder : std::uint64_t {
63 Progressive = 0,
64 Tff = 1,
65 Undetermined = 2,
66 Bff = 6,
67 BffSwapped = 9,
68 TffSwapped = 14,
69};
70
75enum class StereoMode : std::uint64_t {
76 Unknown = std::numeric_limits<std::uint64_t>::max(),
77};
78
82enum class AlphaMode : std::uint64_t {
83 Unknown = std::numeric_limits<std::uint64_t>::max(),
84};
85
90
94enum class AspectRatioType : std::uint64_t {
97 Fixed,
98 Unknown = std::numeric_limits<std::uint64_t>::max(),
99};
100
101} // namespace TagParser
102
104
105namespace TagParser {
106
109 friend class WaveAudioStream;
110 friend class Mp4Track;
111
112public:
113 virtual ~AbstractTrack();
114
115 virtual TrackType type() const;
116 std::istream &inputStream();
117 void setInputStream(std::istream &stream);
118 std::ostream &outputStream();
119 void setOutputStream(std::ostream &stream);
120 CppUtilities::BinaryReader &reader();
121 CppUtilities::BinaryWriter &writer();
122 std::uint64_t startOffset() const;
123 TrackFlags flags() const;
124 MediaFormat format() const;
125 double version() const;
126 std::string_view formatName() const;
127 std::string_view formatAbbreviation() const;
128 const std::string &formatId() const;
129 MediaType mediaType() const;
130 std::string_view mediaTypeName() const;
131 std::uint64_t size() const;
132 std::uint32_t trackNumber() const;
133 void setTrackNumber(std::uint32_t trackNumber);
134 std::uint64_t id() const;
135 void setId(std::uint64_t id);
136 const std::string name() const;
137 void setName(std::string_view name);
138 const CppUtilities::TimeSpan &duration() const;
139 double bitrate() const;
140 double maxBitrate() const;
141 const CppUtilities::DateTime &creationTime() const;
142 const CppUtilities::DateTime &modificationTime() const;
143 const Locale &locale() const;
144 void setLocale(const Locale &locale);
145 std::uint32_t samplingFrequency() const;
146 std::uint32_t extensionSamplingFrequency() const;
147 std::uint16_t bitsPerSample() const;
148 std::uint16_t channelCount() const;
149 std::uint8_t channelConfig() const;
150 std::string_view channelConfigString() const;
151 std::uint8_t extensionChannelConfig() const;
152 std::string_view extensionChannelConfigString() const;
153 std::uint64_t sampleCount() const;
154 int quality() const;
155 const Size &pixelSize() const;
156 const Size &displaySize() const;
157 const Size &resolution() const;
158 const std::string &compressorName() const;
159 void setCompressorName(std::string_view compressorName);
160 std::uint16_t depth() const;
161 std::uint32_t fps() const;
162 std::string_view chromaFormat() const;
163 const AspectRatio &pixelAspectRatio() const;
164 bool isInterlaced() const;
165 std::uint32_t timeScale() const;
166 bool isEnabled() const;
167 void setEnabled(bool enabled);
168 bool isDefault() const;
169 void setDefault(bool isDefault);
170 bool isForced() const;
171 void setForced(bool forced);
172 bool hasLacing() const;
173 bool isEncrypted() const;
174 std::uint32_t colorSpace() const;
175 const Margin &cropping() const;
176 std::string label() const;
177 std::string description() const;
178 std::string shortDescription() const;
179
180 void parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
181 bool isHeaderValid() const;
182
183protected:
184 AbstractTrack(std::istream &inputStream, std::ostream &outputStream, std::uint64_t startOffset);
185 AbstractTrack(std::iostream &stream, std::uint64_t startOffset);
187
188 std::istream *m_istream;
189 std::ostream *m_ostream;
190 CppUtilities::BinaryReader m_reader;
191 CppUtilities::BinaryWriter m_writer;
192 std::uint64_t m_startOffset;
195 std::string m_formatId;
196 std::string m_formatName;
198 double m_version;
199 std::uint64_t m_size;
200 std::uint32_t m_trackNumber;
201 std::uint64_t m_id;
202 std::string m_name;
203 CppUtilities::TimeSpan m_duration;
204 double m_bitrate;
206 CppUtilities::DateTime m_creationTime;
207 CppUtilities::DateTime m_modificationTime;
209 std::uint32_t m_samplingFrequency;
211 std::uint16_t m_bitsPerSample;
212 std::uint32_t m_bytesPerSecond;
213 std::uint16_t m_channelCount;
214 std::uint8_t m_channelConfig;
216 std::uint16_t m_chunkSize;
217 std::uint64_t m_sampleCount;
222 std::string m_compressorName;
223 std::uint16_t m_depth;
224 std::uint32_t m_fps;
225 std::string_view m_chromaFormat;
227 std::uint32_t m_timeScale;
228 std::uint32_t m_colorSpace;
235
236private:
237 std::string makeDescription(bool verbose) const;
238};
239
243inline std::istream &AbstractTrack::inputStream()
244{
245 return *m_istream;
246}
247
254inline void AbstractTrack::setInputStream(std::istream &stream)
255{
256 m_reader.setStream(m_istream = &stream);
257}
258
262inline std::ostream &AbstractTrack::outputStream()
263{
264 return *m_ostream;
265}
266
273inline void AbstractTrack::setOutputStream(std::ostream &stream)
274{
275 m_writer.setStream(m_ostream = &stream);
276}
277
284inline CppUtilities::BinaryReader &AbstractTrack::reader()
285{
286 return m_reader;
287}
288
295inline CppUtilities::BinaryWriter &AbstractTrack::writer()
296{
297 return m_writer;
298}
299
304{
306}
307
311inline std::uint64_t AbstractTrack::startOffset() const
312{
313 return m_startOffset;
314}
315
321{
322 return m_flags;
323}
324
329{
330 return m_format;
331}
332
336inline double AbstractTrack::version() const
337{
338 return m_version;
339}
340
347inline std::string_view AbstractTrack::formatName() const
348{
349 return m_format || m_formatName.empty() ? m_format.name() : m_formatName;
350}
351
356inline std::string_view AbstractTrack::formatAbbreviation() const
357{
358 const auto abbr = m_format.abbreviation();
359 return !abbr.empty() || m_formatId.empty() ? abbr : m_formatId;
360}
361
366inline const std::string &AbstractTrack::formatId() const
367{
368 return m_formatId;
369}
370
375{
376 return m_mediaType;
377}
378
382inline std::string_view AbstractTrack::mediaTypeName() const
383{
385}
386
390inline std::uint64_t AbstractTrack::size() const
391{
392 return m_size;
393}
394
398inline std::uint32_t AbstractTrack::trackNumber() const
399{
400 return m_trackNumber;
401}
402
408{
410}
411
415inline std::uint64_t AbstractTrack::id() const
416{
417 return m_id;
418}
419
424inline void AbstractTrack::setId(std::uint64_t id)
425{
426 m_id = id;
427}
428
432inline const std::string AbstractTrack::name() const
433{
434 return m_name;
435}
436
441inline void AbstractTrack::setName(std::string_view name)
442{
443 m_name = name;
444}
445
449inline const CppUtilities::TimeSpan &AbstractTrack::duration() const
450{
451 return m_duration;
452}
453
457inline double AbstractTrack::bitrate() const
458{
459 return m_bitrate;
460}
461
465inline double AbstractTrack::maxBitrate() const
466{
467 return m_maxBitrate;
468}
469
473inline const CppUtilities::DateTime &AbstractTrack::creationTime() const
474{
475 return m_creationTime;
476}
477
481inline const CppUtilities::DateTime &AbstractTrack::modificationTime() const
482{
483 return m_modificationTime;
484}
485
491inline const Locale &AbstractTrack::locale() const
492{
493 return m_locale;
494}
495
500inline void AbstractTrack::setLocale(const Locale &locale)
501{
503}
504
508inline std::uint32_t AbstractTrack::samplingFrequency() const
509{
510 return m_samplingFrequency;
511}
512
518{
520}
521
525inline std::uint16_t AbstractTrack::bitsPerSample() const
526{
527 return m_bitsPerSample;
528}
529
535inline std::uint16_t AbstractTrack::channelCount() const
536{
537 return m_channelCount;
538}
539
546inline std::uint8_t AbstractTrack::channelConfig() const
547{
548 return m_channelConfig;
549}
550
554inline std::uint64_t AbstractTrack::sampleCount() const
555{
556 return m_sampleCount;
557}
558
564inline int AbstractTrack::quality() const
565{
566 return m_quality;
567}
568
574inline const Size &AbstractTrack::pixelSize() const
575{
576 return m_pixelSize;
577}
578
584inline const Size &AbstractTrack::displaySize() const
585{
586 return m_displaySize;
587}
588
594inline const Size &AbstractTrack::resolution() const
595{
596 return m_resolution;
597}
598
602inline const std::string &AbstractTrack::compressorName() const
603{
604 return m_compressorName;
605}
606
611inline void AbstractTrack::setCompressorName(std::string_view compressorName)
612{
614}
615
619inline std::uint16_t AbstractTrack::depth() const
620{
621 return m_depth;
622}
623
629inline std::uint32_t AbstractTrack::fps() const
630{
631 return m_fps;
632}
633
639inline std::string_view AbstractTrack::chromaFormat() const
640{
641 return m_chromaFormat;
642}
643
648{
649 return m_pixelAspectRatio;
650}
651
658{
660}
661
667inline std::uint32_t AbstractTrack::timeScale() const
668{
669 return m_timeScale;
670}
671
675inline bool AbstractTrack::isEnabled() const
676{
678}
679
684inline void AbstractTrack::setEnabled(bool enabled)
685{
686 CppUtilities::modFlagEnum(m_flags, TrackFlags::Enabled, enabled);
687}
688
692inline bool AbstractTrack::isDefault() const
693{
695}
696
701inline void AbstractTrack::setDefault(bool isDefault)
702{
703 CppUtilities::modFlagEnum(m_flags, TrackFlags::Default, isDefault);
704}
705
709inline bool AbstractTrack::isForced() const
710{
712}
713
718inline void AbstractTrack::setForced(bool forced)
719{
720 CppUtilities::modFlagEnum(m_flags, TrackFlags::Forced, forced);
721}
722
726inline bool AbstractTrack::hasLacing() const
727{
729}
730
734inline bool AbstractTrack::isEncrypted() const
735{
737}
738
742inline std::uint32_t AbstractTrack::colorSpace() const
743{
744 return m_colorSpace;
745}
746
750inline const Margin &AbstractTrack::cropping() const
751{
752 return m_cropping;
753}
754
759{
761}
762
763} // namespace TagParser
764
765#endif // TAG_PARSER_ABSTRACTTRACK_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...
std::uint64_t id() const
Returns the track ID if known; otherwise returns 0.
std::ostream * m_ostream
std::string_view formatAbbreviation() const
Returns the a more or less common abbreviation for the format of the track if known; otherwise return...
std::uint64_t size() const
Returns the size in bytes if known; otherwise returns 0.
std::uint32_t m_colorSpace
std::uint32_t timeScale() const
Returns the time scale if known; otherwise returns 0.
const CppUtilities::DateTime & modificationTime() const
Returns the time of the last modification if known; otherwise returns a DateTime of zero ticks.
std::uint8_t m_extensionChannelConfig
std::uint32_t extensionSamplingFrequency() const
Returns the number of samples per second if known; otherwise returns 0.
std::string_view m_chromaFormat
std::uint64_t m_sampleCount
std::uint16_t depth() const
Returns the bit depth if known; otherwise returns 0.
std::uint64_t startOffset() const
Returns the start offset of the track in the associated stream.
const Locale & locale() const
Returns the locale of the track if known; otherwise returns an empty locale.
std::uint32_t m_bytesPerSecond
const std::string & compressorName() const
Returns the compressor name if known; otherwise returns an empty string.
const CppUtilities::DateTime & creationTime() const
Returns the creation time if known; otherwise returns a DateTime of zero ticks.
double bitrate() const
Returns the average bitrate in kbit/s if known; otherwise returns zero.
AspectRatioType m_aspectRatioType
std::string_view formatName() const
Returns the format of the track as C-style string if known; otherwise returns the format abbreviation...
AspectRatio m_pixelAspectRatio
const Size & displaySize() const
Returns the size of the video frames to display if known; otherwise returns a zero size.
void setEnabled(bool enabled)
Sets whether the track is enabled.
double version() const
Returns the version/level of the track if known; otherwise returns 0.
const Size & pixelSize() const
Returns the size of the encoded video frames if known; otherwise returns a zero size.
std::uint16_t m_bitsPerSample
void setDefault(bool isDefault)
Sets whether the track is a default track.
std::uint32_t m_trackNumber
void setId(std::uint64_t id)
Sets the track ID.
std::istream & inputStream()
Returns the associated input stream.
virtual TrackType type() const
Returns the type of the track if known; otherwise returns TrackType::Unspecified.
void setCompressorName(std::string_view compressorName)
Returns the compressor name if known; otherwise returns an empty string.
bool isEnabled() const
Returns true if the track is marked as enabled; otherwise returns false.
std::uint16_t m_channelCount
bool hasLacing() const
Returns true if the track has lacing; otherwise returns false.
std::uint64_t sampleCount() const
Returns the number of samples/frames if known; otherwise returns 0.
std::uint8_t m_channelConfig
std::uint32_t samplingFrequency() const
Returns the number of samples per second if known; otherwise returns 0.
const AspectRatio & pixelAspectRatio() const
Returns the pixel aspect ratio (PAR).
CppUtilities::BinaryReader & reader()
Returns a binary reader for the associated stream.
CppUtilities::TimeSpan m_duration
std::uint32_t trackNumber() const
Returns the track number if known; otherwise returns 0.
const std::string & formatId() const
Returns the format/codec ID.
CppUtilities::BinaryReader m_reader
int quality() const
Returns the quality if known; otherwise returns 0.
std::uint32_t fps() const
Returns the number of frames per second if known; otherwise returns 0.
void setName(std::string_view name)
Sets the name.
std::string_view mediaTypeName() const
Returns the string representation of the media type of the track.
std::uint64_t m_startOffset
std::uint32_t colorSpace() const
Returns the color space if known; otherwise returns 0.
TrackFlags flags() const
Returns flags (various boolean properties) of this track.
MediaType mediaType() const
Returns the media type if known; otherwise returns MediaType::Other.
CppUtilities::DateTime m_modificationTime
void setTrackNumber(std::uint32_t trackNumber)
Sets the track number.
CppUtilities::BinaryWriter m_writer
std::uint16_t channelCount() const
Returns the number of channels if known; otherwise returns 0.
std::uint16_t bitsPerSample() const
Returns the number of bits per sample; otherwise returns 0.
bool isHeaderValid() const
Returns an indication whether the track header is valid.
void setOutputStream(std::ostream &stream)
Assigns another output stream.
std::ostream & outputStream()
Returns the associated output stream.
void setForced(bool forced)
Sets whether the track is forced.
void setInputStream(std::istream &stream)
Assigns another input stream.
double maxBitrate() const
Returns the maximum bitrate in kbit/s if known; otherwise returns zero.
const CppUtilities::TimeSpan & duration() const
Returns the duration if known; otherwise returns a TimeSpan of zero ticks.
std::uint32_t m_extensionSamplingFrequency
virtual void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)=0
This method is internally called to parse header information.
std::string_view chromaFormat() const
Returns the chroma subsampling format if known; otherwise returns nullptr.
bool isForced() const
Returns true if the track is marked as forced; otherwise returns false.
bool isEncrypted() const
Returns true if the track is marked as encrypted; otherwise returns false.
std::uint8_t channelConfig() const
Returns the channel configuration.
const Size & resolution() const
Returns the resolution if known; otherwise returns a zero size.
const std::string name() const
Returns the track name if known; otherwise returns an empty string.
bool isDefault() const
Returns true if the track is marked as default; otherwise returns false.
CppUtilities::DateTime m_creationTime
void setLocale(const Locale &locale)
Sets the locale of the track.
std::istream * m_istream
std::uint32_t m_samplingFrequency
bool isInterlaced() const
Returns true if the video is interlaced; otherwise returns false.
const Margin & cropping() const
Returns the cropping if known; otherwise returns zero margins.
CppUtilities::BinaryWriter & writer()
Returns a binary writer for the associated stream.
MediaFormat format() const
Returns the format of the track if known; otherwise returns MediaFormat::Unknown.
Implementation of TagParser::AbstractTrack for ADTS streams.
Definition: adtsstream.h:10
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
Implementation of TagParser::AbstractTrack for raw FLAC streams.
Definition: flacstream.h:14
Implementation of TagParser::AbstractTrack for ADTS streams.
Definition: ivfstream.h:10
The Margin class defines the four margins of a rectangle.
Definition: margin.h:16
Implementation of TagParser::AbstractTrack for the Matroska container.
Definition: matroskatrack.h:48
The MediaFormat class specifies the format of media data.
Definition: mediaformat.h:246
std::string_view abbreviation() const
Returns the abbreviation of the media format as C-style string.
std::string_view name() const
Returns the name of the media format as C-style string.
Definition: mediaformat.cpp:17
Implementation of TagParser::AbstractTrack for the MP4 container.
Definition: mp4track.h:119
Implementation of TagParser::AbstractTrack MPEG audio streams.
Implementation of TagParser::AbstractTrack for OGG streams.
Definition: oggstream.h:13
The Size class defines the size of a two-dimensional object using integer point precision.
Definition: size.h:17
Implementation of TagParser::AbstractTrack for the RIFF WAVE container format.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
constexpr TAG_PARSER_EXPORT std::string_view bitrate()
The track's bit rate in bits per second.
constexpr TAG_PARSER_EXPORT std::string_view description()
constexpr TAG_PARSER_EXPORT std::string_view duration()
constexpr TAG_PARSER_EXPORT std::string_view fps()
TAG_PARSER_EXPORT std::string_view channelConfigString(std::uint8_t config)
Returns the string representation for the specified MPEG-4 channel config.
Definition: mp4ids.cpp:434
TAG_PARSER_EXPORT std::uint8_t channelCount(std::uint8_t config)
Returns the channel count for the specified MPEG-4 channel config.
Definition: mp4ids.cpp:461
constexpr TAG_PARSER_EXPORT std::string_view trackNumber()
constexpr TAG_PARSER_EXPORT std::string_view version()
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
AspectRatioType
The AspectRatioType enum specifies the possible modifications to the aspect ratio.
Definition: abstracttrack.h:94
StereoMode
The StereoMode enum specifies the Stereo-3D video mode.
Definition: abstracttrack.h:75
DisplayUnit
The DisplayUnit enum specifies how display width and heigh are interpreted.
Definition: abstracttrack.h:89
AlphaMode
The AlphaMode enum specifies the alpha video mode.
Definition: abstracttrack.h:82
MediaType
The MediaType enum specifies the type of media data (audio, video, text, ...).
Definition: mediaformat.h:14
FieldOrder
The FieldOrder enum declares the field ordering of the video.
Definition: abstracttrack.h:62
TrackType
The TrackType enum specifies the underlying file type of a track and the concrete class of the track ...
Definition: abstracttrack.h:31
TAG_PARSER_EXPORT std::string_view mediaTypeName(MediaType mediaType)
Returns the string representation for the specified mediaType.
TrackFlags
The TrackFlags enum specifies miscellaneous boolean properties of a track.
Definition: abstracttrack.h:46
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(TagParser, TagParser::TagCreationFlags)
The AspectRatio struct defines an aspect ratio.
Definition: aspectratio.h:13
The Locale struct specifies a language and/or a country using one or more LocaleDetail objects.
Definition: localehelper.h:61