Tag Parser  8.0.0
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  constexpr AdtsFrame();
17 
18  void parseHeader(IoUtilities::BinaryReader &reader);
19 
20  constexpr bool isValid() const;
21  constexpr bool isMpeg4() const;
22  constexpr bool hasCrc() const;
23  constexpr byte mpeg4AudioObjectId() const;
24  constexpr byte mpeg4SamplingFrequencyIndex() const;
25  constexpr byte mpeg4ChannelConfig() const;
26  constexpr uint16 totalSize() const;
27  constexpr byte headerSize() const;
28  constexpr uint16 dataSize() const;
29  constexpr uint16 bufferFullness() const;
30  constexpr byte frameCount() const;
31  constexpr uint16 crc() const;
32 
33 private:
34  uint16 m_header1;
35  uint64 m_header2;
36 };
37 
42  : m_header1(0)
43  , m_header2(0)
44 {
45 }
46 
50 constexpr bool AdtsFrame::isValid() const
51 {
52  return ((m_header1 & 0xFFF6u) == 0xFFF0u) && (totalSize() >= headerSize());
53 }
54 
58 constexpr bool AdtsFrame::isMpeg4() const
59 {
60  return m_header1 & 0x8u;
61 }
62 
66 constexpr bool AdtsFrame::hasCrc() const
67 {
68  return (m_header1 & 0x1u) == 0;
69 }
70 
76 constexpr byte AdtsFrame::mpeg4AudioObjectId() const
77 {
78  return (m_header2 >> 0x36) + 0x1u;
79 }
80 
86 {
87  return (m_header2 >> 0x32) & 0xFu;
88 }
89 
95 constexpr byte AdtsFrame::mpeg4ChannelConfig() const
96 {
97  return (m_header2 >> 0x2E) & 0x7u;
98 }
99 
103 constexpr uint16 AdtsFrame::totalSize() const
104 {
105  return (m_header2 >> 0x1D) & 0x1FFFu;
106 }
107 
111 constexpr byte AdtsFrame::headerSize() const
112 {
113  return hasCrc() ? 9 : 7;
114 }
115 
119 constexpr uint16 AdtsFrame::dataSize() const
120 {
121  return totalSize() - headerSize();
122 }
123 
127 constexpr uint16 AdtsFrame::bufferFullness() const
128 {
129  return (m_header2 >> 0x12) & 0x7FFu;
130 }
131 
135 constexpr byte AdtsFrame::frameCount() const
136 {
137  return ((m_header2 >> 0x10) & 0x3u) + 0x1u;
138 }
139 
144 constexpr uint16 AdtsFrame::crc() const
145 {
146  return m_header2 & 0xFFFFu;
147 }
148 
149 } // namespace TagParser
150 
151 #endif // TAG_PARSER_ADTSFRAME_H
constexpr AdtsFrame()
Constructs a new frame.
Definition: adtsframe.h:41
constexpr byte frameCount() const
Returns the number of AAC frames (RDBs) in the ADTS frame.
Definition: adtsframe.h:135
constexpr bool isMpeg4() const
Returns whether the MPEG version is MPEG-4; otherwise the MPEG version is MPEG-2. ...
Definition: adtsframe.h:58
constexpr uint16 dataSize() const
Returns the data size (total size minus header size) in bytes.
Definition: adtsframe.h:119
constexpr uint16 crc() const
Returns the CRC-16 checksum of the frame.
Definition: adtsframe.h:144
constexpr uint16 totalSize() const
Returns the size of the frame (including the header) in bytes.
Definition: adtsframe.h:103
constexpr byte mpeg4AudioObjectId() const
Returns the MPEG-4 audio object type ID.
Definition: adtsframe.h:76
The AdtsFrame class is used to parse "Audio Data Transport Stream" frames.
Definition: adtsframe.h:14
constexpr uint16 bufferFullness() const
Returns the buffer fullness.
Definition: adtsframe.h:127
Contains utility classes helping to read and write streams.
constexpr bool isValid() const
Returns an indication whether the frame is valid.
Definition: adtsframe.h:50
constexpr byte headerSize() const
Retruns the header size in bytes (9 if CRC is present; otherwise 7).
Definition: adtsframe.h:111
constexpr byte mpeg4SamplingFrequencyIndex() const
Returns the MPEG-4 sample rate index.
Definition: adtsframe.h:85
constexpr byte mpeg4ChannelConfig() const
Returns the MPEG-4 channel configuration.
Definition: adtsframe.h:95
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
constexpr bool hasCrc() const
Returns whether a CRC-16 checksum is present ("protection absent" bit is NOT set).
Definition: adtsframe.h:66