tagparser/adts/adtsframe.cpp

36 lines
914 B
C++
Raw Permalink Normal View History

2015-09-06 19:57:33 +02:00
#include "./adtsframe.h"
2015-09-06 15:42:18 +02:00
2015-09-06 19:57:33 +02:00
#include "../exceptions.h"
2015-07-18 00:55:35 +02:00
#include <c++utilities/io/binaryreader.h>
using namespace std;
namespace TagParser {
2015-07-18 00:55:35 +02:00
/*!
* \class TagParser::AdtsFrame
2015-07-18 00:55:35 +02:00
* \brief The AdtsFrame class is used to parse "Audio Data Transport Stream" frames.
*/
/*!
* \brief Parses the header read using the specified \a reader.
* \throws Throws InvalidDataException if the data read from the stream is
* no valid frame header.
*/
2019-06-10 22:49:11 +02:00
void AdtsFrame::parseHeader(CppUtilities::BinaryReader &reader)
2015-07-18 00:55:35 +02:00
{
m_header1 = reader.readUInt16BE();
// check whether syncword is present
2018-03-07 01:17:50 +01:00
if ((m_header1 & 0xFFF6u) != 0xFFF0u) {
2015-07-18 00:55:35 +02:00
throw InvalidDataException();
}
2015-08-13 03:40:31 +02:00
m_header2 = hasCrc() ? reader.readUInt56BE() : (reader.readUInt40BE() << 16);
// check whether frame length is ok
2018-03-07 01:17:50 +01:00
if (totalSize() < headerSize()) {
throw InvalidDataException();
}
2015-07-18 00:55:35 +02:00
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser