Tag Parser  7.0.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 TAG_PARSER_MP3FRAMEAUDIOSTREAM_H
2 #define TAG_PARSER_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 TagParser {
15 
19 enum class MpegChannelMode {
20  Stereo,
21  JointStereo,
22  DualChannel,
24  Unspecifed
25 };
26 
28 
29 enum class XingHeaderFlags {
30  None = 0x0u,
31  HasFramesField = 0x1u,
32  HasBytesField = 0x2u,
33  HasTocField = 0x4u,
34  HasQualityIndicator = 0x8u
35 };
36 
38 public:
40 
41  void parseHeader(IoUtilities::BinaryReader &reader);
42 
43  bool isValid() const;
44  double mpegVersion() const;
45  int layer() const;
46  bool isProtectedByCrc() const;
47  uint32 bitrate() const;
48  uint32 samplingFrequency() const;
49  uint32 paddingSize() const;
50  MpegChannelMode channelMode() const;
51  bool hasCopyright() const;
52  bool isOriginal() const;
53  uint32 sampleCount() const;
54  uint32 size() const;
55  bool isXingHeaderAvailable() const;
56  XingHeaderFlags xingHeaderFlags() const;
57  bool isXingFramefieldPresent() const;
58  bool isXingBytesfieldPresent() const;
59  bool isXingTocFieldPresent() const;
60  bool isXingQualityIndicatorFieldPresent() const;
61  uint32 xingFrameCount() const;
62  uint32 xingBytesfield() const;
63  uint32 xingQualityIndicator() const;
64 
65 private:
66  static const uint64 m_xingHeaderOffset;
67  static const int m_bitrateTable[0x2][0x3][0xF];
68  static const uint32 m_sync;
69  uint32 m_header;
70  uint64 m_xingHeader;
71  XingHeaderFlags m_xingHeaderFlags;
72  uint32 m_xingFramefield;
73  uint32 m_xingBytesfield;
74  uint32 m_xingQualityIndicator;
75 };
76 
81  : m_header(0)
82  , m_xingHeader(0)
83  , m_xingHeaderFlags(XingHeaderFlags::None)
84  , m_xingFramefield(0)
85  , m_xingBytesfield(0)
86  , m_xingQualityIndicator(0)
87 {
88 }
89 
93 inline bool MpegAudioFrame::isValid() const
94 {
95  return (m_header & m_sync) == m_sync;
96 }
97 
102 {
103  return (m_header & 0x10000u) != 0x10000u;
104 }
105 
109 inline uint32 MpegAudioFrame::bitrate() const
110 {
111  if (mpegVersion() > 0.0 && layer() > 0)
112  return m_bitrateTable[mpegVersion() == 1.0 ? 0 : 1][layer() - 1][(m_header & 0xf000u) >> 12];
113  else
114  return 0;
115 }
116 
120 inline uint32 MpegAudioFrame::paddingSize() const
121 {
122  if (isValid()) {
123  return (m_header & 0x60000u) == 0x60000u ? 4u : 1u * (m_header & 0x200u);
124  } else {
125  return 0;
126  }
127 }
128 
132 inline bool MpegAudioFrame::hasCopyright() const
133 {
134  return (m_header & 0x8u) == 0x8u;
135 }
136 
140 inline bool MpegAudioFrame::isOriginal() const
141 {
142  return (m_header & 0x4u) == 0x4u;
143 }
144 
146 {
147  return static_cast<XingHeaderFlags>(static_cast<int>(lhs) | static_cast<int>(rhs));
148 }
149 
151 {
152  return static_cast<XingHeaderFlags>(static_cast<int>(lhs) & static_cast<int>(rhs));
153 }
154 
159 {
160  return ((m_xingHeader & 0x58696e6700000000uL) == 0x58696e6700000000uL) || ((m_xingHeader & 0x496e666f00000000uL) == 0x496e666f00000000uL);
161 }
162 
167 {
168  return m_xingHeaderFlags;
169 }
170 
175 {
176  return (isXingHeaderAvailable()) ? ((m_xingHeaderFlags & XingHeaderFlags::HasFramesField) == XingHeaderFlags::HasFramesField) : false;
177 }
178 
183 {
184  return (isXingHeaderAvailable()) ? ((m_xingHeaderFlags & XingHeaderFlags::HasFramesField) == XingHeaderFlags::HasFramesField) : false;
185 }
186 
191 {
192  return (isXingHeaderAvailable()) ? ((m_xingHeaderFlags & XingHeaderFlags::HasTocField) == XingHeaderFlags::HasTocField) : false;
193 }
194 
199 {
201 }
202 
206 inline uint32 MpegAudioFrame::xingFrameCount() const
207 {
208  return m_xingFramefield;
209 }
210 
214 inline uint32 MpegAudioFrame::xingBytesfield() const
215 {
216  return m_xingBytesfield;
217 }
218 
223 {
224  return m_xingQualityIndicator;
225 }
226 
227 } // namespace TagParser
228 
229 #endif // TAG_PARSER_MP3FRAMEAUDIOSTREAM_H
XingHeaderFlags xingHeaderFlags() const
Returns the Xing header flags.
MpegChannelMode
Specifies the channel mode.
double mpegVersion() const
Returns the MPEG version if known (1.0, 2.0 or 2.5); otherwise returns 0.
TAG_PARSER_EXPORT const char * bitrate()
The track&#39;s bit rate in bits per second.
bool isProtectedByCrc() const
Returns an indication whether the frame is protected by CRC.
bool isXingHeaderAvailable() const
Returns an indication whether a Xing header is present.
bool isXingBytesfieldPresent() const
Returns an indication whether the Xing bytes field is present.
MpegAudioFrame()
Constructs a new frame.
uint32 paddingSize() const
Returns the padding size if known; otherwise returns 0.
int layer() const
Returns the MPEG layer if known (1, 2, or 3); otherwise returns 0.
Contains utility classes helping to read and write streams.
bool isXingFramefieldPresent() const
Returns an indication whether the Xing frame field is present.
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.
XingHeaderFlags operator|(XingHeaderFlags lhs, XingHeaderFlags rhs)
bool isOriginal() const
Returns an indication whether the frame labeled as original.
bool isXingQualityIndicatorFieldPresent() const
Returns an indication whether the Xing quality indicator field is present.
XingHeaderFlags operator &(XingHeaderFlags lhs, XingHeaderFlags rhs)
bool isValid() const
Returns an indication whether the frame is valid.
uint32 xingFrameCount() const
Returns an indication whether the Xing frame count is present.
bool hasCopyright() const
Returns an indication whether the frame is copyrighted.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
uint32 bitrate() const
Returns the bitrate of the frame if known; otherwise returns 0.