2015-09-06 19:57:33 +02:00
|
|
|
#include "./avcconfiguration.h"
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-08-23 23:19:44 +02:00
|
|
|
#include "../diagnostics.h"
|
2016-02-17 20:19:05 +01:00
|
|
|
#include "../exceptions.h"
|
|
|
|
#include "../mediaformat.h"
|
|
|
|
|
|
|
|
#include <c++utilities/io/binaryreader.h>
|
|
|
|
|
2018-06-02 22:56:08 +02:00
|
|
|
#include <limits>
|
|
|
|
|
2016-02-17 20:19:05 +01:00
|
|
|
using namespace std;
|
|
|
|
using namespace IoUtilities;
|
|
|
|
|
2018-03-06 23:09:15 +01:00
|
|
|
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.
|
2018-08-23 23:19:44 +02:00
|
|
|
* \todo Implement logging/reporting parsing errors.
|
2016-08-04 00:16:19 +02:00
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
void AvcConfiguration::parse(BinaryReader &reader, std::uint64_t maxSize, Diagnostics &diag)
|
2016-02-17 20:19:05 +01:00
|
|
|
{
|
2018-08-23 23:19:44 +02:00
|
|
|
VAR_UNUSED(diag)
|
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
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint8_t entryCount = reader.readByte() & 0x0f;
|
2016-02-17 20:19:05 +01:00
|
|
|
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 {
|
2019-03-13 19:06:42 +01:00
|
|
|
spsInfos.back().parse(
|
|
|
|
reader, maxSize > numeric_limits<std::uint32_t>::max() ? numeric_limits<std::uint32_t>::max() : static_cast<std::uint32_t>(maxSize));
|
2018-03-07 01:17:50 +01:00
|
|
|
} catch (const TruncatedDataException &) {
|
|
|
|
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 {
|
2019-03-13 19:06:42 +01:00
|
|
|
ppsInfos.back().parse(
|
|
|
|
reader, maxSize > numeric_limits<std::uint32_t>::max() ? numeric_limits<std::uint32_t>::max() : static_cast<std::uint32_t>(maxSize));
|
2018-03-07 01:17:50 +01:00
|
|
|
} catch (const TruncatedDataException &) {
|
|
|
|
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
|