Tag Parser  6.2.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 
127 string AbstractTrack::label() const
128 {
129  stringstream ss;
130  ss << "ID: " << id();
131  ss << ", type: " << mediaTypeName();
132  if(!name().empty()) {
133  ss << ", name: \"" << name() << "\"";
134  }
135  if(!language().empty() && language() != "und") {
136  ss << ", language: \"" << language() << "\"";
137  }
138  return ss.str();
139 }
140 
154 {
156  m_headerValid = false;
157  m_istream->seekg(m_startOffset, ios_base::beg);
158  try {
160  m_headerValid = true;
161  } catch(Failure &) {
162  throw;
163  }
164 }
165 
176 }
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.
std::string label() const
Returns a label for the track.
GeneralMediaFormat general
Definition: mediaformat.h:269
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
uint64 id() const
Returns the track ID if known; otherwise returns 0.
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.
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
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.