Tag Parser  6.3.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 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  void setId(uint64 id);
68  const std::string name() const;
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  uint32 samplingFrequency() const;
76  uint32 extensionSamplingFrequency() const;
77  uint16 bitsPerSample() const;
78  uint16 channelCount() const;
79  byte channelConfig() const;
80  const char *channelConfigString() const;
81  byte extensionChannelConfig() const;
82  const char *extensionChannelConfigString() const;
83  uint64 sampleCount() const;
84  int quality() const;
85  const Size &pixelSize() const;
86  const Size &displaySize() const;
87  const Size &resolution() const;
88  const std::string &compressorName() const;
89  uint16 depth() const;
90  uint32 fps() const;
91  const char *chromaFormat() const;
92  const AspectRatio &pixelAspectRatio() const;
93  bool isInterlaced() const;
94  uint32 timeScale() const;
95  bool isEnabled() const;
96  bool isDefault() const;
97  bool isForced() const;
98  bool hasLacing() const;
99  bool isEncrypted() const;
100  uint32 colorSpace() const;
101  const Margin &cropping() const;
102  std::string label() const;
103 
104  void parseHeader();
105  bool isHeaderValid() const;
106 
107 protected:
108  AbstractTrack(std::istream &inputStream, std::ostream &outputStream, uint64 startOffset);
109  AbstractTrack(std::iostream &stream, uint64 startOffset);
110  virtual void internalParseHeader() = 0;
111 
112  std::istream *m_istream;
113  std::ostream *m_ostream;
114  IoUtilities::BinaryReader m_reader;
115  IoUtilities::BinaryWriter m_writer;
119  std::string m_formatId;
120  std::string m_formatName;
122  double m_version;
123  uint64 m_size;
125  uint64 m_id;
126  std::string m_name;
128  double m_bitrate;
129  double m_maxBitrate;
132  std::string m_language;
140  uint16 m_chunkSize;
146  std::string m_compressorName;
147  uint16 m_depth;
148  uint32 m_fps;
149  const char *m_chromaFormat;
152  uint32 m_timeScale;
153  bool m_enabled;
154  bool m_default;
155  bool m_forced;
156  bool m_lacing;
160  uint32 m_colorSpace;
162 };
163 
167 inline std::istream &AbstractTrack::inputStream()
168 {
169  return *m_istream;
170 }
171 
178 inline void AbstractTrack::setInputStream(std::istream &stream)
179 {
180  m_reader.setStream(m_istream = &stream);
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_writer.setStream(m_ostream = &stream);
200 }
201 
208 inline IoUtilities::BinaryReader &AbstractTrack::reader()
209 {
210  return m_reader;
211 }
212 
219 inline IoUtilities::BinaryWriter &AbstractTrack::writer()
220 {
221  return m_writer;
222 }
223 
228 {
229  return TrackType::Unspecified;
230 }
231 
235 inline uint64 AbstractTrack::startOffset() const
236 {
237  return m_startOffset;
238 }
239 
244 {
245  return m_format;
246 }
247 
251 inline double AbstractTrack::version() const
252 {
253  return m_version;
254 }
255 
263 inline const char *AbstractTrack::formatName() const
264 {
265  return m_format || m_formatName.empty() ? m_format.name() : m_formatName.c_str();
266 }
267 
272 inline const char *AbstractTrack::formatAbbreviation() const
273 {
274  const char *abbr = m_format.abbreviation();
275  return *abbr || m_formatId.empty() ? m_format.abbreviation() : m_formatId.c_str();
276 }
277 
282 inline const std::string &AbstractTrack::formatId() const
283 {
284  return m_formatId;
285 }
286 
291 {
292  return m_mediaType;
293 }
294 
298 inline const char *AbstractTrack::mediaTypeName() const
299 {
300  return ::Media::mediaTypeName(m_mediaType);
301 }
302 
306 inline uint64 AbstractTrack::size() const
307 {
308  return m_size;
309 }
310 
314 inline uint32 AbstractTrack::trackNumber() const
315 {
316  return m_trackNumber;
317 }
318 
322 inline uint64 AbstractTrack::id() const
323 {
324  return m_id;
325 }
326 
331 inline void AbstractTrack::setId(uint64 id)
332 {
333  m_id = id;
334 }
335 
339 inline const std::string AbstractTrack::name() const
340 {
341  return m_name;
342 }
343 
348 {
349  return m_duration;
350 }
351 
355 inline double AbstractTrack::bitrate() const
356 {
357  return m_bitrate;
358 }
359 
363 inline double AbstractTrack::maxBitrate() const
364 {
365  return m_maxBitrate;
366 }
367 
372 {
373  return m_creationTime;
374 }
375 
380 {
381  return m_modificationTime;
382 }
383 
389 inline const std::string &AbstractTrack::language() const
390 {
391  return m_language;
392 }
393 
397 inline uint32 AbstractTrack::samplingFrequency() const
398 {
399  return m_samplingFrequency;
400 }
401 
407 {
408  return m_extensionSamplingFrequency;
409 }
410 
414 inline uint16 AbstractTrack::bitsPerSample() const
415 {
416  return m_bitsPerSample;
417 }
418 
424 inline uint16 AbstractTrack::channelCount() const
425 {
426  return m_channelCount;
427 }
428 
435 inline byte AbstractTrack::channelConfig() const
436 {
437  return m_channelConfig;
438 }
439 
443 inline uint64 AbstractTrack::sampleCount() const
444 {
445  return m_sampleCount;
446 }
447 
453 inline int AbstractTrack::quality() const
454 {
455  return m_quality;
456 }
457 
463 inline const Size &AbstractTrack::pixelSize() const
464 {
465  return m_pixelSize;
466 }
467 
473 inline const Size &AbstractTrack::displaySize() const
474 {
475  return m_displaySize;
476 }
477 
483 inline const Size &AbstractTrack::resolution() const
484 {
485  return m_resolution;
486 }
487 
491 inline const std::string &AbstractTrack::compressorName() const
492 {
493  return m_compressorName;
494 }
495 
499 inline uint16 AbstractTrack::depth() const
500 {
501  return m_depth;
502 }
503 
509 inline uint32 AbstractTrack::fps() const
510 {
511  return m_fps;
512 }
513 
519 inline const char *AbstractTrack::chromaFormat() const
520 {
521  return m_chromaFormat;
522 }
523 
528 {
529  return m_pixelAspectRatio;
530 }
531 
537 inline bool AbstractTrack::isInterlaced() const
538 {
539  return m_interlaced;
540 }
541 
547 inline uint32 AbstractTrack::timeScale() const
548 {
549  return m_timeScale;
550 }
551 
555 inline bool AbstractTrack::isEnabled() const
556 {
557  return m_enabled;
558 }
559 
563 inline bool AbstractTrack::isDefault() const
564 {
565  return m_default;
566 }
567 
571 inline bool AbstractTrack::isForced() const
572 {
573  return m_forced;
574 }
575 
579 inline bool AbstractTrack::hasLacing() const
580 {
581  return m_lacing;
582 }
583 
587 inline bool AbstractTrack::isEncrypted() const
588 {
589  return m_encrypted;
590 }
591 
595 inline uint32 AbstractTrack::colorSpace() const
596 {
597  return m_colorSpace;
598 }
599 
603 inline const Margin &AbstractTrack::cropping() const
604 {
605  return m_cropping;
606 }
607 
611 inline bool AbstractTrack::isHeaderValid() const
612 {
613  return m_headerValid;
614 }
615 
616 }
617 
618 #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 output stream.
MediaType
The MediaType enum specifies the type of media data (audio, video, text, ...).
Definition: mediaformat.h:13
TAG_PARSER_EXPORT const char * trackNumber()
void setId(uint64 id)
Sets the track ID.
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 another 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 another 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:257
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.