Tag Parser  9.4.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 <cstdint>
7 
8 namespace CppUtilities {
9 class BinaryReader;
10 }
11 
12 namespace TagParser {
13 
15 public:
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 
33 private:
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 
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 std::uint8_t AdtsFrame::mpeg4AudioObjectId() const
77 {
78  return (m_header2 >> 0x36) + 0x1u;
79 }
80 
85 constexpr std::uint8_t AdtsFrame::mpeg4SamplingFrequencyIndex() const
86 {
87  return (m_header2 >> 0x32) & 0xFu;
88 }
89 
95 constexpr std::uint8_t AdtsFrame::mpeg4ChannelConfig() const
96 {
97  return (m_header2 >> 0x2E) & 0x7u;
98 }
99 
103 constexpr std::uint16_t AdtsFrame::totalSize() const
104 {
105  return (m_header2 >> 0x1D) & 0x1FFFu;
106 }
107 
111 constexpr std::uint8_t AdtsFrame::headerSize() const
112 {
113  return hasCrc() ? 9 : 7;
114 }
115 
119 constexpr std::uint16_t AdtsFrame::dataSize() const
120 {
121  return totalSize() - headerSize();
122 }
123 
127 constexpr std::uint16_t AdtsFrame::bufferFullness() const
128 {
129  return (m_header2 >> 0x12) & 0x7FFu;
130 }
131 
135 constexpr std::uint8_t AdtsFrame::frameCount() const
136 {
137  return ((m_header2 >> 0x10) & 0x3u) + 0x1u;
138 }
139 
144 constexpr std::uint16_t AdtsFrame::crc() const
145 {
146  return m_header2 & 0xFFFFu;
147 }
148 
149 } // namespace TagParser
150 
151 #endif // TAG_PARSER_ADTSFRAME_H
TagParser::AdtsFrame::isMpeg4
constexpr bool isMpeg4() const
Returns whether the MPEG version is MPEG-4; otherwise the MPEG version is MPEG-2.
Definition: adtsframe.h:58
TagParser::AdtsFrame::totalSize
constexpr std::uint16_t totalSize() const
Returns the size of the frame (including the header) in bytes.
Definition: adtsframe.h:103
TagParser::AdtsFrame::crc
constexpr std::uint16_t crc() const
Returns the CRC-16 checksum of the frame.
Definition: adtsframe.h:144
TagParser::AdtsFrame::mpeg4AudioObjectId
constexpr std::uint8_t mpeg4AudioObjectId() const
Returns the MPEG-4 audio object type ID.
Definition: adtsframe.h:76
TagParser::AdtsFrame::bufferFullness
constexpr std::uint16_t bufferFullness() const
Returns the buffer fullness.
Definition: adtsframe.h:127
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagParser::AdtsFrame::frameCount
constexpr std::uint8_t frameCount() const
Returns the number of AAC frames (RDBs) in the ADTS frame.
Definition: adtsframe.h:135
CppUtilities
Definition: abstractcontainer.h:15
TagParser::AdtsFrame::headerSize
constexpr std::uint8_t headerSize() const
Retruns the header size in bytes (9 if CRC is present; otherwise 7).
Definition: adtsframe.h:111
TagParser::AdtsFrame::mpeg4SamplingFrequencyIndex
constexpr std::uint8_t mpeg4SamplingFrequencyIndex() const
Returns the MPEG-4 sample rate index.
Definition: adtsframe.h:85
TagParser::AdtsFrame::hasCrc
constexpr bool hasCrc() const
Returns whether a CRC-16 checksum is present ("protection absent" bit is NOT set).
Definition: adtsframe.h:66
TagParser::AdtsFrame::mpeg4ChannelConfig
constexpr std::uint8_t mpeg4ChannelConfig() const
Returns the MPEG-4 channel configuration.
Definition: adtsframe.h:95
TagParser::AdtsFrame::isValid
constexpr bool isValid() const
Returns an indication whether the frame is valid.
Definition: adtsframe.h:50
TagParser::AdtsFrame::dataSize
constexpr std::uint16_t dataSize() const
Returns the data size (total size minus header size) in bytes.
Definition: adtsframe.h:119
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
TagParser::AdtsFrame::AdtsFrame
constexpr AdtsFrame()
Constructs a new frame.
Definition: adtsframe.h:41
TagParser::AdtsFrame
The AdtsFrame class is used to parse "Audio Data Transport Stream" frames.
Definition: adtsframe.h:14