Tag Parser  6.4.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
abstracttrack.cpp
Go to the documentation of this file.
1 #include "./abstracttrack.h"
2 #include "./exceptions.h"
3 #include "./mediaformat.h"
4 
5 #include "./mp4/mp4ids.h"
6 
8 
9 using namespace std;
10 using namespace ConversionUtilities;
11 using namespace ChronoUtilities;
12 using namespace IoUtilities;
13 
14 namespace Media {
15 
32 AbstractTrack::AbstractTrack(istream &inputStream, ostream &outputStream, uint64 startOffset) :
33  m_istream(&inputStream),
34  m_ostream(&outputStream),
35  m_reader(BinaryReader(&inputStream)),
36  m_writer(BinaryWriter(&outputStream)),
37  m_startOffset(startOffset),
38  m_headerValid(false),
39  m_format(),
40  m_mediaType(MediaType::Unknown),
41  m_version(0.0),
42  m_size(0),
43  m_trackNumber(0),
44  m_id(0),
45  m_bitrate(0.0),
46  m_maxBitrate(0.0),
47  m_samplingFrequency(0),
48  m_extensionSamplingFrequency(0),
49  m_bitsPerSample(0),
50  m_bytesPerSecond(0),
51  m_channelCount(0),
52  m_channelConfig(0),
53  m_extensionChannelConfig(0),
54  m_sampleCount(0),
55  m_quality(0),
56  m_depth(0),
57  m_fps(0),
58  m_chromaFormat(nullptr),
59  m_interlaced(false),
60  m_timeScale(0),
61  m_enabled(true),
62  m_default(false),
63  m_forced(false),
64  m_lacing(false),
65  m_encrypted(false),
66  m_usedInPresentation(true),
67  m_usedWhenPreviewing(true),
68  m_colorSpace(0)
69 {}
70 
78 AbstractTrack::AbstractTrack(std::iostream &stream, uint64 startOffset) :
79  AbstractTrack(stream, stream, startOffset)
80 {}
81 
86 {}
87 
92 {
93  switch(m_format.general) {
97  return mpegChannelModeString(static_cast<MpegChannelMode>(m_channelConfig));
98  default:
99  return nullptr;
100  }
101 }
102 
107 {
109 }
110 
115 {
116  switch(m_format.general) {
119  default:
120  return nullptr;
121  }
122 }
123 
130 string AbstractTrack::label() const
131 {
132  stringstream ss;
133  ss << "ID: " << id();
134  ss << ", type: " << mediaTypeName();
135  if(!name().empty()) {
136  ss << ", name: \"" << name() << "\"";
137  }
138  if(!language().empty() && language() != "und") {
139  ss << ", language: \"" << language() << "\"";
140  }
141  return ss.str();
142 }
143 
156 {
157  // use abbreviated format
158  const char *format = m_format.shortAbbreviation();
159  if(!format || !*format) {
160  // fall back to media type name if no abbreviation available
161  format = mediaTypeName();
162  }
163 
164  // find additional info
165  const char *additionalInfo = nullptr;
166  switch(m_mediaType) {
167  case MediaType::Video:
168  if(!displaySize().isNull()) {
169  additionalInfo = displaySize().abbreviation();
170  } else if(!pixelSize().isNull()) {
171  additionalInfo = pixelSize().abbreviation();
172  }
173  break;
174  case MediaType::Audio:
175  case MediaType::Text:
176  if(channelCount()) {
177  if(!language().empty() && language() != "und") {
178  return argsToString(format, '-', channelCount(), "ch-", language());
179  } else {
180  return argsToString(format, '-', channelCount(), 'c', 'h');
181  }
182  } else if(!language().empty() && language() != "und") {
183  additionalInfo = language().data();
184  }
185  break;
186  default:
187  ;
188  }
189 
190  if(additionalInfo) {
191  return argsToString(format, '-', additionalInfo);
192  }
193  return format;
194 }
195 
209 {
211  m_headerValid = false;
212  m_istream->seekg(m_startOffset, ios_base::beg);
213  try {
215  m_headerValid = true;
216  } catch(Failure &) {
217  throw;
218  }
219 }
220 
231 }
const std::string name() const
Returns the track name if known; otherwise returns an empty string.
MediaType
The MediaType enum specifies the type of media data (audio, video, text, ...).
Definition: mediaformat.h:13
void invalidateStatus()
Invalidates the current status.
byte extensionChannelConfig() const
Returns the extension channel configuration if available; otherwise returns nullptr.
AbstractTrack(std::istream &inputStream, std::ostream &outputStream, uint64 startOffset)
Constructs a new track.
uint16 channelCount() const
Returns the number of channels if known; otherwise returns 0.
std::string label() const
Returns a label for the track.
GeneralMediaFormat general
Definition: mediaformat.h:271
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
Definition: abstracttrack.h:40
STL namespace.
TAG_PARSER_EXPORT const char * channelConfigString(byte config)
Returns the string representation for the specified MPEG-4 channel config.
Definition: mp4ids.cpp:315
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. ...
const char * abbreviation() const
Returns an abbreviation for the current instance, eg.
Definition: size.cpp:9
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.
const char * channelConfigString() const
Returns a string with the channel configuration if available; otherwise returns nullptr.
Contains utility classes helping to read and write streams.
const char * shortAbbreviation() const
Returns a short abbreviation of the media format as C-style string.
The class inherits from std::exception and serves as base class for exceptions thrown by the elements...
Definition: exceptions.h:11
uint64 startOffset() const
Returns the start offset of the track in the associated stream.
const char * mediaTypeName() const
Returns the string representation of the media type of the track.
const std::string & language() const
Returns the language of the track if known; otherwise returns an empty string.
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
virtual void internalParseHeader()=0
This method is internally called to parse header information.
const char * extensionChannelConfigString() const
Returns a string with the extension channel configuration if available; otherwise returns nullptr...
std::istream * m_istream
std::string description() const
Returns a short description about the track.
TAG_PARSER_EXPORT const char * mpegChannelModeString(MpegChannelMode channelMode)
Returns the string representation for the specified channelMode.
void parseHeader()
Parses technical information about the track from the header.
virtual ~AbstractTrack()
Destroys the track.