Tag Parser  7.0.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
adtsstream.cpp
Go to the documentation of this file.
1 #include "./adtsstream.h"
2 
3 #include "../mp4/mp4ids.h"
4 
5 #include "../exceptions.h"
6 
7 #include <string>
8 
9 using namespace std;
10 
11 namespace TagParser {
12 
18 void AdtsStream::internalParseHeader(Diagnostics &diag)
19 {
20  //static const string context("parsing ADTS frame header");
21  if (!m_istream) {
22  throw NoDataFoundException();
23  }
24  // get size
25  m_istream->seekg(-128, ios_base::end);
26  if (m_reader.readUInt24BE() == 0x544147) {
27  m_size = static_cast<uint64>(m_istream->tellg()) - 3u - m_startOffset;
28  } else {
29  m_size = static_cast<uint64>(m_istream->tellg()) + 125u - m_startOffset;
30  }
31  m_istream->seekg(m_startOffset, ios_base::beg);
32  // parse frame header
33  m_firstFrame.parseHeader(m_reader);
34  m_format = Mpeg4AudioObjectIds::idToMediaFormat(m_firstFrame.mpeg4AudioObjectId());
35  m_channelCount = Mpeg4ChannelConfigs::channelCount(m_channelConfig = m_firstFrame.mpeg4ChannelConfig());
36  byte sampleRateIndex = m_firstFrame.mpeg4SamplingFrequencyIndex();
37  m_samplingFrequency = sampleRateIndex < sizeof(mpeg4SamplingFrequencyTable) ? mpeg4SamplingFrequencyTable[sampleRateIndex] : 0;
38 }
39 
40 } // namespace TagParser
TAG_PARSER_EXPORT byte channelCount(byte config)
Returns the channel count for the specified MPEG-4 channel config.
Definition: mp4ids.cpp:445
STL namespace.
TAG_PARSER_EXPORT MediaFormat idToMediaFormat(byte mpeg4AudioObjectId, bool sbrPresent=false, bool psPresent=false)
Definition: mp4ids.cpp:352
uint32 mpeg4SamplingFrequencyTable[13]
Definition: mp4ids.cpp:408