Tag Parser  7.1.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 };
38 
40  friend class MpegAudioFrameStream;
41  friend class WaveAudioStream;
42  friend class Mp4Track;
43 
44 public:
45  virtual ~AbstractTrack();
46 
47  virtual TrackType type() const;
48  std::istream &inputStream();
49  void setInputStream(std::istream &stream);
50  std::ostream &outputStream();
51  void setOutputStream(std::ostream &stream);
52  IoUtilities::BinaryReader &reader();
53  IoUtilities::BinaryWriter &writer();
54  uint64 startOffset() const;
55  MediaFormat format() const;
56  double version() const;
57  const char *formatName() const;
58  const char *formatAbbreviation() const;
59  const std::string &formatId() const;
60  MediaType mediaType() const;
61  const char *mediaTypeName() const;
62  uint64 size() const;
63  uint32 trackNumber() const;
64  void setTrackNumber(uint32 trackNumber);
65  uint64 id() const;
66  void setId(uint64 id);
67  const std::string name() const;
68  void setName(const std::string &name);
69  const ChronoUtilities::TimeSpan &duration() const;
70  double bitrate() const;
71  double maxBitrate() const;
72  const ChronoUtilities::DateTime &creationTime() const;
73  const ChronoUtilities::DateTime &modificationTime() const;
74  const std::string &language() const;
75  void setLanguage(const std::string &language);
76  uint32 samplingFrequency() const;
77  uint32 extensionSamplingFrequency() const;
78  uint16 bitsPerSample() const;
79  uint16 channelCount() const;
80  byte channelConfig() const;
81  const char *channelConfigString() const;
82  byte extensionChannelConfig() const;
83  const char *extensionChannelConfigString() const;
84  uint64 sampleCount() const;
85  int quality() const;
86  const Size &pixelSize() const;
87  const Size &displaySize() const;
88  const Size &resolution() const;
89  const std::string &compressorName() const;
90  void setCompressorName(const std::string &compressorName);
91  uint16 depth() const;
92  uint32 fps() const;
93  const char *chromaFormat() const;
94  const AspectRatio &pixelAspectRatio() const;
95  bool isInterlaced() const;
96  uint32 timeScale() const;
97  bool isEnabled() const;
98  void setEnabled(bool enabled);
99  bool isDefault() const;
100  void setDefault(bool isDefault);
101  bool isForced() const;
102  void setForced(bool forced);
103  bool hasLacing() const;
104  bool isEncrypted() const;
105  uint32 colorSpace() const;
106  const Margin &cropping() const;
107  std::string label() const;
108  std::string description() const;
109 
110  void parseHeader(Diagnostics &diag);
111  bool isHeaderValid() const;
112 
113 protected:
114  AbstractTrack(std::istream &inputStream, std::ostream &outputStream, uint64 startOffset);
115  AbstractTrack(std::iostream &stream, uint64 startOffset);
116  virtual void internalParseHeader(Diagnostics &diag) = 0;
117 
118  std::istream *m_istream;
119  std::ostream *m_ostream;
120  IoUtilities::BinaryReader m_reader;
121  IoUtilities::BinaryWriter m_writer;
125  std::string m_formatId;
126  std::string m_formatName;
128  double m_version;
129  uint64 m_size;
131  uint64 m_id;
132  std::string m_name;
134  double m_bitrate;
135  double m_maxBitrate;
138  std::string m_language;
146  uint16 m_chunkSize;
152  std::string m_compressorName;
153  uint16 m_depth;
154  uint32 m_fps;
155  const char *m_chromaFormat;
158  uint32 m_timeScale;
159  bool m_enabled;
160  bool m_default;
161  bool m_forced;
162  bool m_lacing;
166  uint32 m_colorSpace;
168 };
169 
173 inline std::istream &AbstractTrack::inputStream()
174 {
175  return *m_istream;
176 }
177 
184 inline void AbstractTrack::setInputStream(std::istream &stream)
185 {
186  m_reader.setStream(m_istream = &stream);
187 }
188 
192 inline std::ostream &AbstractTrack::outputStream()
193 {
194  return *m_ostream;
195 }
196 
203 inline void AbstractTrack::setOutputStream(std::ostream &stream)
204 {
205  m_writer.setStream(m_ostream = &stream);
206 }
207 
214 inline IoUtilities::BinaryReader &AbstractTrack::reader()
215 {
216  return m_reader;
217 }
218 
225 inline IoUtilities::BinaryWriter &AbstractTrack::writer()
226 {
227  return m_writer;
228 }
229 
234 {
235  return TrackType::Unspecified;
236 }
237 
241 inline uint64 AbstractTrack::startOffset() const
242 {
243  return m_startOffset;
244 }
245 
250 {
251  return m_format;
252 }
253 
257 inline double AbstractTrack::version() const
258 {
259  return m_version;
260 }
261 
269 inline const char *AbstractTrack::formatName() const
270 {
271  return m_format || m_formatName.empty() ? m_format.name() : m_formatName.c_str();
272 }
273 
278 inline const char *AbstractTrack::formatAbbreviation() const
279 {
280  const char *abbr = m_format.abbreviation();
281  return *abbr || m_formatId.empty() ? m_format.abbreviation() : m_formatId.c_str();
282 }
283 
288 inline const std::string &AbstractTrack::formatId() const
289 {
290  return m_formatId;
291 }
292 
297 {
298  return m_mediaType;
299 }
300 
304 inline const char *AbstractTrack::mediaTypeName() const
305 {
307 }
308 
312 inline uint64 AbstractTrack::size() const
313 {
314  return m_size;
315 }
316 
320 inline uint32 AbstractTrack::trackNumber() const
321 {
322  return m_trackNumber;
323 }
324 
330 {
332 }
333 
337 inline uint64 AbstractTrack::id() const
338 {
339  return m_id;
340 }
341 
346 inline void AbstractTrack::setId(uint64 id)
347 {
348  m_id = id;
349 }
350 
354 inline const std::string AbstractTrack::name() const
355 {
356  return m_name;
357 }
358 
363 inline void AbstractTrack::setName(const std::string &name)
364 {
365  m_name = name;
366 }
367 
372 {
373  return m_duration;
374 }
375 
379 inline double AbstractTrack::bitrate() const
380 {
381  return m_bitrate;
382 }
383 
387 inline double AbstractTrack::maxBitrate() const
388 {
389  return m_maxBitrate;
390 }
391 
396 {
397  return m_creationTime;
398 }
399 
404 {
405  return m_modificationTime;
406 }
407 
413 inline const std::string &AbstractTrack::language() const
414 {
415  return m_language;
416 }
417 
422 inline void AbstractTrack::setLanguage(const std::string &language)
423 {
425 }
426 
430 inline uint32 AbstractTrack::samplingFrequency() const
431 {
432  return m_samplingFrequency;
433 }
434 
440 {
442 }
443 
447 inline uint16 AbstractTrack::bitsPerSample() const
448 {
449  return m_bitsPerSample;
450 }
451 
457 inline uint16 AbstractTrack::channelCount() const
458 {
459  return m_channelCount;
460 }
461 
468 inline byte AbstractTrack::channelConfig() const
469 {
470  return m_channelConfig;
471 }
472 
476 inline uint64 AbstractTrack::sampleCount() const
477 {
478  return m_sampleCount;
479 }
480 
486 inline int AbstractTrack::quality() const
487 {
488  return m_quality;
489 }
490 
496 inline const Size &AbstractTrack::pixelSize() const
497 {
498  return m_pixelSize;
499 }
500 
506 inline const Size &AbstractTrack::displaySize() const
507 {
508  return m_displaySize;
509 }
510 
516 inline const Size &AbstractTrack::resolution() const
517 {
518  return m_resolution;
519 }
520 
524 inline const std::string &AbstractTrack::compressorName() const
525 {
526  return m_compressorName;
527 }
528 
533 inline void AbstractTrack::setCompressorName(const std::string &compressorName)
534 {
536 }
537 
541 inline uint16 AbstractTrack::depth() const
542 {
543  return m_depth;
544 }
545 
551 inline uint32 AbstractTrack::fps() const
552 {
553  return m_fps;
554 }
555 
561 inline const char *AbstractTrack::chromaFormat() const
562 {
563  return m_chromaFormat;
564 }
565 
570 {
571  return m_pixelAspectRatio;
572 }
573 
579 inline bool AbstractTrack::isInterlaced() const
580 {
581  return m_interlaced;
582 }
583 
589 inline uint32 AbstractTrack::timeScale() const
590 {
591  return m_timeScale;
592 }
593 
597 inline bool AbstractTrack::isEnabled() const
598 {
599  return m_enabled;
600 }
601 
606 inline void AbstractTrack::setEnabled(bool enabled)
607 {
608  m_enabled = enabled;
609 }
610 
614 inline bool AbstractTrack::isDefault() const
615 {
616  return m_default;
617 }
618 
623 inline void AbstractTrack::setDefault(bool isDefault)
624 {
626 }
627 
631 inline bool AbstractTrack::isForced() const
632 {
633  return m_forced;
634 }
635 
640 inline void AbstractTrack::setForced(bool forced)
641 {
642  m_forced = forced;
643 }
644 
648 inline bool AbstractTrack::hasLacing() const
649 {
650  return m_lacing;
651 }
652 
656 inline bool AbstractTrack::isEncrypted() const
657 {
658  return m_encrypted;
659 }
660 
664 inline uint32 AbstractTrack::colorSpace() const
665 {
666  return m_colorSpace;
667 }
668 
672 inline const Margin &AbstractTrack::cropping() const
673 {
674  return m_cropping;
675 }
676 
680 inline bool AbstractTrack::isHeaderValid() const
681 {
682  return m_headerValid;
683 }
684 
685 } // namespace TagParser
686 
687 #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 const char * language()
TAG_PARSER_EXPORT byte channelCount(byte config)
Returns the channel count for the specified MPEG-4 channel config.
Definition: mp4ids.cpp:445
IoUtilities::BinaryWriter m_writer
bool isEncrypted() const
Returns true if the track is denoted as encrypted; otherwise returns false.
TAG_PARSER_EXPORT const char * trackNumber()
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
TAG_PARSER_EXPORT const char * description()
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.
TAG_PARSER_EXPORT const char * version()
uint32 timeScale() const
Returns the time scale if known; otherwise returns 0.
TAG_PARSER_EXPORT const char * fps()
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:243
void setCompressorName(const std::string &compressorName)
Returns the compressor name if known; otherwise returns an empty string.
TAG_PARSER_EXPORT const char * bitrate()
The track&#39;s bit rate in bits per second.
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.
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...
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:117
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:418
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.
bool isEnabled() const
Returns true if the track is denoted as enabled; otherwise returns false.
const char *TAG_PARSER_EXPORT 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.
TAG_PARSER_EXPORT const char * duration()
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.
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:39
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.
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:10
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:154
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.