MCPcopy Create free account
hub / github.com/IENT/YUView / checkForObuFormat

Function checkForObuFormat

YUViewLib/src/ffmpeg/AVPacketWrapper.cpp:80–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80bool checkForObuFormat(QByteArray &data)
81{
82 // TODO: We already have an implementation of this in the parser
83 // That should also be used here so we only have one place where we parse OBUs.
84 try
85 {
86 size_t posInData = 0;
87 while (posInData + 2 <= size_t(data.length()))
88 {
89 parser::reader::SubByteReaderLogging reader(
90 parser::reader::SubByteReaderLogging::convertToByteVector(data), nullptr, "", posInData);
91
92 QString bitsRead;
93 auto forbiddenBit = reader.readFlag("obu_forbidden_bit");
94 if (forbiddenBit)
95 return false;
96 auto obu_type = reader.readBits("obu_type", 4);
97 if (obu_type == 0 || (obu_type >= 9 && obu_type <= 14))
98 // RESERVED obu types should not occur (highly unlikely)
99 return false;
100 auto obu_extension_flag = reader.readFlag("obu_extension_flag");
101 auto obu_has_size_field = reader.readFlag("obu_has_size_field");
102 reader.readFlag("obu_reserved_1bit", parser::reader::Options().withCheckEqualTo(1));
103
104 if (obu_extension_flag)
105 {
106 reader.readBits("temporal_id", 3);
107 reader.readBits("spatial_id", 2);
108 reader.readBits(
109 "extension_header_reserved_3bits", 3, parser::reader::Options().withCheckEqualTo(0));
110 }
111 size_t obu_size;
112 if (obu_has_size_field)
113 {
114 obu_size = reader.readLEB128("obu_size");
115 }
116 else
117 {
118 obu_size = (size_t(data.size()) - posInData) - 1 - (obu_extension_flag ? 1 : 0);
119 }
120 posInData += obu_size + reader.nrBytesRead();
121 }
122 }
123 catch (...)
124 {
125 return false;
126 }
127 return true;
128}
129
130} // namespace
131

Callers 1

Calls 6

OptionsClass · 0.85
readFlagMethod · 0.80
nrBytesReadMethod · 0.80
readBitsMethod · 0.45
readLEB128Method · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected