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

Method parseAnnexBFile

YUViewLib/src/parser/ParserAnnexB.cpp:149–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149bool ParserAnnexB::parseAnnexBFile(std::unique_ptr<FileSourceAnnexBFile> &file, QWidget *mainWindow)
150{
151 DEBUG_ANNEXB("ParserAnnexB::parseAnnexBFile");
152
153 int64_t maxPos = file->getFileSize();
154 QScopedPointer<QProgressDialog> progressDialog;
155 int curPercentValue = 0;
156 if (mainWindow)
157 {
158 // Show a modal QProgressDialog while this operation is running.
159 // If the user presses cancel, we will cancel and return false (opening the file failed).
160 // First, get a pointer to the main window to use as a parent for the modal parsing progress
161 // dialog.
162 progressDialog.reset(
163 new QProgressDialog("Parsing AnnexB bitstream...", "Cancel", 0, 100, mainWindow));
164 progressDialog->setMinimumDuration(1000); // Show after 1s
165 progressDialog->setAutoClose(false);
166 progressDialog->setAutoReset(false);
167 progressDialog->setWindowModality(Qt::WindowModal);
168 }
169
170 stream_info.file_size = file->getFileSize();
171 stream_info.parsing = true;
172 emit streamInfoUpdated();
173
174 // Just push all NAL units from the annexBFile into the annexBParser
175 int nalID = 0;
176 pairUint64 nalStartEndPosFile;
177 bool abortParsing = false;
178 QElapsedTimer signalEmitTimer;
179 signalEmitTimer.start();
180 while (!file->atEnd() && !abortParsing)
181 {
182 // Update the progress dialog
183 int64_t pos = file->pos();
184 if (stream_info.file_size > 0)
185 progressPercentValue = functions::clip((int)(pos * 100 / stream_info.file_size), 0, 100);
186
187 try
188 {
189 auto nalData = reader::SubByteReaderLogging::convertToByteVector(
190 file->getNextNALUnit(false, &nalStartEndPosFile));
191 auto parsingResult =
192 this->parseAndAddNALUnit(nalID, nalData, {}, nalStartEndPosFile, nullptr);
193 if (!parsingResult.success)
194 {
195 DEBUG_ANNEXB("ParserAnnexB::parseAndAddNALUnit Error parsing NAL " << nalID);
196 }
197 else if (parsingResult.bitrateEntry)
198 {
199 this->bitratePlotModel->addBitratePoint(0, *parsingResult.bitrateEntry);
200 }
201 }
202 catch (const std::exception &exc)
203 {
204 (void)exc;
205 // Reading a NAL unit failed at some point.
206 // This is not too bad. Just don't use this NAL unit and continue with the next one.

Callers 2

runParsingOfFileMethod · 0.95

Calls 8

clipFunction · 0.85
getFileSizeMethod · 0.80
posMethod · 0.80
getNextNALUnitMethod · 0.80
addBitratePointMethod · 0.80
atEndMethod · 0.45
parseAndAddNALUnitMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected