Tag Parser  9.1.2
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
avcconfiguration.cpp
Go to the documentation of this file.
1 #include "./avcconfiguration.h"
2 
3 #include "../diagnostics.h"
4 #include "../exceptions.h"
5 #include "../mediaformat.h"
6 
7 #include <c++utilities/io/binaryreader.h>
8 
9 #include <limits>
10 
11 using namespace std;
12 using namespace CppUtilities;
13 
14 namespace TagParser {
15 
26 void AvcConfiguration::parse(BinaryReader &reader, std::uint64_t maxSize, Diagnostics &diag)
27 {
28  CPP_UTILITIES_UNUSED(diag)
29  if (maxSize < 7) {
30  throw TruncatedDataException();
31  }
32  maxSize -= 7;
33 
34  reader.stream()->seekg(1, ios_base::cur); // always 1
35  profileIndication = reader.readByte();
36  profileCompat = reader.readByte();
37  levelIndication = reader.readByte();
38  naluSizeLength = (reader.readByte() & 0x03) + 1;
39 
40  // read SPS info entries
41  std::uint8_t entryCount = reader.readByte() & 0x0f;
42  spsInfos.reserve(entryCount);
43  for (; entryCount; --entryCount) {
44  if (maxSize < 2) {
45  throw TruncatedDataException();
46  }
47  spsInfos.emplace_back();
48  try {
49  spsInfos.back().parse(
50  reader, maxSize > numeric_limits<std::uint32_t>::max() ? numeric_limits<std::uint32_t>::max() : static_cast<std::uint32_t>(maxSize));
51  } catch (const TruncatedDataException &) {
52  if (spsInfos.back().size > maxSize - 2) {
53  throw;
54  }
55  spsInfos.pop_back();
56  } catch (const Failure &) {
57  spsInfos.pop_back();
58  // TODO: log parsing error
59  }
60  maxSize -= spsInfos.back().size;
61  }
62 
63  // read PPS info entries
64  entryCount = reader.readByte();
65  ppsInfos.reserve(entryCount);
66  for (; entryCount; --entryCount) {
67  if (maxSize < 2) {
68  throw TruncatedDataException();
69  }
70  ppsInfos.emplace_back();
71  try {
72  ppsInfos.back().parse(
73  reader, maxSize > numeric_limits<std::uint32_t>::max() ? numeric_limits<std::uint32_t>::max() : static_cast<std::uint32_t>(maxSize));
74  } catch (const TruncatedDataException &) {
75  if (ppsInfos.back().size > maxSize - 2) {
76  throw;
77  }
78  ppsInfos.pop_back();
79  } catch (const Failure &) {
80  ppsInfos.pop_back();
81  // TODO: log parsing error
82  }
83  maxSize -= ppsInfos.back().size;
84  }
85 
86  // ignore remaining data
87 }
88 
89 } // namespace TagParser
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagParser::Failure
The class inherits from std::exception and serves as base class for exceptions thrown by the elements...
Definition: exceptions.h:11
avcconfiguration.h
CppUtilities
Definition: abstractcontainer.h:15
TagParser::TruncatedDataException
The exception that is thrown when the data to be parsed is truncated and therefore can not be parsed ...
Definition: exceptions.h:39