tagparser/avc/avcconfiguration.cpp

86 lines
2.4 KiB
C++
Raw Normal View History

2015-09-06 19:57:33 +02:00
#include "./avcconfiguration.h"
2015-04-22 19:22:01 +02:00
2016-02-17 20:19:05 +01:00
#include "../exceptions.h"
#include "../mediaformat.h"
#include <c++utilities/io/binaryreader.h>
using namespace std;
using namespace IoUtilities;
namespace TagParser {
2015-04-22 19:22:01 +02:00
2016-08-04 00:16:19 +02:00
/*!
* \class AvcConfiguration
* \brief The AvcConfiguration struct provides a parser for AVC configuration.
*/
/*!
* \brief Parses the AVC configuration using the specified \a reader.
* \throws Throws TruncatedDataException() when the config size exceeds the specified \a maxSize.
* \remarks Logging/reporting parsing errors is not implemented yet.
*/
2016-02-17 20:19:05 +01:00
void AvcConfiguration::parse(BinaryReader &reader, uint64 maxSize)
{
2018-03-07 01:17:50 +01:00
if (maxSize < 7) {
2016-02-17 20:19:05 +01:00
throw TruncatedDataException();
}
maxSize -= 7;
reader.stream()->seekg(1, ios_base::cur); // always 1
profileIndication = reader.readByte();
profileCompat = reader.readByte();
levelIndication = reader.readByte();
naluSizeLength = (reader.readByte() & 0x03) + 1;
// read SPS info entries
byte entryCount = reader.readByte() & 0x0f;
spsInfos.reserve(entryCount);
2018-03-07 01:17:50 +01:00
for (; entryCount; --entryCount) {
if (maxSize < 2) {
2016-02-17 20:19:05 +01:00
throw TruncatedDataException();
}
spsInfos.emplace_back();
try {
spsInfos.back().parse(reader, maxSize);
2018-03-07 01:17:50 +01:00
} catch (const TruncatedDataException &) {
2016-02-17 20:19:05 +01:00
// TODO: log parsing error
2018-03-07 01:17:50 +01:00
if (spsInfos.back().size > maxSize - 2) {
2016-02-17 20:19:05 +01:00
throw;
}
spsInfos.pop_back();
2018-03-07 01:17:50 +01:00
} catch (const Failure &) {
2016-02-17 20:19:05 +01:00
spsInfos.pop_back();
// TODO: log parsing error
}
maxSize -= spsInfos.back().size;
}
// read PPS info entries
entryCount = reader.readByte();
ppsInfos.reserve(entryCount);
2018-03-07 01:17:50 +01:00
for (; entryCount; --entryCount) {
if (maxSize < 2) {
2016-02-17 20:19:05 +01:00
throw TruncatedDataException();
}
ppsInfos.emplace_back();
try {
ppsInfos.back().parse(reader, maxSize);
2018-03-07 01:17:50 +01:00
} catch (const TruncatedDataException &) {
2016-02-17 20:19:05 +01:00
// TODO: log parsing error
2018-03-07 01:17:50 +01:00
if (ppsInfos.back().size > maxSize - 2) {
2016-02-17 20:19:05 +01:00
throw;
}
ppsInfos.pop_back();
2018-03-07 01:17:50 +01:00
} catch (const Failure &) {
2016-02-17 20:19:05 +01:00
ppsInfos.pop_back();
// TODO: log parsing error
}
maxSize -= ppsInfos.back().size;
}
// ignore remaining data
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser