Tag Parser  7.0.3
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
adtsframe.h
Go to the documentation of this file.
1 #ifndef TAG_PARSER_ADTSFRAME_H
2 #define TAG_PARSER_ADTSFRAME_H
3 
4 #include "../global.h"
5 
6 #include <c++utilities/conversion/types.h>
7 
8 namespace IoUtilities {
9 class BinaryReader;
10 }
11 
12 namespace TagParser {
13 
15 public:
16  AdtsFrame();
17 
18  void parseHeader(IoUtilities::BinaryReader &reader);
19 
20  bool isValid() const;
21  bool isMpeg4() const;
22  bool hasCrc() const;
23  byte mpeg4AudioObjectId() const;
24  byte mpeg4SamplingFrequencyIndex() const;
25  byte mpeg4ChannelConfig() const;
26  uint16 totalSize() const;
27  byte headerSize() const;
28  uint16 dataSize() const;
29  uint16 bufferFullness() const;
30  byte frameCount() const;
31  uint16 crc() const;
32 
33 private:
34  uint16 m_header1;
35  uint64 m_header2;
36 };
37 
42  : m_header1(0)
43 {
44 }
45 
49 inline bool AdtsFrame::isValid() const
50 {
51  return ((m_header1 & 0xFFF6u) == 0xFFF0u) && (totalSize() >= headerSize());
52 }
53 
57 inline bool AdtsFrame::isMpeg4() const
58 {
59  return m_header1 & 0x8u;
60 }
61 
65 inline bool AdtsFrame::hasCrc() const
66 {
67  return (m_header1 & 0x1u) == 0;
68 }
69 
75 inline byte AdtsFrame::mpeg4AudioObjectId() const
76 {
77  return (m_header2 >> 0x36) + 0x1u;
78 }
79 
85 {
86  return (m_header2 >> 0x32) & 0xFu;
87 }
88 
94 inline byte AdtsFrame::mpeg4ChannelConfig() const
95 {
96  return (m_header2 >> 0x2E) & 0x7u;
97 }
98 
102 inline uint16 AdtsFrame::totalSize() const
103 {
104  return (m_header2 >> 0x1D) & 0x1FFFu;
105 }
106 
110 inline byte AdtsFrame::headerSize() const
111 {
112  return hasCrc() ? 9 : 7;
113 }
114 
118 inline uint16 AdtsFrame::dataSize() const
119 {
120  return totalSize() - headerSize();
121 }
122 
126 inline uint16 AdtsFrame::bufferFullness() const
127 {
128  return (m_header2 >> 0x12) & 0x7FFu;
129 }
130 
134 inline byte AdtsFrame::frameCount() const
135 {
136  return ((m_header2 >> 0x10) & 0x3u) + 0x1u;
137 }
138 
143 inline uint16 AdtsFrame::crc() const
144 {
145  return m_header2 & 0xFFFFu;
146 }
147 
148 } // namespace TagParser
149 
150 #endif // TAG_PARSER_ADTSFRAME_H
bool isMpeg4() const
Returns whether the MPEG version is MPEG-4; otherwise the MPEG version is MPEG-2. ...
Definition: adtsframe.h:57
uint16 totalSize() const
Returns the size of the frame (including the header) in bytes.
Definition: adtsframe.h:102
uint16 bufferFullness() const
Returns the buffer fullness.
Definition: adtsframe.h:126
uint16 crc() const
Returns the CRC-16 checksum of the frame.
Definition: adtsframe.h:143
bool hasCrc() const
Returns whether a CRC-16 checksum is present ("protection absent" bit is NOT set).
Definition: adtsframe.h:65
Contains utility classes helping to read and write streams.
byte mpeg4AudioObjectId() const
Returns the MPEG-4 audio object type ID.
Definition: adtsframe.h:75
AdtsFrame()
Constructs a new frame.
Definition: adtsframe.h:41
bool isValid() const
Returns an indication whether the frame is valid.
Definition: adtsframe.h:49
byte mpeg4ChannelConfig() const
Returns the MPEG-4 channel configuration.
Definition: adtsframe.h:94
byte frameCount() const
Returns the number of AAC frames (RDBs) in the ADTS frame.
Definition: adtsframe.h:134
uint16 dataSize() const
Returns the data size (total size minus header size) in bytes.
Definition: adtsframe.h:118
byte mpeg4SamplingFrequencyIndex() const
Returns the MPEG-4 sample rate index.
Definition: adtsframe.h:84
byte headerSize() const
Retruns the header size in bytes (9 if CRC is present; otherwise 7).
Definition: adtsframe.h:110
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.