Tag Parser 12.1.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
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 <memory>
19#include <string>
20#include <string_view>
21
22namespace TagParser {
23
24class AbortableProgressFeedback;
26class WaveAudioStream;
27class Mp4Track;
28
43
47enum class TrackFlags : std::uint64_t {
48 None = 0,
49 HeaderValid = (1 << 0),
50 Enabled = (1 << 2),
51 Default = (1 << 3),
52 Forced = (1 << 4),
53 Lacing = (1 << 5),
54 Encrypted = (1 << 6),
55 UsedInPresentation = (1 << 7),
56 UsedWhenPreviewing = (1 << 8),
57 Interlaced = (1 << 9),
58};
59
63enum class FieldOrder : std::uint64_t {
64 Progressive = 0,
65 Tff = 1,
66 Undetermined = 2,
67 Bff = 6,
68 BffSwapped = 9,
69 TffSwapped = 14,
70};
71
76enum class StereoMode : std::uint64_t {
77 Unknown = std::numeric_limits<std::uint64_t>::max(),
78};
79
83enum class AlphaMode : std::uint64_t {
84 Unknown = std::numeric_limits<std::uint64_t>::max(),
85};
86
91
95enum class AspectRatioType : std::uint64_t {
98 Fixed,
99 Unknown = std::numeric_limits<std::uint64_t>::max(),
100};
101
102} // namespace TagParser
103
105
106namespace TagParser {
107
108struct AbstractTrackPrivate;
109
112 friend class WaveAudioStream;
113 friend class Mp4Track;
114
115public:
116 virtual ~AbstractTrack();
117
118 virtual TrackType type() const;
119 std::istream &inputStream();
120 void setInputStream(std::istream &stream);
121 std::ostream &outputStream();
122 void setOutputStream(std::ostream &stream);
123 CppUtilities::BinaryReader &reader();
124 CppUtilities::BinaryWriter &writer();
125 std::uint64_t startOffset() const;
126 TrackFlags flags() const;
127 MediaFormat format() const;
128 double version() const;
129 std::string_view formatName() const;
130 std::string_view formatAbbreviation() const;
131 const std::string &formatId() const;
132 MediaType mediaType() const;
133 std::string_view mediaTypeName() const;
134 std::uint64_t size() const;
135 void setSize(std::uint64_t size);
136 std::uint32_t trackNumber() const;
137 void setTrackNumber(std::uint32_t trackNumber);
138 std::uint64_t id() const;
139 void setId(std::uint64_t id);
140 const std::string name() const;
141 void setName(std::string_view name);
142 const CppUtilities::TimeSpan &duration() const;
143 double bitrate() const;
144 double maxBitrate() const;
145 const CppUtilities::DateTime &creationTime() const;
146 const CppUtilities::DateTime &modificationTime() const;
147 const Locale &locale() const;
148 void setLocale(const Locale &locale);
149 std::uint32_t samplingFrequency() const;
150 std::uint32_t extensionSamplingFrequency() const;
151 std::uint16_t bitsPerSample() const;
152 std::uint16_t channelCount() const;
153 std::uint8_t channelConfig() const;
154 std::string_view channelConfigString() const;
155 std::uint8_t extensionChannelConfig() const;
156 std::string_view extensionChannelConfigString() const;
157 std::uint64_t sampleCount() const;
158 int quality() const;
159 const Size &pixelSize() const;
160 const Size &displaySize() const;
161 const Size &resolution() const;
162 const std::string &compressorName() const;
163 void setCompressorName(std::string_view compressorName);
164 std::uint16_t depth() const;
165 std::uint32_t fps() const;
166 std::string_view chromaFormat() const;
167 const AspectRatio &pixelAspectRatio() const;
168 bool isInterlaced() const;
169 std::uint32_t timeScale() const;
170 bool isEnabled() const;
171 void setEnabled(bool enabled);
172 bool isDefault() const;
173 void setDefault(bool isDefault);
174 bool isForced() const;
175 void setForced(bool forced);
176 bool hasLacing() const;
177 bool isEncrypted() const;
178 std::uint32_t colorSpace() const;
179 const Margin &cropping() const;
180 std::string label() const;
181 std::string description() const;
182 std::string shortDescription() const;
183
184 void parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress);
185 bool isHeaderValid() const;
186
187protected:
188 AbstractTrack(std::istream &inputStream, std::ostream &outputStream, std::uint64_t startOffset);
189 AbstractTrack(std::iostream &stream, std::uint64_t startOffset);
191
192 std::istream *m_istream;
193 std::ostream *m_ostream;
194 CppUtilities::BinaryReader m_reader;
195 CppUtilities::BinaryWriter m_writer;
196 std::uint64_t m_startOffset;
199 std::string m_formatId;
200 std::string m_formatName;
202 double m_version;
203 std::uint64_t m_size;
204 std::uint32_t m_trackNumber;
205 std::uint64_t m_id;
206 std::string m_name;
207 CppUtilities::TimeSpan m_duration;
208 double m_bitrate;
210 CppUtilities::DateTime m_creationTime;
211 CppUtilities::DateTime m_modificationTime;
213 std::uint32_t m_samplingFrequency;
215 std::uint16_t m_bitsPerSample;
216 std::uint32_t m_bytesPerSecond;
217 std::uint16_t m_channelCount;
218 std::uint8_t m_channelConfig;
220 std::uint16_t m_chunkSize;
221 std::uint64_t m_sampleCount;
226 std::string m_compressorName;
227 std::uint16_t m_depth;
228 std::uint32_t m_fps;
229 std::string_view m_chromaFormat;
231 std::uint32_t m_timeScale;
232 std::uint32_t m_colorSpace;
239 std::unique_ptr<AbstractTrackPrivate> m_p;
240
241private:
242 std::string makeDescription(bool verbose) const;
243};
244
248inline std::istream &AbstractTrack::inputStream()
249{
250 return *m_istream;
251}
252
259inline void AbstractTrack::setInputStream(std::istream &stream)
260{
261 m_reader.setStream(m_istream = &stream);
262}
263
267inline std::ostream &AbstractTrack::outputStream()
268{
269 return *m_ostream;
270}
271
278inline void AbstractTrack::setOutputStream(std::ostream &stream)
279{
280 m_writer.setStream(m_ostream = &stream);
281}
282
289inline CppUtilities::BinaryReader &AbstractTrack::reader()
290{
291 return m_reader;
292}
293
300inline CppUtilities::BinaryWriter &AbstractTrack::writer()
301{
302 return m_writer;
303}
304
309{
311}
312
316inline std::uint64_t AbstractTrack::startOffset() const
317{
318 return m_startOffset;
319}
320
326{
327 return m_flags;
328}
329
334{
335 return m_format;
336}
337
341inline double AbstractTrack::version() const
342{
343 return m_version;
344}
345
352inline std::string_view AbstractTrack::formatName() const
353{
354 return m_format || m_formatName.empty() ? m_format.name() : m_formatName;
355}
356
361inline std::string_view AbstractTrack::formatAbbreviation() const
362{
363 const auto abbr = m_format.abbreviation();
364 return !abbr.empty() || m_formatId.empty() ? abbr : m_formatId;
365}
366
371inline const std::string &AbstractTrack::formatId() const
372{
373 return m_formatId;
374}
375
380{
381 return m_mediaType;
382}
383
387inline std::string_view AbstractTrack::mediaTypeName() const
388{
389 return ::TagParser::mediaTypeName(m_mediaType);
390}
391
395inline std::uint64_t AbstractTrack::size() const
396{
397 return m_size;
398}
399
408inline void AbstractTrack::setSize(std::uint64_t size)
409{
410 m_size = size;
411}
412
416inline std::uint32_t AbstractTrack::trackNumber() const
417{
418 return m_trackNumber;
419}
420
425inline void AbstractTrack::setTrackNumber(std::uint32_t trackNumber)
426{
428}
429
433inline std::uint64_t AbstractTrack::id() const
434{
435 return m_id;
436}
437
442inline void AbstractTrack::setId(std::uint64_t id)
443{
444 m_id = id;
445}
446
450inline const std::string AbstractTrack::name() const
451{
452 return m_name;
453}
454
459inline void AbstractTrack::setName(std::string_view name)
460{
461 m_name = name;
462}
463
467inline const CppUtilities::TimeSpan &AbstractTrack::duration() const
468{
469 return m_duration;
470}
471
475inline double AbstractTrack::bitrate() const
476{
477 return m_bitrate;
478}
479
483inline double AbstractTrack::maxBitrate() const
484{
485 return m_maxBitrate;
486}
487
491inline const CppUtilities::DateTime &AbstractTrack::creationTime() const
492{
493 return m_creationTime;
494}
495
499inline const CppUtilities::DateTime &AbstractTrack::modificationTime() const
500{
501 return m_modificationTime;
502}
503
509inline const Locale &AbstractTrack::locale() const
510{
511 return m_locale;
512}
513
518inline void AbstractTrack::setLocale(const Locale &locale)
519{
521}
522
526inline std::uint32_t AbstractTrack::samplingFrequency() const
527{
528 return m_samplingFrequency;
529}
530
536{
538}
539
543inline std::uint16_t AbstractTrack::bitsPerSample() const
544{
545 return m_bitsPerSample;
546}
547
553inline std::uint16_t AbstractTrack::channelCount() const
554{
555 return m_channelCount;
556}
557
564inline std::uint8_t AbstractTrack::channelConfig() const
565{
566 return m_channelConfig;
567}
568
572inline std::uint64_t AbstractTrack::sampleCount() const
573{
574 return m_sampleCount;
575}
576
582inline int AbstractTrack::quality() const
583{
584 return m_quality;
585}
586
592inline const Size &AbstractTrack::pixelSize() const
593{
594 return m_pixelSize;
595}
596
602inline const Size &AbstractTrack::displaySize() const
603{
604 return m_displaySize;
605}
606
612inline const Size &AbstractTrack::resolution() const
613{
614 return m_resolution;
615}
616
620inline const std::string &AbstractTrack::compressorName() const
621{
622 return m_compressorName;
623}
624
629inline void AbstractTrack::setCompressorName(std::string_view compressorName)
630{
632}
633
637inline std::uint16_t AbstractTrack::depth() const
638{
639 return m_depth;
640}
641
647inline std::uint32_t AbstractTrack::fps() const
648{
649 return m_fps;
650}
651
657inline std::string_view AbstractTrack::chromaFormat() const
658{
659 return m_chromaFormat;
660}
661
666{
667 return m_pixelAspectRatio;
668}
669
676{
678}
679
685inline std::uint32_t AbstractTrack::timeScale() const
686{
687 return m_timeScale;
688}
689
693inline bool AbstractTrack::isEnabled() const
694{
696}
697
702inline void AbstractTrack::setEnabled(bool enabled)
703{
704 CppUtilities::modFlagEnum(m_flags, TrackFlags::Enabled, enabled);
705}
706
710inline bool AbstractTrack::isDefault() const
711{
713}
714
719inline void AbstractTrack::setDefault(bool isDefault)
720{
721 CppUtilities::modFlagEnum(m_flags, TrackFlags::Default, isDefault);
722}
723
727inline bool AbstractTrack::isForced() const
728{
730}
731
736inline void AbstractTrack::setForced(bool forced)
737{
738 CppUtilities::modFlagEnum(m_flags, TrackFlags::Forced, forced);
739}
740
744inline bool AbstractTrack::hasLacing() const
745{
747}
748
752inline bool AbstractTrack::isEncrypted() const
753{
755}
756
760inline std::uint32_t AbstractTrack::colorSpace() const
761{
762 return m_colorSpace;
763}
764
768inline const Margin &AbstractTrack::cropping() const
769{
770 return m_cropping;
771}
772
777{
779}
780
781} // namespace TagParser
782
783#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::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 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::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...
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.
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.
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::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::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::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.
std::unique_ptr< AbstractTrackPrivate > m_p
void setSize(std::uint64_t size)
Sets the size in bytes.
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.
Implementation of TagParser::AbstractTrack for raw FLAC streams.
Definition flacstream.h:14
Implementation of TagParser::AbstractTrack for IVF 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.
The MediaFormat class specifies the format of media data.
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.
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.
Definition global.h:13
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.
StereoMode
The StereoMode enum specifies the Stereo-3D video mode.
DisplayUnit
The DisplayUnit enum specifies how display width and heigh are interpreted.
AlphaMode
The AlphaMode enum specifies the alpha video mode.
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.
TrackType
The TrackType enum specifies the underlying file type of a track and the concrete class of the track ...
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.
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.