Skip to content

Commit

Permalink
Small bugfix for reading hevcc mp4 extradata
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Jul 3, 2020
1 parent fd7066d commit caee16e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
16 changes: 8 additions & 8 deletions YUViewLib/src/parser/common/SubByteReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,24 @@ uint64_t SubByteReader::readBits64(int nrBits, QString &bitsRead)

QByteArray SubByteReader::readBytes(int nrBytes)
{
if (skipEmulationPrevention)
throw std::logic_error("Reading bytes with emulation prevention active is not supported.");
if (posInBuffer_bits != 0 && posInBuffer_bits != 8)
throw std::logic_error("When reading bytes from the bitstream, it should be byte alligned.");

if (posInBuffer_bits == 8)
if (!gotoNextByte())
if (!this->gotoNextByte())
// We are at the end of the buffer but we need to read more. Error.
throw std::logic_error("Error while reading annexB file. Trying to read over buffer boundary.");

QByteArray retArray;
for (int i = 0; i < nrBytes; i++)
{
if (posInBuffer_bytes >= (unsigned int)byteArray.size())
throw std::logic_error("Error while reading annexB file. Trying to read over buffer boundary.");

retArray.append(byteArray[posInBuffer_bytes]);
posInBuffer_bytes++;

if (!this->gotoNextByte())
{
if (i < nrBytes - 1)
throw std::logic_error("Error while reading annexB file. Trying to read over buffer boundary.");
}
}

return retArray;
Expand Down Expand Up @@ -322,7 +322,7 @@ bool SubByteReader::gotoNextByte()

if (posInBuffer_bytes >= (unsigned int)byteArray.size())
// The next byte is outside of the current buffer. Error.
return false;
return false;

if (skipEmulationPrevention)
{
Expand Down
28 changes: 21 additions & 7 deletions YUViewLib/src/parser/parserAVFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ bool parserAVFormat::runParsingOfFile(QString compressedFilePath)
{
// Open the file but don't parse it yet.
QScopedPointer<fileSourceFFmpegFile> ffmpegFile(new fileSourceFFmpegFile());
if (!ffmpegFile->openFile(compressedFilePath, nullptr, nullptr, false))
if (!ffmpegFile->openFile(compressedFilePath, nullptr, nullptr, false))
{
emit backgroundParsingDone("Error opening the ffmpeg file.");
return false;
Expand Down Expand Up @@ -650,12 +650,26 @@ bool parserAVFormat::runParsingOfFile(QString compressedFilePath)
// ffmpegFile->seekFileToBeginning();

// First get the extradata and push it to the parser
QByteArray extradata = ffmpegFile->getExtradata();
parseExtradata(extradata);

// Parse the metadata
QStringPairList metadata = ffmpegFile->getMetadata();
parseMetadata(metadata);
try
{
QByteArray extradata = ffmpegFile->getExtradata();
parseExtradata(extradata);
}
catch (...)
{
emit backgroundParsingDone("Error parsing Extradata from container");
return false;
}
try
{
QStringPairList metadata = ffmpegFile->getMetadata();
parseMetadata(metadata);
}
catch (...)
{
emit backgroundParsingDone("Error parsing Metadata from container");
return false;
}

// After opening the file, we can get information on it
streamInfoAllStreams = ffmpegFile->getFileInfoForAllStreams();
Expand Down
1 change: 0 additions & 1 deletion YUViewLib/src/ui/bitstreamAnalysisWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ void BitstreamAnalysisWidget::restartParsingOfCurrentItem()
this->ui.streamInfoTreeWidget->clear();
this->ui.dataTreeView->setModel(nullptr);
this->ui.plotViewWidget->setModel(nullptr);
this->parser.reset();
return;
}

Expand Down

0 comments on commit caee16e

Please sign in to comment.