Tag Parser  8.2.0
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 IoUtilities;
13 
14 namespace TagParser {
15 
26 void AvcConfiguration::parse(BinaryReader &reader, uint64 maxSize, Diagnostics &diag)
27 {
28  VAR_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  byte 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(reader, maxSize > numeric_limits<uint32>::max() ? numeric_limits<uint32>::max() : static_cast<uint32>(maxSize));
50  } catch (const TruncatedDataException &) {
51  if (spsInfos.back().size > maxSize - 2) {
52  throw;
53  }
54  spsInfos.pop_back();
55  } catch (const Failure &) {
56  spsInfos.pop_back();
57  // TODO: log parsing error
58  }
59  maxSize -= spsInfos.back().size;
60  }
61 
62  // read PPS info entries
63  entryCount = reader.readByte();
64  ppsInfos.reserve(entryCount);
65  for (; entryCount; --entryCount) {
66  if (maxSize < 2) {
67  throw TruncatedDataException();
68  }
69  ppsInfos.emplace_back();
70  try {
71  ppsInfos.back().parse(reader, maxSize > numeric_limits<uint32>::max() ? numeric_limits<uint32>::max() : static_cast<uint32>(maxSize));
72  } catch (const TruncatedDataException &) {
73  if (ppsInfos.back().size > maxSize - 2) {
74  throw;
75  }
76  ppsInfos.pop_back();
77  } catch (const Failure &) {
78  ppsInfos.pop_back();
79  // TODO: log parsing error
80  }
81  maxSize -= ppsInfos.back().size;
82  }
83 
84  // ignore remaining data
85 }
86 
87 } // namespace TagParser
The exception that is thrown when the data to be parsed is truncated and therefore can not be parsed ...
Definition: exceptions.h:39
Contains utility classes helping to read and write streams.
The class inherits from std::exception and serves as base class for exceptions thrown by the elements...
Definition: exceptions.h:11
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156