Tag Parser  6.2.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 ABSTRACTTRACK_H
2 #define ABSTRACTTRACK_H
3 
4 #include "./statusprovider.h"
5 #include "./size.h"
6 #include "./margin.h"
7 #include "./aspectratio.h"
8 #include "./mediaformat.h"
9 
10 #include <c++utilities/conversion/types.h>
11 #include <c++utilities/io/binaryreader.h>
12 #include <c++utilities/io/binarywriter.h>
13 #include <c++utilities/chrono/datetime.h>
14 #include <c++utilities/chrono/timespan.h>
15 
16 #include <iosfwd>
17 #include <string>
18 
19 namespace Media {
20 
22 class WaveAudioStream;
23 class Mp4Track;
24 
28 enum class TrackType
29 {
30  Unspecified,
33  Mp4Track,
35  OggStream,
36  AdtsStream,
37  FlacStream,
38 };
39 
41 {
42  friend class MpegAudioFrameStream;
43  friend class WaveAudioStream;
44  friend class Mp4Track;
45 
46 public:
47  virtual ~AbstractTrack();
48 
49  virtual TrackType type() const;
50  std::istream &inputStream();
51  void setInputStream(std::istream &stream);
52  std::ostream &outputStream();
53  void setOutputStream(std::ostream &stream);
54  IoUtilities::BinaryReader &reader();
55  IoUtilities::BinaryWriter &writer();
56  uint64 startOffset() const;
57  MediaFormat format() const;
58  double version() const;
59  const char *formatName() const;
60  const char *formatAbbreviation() const;
61  const std::string &formatId() const;
62  MediaType mediaType() const;
63  const char *mediaTypeName() const;
64  uint64 size() const;
65  uint32 trackNumber() const;
66  uint64 id() const;
67  const std::string name() const;
68  const ChronoUtilities::TimeSpan &duration() const;
69  double bitrate() const;
70  double maxBitrate() const;
71  const ChronoUtilities::DateTime &creationTime() const;
72  const ChronoUtilities::DateTime &modificationTime() const;
73  const std::string &language() const;
74  uint32 samplingFrequency() const;
75  uint32 extensionSamplingFrequency() const;
76  uint16 bitsPerSample() const;
77  uint16 channelCount() const;
78  byte channelConfig() const;
79  const char *channelConfigString() const;
80  byte extensionChannelConfig() const;
81  const char *extensionChannelConfigString() const;
82  uint64 sampleCount() const;
83  int quality() const;
84  const Size &pixelSize() const;
85  const Size &displaySize() const;
86  const Size &resolution() const;
87  const std::string &compressorName() const;
88  uint16 depth() const;
89  uint32 fps() const;
90  const char *chromaFormat() const;
91  const AspectRatio &pixelAspectRatio() const;
92  bool isInterlaced() const;
93  uint32 timeScale() const;
94  bool isEnabled() const;
95  bool isDefault() const;
96  bool isForced() const;
97  bool hasLacing() const;
98  bool isEncrypted() const;
99  uint32 colorSpace() const;
100  const Margin &cropping() const;
101  std::string label() const;
102 
103  void parseHeader();
104  bool isHeaderValid() const;
105 
106 protected:
107  AbstractTrack(std::istream &inputStream, std::ostream &outputStream, uint64 startOffset);
108  AbstractTrack(std::iostream &stream, uint64 startOffset);
109  virtual void internalParseHeader() = 0;
110 
111  std::istream *m_istream;
112  std::ostream *m_ostream;
113  IoUtilities::BinaryReader m_reader;
114  IoUtilities::BinaryWriter m_writer;
118  std::string m_formatId;
119  std::string m_formatName;
121  double m_version;
122  uint64 m_size;
124  uint64 m_id;
125  std::string m_name;
127  double m_bitrate;
128  double m_maxBitrate;
131  std::string m_language;
139  uint16 m_chunkSize;
145  std::string m_compressorName;
146  uint16 m_depth;
147  uint32 m_fps;
148  const char *m_chromaFormat;
151  uint32 m_timeScale;
152  bool m_enabled;
153  bool m_default;
154  bool m_forced;
155  bool m_lacing;
159  uint32 m_colorSpace;
161 };
162 
166 inline std::istream &AbstractTrack::inputStream()
167 {
168  return *m_istream;
169 }
170 
177 inline void AbstractTrack::setInputStream(std::istream &stream)
178 {
179  m_istream = &stream;
180  m_reader.setStream(m_istream);
181 }
182 
186 inline std::ostream &AbstractTrack::outputStream()
187 {
188  return *m_ostream;
189 }
190 
197 inline void AbstractTrack::setOutputStream(std::ostream &stream)
198 {
199  m_ostream = &stream;
200  m_writer.setStream(m_ostream);
201 }
202 
209 inline IoUtilities::BinaryReader &AbstractTrack::reader()
210 {
211  return m_reader;
212 }
213 
220 inline IoUtilities::BinaryWriter &AbstractTrack::writer()
221 {
222  return m_writer;
223 }
224 
229 {
230  return TrackType::Unspecified;
231 }
232 
236 inline uint64 AbstractTrack::startOffset() const
237 {
238  return m_startOffset;
239 }
240 
245 {
246  return m_format;
247 }
248 
252 inline double AbstractTrack::version() const
253 {
254  return m_version;
255 }
256 
264 inline const char *AbstractTrack::formatName() const
265 {
266  return m_format || m_formatName.empty() ? m_format.name() : m_formatName.c_str();
267 }
268 
273 inline const char *AbstractTrack::formatAbbreviation() const
274 {
275  const char *abbr = m_format.abbreviation();
276  return *abbr || m_formatId.empty() ? m_format.abbreviation() : m_formatId.c_str();
277 }
278 
283 inline const std::string &AbstractTrack::formatId() const
284 {
285  return m_formatId;
286 }
287 
292 {
293  return m_mediaType;
294 }
295 
299 inline const char *AbstractTrack::mediaTypeName() const
300 {
301  return ::Media::mediaTypeName(m_mediaType);
302 }
303 
307 inline uint64 AbstractTrack::size() const
308 {
309  return m_size;
310 }
311 
315 inline uint32 AbstractTrack::trackNumber() const
316 {
317  return m_trackNumber;
318 }
319 
323 inline uint64 AbstractTrack::id() const
324 {
325  return m_id;
326 }
327 
331 inline const std::string AbstractTrack::name() const
332 {
333  return m_name;
334 }
335 
340 {
341  return m_duration;
342 }
343 
347 inline double AbstractTrack::bitrate() const
348 {
349  return m_bitrate;
350 }
351 
355 inline double AbstractTrack::maxBitrate() const
356 {
357  return m_maxBitrate;
358 }
359 
364 {
365  return m_creationTime;
366 }
367 
372 {
373  return m_modificationTime;
374 }
375 
381 inline const std::string &AbstractTrack::language() const
382 {
383  return m_language;
384 }
385 
389 inline uint32 AbstractTrack::samplingFrequency() const
390 {
391  return m_samplingFrequency;
392 }
393 
399 {
400  return m_extensionSamplingFrequency;
401 }
402 
406 inline uint16 AbstractTrack::bitsPerSample() const
407 {
408  return m_bitsPerSample;
409 }
410 
416 inline uint16 AbstractTrack::channelCount() const
417 {
418  return m_channelCount;
419 }
420 
427 inline byte AbstractTrack::channelConfig() const
428 {
429  return m_channelConfig;
430 }
431 
435 inline uint64 AbstractTrack::sampleCount() const
436 {
437  return m_sampleCount;
438 }
439 
445 inline int AbstractTrack::quality() const
446 {
447  return m_quality;
448 }
449 
455 inline const Size &AbstractTrack::pixelSize() const
456 {
457  return m_pixelSize;
458 }
459 
465 inline const Size &AbstractTrack::displaySize() const
466 {
467  return m_displaySize;
468 }
469 
475 inline const Size &AbstractTrack::resolution() const
476 {
477  return m_resolution;
478 }
479 
483 inline const std::string &AbstractTrack::compressorName() const
484 {
485  return m_compressorName;
486 }
487 
491 inline uint16 AbstractTrack::depth() const
492 {
493  return m_depth;
494 }
495 
501 inline uint32 AbstractTrack::fps() const
502 {
503  return m_fps;
504 }
505 
511 inline const char *AbstractTrack::chromaFormat() const
512 {
513  return m_chromaFormat;
514 }
515 
520 {
521  return m_pixelAspectRatio;
522 }
523 
529 inline bool AbstractTrack::isInterlaced() const
530 {
531  return m_interlaced;
532 }
533 
539 inline uint32 AbstractTrack::timeScale() const
540 {
541  return m_timeScale;
542 }
543 
547 inline bool AbstractTrack::isEnabled() const
548 {
549  return m_enabled;
550 }
551 
555 inline bool AbstractTrack::isDefault() const
556 {
557  return m_default;
558 }
559 
563 inline bool AbstractTrack::isForced() const
564 {
565  return m_forced;
566 }
567 
571 inline bool AbstractTrack::hasLacing() const
572 {
573  return m_lacing;
574 }
575 
579 inline bool AbstractTrack::isEncrypted() const
580 {
581  return m_encrypted;
582 }
583 
587 inline uint32 AbstractTrack::colorSpace() const
588 {
589  return m_colorSpace;
590 }
591 
595 inline const Margin &AbstractTrack::cropping() const
596 {
597  return m_cropping;
598 }
599 
603 inline bool AbstractTrack::isHeaderValid() const
604 {
605  return m_headerValid;
606 }
607 
608 }
609 
610 #endif // ABSTRACTTRACK_H
TAG_PARSER_EXPORT const char * duration()
const std::string name() const
Returns the track name if known; otherwise returns an empty string.
std::ostream & outputStream()
Returns the associated input stream.
MediaType
The MediaType enum specifies the type of media data (audio, video, text, ...).
Definition: mediaformat.h:13
TAG_PARSER_EXPORT const char * trackNumber()
TAG_PARSER_EXPORT const char * language()
uint16 bitsPerSample() const
Returns the number of bits per sample; otherwise returns 0.
const AspectRatio & pixelAspectRatio() const
Returns the pixel aspect ratio (PAR).
bool isEncrypted() const
Returns true if the track is denoted as encrypted; otherwise returns false.
The Size class defines the size of a two-dimensional object using integer point precision.
Definition: size.h:16
The AspectRatio struct defines an aspect ratio.
Definition: aspectratio.h:10
const char * formatName() const
Returns the format of the track as C-style string if known; otherwise returns the format abbreviation...
uint32 timeScale() const
Returns the time scale if known; otherwise returns 0.
uint16 channelCount() const
Returns the number of channels if known; otherwise returns 0.
Implementation of Media::AbstractTrack for the MP4 container.
Definition: mp4track.h:119
AspectRatio m_pixelAspectRatio
int quality() const
Returns the quality if known; otherwise returns 0.
std::istream & inputStream()
Returns the associated input stream.
std::string m_formatId
double version() const
Returns the version/level of the track if known; otherwise returns 0.
double bitrate() const
Returns the average bitrate in kbit/s if known; otherwise returns zero.
const ChronoUtilities::DateTime & modificationTime() const
Returns the time of the last modification if known; otherwise returns a DateTime of zero ticks...
TrackType
Specifies the track type.
Definition: abstracttrack.h:28
byte channelConfig() const
Returns the channel configuration.
void setOutputStream(std::ostream &stream)
Assigns an other output stream.
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
Definition: abstracttrack.h:40
bool isInterlaced() const
Returns true if the video is denoted as interlaced; otherwise returns false.
virtual TrackType type() const
Returns the type of the track if known; otherwise returns TrackType::Unspecified. ...
const ChronoUtilities::TimeSpan & duration() const
Returns the duration if known; otherwise returns a TimeSpan of zero ticks.
IoUtilities::BinaryReader m_reader
uint16 depth() const
Returns the bit depth if known; otherwise returns 0.
bool isHeaderValid() const
Returns an indication whether the track header is valid.
Implementation of Media::AbstractTrack MPEG audio streams.
ChronoUtilities::DateTime m_creationTime
TAG_PARSER_EXPORT const char * channelConfigString(byte config)
Returns the string representation for the specified MPEG-4 channel config.
Definition: mp4ids.cpp:315
IoUtilities::BinaryWriter m_writer
const Size & displaySize() const
Returns the size of the video frames to display if known; otherwise returns a zero size...
MediaFormat format() const
Returns the format of the track if known; otherwise returns MediaFormat::Unknown. ...
bool hasLacing() const
Returns true if the track has lacing; otherwise returns false.
Implementation of Media::AbstractTrack for the RIFF WAVE container format.
IoUtilities::BinaryWriter & writer()
Returns a binary writer for the associated stream.
uint32 samplingFrequency() const
Returns the number of samples per second if known; otherwise returns 0.
uint64 id() const
Returns the track ID if known; otherwise returns 0.
const Size & pixelSize() const
Returns the size of the encoded video frames if known; otherwise returns a zero size.
IoUtilities::BinaryReader & reader()
Returns a binary reader for the associated stream.
uint32 m_extensionSamplingFrequency
const Margin & cropping() const
Returns the cropping if known; otherwise returns zero margins.
bool isDefault() const
Returns true if the track is denoted as default; otherwise returns false.
const std::string & compressorName() const
Returns the compressor name if known; otherwise returns an empty string.
const char * chromaFormat() const
Returns the chroma subsampling format if known; otherwise returns nullptr.
const Size & resolution() const
Returns the resolution if known; otherwise returns a zero size.
std::string m_language
uint32 colorSpace() const
Returns the color space if known; otherwise returns 0.
uint64 sampleCount() const
Returns the number of samples if known; otherwise returns 0.
uint64 startOffset() const
Returns the start offset of the track in the associated stream.
std::string m_compressorName
ChronoUtilities::DateTime m_modificationTime
const char * formatAbbreviation() const
Returns the a more or less common abbreviation for the format of the track as C-style string if known...
bool isEnabled() const
Returns true if the track is denoted as enabled; otherwise returns false.
ChronoUtilities::TimeSpan m_duration
TAG_PARSER_EXPORT byte channelCount(byte config)
Returns the channel count for the specified MPEG-4 channel config.
Definition: mp4ids.cpp:342
const char * mediaTypeName() const
Returns the string representation of the media type of the track.
TAG_PARSER_EXPORT const char * fps()
const ChronoUtilities::DateTime & creationTime() const
Returns the creation time if known; otherwise returns a DateTime of zero ticks.
uint32 extensionSamplingFrequency() const
Returns the number of samples per second if known; otherwise returns 0.
uint32 trackNumber() const
Returns the track number if known; otherwise returns 0.
const std::string & language() const
Returns the language of the track if known; otherwise returns an empty string.
bool isForced() const
Returns true if the track is denoted as forced; otherwise returns false.
std::ostream * m_ostream
const char * m_chromaFormat
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
const char *TAG_PARSER_EXPORT mediaTypeName(MediaType mediaType)
Returns the string representation for the specified mediaType.
The StatusProvider class acts as a base class for objects providing status information.
void setInputStream(std::istream &stream)
Assigns an other input stream.
uint32 fps() const
Returns the number of frames per second if known; otherwise returns 0.
uint64 size() const
Returns the size in bytes if known; otherwise returns 0.
std::string m_formatName
std::istream * m_istream
double maxBitrate() const
Returns the maximum bitrate in kbit/s if known; otherwise returns zero.
const std::string & formatId() const
Returns the format/codec ID.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
The MediaFormat class specifies the format of media data.
Definition: mediaformat.h:256
TAG_PARSER_EXPORT const char * version()
The Margin class defines the four margins of a rectangle.
Definition: margin.h:16
MediaType mediaType() const
Returns the media type if known; otherwise returns MediaType::Other.