Tag Parser 12.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
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
9using namespace std;
10using namespace CppUtilities;
11
12namespace TagParser {
13
16
33AbstractTrack::AbstractTrack(istream &inputStream, ostream &outputStream, std::uint64_t startOffset)
34 : m_istream(&inputStream)
35 , m_ostream(&outputStream)
36 , m_reader(BinaryReader(&inputStream))
37 , m_writer(BinaryWriter(&outputStream))
38 , m_startOffset(startOffset)
40 , m_format()
41 , m_mediaType(MediaType::Unknown)
42 , m_version(0.0)
43 , m_size(0)
44 , m_trackNumber(0)
45 , m_id(0)
46 , m_bitrate(0.0)
47 , m_maxBitrate(0.0)
48 , m_samplingFrequency(0)
49 , m_extensionSamplingFrequency(0)
50 , m_bitsPerSample(0)
51 , m_bytesPerSecond(0)
52 , m_channelCount(0)
53 , m_channelConfig(0)
54 , m_extensionChannelConfig(0)
55 , m_sampleCount(0)
56 , m_quality(0)
57 , m_depth(0)
58 , m_fps(0)
59 , m_timeScale(0)
60 , m_colorSpace(0)
61 , m_fieldOrder(FieldOrder::Undetermined)
62 , m_stereoMode(StereoMode::Unknown)
63 , m_alphaMode(AlphaMode::Unknown)
64 , m_displayUnit(DisplayUnit::Unknown)
65 , m_aspectRatioType(AspectRatioType::Unknown)
66{
67}
68
76AbstractTrack::AbstractTrack(std::iostream &stream, std::uint64_t startOffset)
77 : AbstractTrack(stream, stream, startOffset)
78{
79}
80
87
91std::string_view AbstractTrack::channelConfigString() const
92{
93 switch (m_format.general) {
99 default:
100 return std::string_view();
101 }
102}
103
108{
110}
111
116{
117 switch (m_format.general) {
120 default:
121 return std::string_view();
122 }
123}
124
132{
133 stringstream ss;
134 ss << "ID: " << id();
135 ss << ", type: " << mediaTypeName();
136 if (!name().empty()) {
137 ss << ", name: \"" << name() << "\"";
138 }
139 if (const auto &language = locale().fullOrSomeAbbreviatedName(); !language.empty()) {
140 ss << ", language: " << language << "";
141 }
142 return ss.str();
143}
144
146string AbstractTrack::makeDescription(bool verbose) const
147{
148 // use abbreviated format
149 const auto format = MediaFormat(m_format.general, verbose ? m_format.sub : 0, verbose ? m_format.extension : 0);
151 if (formatName.empty()) {
152 // fall back to media type name if no abbreviation available
154 }
155
156 // find additional info and level
157 auto additionalInfoRef = std::string_view();
158 auto level = std::string();
159 switch (m_mediaType) {
160 case MediaType::Video:
161 if (!pixelSize().isNull()) {
162 additionalInfoRef = pixelSize().abbreviation();
163 } else if (!displaySize().isNull()) {
164 additionalInfoRef = displaySize().abbreviation();
165 }
166 if (verbose) {
167 switch (format.general) {
171 if (version() != 0.0) {
172 level = "@L" + numberToString(version());
173 }
174 break;
175 default:;
176 }
177 }
178 break;
179 case MediaType::Audio:
180 case MediaType::Text:
181 if (channelCount()) {
182 if (const auto &localeName = locale().someAbbreviatedName(); !localeName.empty()) {
183 return argsToString(formatName, '-', channelCount(), "ch-", localeName);
184 } else {
185 return argsToString(formatName, '-', channelCount(), 'c', 'h');
186 }
187 } else if (const auto &localeName = locale().someAbbreviatedName(); !localeName.empty()) {
188 additionalInfoRef = localeName;
189 }
190 break;
191 default:;
192 }
193
194 if (!additionalInfoRef.empty()) {
195 return argsToString(formatName, level, '-', additionalInfoRef);
196 }
197 return argsToString(formatName, level);
198}
200
213{
214 return makeDescription(true);
215}
216
227{
228 return makeDescription(false);
229}
230
244{
246 m_istream->seekg(static_cast<streamoff>(m_startOffset), ios_base::beg);
247 try {
248 internalParseHeader(diag, progress);
250 } catch (const Failure &) {
251 throw;
252 }
253}
254
265} // namespace TagParser
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
std::uint64_t id() const
Returns the track ID if known; otherwise returns 0.
std::string label() const
Returns a label for the track.
virtual void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)=0
This method is internally called to parse header information.
std::uint8_t m_extensionChannelConfig
const Locale & locale() const
Returns the locale of the track if known; otherwise returns an empty locale.
std::string_view extensionChannelConfigString() const
Returns a string with the extension channel configuration if available; otherwise returns nullptr.
std::string_view formatName() const
Returns the format of the track as C-style string if known; otherwise returns the format abbreviation...
const Size & displaySize() const
Returns the size of the video frames to display if known; otherwise returns a zero size.
double version() const
Returns the version/level of the track if known; otherwise returns 0.
const Size & pixelSize() const
Returns the size of the encoded video frames if known; otherwise returns a zero size.
std::uint8_t extensionChannelConfig() const
Returns the extension channel configuration if available; otherwise returns nullptr.
AbstractTrack(std::istream &inputStream, std::ostream &outputStream, std::uint64_t startOffset)
Constructs a new track.
std::string shortDescription() const
Returns a short description about the track.
std::string_view mediaTypeName() const
Returns the string representation of the media type of the track.
void parseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses technical information about the track from the header.
std::uint16_t channelCount() const
Returns the number of channels if known; otherwise returns 0.
std::string_view channelConfigString() const
Returns a string with the channel configuration if available; otherwise returns nullptr.
const std::string name() const
Returns the track name if known; otherwise returns an empty string.
std::string description() const
Returns a description about the track.
MediaFormat format() const
Returns the format of the track if known; otherwise returns MediaFormat::Unknown.
virtual ~AbstractTrack()
Destroys the track.
The Diagnostics class is a container for DiagMessage.
The class inherits from std::exception and serves as base class for exceptions thrown by the elements...
The MediaFormat class specifies the format of media data.
std::string_view shortAbbreviation() const
Returns a short abbreviation of the media format as C-style string.
unsigned char extension
GeneralMediaFormat general
std::string_view abbreviation() const
Returns an abbreviation for the current instance, eg.
Definition size.cpp:17
TAG_PARSER_EXPORT std::string_view channelConfigString(std::uint8_t config)
Returns the string representation for the specified MPEG-4 channel config.
Definition mp4ids.cpp:439
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
AspectRatioType
The AspectRatioType enum specifies the possible modifications to the aspect ratio.
TAG_PARSER_EXPORT std::string_view mpegChannelModeString(MpegChannelMode channelMode)
Returns the string representation for the specified channelMode.
StereoMode
The StereoMode enum specifies the Stereo-3D video mode.
DisplayUnit
The DisplayUnit enum specifies how display width and heigh are interpreted.
AlphaMode
The AlphaMode enum specifies the alpha video mode.
MediaType
The MediaType enum specifies the type of media data (audio, video, text, ...).
Definition mediaformat.h:14
FieldOrder
The FieldOrder enum declares the field ordering of the video.
MpegChannelMode
Specifies the channel mode.
TrackFlags
The TrackFlags enum specifies miscellaneous boolean properties of a track.
The AbstractTrackPrivate struct contains private fields of the AbstractTrack class.