tagparser/adts/adtsstream.cpp

44 lines
1.4 KiB
C++
Raw Normal View History

2015-09-06 19:57:33 +02:00
#include "./adtsstream.h"
2015-07-15 00:10:24 +02:00
2015-09-06 19:57:33 +02:00
#include "../mp4/mp4ids.h"
2015-09-06 15:42:18 +02:00
2015-09-06 19:57:33 +02:00
#include "../exceptions.h"
2015-07-15 00:10:24 +02:00
#include <string>
using namespace std;
namespace TagParser {
2015-07-15 00:10:24 +02:00
/*!
* \class TagParser::AdtsStream
* \brief Implementation of TagParser::AbstractTrack for ADTS streams.
2015-07-15 00:10:24 +02:00
*/
void AdtsStream::internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress)
2015-07-15 00:10:24 +02:00
{
2019-06-12 20:40:45 +02:00
CPP_UTILITIES_UNUSED(diag)
CPP_UTILITIES_UNUSED(progress)
2015-07-15 00:10:24 +02:00
//static const string context("parsing ADTS frame header");
2018-03-07 01:17:50 +01:00
if (!m_istream) {
2015-07-15 00:10:24 +02:00
throw NoDataFoundException();
}
// get size
m_istream->seekg(-128, ios_base::end);
2018-03-07 01:17:50 +01:00
if (m_reader.readUInt24BE() == 0x544147) {
2019-03-13 19:06:42 +01:00
m_size = static_cast<std::uint64_t>(m_istream->tellg()) - 3u - m_startOffset;
2015-07-15 00:10:24 +02:00
} else {
2019-03-13 19:06:42 +01:00
m_size = static_cast<std::uint64_t>(m_istream->tellg()) + 125u - m_startOffset;
2015-07-15 00:10:24 +02:00
}
m_istream->seekg(static_cast<streamoff>(m_startOffset), ios_base::beg);
2015-07-15 00:10:24 +02:00
// parse frame header
m_firstFrame.parseHeader(m_reader);
m_format = Mpeg4AudioObjectIds::idToMediaFormat(m_firstFrame.mpeg4AudioObjectId());
m_channelCount = Mpeg4ChannelConfigs::channelCount(m_channelConfig = m_firstFrame.mpeg4ChannelConfig());
2019-03-13 19:06:42 +01:00
std::uint8_t sampleRateIndex = m_firstFrame.mpeg4SamplingFrequencyIndex();
m_samplingFrequency = sampleRateIndex < sizeof(mpeg4SamplingFrequencyTable) ? mpeg4SamplingFrequencyTable[sampleRateIndex] : 0;
2015-07-15 00:10:24 +02:00
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser