Tag Parser  6.5.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  void setTrackNumber(uint32 trackNumber);
67  uint64 id() const;
68  void setId(uint64 id);
69  const std::string name() const;
70  void setName(const std::string &name);
71  const ChronoUtilities::TimeSpan &duration() const;
72  double bitrate() const;
73  double maxBitrate() const;
74  const ChronoUtilities::DateTime &creationTime() const;
75  const ChronoUtilities::DateTime &modificationTime() const;
76  const std::string &language() const;
77  void setLanguage(const std::string &language);
78  uint32 samplingFrequency() const;
79  uint32 extensionSamplingFrequency() const;
80  uint16 bitsPerSample() const;
81  uint16 channelCount() const;
82  byte channelConfig() const;
83  const char *channelConfigString() const;
84  byte extensionChannelConfig() const;
85  const char *extensionChannelConfigString() const;
86  uint64 sampleCount() const;
87  int quality() const;
88  const Size &pixelSize() const;
89  const Size &displaySize() const;
90  const Size &resolution() const;
91  const std::string &compressorName() const;
92  void setCompressorName(const std::string &compressorName);
93  uint16 depth() const;
94  uint32 fps() const;
95  const char *chromaFormat() const;
96  const AspectRatio &pixelAspectRatio() const;
97  bool isInterlaced() const;
98  uint32 timeScale() const;
99  bool isEnabled() const;
100  void setEnabled(bool enabled);
101  bool isDefault() const;
102  void setDefault(bool isDefault);
103  bool isForced() const;
104  void setForced(bool forced);
105  bool hasLacing() const;
106  bool isEncrypted() const;
107  uint32 colorSpace() const;
108  const Margin &cropping() const;
109  std::string label() const;
110  std::string description() const;
111 
112  void parseHeader();
113  bool isHeaderValid() const;
114 
115 protected:
116  AbstractTrack(std::istream &inputStream, std::ostream &outputStream, uint64 startOffset);
117  AbstractTrack(std::iostream &stream, uint64 startOffset);
118  virtual void internalParseHeader() = 0;
119 
120  std::istream *m_istream;
121  std::ostream *m_ostream;
122  IoUtilities::BinaryReader m_reader;
123  IoUtilities::BinaryWriter m_writer;
127  std::string m_formatId;
128  std::string m_formatName;
130  double m_version;
131  uint64 m_size;
133  uint64 m_id;
134  std::string m_name;
136  double m_bitrate;
137  double m_maxBitrate;
140  std::string m_language;
148  uint16 m_chunkSize;
154  std::string m_compressorName;
155  uint16 m_depth;
156  uint32 m_fps;
157  const char *m_chromaFormat;
160  uint32 m_timeScale;
161  bool m_enabled;
162  bool m_default;
163  bool m_forced;
164  bool m_lacing;
168  uint32 m_colorSpace;
170 };
171 
175 inline std::istream &AbstractTrack::inputStream()
176 {
177  return *m_istream;
178 }
179 
186 inline void AbstractTrack::setInputStream(std::istream &stream)
187 {
188  m_reader.setStream(m_istream = &stream);
189 }
190 
194 inline std::ostream &AbstractTrack::outputStream()
195 {
196  return *m_ostream;
197 }
198 
205 inline void AbstractTrack::setOutputStream(std::ostream &stream)
206 {
207  m_writer.setStream(m_ostream = &stream);
208 }
209 
216 inline IoUtilities::BinaryReader &AbstractTrack::reader()
217 {
218  return m_reader;
219 }
220 
227 inline IoUtilities::BinaryWriter &AbstractTrack::writer()
228 {
229  return m_writer;
230 }
231 
236 {
237  return TrackType::Unspecified;
238 }
239 
243 inline uint64 AbstractTrack::startOffset() const
244 {
245  return m_startOffset;
246 }
247 
252 {
253  return m_format;
254 }
255 
259 inline double AbstractTrack::version() const
260 {
261  return m_version;
262 }
263 
271 inline const char *AbstractTrack::formatName() const
272 {
273  return m_format || m_formatName.empty() ? m_format.name() : m_formatName.c_str();
274 }
275 
280 inline const char *AbstractTrack::formatAbbreviation() const
281 {
282  const char *abbr = m_format.abbreviation();
283  return *abbr || m_formatId.empty() ? m_format.abbreviation() : m_formatId.c_str();
284 }
285 
290 inline const std::string &AbstractTrack::formatId() const
291 {
292  return m_formatId;
293 }
294 
299 {
300  return m_mediaType;
301 }
302 
306 inline const char *AbstractTrack::mediaTypeName() const
307 {
308  return ::Media::mediaTypeName(m_mediaType);
309 }
310 
314 inline uint64 AbstractTrack::size() const
315 {
316  return m_size;
317 }
318 
322 inline uint32 AbstractTrack::trackNumber() const
323 {
324  return m_trackNumber;
325 }
326 
332 {
333  m_trackNumber = trackNumber;
334 }
335 
339 inline uint64 AbstractTrack::id() const
340 {
341  return m_id;
342 }
343 
348 inline void AbstractTrack::setId(uint64 id)
349 {
350  m_id = id;
351 }
352 
356 inline const std::string AbstractTrack::name() const
357 {
358  return m_name;
359 }
360 
365 inline void AbstractTrack::setName(const std::string &name)
366 {
367  m_name = name;
368 }
369 
374 {
375  return m_duration;
376 }
377 
381 inline double AbstractTrack::bitrate() const
382 {
383  return m_bitrate;
384 }
385 
389 inline double AbstractTrack::maxBitrate() const
390 {
391  return m_maxBitrate;
392 }
393 
398 {
399  return m_creationTime;
400 }
401 
406 {
407  return m_modificationTime;
408 }
409 
415 inline const std::string &AbstractTrack::language() const
416 {
417  return m_language;
418 }
419 
424 inline void AbstractTrack::setLanguage(const std::string &language)
425 {
426  m_language = language;
427 }
428 
432 inline uint32 AbstractTrack::samplingFrequency() const
433 {
434  return m_samplingFrequency;
435 }
436 
442 {
443  return m_extensionSamplingFrequency;
444 }
445 
449 inline uint16 AbstractTrack::bitsPerSample() const
450 {
451  return m_bitsPerSample;
452 }
453 
459 inline uint16 AbstractTrack::channelCount() const
460 {
461  return m_channelCount;
462 }
463 
470 inline byte AbstractTrack::channelConfig() const
471 {
472  return m_channelConfig;
473 }
474 
478 inline uint64 AbstractTrack::sampleCount() const
479 {
480  return m_sampleCount;
481 }
482 
488 inline int AbstractTrack::quality() const
489 {
490  return m_quality;
491 }
492 
498 inline const Size &AbstractTrack::pixelSize() const
499 {
500  return m_pixelSize;
501 }
502 
508 inline const Size &AbstractTrack::displaySize() const
509 {
510  return m_displaySize;
511 }
512 
518 inline const Size &AbstractTrack::resolution() const
519 {
520  return m_resolution;
521 }
522 
526 inline const std::string &AbstractTrack::compressorName() const
527 {
528  return m_compressorName;
529 }
530 
535 inline void AbstractTrack::setCompressorName(const std::string &compressorName)
536 {
537  m_compressorName = compressorName;
538 }
539 
543 inline uint16 AbstractTrack::depth() const
544 {
545  return m_depth;
546 }
547 
553 inline uint32 AbstractTrack::fps() const
554 {
555  return m_fps;
556 }
557 
563 inline const char *AbstractTrack::chromaFormat() const
564 {
565  return m_chromaFormat;
566 }
567 
572 {
573  return m_pixelAspectRatio;
574 }
575 
581 inline bool AbstractTrack::isInterlaced() const
582 {
583  return m_interlaced;
584 }
585 
591 inline uint32 AbstractTrack::timeScale() const
592 {
593  return m_timeScale;
594 }
595 
599 inline bool AbstractTrack::isEnabled() const
600 {
601  return m_enabled;
602 }
603 
608 inline void AbstractTrack::setEnabled(bool enabled)
609 {
610  m_enabled = enabled;
611 }
612 
616 inline bool AbstractTrack::isDefault() const
617 {
618  return m_default;
619 }
620 
625 inline void AbstractTrack::setDefault(bool isDefault)
626 {
627  m_default = isDefault;
628 }
629 
633 inline bool AbstractTrack::isForced() const
634 {
635  return m_forced;
636 }
637 
642 inline void AbstractTrack::setForced(bool forced)
643 {
644  m_forced = forced;
645 }
646 
650 inline bool AbstractTrack::hasLacing() const
651 {
652  return m_lacing;
653 }
654 
658 inline bool AbstractTrack::isEncrypted() const
659 {
660  return m_encrypted;
661 }
662 
666 inline uint32 AbstractTrack::colorSpace() const
667 {
668  return m_colorSpace;
669 }
670 
674 inline const Margin &AbstractTrack::cropping() const
675 {
676  return m_cropping;
677 }
678 
682 inline bool AbstractTrack::isHeaderValid() const
683 {
684  return m_headerValid;
685 }
686 
687 }
688 
689 #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
void setDefault(bool isDefault)
Sets whether the track is a default track.
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:120
AspectRatio m_pixelAspectRatio
void setForced(bool forced)
Sets whether the track is forced.
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.
void setEnabled(bool enabled)
Sets whether the track is enabled.
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:317
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.
TAG_PARSER_EXPORT const char * bitrate()
The track&#39;s bit rate in bits per second.
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.
void setTrackNumber(uint32 trackNumber)
Sets the track number.
std::string m_language
uint32 colorSpace() const
Returns the color space if known; otherwise returns 0.
uint64 sampleCount() const
Returns the number of samples/frames if known; otherwise returns 0.
void setCompressorName(const std::string &compressorName)
Returns the compressor name if known; otherwise returns an empty string.
uint64 startOffset() const
Returns the start offset of the track in the associated stream.
void setName(const std::string &name)
Sets the name.
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:344
const char * mediaTypeName() const
Returns the string representation of the media type of the track.
TAG_PARSER_EXPORT const char * description()
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.
void setLanguage(const std::string &language)
Sets the language of the track.
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:260
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.