Tag Parser  7.1.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 "../exceptions.h"
4 #include "../mediaformat.h"
5 
6 #include <c++utilities/io/binaryreader.h>
7 
8 #include <limits>
9 
10 using namespace std;
11 using namespace IoUtilities;
12 
13 namespace TagParser {
14 
25 void AvcConfiguration::parse(BinaryReader &reader, uint64 maxSize)
26 {
27  if (maxSize < 7) {
28  throw TruncatedDataException();
29  }
30  maxSize -= 7;
31 
32  reader.stream()->seekg(1, ios_base::cur); // always 1
33  profileIndication = reader.readByte();
34  profileCompat = reader.readByte();
35  levelIndication = reader.readByte();
36  naluSizeLength = (reader.readByte() & 0x03) + 1;
37 
38  // read SPS info entries
39  byte entryCount = reader.readByte() & 0x0f;
40  spsInfos.reserve(entryCount);
41  for (; entryCount; --entryCount) {
42  if (maxSize < 2) {
43  throw TruncatedDataException();
44  }
45  spsInfos.emplace_back();
46  try {
47  spsInfos.back().parse(reader, maxSize > numeric_limits<uint32>::max() ? numeric_limits<uint32>::max() : static_cast<uint32>(maxSize));
48  } catch (const TruncatedDataException &) {
49  // TODO: log parsing error
50  if (spsInfos.back().size > maxSize - 2) {
51  throw;
52  }
53  spsInfos.pop_back();
54  } catch (const Failure &) {
55  spsInfos.pop_back();
56  // TODO: log parsing error
57  }
58  maxSize -= spsInfos.back().size;
59  }
60 
61  // read PPS info entries
62  entryCount = reader.readByte();
63  ppsInfos.reserve(entryCount);
64  for (; entryCount; --entryCount) {
65  if (maxSize < 2) {
66  throw TruncatedDataException();
67  }
68  ppsInfos.emplace_back();
69  try {
70  ppsInfos.back().parse(reader, maxSize > numeric_limits<uint32>::max() ? numeric_limits<uint32>::max() : static_cast<uint32>(maxSize));
71  } catch (const TruncatedDataException &) {
72  // TODO: log parsing error
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:32
STL namespace.
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