Tag Parser  6.4.1
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 using namespace std;
9 using namespace IoUtilities;
10 
11 namespace Media {
12 
23 void AvcConfiguration::parse(BinaryReader &reader, uint64 maxSize)
24 {
25  if(maxSize < 7) {
26  throw TruncatedDataException();
27  }
28  maxSize -= 7;
29 
30  reader.stream()->seekg(1, ios_base::cur); // always 1
31  profileIndication = reader.readByte();
32  profileCompat = reader.readByte();
33  levelIndication = reader.readByte();
34  naluSizeLength = (reader.readByte() & 0x03) + 1;
35 
36  // read SPS info entries
37  byte entryCount = reader.readByte() & 0x0f;
38  spsInfos.reserve(entryCount);
39  for(; entryCount; --entryCount) {
40  if(maxSize < 2) {
41  throw TruncatedDataException();
42  }
43  spsInfos.emplace_back();
44  try {
45  spsInfos.back().parse(reader, maxSize);
46  } catch(const TruncatedDataException &) {
47  // TODO: log parsing error
48  if(spsInfos.back().size > maxSize - 2) {
49  throw;
50  }
51  spsInfos.pop_back();
52  } catch(const Failure &) {
53  spsInfos.pop_back();
54  // TODO: log parsing error
55  }
56  maxSize -= spsInfos.back().size;
57  }
58 
59  // read PPS info entries
60  entryCount = reader.readByte();
61  ppsInfos.reserve(entryCount);
62  for(; entryCount; --entryCount) {
63  if(maxSize < 2) {
64  throw TruncatedDataException();
65  }
66  ppsInfos.emplace_back();
67  try {
68  ppsInfos.back().parse(reader, maxSize);
69  } catch(const TruncatedDataException &) {
70  // TODO: log parsing error
71  if(ppsInfos.back().size > maxSize - 2) {
72  throw;
73  }
74  ppsInfos.pop_back();
75  } catch(const Failure &) {
76  ppsInfos.pop_back();
77  // TODO: log parsing error
78  }
79  maxSize -= ppsInfos.back().size;
80  }
81 
82  // ignore remaining data
83 }
84 
85 }
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
The exception that is thrown when the data to be parsed is truncated and therefore can not be parsed ...
Definition: exceptions.h:35
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9