Tag Parser  8.2.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 "./margin.h"
7 #include "./mediaformat.h"
8 #include "./size.h"
9 
10 #include <c++utilities/chrono/datetime.h>
11 #include <c++utilities/chrono/timespan.h>
12 #include <c++utilities/conversion/types.h>
13 #include <c++utilities/io/binaryreader.h>
14 #include <c++utilities/io/binarywriter.h>
15 
16 #include <iosfwd>
17 #include <string>
18 
19 namespace TagParser {
20 
22 class WaveAudioStream;
23 class Mp4Track;
24 
28 enum class TrackType {
29  Unspecified,
32  Mp4Track,
34  OggStream,
35  AdtsStream,
36  FlacStream,
37  IvfStream,
38 };
39 
41  friend class MpegAudioFrameStream;
42  friend class WaveAudioStream;
43  friend class Mp4Track;
44 
45 public:
46  virtual ~AbstractTrack();
47 
48  virtual TrackType type() const;
49  std::istream &inputStream();
50  void setInputStream(std::istream &stream);
51  std::ostream &outputStream();
52  void setOutputStream(std::ostream &stream);
53  IoUtilities::BinaryReader &reader();
54  IoUtilities::BinaryWriter &writer();
55  uint64 startOffset() const;
56  MediaFormat format() const;
57  double version() const;
58  const char *formatName() const;
59  const char *formatAbbreviation() const;
60  const std::string &formatId() const;
61  MediaType mediaType() const;
62  const char *mediaTypeName() const;
63  uint64 size() const;
64  uint32 trackNumber() const;
65  void setTrackNumber(uint32 trackNumber);
66  uint64 id() const;
67  void setId(uint64 id);
68  const std::string name() const;
69  void setName(const std::string &name);
70  const ChronoUtilities::TimeSpan &duration() const;
71  double bitrate() const;
72  double maxBitrate() const;
73  const ChronoUtilities::DateTime &creationTime() const;
74  const ChronoUtilities::DateTime &modificationTime() const;
75  const std::string &language() const;
76  void setLanguage(const std::string &language);
77  uint32 samplingFrequency() const;
78  uint32 extensionSamplingFrequency() const;
79  uint16 bitsPerSample() const;
80  uint16 channelCount() const;
81  byte channelConfig() const;
82  const char *channelConfigString() const;
83  byte extensionChannelConfig() const;
84  const char *extensionChannelConfigString() const;
85  uint64 sampleCount() const;
86  int quality() const;
87  const Size &pixelSize() const;
88  const Size &displaySize() const;
89  const Size &resolution() const;
90  const std::string &compressorName() const;
91  void setCompressorName(const std::string &compressorName);
92  uint16 depth() const;
93  uint32 fps() const;
94  const char *chromaFormat() const;
95  const AspectRatio &pixelAspectRatio() const;
96  bool isInterlaced() const;
97  uint32 timeScale() const;
98  bool isEnabled() const;
99  void setEnabled(bool enabled);
100  bool isDefault() const;
101  void setDefault(bool isDefault);
102  bool isForced() const;
103  void setForced(bool forced);
104  bool hasLacing() const;
105  bool isEncrypted() const;
106  uint32 colorSpace() const;
107  const Margin &cropping() const;
108  std::string label() const;
109  std::string description() const;
110 
111  void parseHeader(Diagnostics &diag);
112  bool isHeaderValid() const;
113 
114 protected:
115  AbstractTrack(std::istream &inputStream, std::ostream &outputStream, uint64 startOffset);
116  AbstractTrack(std::iostream &stream, uint64 startOffset);
117  virtual void internalParseHeader(Diagnostics &diag) = 0;
118 
119  std::istream *m_istream;
120  std::ostream *m_ostream;
121  IoUtilities::BinaryReader m_reader;
122  IoUtilities::BinaryWriter m_writer;
126  std::string m_formatId;
127  std::string m_formatName;
129  double m_version;
130  uint64 m_size;
132  uint64 m_id;
133  std::string m_name;
135  double m_bitrate;
136  double m_maxBitrate;
139  std::string m_language;
147  uint16 m_chunkSize;
153  std::string m_compressorName;
154  uint16 m_depth;
155  uint32 m_fps;
156  const char *m_chromaFormat;
159  uint32 m_timeScale;
160  bool m_enabled;
161  bool m_default;
162  bool m_forced;
163  bool m_lacing;
167  uint32 m_colorSpace;
169 };
170 
174 inline std::istream &AbstractTrack::inputStream()
175 {
176  return *m_istream;
177 }
178 
185 inline void AbstractTrack::setInputStream(std::istream &stream)
186 {
187  m_reader.setStream(m_istream = &stream);
188 }
189 
193 inline std::ostream &AbstractTrack::outputStream()
194 {
195  return *m_ostream;
196 }
197 
204 inline void AbstractTrack::setOutputStream(std::ostream &stream)
205 {
206  m_writer.setStream(m_ostream = &stream);
207 }
208 
215 inline IoUtilities::BinaryReader &AbstractTrack::reader()
216 {
217  return m_reader;
218 }
219 
226 inline IoUtilities::BinaryWriter &AbstractTrack::writer()
227 {
228  return m_writer;
229 }
230 
235 {
236  return TrackType::Unspecified;
237 }
238 
242 inline uint64 AbstractTrack::startOffset() const
243 {
244  return m_startOffset;
245 }
246 
251 {
252  return m_format;
253 }
254 
258 inline double AbstractTrack::version() const
259 {
260  return m_version;
261 }
262 
270 inline const char *AbstractTrack::formatName() const
271 {
272  return m_format || m_formatName.empty() ? m_format.name() : m_formatName.c_str();
273 }
274 
279 inline const char *AbstractTrack::formatAbbreviation() const
280 {
281  const char *abbr = m_format.abbreviation();
282  return *abbr || m_formatId.empty() ? m_format.abbreviation() : m_formatId.c_str();
283 }
284 
289 inline const std::string &AbstractTrack::formatId() const
290 {
291  return m_formatId;
292 }
293 
298 {
299  return m_mediaType;
300 }
301 
305 inline const char *AbstractTrack::mediaTypeName() const
306 {
308 }
309 
313 inline uint64 AbstractTrack::size() const
314 {
315  return m_size;
316 }
317 
321 inline uint32 AbstractTrack::trackNumber() const
322 {
323  return m_trackNumber;
324 }
325 
331 {
333 }
334 
338 inline uint64 AbstractTrack::id() const
339 {
340  return m_id;
341 }
342 
347 inline void AbstractTrack::setId(uint64 id)
348 {
349  m_id = id;
350 }
351 
355 inline const std::string AbstractTrack::name() const
356 {
357  return m_name;
358 }
359 
364 inline void AbstractTrack::setName(const std::string &name)
365 {
366  m_name = name;
367 }
368 
373 {
374  return m_duration;
375 }
376 
380 inline double AbstractTrack::bitrate() const
381 {
382  return m_bitrate;
383 }
384 
388 inline double AbstractTrack::maxBitrate() const
389 {
390  return m_maxBitrate;
391 }
392 
397 {
398  return m_creationTime;
399 }
400 
405 {
406  return m_modificationTime;
407 }
408 
414 inline const std::string &AbstractTrack::language() const
415 {
416  return m_language;
417 }
418 
423 inline void AbstractTrack::setLanguage(const std::string &language)
424 {
426 }
427 
431 inline uint32 AbstractTrack::samplingFrequency() const
432 {
433  return m_samplingFrequency;
434 }
435 
441 {
443 }
444 
448 inline uint16 AbstractTrack::bitsPerSample() const
449 {
450  return m_bitsPerSample;
451 }
452 
458 inline uint16 AbstractTrack::channelCount() const
459 {
460  return m_channelCount;
461 }
462 
469 inline byte AbstractTrack::channelConfig() const
470 {
471  return m_channelConfig;
472 }
473 
477 inline uint64 AbstractTrack::sampleCount() const
478 {
479  return m_sampleCount;
480 }
481 
487 inline int AbstractTrack::quality() const
488 {
489  return m_quality;
490 }
491 
497 inline const Size &AbstractTrack::pixelSize() const
498 {
499  return m_pixelSize;
500 }
501 
507 inline const Size &AbstractTrack::displaySize() const
508 {
509  return m_displaySize;
510 }
511 
517 inline const Size &AbstractTrack::resolution() const
518 {
519  return m_resolution;
520 }
521 
525 inline const std::string &AbstractTrack::compressorName() const
526 {
527  return m_compressorName;
528 }
529 
534 inline void AbstractTrack::setCompressorName(const std::string &compressorName)
535 {
537 }
538 
542 inline uint16 AbstractTrack::depth() const
543 {
544  return m_depth;
545 }
546 
552 inline uint32 AbstractTrack::fps() const
553 {
554  return m_fps;
555 }
556 
562 inline const char *AbstractTrack::chromaFormat() const
563 {
564  return m_chromaFormat;
565 }
566 
571 {
572  return m_pixelAspectRatio;
573 }
574 
580 inline bool AbstractTrack::isInterlaced() const
581 {
582  return m_interlaced;
583 }
584 
590 inline uint32 AbstractTrack::timeScale() const
591 {
592  return m_timeScale;
593 }
594 
598 inline bool AbstractTrack::isEnabled() const
599 {
600  return m_enabled;
601 }
602 
607 inline void AbstractTrack::setEnabled(bool enabled)
608 {
609  m_enabled = enabled;
610 }
611 
615 inline bool AbstractTrack::isDefault() const
616 {
617  return m_default;
618 }
619 
624 inline void AbstractTrack::setDefault(bool isDefault)
625 {
627 }
628 
632 inline bool AbstractTrack::isForced() const
633 {
634  return m_forced;
635 }
636 
641 inline void AbstractTrack::setForced(bool forced)
642 {
643  m_forced = forced;
644 }
645 
649 inline bool AbstractTrack::hasLacing() const
650 {
651  return m_lacing;
652 }
653 
657 inline bool AbstractTrack::isEncrypted() const
658 {
659  return m_encrypted;
660 }
661 
665 inline uint32 AbstractTrack::colorSpace() const
666 {
667  return m_colorSpace;
668 }
669 
673 inline const Margin &AbstractTrack::cropping() const
674 {
675  return m_cropping;
676 }
677 
681 inline bool AbstractTrack::isHeaderValid() const
682 {
683  return m_headerValid;
684 }
685 
686 } // namespace TagParser
687 
688 #endif // TAG_PARSER_ABSTRACTTRACK_H
const std::string & language() const
Returns the language of the track if known; otherwise returns an empty string.
TAG_PARSER_EXPORT byte channelCount(byte config)
Returns the channel count for the specified MPEG-4 channel config.
Definition: mp4ids.cpp:452
IoUtilities::BinaryWriter m_writer
bool isEncrypted() const
Returns true if the track is denoted as encrypted; otherwise returns false.
bool isDefault() const
Returns true if the track is denoted as default; otherwise returns false.
The Margin class defines the four margins of a rectangle.
Definition: margin.h:16
IoUtilities::BinaryReader m_reader
const std::string name() const
Returns the track name if known; otherwise returns an empty string.
Implementation of TagParser::AbstractTrack for the RIFF WAVE container format.
uint32 trackNumber() const
Returns the track number if known; otherwise returns 0.
constexpr TAG_PARSER_EXPORT const char * fps()
constexpr TAG_PARSER_EXPORT const char * version()
uint32 timeScale() const
Returns the time scale if known; otherwise returns 0.
byte channelConfig() const
Returns the channel configuration.
MediaType
The MediaType enum specifies the type of media data (audio, video, text, ...).
Definition: mediaformat.h:13
void setInputStream(std::istream &stream)
Assigns another input stream.
bool hasLacing() const
Returns true if the track has lacing; otherwise returns false.
std::ostream & outputStream()
Returns the associated output stream.
The MediaFormat class specifies the format of media data.
Definition: mediaformat.h:244
void setCompressorName(const std::string &compressorName)
Returns the compressor name if known; otherwise returns an empty string.
uint32 extensionSamplingFrequency() const
Returns the number of samples per second if known; otherwise returns 0.
IoUtilities::BinaryReader & reader()
Returns a binary reader for the associated stream.
uint32 colorSpace() const
Returns the color space if known; otherwise returns 0.
constexpr TAG_PARSER_EXPORT const char * trackNumber()
double bitrate() const
Returns the average bitrate in kbit/s if known; otherwise returns zero.
const std::string & formatId() const
Returns the format/codec ID.
const ChronoUtilities::DateTime & creationTime() const
Returns the creation time if known; otherwise returns a DateTime of zero ticks.
const char * formatAbbreviation() const
Returns the a more or less common abbreviation for the format of the track as C-style string if known...
constexpr TAG_PARSER_EXPORT const char * language()
double version() const
Returns the version/level of the track if known; otherwise returns 0.
void setForced(bool forced)
Sets whether the track is forced.
Implementation of TagParser::AbstractTrack for the MP4 container.
Definition: mp4track.h:118
The Size class defines the size of a two-dimensional object using integer point precision.
Definition: size.h:16
double maxBitrate() const
Returns the maximum bitrate in kbit/s if known; otherwise returns zero.
AspectRatio m_pixelAspectRatio
const AspectRatio & pixelAspectRatio() const
Returns the pixel aspect ratio (PAR).
uint64 startOffset() const
Returns the start offset of the track in the associated stream.
const char * formatName() const
Returns the format of the track as C-style string if known; otherwise returns the format abbreviation...
MediaType mediaType() const
Returns the media type if known; otherwise returns MediaType::Other.
const std::string & compressorName() const
Returns the compressor name if known; otherwise returns an empty string.
ChronoUtilities::TimeSpan m_duration
void setOutputStream(std::ostream &stream)
Assigns another output stream.
uint64 size() const
Returns the size in bytes if known; otherwise returns 0.
std::ostream * m_ostream
TAG_PARSER_EXPORT const char * channelConfigString(byte config)
Returns the string representation for the specified MPEG-4 channel config.
Definition: mp4ids.cpp:425
MediaFormat format() const
Returns the format of the track if known; otherwise returns MediaFormat::Unknown.
int quality() const
Returns the quality if known; otherwise returns 0.
std::istream & inputStream()
Returns the associated input stream.
const Size & resolution() const
Returns the resolution if known; otherwise returns a zero size.
const Margin & cropping() const
Returns the cropping if known; otherwise returns zero margins.
std::istream * m_istream
void setName(const std::string &name)
Sets the name.
uint32 samplingFrequency() const
Returns the number of samples per second if known; otherwise returns 0.
constexpr TAG_PARSER_EXPORT const char * bitrate()
The track's bit rate in bits per second.
bool isEnabled() const
Returns true if the track is denoted as enabled; otherwise returns false.
TAG_PARSER_EXPORT const char * mediaTypeName(MediaType mediaType)
Returns the string representation for the specified mediaType.
const Size & pixelSize() const
Returns the size of the encoded video frames if known; otherwise returns a zero size.
uint64 id() const
Returns the track ID if known; otherwise returns 0.
uint64 sampleCount() const
Returns the number of samples/frames if known; otherwise returns 0.
ChronoUtilities::DateTime m_creationTime
const char * mediaTypeName() const
Returns the string representation of the media type of the track.
void setId(uint64 id)
Sets the track ID.
const char * name() const
Returns the name of the media format as C-style string.
Definition: mediaformat.cpp:17
virtual TrackType type() const
Returns the type of the track if known; otherwise returns TrackType::Unspecified.
Implementation of TagParser::AbstractTrack MPEG audio streams.
const char * abbreviation() const
Returns the abbreviation of the media format as C-style string.
const ChronoUtilities::TimeSpan & duration() const
Returns the duration if known; otherwise returns a TimeSpan of zero ticks.
bool isInterlaced() const
Returns true if the video is denoted as interlaced; otherwise returns false.
constexpr TAG_PARSER_EXPORT const char * duration()
const ChronoUtilities::DateTime & modificationTime() const
Returns the time of the last modification if known; otherwise returns a DateTime of zero ticks.
void setTrackNumber(uint32 trackNumber)
Sets the track number.
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
Definition: abstracttrack.h:40
bool isHeaderValid() const
Returns an indication whether the track header is valid.
bool isForced() const
Returns true if the track is denoted as forced; otherwise returns false.
ChronoUtilities::DateTime m_modificationTime
const char * chromaFormat() const
Returns the chroma subsampling format if known; otherwise returns nullptr.
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.
uint32 fps() const
Returns the number of frames per second if known; otherwise returns 0.
constexpr TAG_PARSER_EXPORT const char * description()
void setLanguage(const std::string &language)
Sets the language of the track.
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
IoUtilities::BinaryWriter & writer()
Returns a binary writer for the associated stream.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
TrackType
Specifies the track type.
Definition: abstracttrack.h:28
The AspectRatio struct defines an aspect ratio.
Definition: aspectratio.h:13
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
uint16 channelCount() const
Returns the number of channels if known; otherwise returns 0.
void setDefault(bool isDefault)
Sets whether the track is a default track.
uint16 bitsPerSample() const
Returns the number of bits per sample; otherwise returns 0.
uint16 depth() const
Returns the bit depth if known; otherwise returns 0.