Tag Parser  6.5.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
mpegaudioframe.h
Go to the documentation of this file.
1 #ifndef MP3FRAMEAUDIOSTREAM_H
2 #define MP3FRAMEAUDIOSTREAM_H
3 
4 #include "../global.h"
5 
6 #include <c++utilities/conversion/types.h>
7 
8 #include <iostream>
9 
10 namespace IoUtilities {
11 class BinaryReader;
12 }
13 
14 namespace Media
15 {
16 
20 enum class MpegChannelMode
21 {
22  Stereo,
23  JointStereo,
24  DualChannel,
26  Unspecifed
27 };
28 
30 
31 enum class XingHeaderFlags
32 {
33  None = 0x0u,
34  HasFramesField = 0x1u,
35  HasBytesField = 0x2u,
36  HasTocField = 0x4u,
37  HasQualityIndicator = 0x8u
38 };
39 
41 {
42 public:
44 
45  void parseHeader(IoUtilities::BinaryReader &reader);
46 
47  bool isValid() const;
48  double mpegVersion() const;
49  int layer() const;
50  bool isProtectedByCrc() const;
51  uint32 bitrate() const;
52  uint32 samplingFrequency() const;
53  uint32 paddingSize() const;
54  MpegChannelMode channelMode() const;
55  bool hasCopyright() const;
56  bool isOriginal() const;
57  uint32 sampleCount() const;
58  uint32 size() const;
59  bool isXingHeaderAvailable() const;
60  XingHeaderFlags xingHeaderFlags() const;
61  bool isXingFramefieldPresent() const;
62  bool isXingBytesfieldPresent() const;
63  bool isXingTocFieldPresent() const;
64  bool isXingQualityIndicatorFieldPresent() const;
65  uint32 xingFrameCount() const;
66  uint32 xingBytesfield() const;
67  uint32 xingQualityIndicator() const;
68 
69 private:
70  static const uint64 m_xingHeaderOffset;
71  static const int m_bitrateTable[0x2][0x3][0xF];
72  static const uint32 m_sync;
73  uint32 m_header;
74  uint64 m_xingHeader;
75  XingHeaderFlags m_xingHeaderFlags;
76  uint32 m_xingFramefield;
77  uint32 m_xingBytesfield;
78  uint32 m_xingQualityIndicator;
79 };
80 
85  m_header(0),
86  m_xingHeader(0),
87  m_xingHeaderFlags(XingHeaderFlags::None),
88  m_xingFramefield(0),
89  m_xingBytesfield(0),
90  m_xingQualityIndicator(0)
91 {}
92 
96 inline bool MpegAudioFrame::isValid() const
97 {
98  return (m_header & m_sync) == m_sync;
99 }
100 
105 {
106  return (m_header & 0x10000u) != 0x10000u;
107 }
108 
112 inline uint32 MpegAudioFrame::bitrate() const
113 {
114  if(mpegVersion() > 0.0 && layer() > 0)
115  return m_bitrateTable[mpegVersion() == 1.0 ? 0 : 1][layer() - 1][(m_header & 0xf000u) >> 12];
116  else
117  return 0;
118 }
119 
123 inline uint32 MpegAudioFrame::paddingSize() const
124 {
125  if(isValid()) {
126  return (m_header & 0x60000u) == 0x60000u ? 4u : 1u * (m_header & 0x200u);
127  } else {
128  return 0;
129  }
130 }
131 
135 inline bool MpegAudioFrame::hasCopyright() const
136 {
137  return (m_header & 0x8u) == 0x8u;
138 }
139 
143 inline bool MpegAudioFrame::isOriginal() const
144 {
145  return (m_header & 0x4u) == 0x4u;
146 }
147 
149 {
150  return static_cast<XingHeaderFlags>(static_cast<int>(lhs) | static_cast<int>(rhs));
151 }
152 
154 {
155  return static_cast<XingHeaderFlags>(static_cast<int>(lhs) & static_cast<int>(rhs));
156 }
157 
158 
163 {
164  return ((m_xingHeader & 0x58696e6700000000uL) == 0x58696e6700000000uL) || ((m_xingHeader & 0x496e666f00000000uL) == 0x496e666f00000000uL);
165 }
166 
171 {
172  return m_xingHeaderFlags;
173 }
174 
179 {
180  return (isXingHeaderAvailable())
182  : false;
183 }
184 
189 {
190  return (isXingHeaderAvailable())
192  : false;
193 }
194 
199 {
200  return (isXingHeaderAvailable())
202  : false;
203 }
204 
209 {
210  return (isXingHeaderAvailable())
212  : false;
213 }
214 
218 inline uint32 MpegAudioFrame::xingFrameCount() const
219 {
220  return m_xingFramefield;
221 }
222 
226 inline uint32 MpegAudioFrame::xingBytesfield() const
227 {
228  return m_xingBytesfield;
229 }
230 
235 {
236  return m_xingQualityIndicator;
237 }
238 
239 }
240 
241 #endif // MP3FRAMEAUDIOSTREAM_H
uint32 bitrate() const
Returns the bitrate of the frame if known; otherwise returns 0.
double mpegVersion() const
Returns the MPEG version if known (1.0, 2.0 or 2.5); otherwise returns 0.
bool isXingFramefieldPresent() const
Returns an indication whether the Xing frame field is present.
TAG_PARSER_EXPORT const char * bitrate()
The track&#39;s bit rate in bits per second.
MpegAudioFrame()
Constructs a new frame.
The MpegAudioFrame class is used to parse MPEG audio frames.
uint32 xingFrameCount() const
Returns an indication whether the Xing frame count is present.
Contains utility classes helping to read and write streams.
bool isXingHeaderAvailable() const
Returns an indication whether a Xing header is present.
bool hasCopyright() const
Returns an indication whether the frame is copyrighted.
MpegChannelMode
Specifies the channel mode.
uint32 paddingSize() const
Returns the padding size if known; otherwise returns 0.
bool isXingQualityIndicatorFieldPresent() const
Returns an indication whether the Xing quality indicator field is present.
int layer() const
Returns the MPEG layer if known (1, 2, or 3); otherwise returns 0.
bool isOriginal() const
Returns an indication whether the frame labeled as original.
bool isValid() const
Returns an indication whether the frame is valid.
XingHeaderFlags operator&(XingHeaderFlags lhs, XingHeaderFlags rhs)
XingHeaderFlags operator|(XingHeaderFlags lhs, XingHeaderFlags rhs)
XingHeaderFlags xingHeaderFlags() const
Returns the Xing header flags.
bool isProtectedByCrc() const
Returns an indication whether the frame is protected by CRC.
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
uint32 xingBytesfield() const
Returns the Xing bytes field if known; otherwise returns 0.
uint32 xingQualityIndicator() const
Returns the Xing quality indicator if known; otherwise returns 0.
TAG_PARSER_EXPORT const char * mpegChannelModeString(MpegChannelMode channelMode)
Returns the string representation for the specified channelMode.
bool isXingTocFieldPresent() const
Returns an indication whether the Xing TOC is present.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
bool isXingBytesfieldPresent() const
Returns an indication whether the Xing bytes field is present.