Tag Parser 10.3.1
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
59} // namespace TagParser
60
62
63namespace TagParser {
64
67 friend class WaveAudioStream;
68 friend class Mp4Track;
69
70public:
71 virtual ~AbstractTrack();
72
73 virtual TrackType type() const;
74 std::istream &inputStream();
75 void setInputStream(std::istream &stream);
76 std::ostream &outputStream();
77 void setOutputStream(std::ostream &stream);
78 CppUtilities::BinaryReader &reader();
79 CppUtilities::BinaryWriter &writer();
80 std::uint64_t startOffset() const;
81 TrackFlags flags() const;
82 MediaFormat format() const;
83 double version() const;
84 std::string_view formatName() const;
85 std::string_view formatAbbreviation() const;
86 const std::string &formatId() const;
87 MediaType mediaType() const;
88 std::string_view mediaTypeName() const;
89 std::uint64_t size() const;
90 std::uint32_t trackNumber() const;
91 void setTrackNumber(std::uint32_t trackNumber);
92 std::uint64_t id() const;
93 void setId(std::uint64_t id);
94 const std::string name() const;
95 void setName(std::string_view name);
96 const CppUtilities::TimeSpan &duration() const;
97 double bitrate() const;
98 double maxBitrate() const;
99 const CppUtilities::DateTime &creationTime() const;
100 const CppUtilities::DateTime &modificationTime() const;
101 const Locale &locale() const;
102 void setLocale(const Locale &locale);
103 std::uint32_t samplingFrequency() const;
104 std::uint32_t extensionSamplingFrequency() const;
105 std::uint16_t bitsPerSample() const;
106 std::uint16_t channelCount() const;
107 std::uint8_t channelConfig() const;
108 std::string_view channelConfigString() const;
109 std::uint8_t extensionChannelConfig() const;
110 std::string_view extensionChannelConfigString() const;
111 std::uint64_t sampleCount() const;
112 int quality() const;
113 const Size &pixelSize() const;
114 const Size &displaySize() const;
115 const Size &resolution() const;
116 const std::string &compressorName() const;
117 void setCompressorName(std::string_view compressorName);
118 std::uint16_t depth() const;
119 std::uint32_t fps() const;
120 std::string_view chromaFormat() const;
121 const AspectRatio &pixelAspectRatio() const;
122 bool isInterlaced() const;
123 std::uint32_t timeScale() const;
124 bool isEnabled() const;
125 void setEnabled(bool enabled);
126 bool isDefault() const;
127 void setDefault(bool isDefault);
128 bool isForced() const;
129 void setForced(bool forced);
130 bool hasLacing() const;
131 bool isEncrypted() const;
132 std::uint32_t colorSpace() const;
133 const Margin &cropping() const;
134 std::string label() const;
135 std::string description() const;
136 std::string shortDescription() const;
137
138 void parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
139 bool isHeaderValid() const;
140
141protected:
142 AbstractTrack(std::istream &inputStream, std::ostream &outputStream, std::uint64_t startOffset);
143 AbstractTrack(std::iostream &stream, std::uint64_t startOffset);
145
146 std::istream *m_istream;
147 std::ostream *m_ostream;
148 CppUtilities::BinaryReader m_reader;
149 CppUtilities::BinaryWriter m_writer;
150 std::uint64_t m_startOffset;
153 std::string m_formatId;
154 std::string m_formatName;
156 double m_version;
157 std::uint64_t m_size;
158 std::uint32_t m_trackNumber;
159 std::uint64_t m_id;
160 std::string m_name;
161 CppUtilities::TimeSpan m_duration;
162 double m_bitrate;
164 CppUtilities::DateTime m_creationTime;
165 CppUtilities::DateTime m_modificationTime;
167 std::uint32_t m_samplingFrequency;
169 std::uint16_t m_bitsPerSample;
170 std::uint32_t m_bytesPerSecond;
171 std::uint16_t m_channelCount;
172 std::uint8_t m_channelConfig;
174 std::uint16_t m_chunkSize;
175 std::uint64_t m_sampleCount;
180 std::string m_compressorName;
181 std::uint16_t m_depth;
182 std::uint32_t m_fps;
183 std::string_view m_chromaFormat;
185 std::uint32_t m_timeScale;
186 std::uint32_t m_colorSpace;
188
189private:
190 std::string makeDescription(bool verbose) const;
191};
192
196inline std::istream &AbstractTrack::inputStream()
197{
198 return *m_istream;
199}
200
207inline void AbstractTrack::setInputStream(std::istream &stream)
208{
209 m_reader.setStream(m_istream = &stream);
210}
211
215inline std::ostream &AbstractTrack::outputStream()
216{
217 return *m_ostream;
218}
219
226inline void AbstractTrack::setOutputStream(std::ostream &stream)
227{
228 m_writer.setStream(m_ostream = &stream);
229}
230
237inline CppUtilities::BinaryReader &AbstractTrack::reader()
238{
239 return m_reader;
240}
241
248inline CppUtilities::BinaryWriter &AbstractTrack::writer()
249{
250 return m_writer;
251}
252
257{
259}
260
264inline std::uint64_t AbstractTrack::startOffset() const
265{
266 return m_startOffset;
267}
268
274{
275 return m_flags;
276}
277
282{
283 return m_format;
284}
285
289inline double AbstractTrack::version() const
290{
291 return m_version;
292}
293
300inline std::string_view AbstractTrack::formatName() const
301{
302 return m_format || m_formatName.empty() ? m_format.name() : m_formatName;
303}
304
309inline std::string_view AbstractTrack::formatAbbreviation() const
310{
311 const auto abbr = m_format.abbreviation();
312 return !abbr.empty() || m_formatId.empty() ? abbr : m_formatId;
313}
314
319inline const std::string &AbstractTrack::formatId() const
320{
321 return m_formatId;
322}
323
328{
329 return m_mediaType;
330}
331
335inline std::string_view AbstractTrack::mediaTypeName() const
336{
338}
339
343inline std::uint64_t AbstractTrack::size() const
344{
345 return m_size;
346}
347
351inline std::uint32_t AbstractTrack::trackNumber() const
352{
353 return m_trackNumber;
354}
355
361{
363}
364
368inline std::uint64_t AbstractTrack::id() const
369{
370 return m_id;
371}
372
377inline void AbstractTrack::setId(std::uint64_t id)
378{
379 m_id = id;
380}
381
385inline const std::string AbstractTrack::name() const
386{
387 return m_name;
388}
389
394inline void AbstractTrack::setName(std::string_view name)
395{
396 m_name = name;
397}
398
402inline const CppUtilities::TimeSpan &AbstractTrack::duration() const
403{
404 return m_duration;
405}
406
410inline double AbstractTrack::bitrate() const
411{
412 return m_bitrate;
413}
414
418inline double AbstractTrack::maxBitrate() const
419{
420 return m_maxBitrate;
421}
422
426inline const CppUtilities::DateTime &AbstractTrack::creationTime() const
427{
428 return m_creationTime;
429}
430
434inline const CppUtilities::DateTime &AbstractTrack::modificationTime() const
435{
436 return m_modificationTime;
437}
438
444inline const Locale &AbstractTrack::locale() const
445{
446 return m_locale;
447}
448
453inline void AbstractTrack::setLocale(const Locale &locale)
454{
456}
457
461inline std::uint32_t AbstractTrack::samplingFrequency() const
462{
463 return m_samplingFrequency;
464}
465
471{
473}
474
478inline std::uint16_t AbstractTrack::bitsPerSample() const
479{
480 return m_bitsPerSample;
481}
482
488inline std::uint16_t AbstractTrack::channelCount() const
489{
490 return m_channelCount;
491}
492
499inline std::uint8_t AbstractTrack::channelConfig() const
500{
501 return m_channelConfig;
502}
503
507inline std::uint64_t AbstractTrack::sampleCount() const
508{
509 return m_sampleCount;
510}
511
517inline int AbstractTrack::quality() const
518{
519 return m_quality;
520}
521
527inline const Size &AbstractTrack::pixelSize() const
528{
529 return m_pixelSize;
530}
531
537inline const Size &AbstractTrack::displaySize() const
538{
539 return m_displaySize;
540}
541
547inline const Size &AbstractTrack::resolution() const
548{
549 return m_resolution;
550}
551
555inline const std::string &AbstractTrack::compressorName() const
556{
557 return m_compressorName;
558}
559
564inline void AbstractTrack::setCompressorName(std::string_view compressorName)
565{
567}
568
572inline std::uint16_t AbstractTrack::depth() const
573{
574 return m_depth;
575}
576
582inline std::uint32_t AbstractTrack::fps() const
583{
584 return m_fps;
585}
586
592inline std::string_view AbstractTrack::chromaFormat() const
593{
594 return m_chromaFormat;
595}
596
601{
602 return m_pixelAspectRatio;
603}
604
611{
613}
614
620inline std::uint32_t AbstractTrack::timeScale() const
621{
622 return m_timeScale;
623}
624
628inline bool AbstractTrack::isEnabled() const
629{
631}
632
637inline void AbstractTrack::setEnabled(bool enabled)
638{
639 CppUtilities::modFlagEnum(m_flags, TrackFlags::Enabled, enabled);
640}
641
645inline bool AbstractTrack::isDefault() const
646{
648}
649
654inline void AbstractTrack::setDefault(bool isDefault)
655{
656 CppUtilities::modFlagEnum(m_flags, TrackFlags::Default, isDefault);
657}
658
662inline bool AbstractTrack::isForced() const
663{
665}
666
671inline void AbstractTrack::setForced(bool forced)
672{
673 CppUtilities::modFlagEnum(m_flags, TrackFlags::Forced, forced);
674}
675
679inline bool AbstractTrack::hasLacing() const
680{
682}
683
687inline bool AbstractTrack::isEncrypted() const
688{
690}
691
695inline std::uint32_t AbstractTrack::colorSpace() const
696{
697 return m_colorSpace;
698}
699
703inline const Margin &AbstractTrack::cropping() const
704{
705 return m_cropping;
706}
707
712{
714}
715
716} // namespace TagParser
717
718#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...
Definition: abstracttrack.h:65
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.
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.
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
The Margin class defines the four margins of a rectangle.
Definition: margin.h:16
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:118
Implementation of TagParser::AbstractTrack MPEG audio streams.
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:433
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:460
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
MediaType
The MediaType enum specifies the type of media data (audio, video, text, ...).
Definition: mediaformat.h:14
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