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