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;
|
|
|
|
using namespace IoUtilities;
|
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \class Media::AdtsFrame
|
|
|
|
* \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.
|
|
|
|
*/
|
|
|
|
void AdtsFrame::parseHeader(IoUtilities::BinaryReader &reader)
|
|
|
|
{
|
|
|
|
m_header1 = reader.readUInt16BE();
|
2015-07-31 01:09:41 +02:00
|
|
|
// check whether syncword is present
|
|
|
|
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);
|
2015-07-31 01:09:41 +02:00
|
|
|
// check whether frame length is ok
|
|
|
|
if(totalSize() < headerSize()) {
|
|
|
|
throw InvalidDataException();
|
|
|
|
}
|
2015-07-18 00:55:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Media
|
|
|
|
|