Skip to content

Commit

Permalink
Merge pull request #544 from IENT/feature/improveSEIMessageAnalysisAVC
Browse files Browse the repository at this point in the history
Feature/improve sei message analysis avc
  • Loading branch information
ChristianFeldmann committed Oct 17, 2023
2 parents 3805e69 + 60e1e6d commit b56c923
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 57 deletions.
3 changes: 2 additions & 1 deletion YUViewLib/src/filesource/FileSourceFFmpegFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ bool FileSourceFFmpegFile::goToNextPacket(bool videoPacketsOnly)
(int)this->currentPacket.getDTS(),
this->currentPacket.getFlagKeyframe() ? " - keyframe" : "");

if (this->packetDataFormat == PacketDataFormat::Unknown)
if (this->currentPacket.getPacketType() == PacketType::VIDEO &&
this->packetDataFormat == PacketDataFormat::Unknown)
// This is the first video package that we find and we don't know what the format of the packet
// data is. Guess the format from the data in the first package This format should not change
// from packet to packet
Expand Down
113 changes: 61 additions & 52 deletions YUViewLib/src/parser/AVC/ParserAnnexBAVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,73 +472,82 @@ ParserAnnexBAVC::parseAndAddNALUnit(int
curSlicePoc = currentSliceData->poc;
if (this->curFrameData && this->auDelimiterDetector.isStartOfNewAU(nalAVC, curSlicePoc))
{
// Save the info of the last frame
if (!this->addFrameToList(*this->curFrameData->poc,
this->curFrameData->fileStartEndPos,
this->curFrameData->isRandomAccess))
if (!this->curFrameData->poc)
{
throw std::logic_error("Error - POC " + std::to_string(*this->curFrameData->poc) +
" already in the POC list");
DEBUG_AVC("ParserAnnexBAVC::parseAndAddNALUnit current frame POC not set");
}
if (this->curFrameData->fileStartEndPos)
DEBUG_AVC("ParserAnnexBAVC::parseAndAddNALUnit Adding start/end "
<< this->curFrameData->fileStartEndPos->first << "/"
<< this->curFrameData->fileStartEndPos->second << " - POC "
<< *this->curFrameData->poc << (this->curFrameData->isRandomAccess ? " - ra" : ""));
else
DEBUG_AVC("ParserAnnexBAVC::parseAndAddNALUnit Adding start/end NA/NA - POC "
<< *this->curFrameData->poc << (this->curFrameData->isRandomAccess ? " - ra" : ""));

if (this->sizeCurrentAU > 0)
{
DEBUG_AVC("ParserAnnexBAVC::parseAndAddNALUnit Start of new AU. Adding bitrate "
<< this->sizeCurrentAU);

BitratePlotModel::BitrateEntry entry;
if (bitrateEntry)
// Save the info of the last frame
if (!this->addFrameToList(*this->curFrameData->poc,
this->curFrameData->fileStartEndPos,
this->curFrameData->isRandomAccess))
{
entry.pts = bitrateEntry->pts;
entry.dts = bitrateEntry->dts;
entry.duration = bitrateEntry->duration;
throw std::logic_error("Error - POC " + std::to_string(*this->curFrameData->poc) +
" already in the POC list");
}
if (this->curFrameData->fileStartEndPos)
DEBUG_AVC("ParserAnnexBAVC::parseAndAddNALUnit Adding start/end "
<< this->curFrameData->fileStartEndPos->first << "/"
<< this->curFrameData->fileStartEndPos->second << " - POC "
<< *this->curFrameData->poc
<< (this->curFrameData->isRandomAccess ? " - ra" : ""));
else
{
entry.pts = this->lastFramePOC;
entry.dts = this->counterAU;
entry.duration = 1;
this->lastFramePOC = *this->curFrameData->poc;
}
entry.bitrate = this->sizeCurrentAU;
entry.keyframe = this->currentAUAllSlicesIntra;
entry.frameType =
QString::fromStdString(convertSliceCountsToString(this->currentAUSliceTypes));
parseResult.bitrateEntry = entry;
DEBUG_AVC("ParserAnnexBAVC::parseAndAddNALUnit Adding start/end NA/NA - POC "
<< *this->curFrameData->poc
<< (this->curFrameData->isRandomAccess ? " - ra" : ""));

if (this->lastBufferingPeriodSEI && this->lastPicTimingSEI)
if (this->sizeCurrentAU > 0)
{
try
DEBUG_AVC("ParserAnnexBAVC::parseAndAddNALUnit Start of new AU. Adding bitrate "
<< this->sizeCurrentAU);

BitratePlotModel::BitrateEntry entry;
if (bitrateEntry)
{
if (this->activeParameterSets.spsMap.size() > 0)
this->hrd.addAU(this->sizeCurrentAU * 8,
*this->curFrameData->poc,
this->activeParameterSets.spsMap[0],
this->lastBufferingPeriodSEI,
this->lastPicTimingSEI,
this->getHRDPlotModel());
entry.pts = bitrateEntry->pts;
entry.dts = bitrateEntry->dts;
entry.duration = bitrateEntry->duration;
}
catch (const std::exception &e)
else
{
entry.pts = this->lastFramePOC;
entry.dts = this->counterAU;
entry.duration = 1;
this->lastFramePOC = *this->curFrameData->poc;
}
entry.bitrate = this->sizeCurrentAU;
entry.keyframe = this->currentAUAllSlicesIntra;
entry.frameType =
QString::fromStdString(convertSliceCountsToString(this->currentAUSliceTypes));
parseResult.bitrateEntry = entry;

if (this->lastBufferingPeriodSEI && this->lastPicTimingSEI)
{
specificDescription += " HRD Error: " + std::string(e.what());
try
{
if (this->activeParameterSets.spsMap.size() > 0)
this->hrd.addAU(this->sizeCurrentAU * 8,
*this->curFrameData->poc,
this->activeParameterSets.spsMap[0],
this->lastBufferingPeriodSEI,
this->lastPicTimingSEI,
this->getHRDPlotModel());
}
catch (const std::exception &e)
{
specificDescription += " HRD Error: " + std::string(e.what());
}
}
}
this->sizeCurrentAU = 0;
this->counterAU++;
this->currentAUAllSlicesIntra = true;
this->currentAUSliceTypes.clear();
this->currentAUAssociatedSPS.reset();
this->currentAUPartitionASPS.reset();
this->curFrameData.reset();
}
this->sizeCurrentAU = 0;
this->counterAU++;
this->currentAUAllSlicesIntra = true;
this->currentAUSliceTypes.clear();
this->currentAUAssociatedSPS.reset();
this->currentAUPartitionASPS.reset();
this->curFrameData.reset();
}
curFrameData =
getFrameDataWithUpdatedPosition(curFrameData, nalStartEndPosFile, currentSliceData);
Expand Down
6 changes: 6 additions & 0 deletions YUViewLib/src/parser/AVC/SEI/sei_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ SEIParsingResult sei_message::parse(reader::SubByteReaderLogging & read
// When reading the data above, emulation prevention was alread removed.
this->payloadReader.disableEmulationPrevention();

if (payloadNameMap.count(this->payloadType) > 0)
{
const auto payloadTypeName = payloadNameMap.at(this->payloadType);
subLevel.updateSubLevelName("sei_message() - " + payloadTypeName);
}

return this->parsePayloadData(false, spsMap, associatedSPS);
}

Expand Down
4 changes: 2 additions & 2 deletions YUViewLib/src/parser/common/SubByteReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool SubByteReader::more_rbsp_data() const
posBytes++;
posBits = 0;
}
else
else if (posBits != 0)
{
// Check the remainder of the current byte
unsigned char c = this->byteVector[posBytes];
Expand All @@ -300,7 +300,7 @@ bool SubByteReader::more_rbsp_data() const
return true;
else if (!terminatingBitFound && (c == 128))
terminatingBitFound = true;
else
else if (c != 0)
return true;
posBytes++;
}
Expand Down
16 changes: 15 additions & 1 deletion YUViewLib/src/parser/common/SubByteReaderLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ SubByteReaderLogging::SubByteReaderLogging(const ByteVector & inArr,
}
}

void SubByteReaderLogging::addLogSubLevel(const std::string name)
void SubByteReaderLogging::addLogSubLevel(const std::string &name)
{
if (!this->currentTreeLevel)
return;
Expand All @@ -169,6 +169,14 @@ void SubByteReaderLogging::addLogSubLevel(const std::string name)
this->currentTreeLevel = this->itemHierarchy.top()->createChildItem(name);
}

void SubByteReaderLogging::updateCurrentLevelName(const std::string &name)
{
if (!this->currentTreeLevel)
return;
assert(!name.empty());
this->currentTreeLevel->setName(name);
}

void SubByteReaderLogging::removeLogSubLevel()
{
if (this->itemHierarchy.empty())
Expand Down Expand Up @@ -351,4 +359,10 @@ SubByteReaderLoggingSubLevel::~SubByteReaderLoggingSubLevel()
this->r->removeLogSubLevel();
}

void SubByteReaderLoggingSubLevel::updateSubLevelName(const std::string &name)
{
if (this->r != nullptr)
this->r->updateCurrentLevelName(name);
}

} // namespace parser::reader
5 changes: 4 additions & 1 deletion YUViewLib/src/parser/common/SubByteReaderLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class SubByteReaderLogging : public SubByteReader

private:
friend class SubByteReaderLoggingSubLevel;
void addLogSubLevel(std::string name);
void addLogSubLevel(const std::string &name);
void updateCurrentLevelName(const std::string &name);
void removeLogSubLevel();

void logExceptionAndThrowError [[noreturn]] (const std::exception &ex, const std::string &when);
Expand All @@ -112,6 +113,8 @@ class SubByteReaderLoggingSubLevel
SubByteReaderLoggingSubLevel(SubByteReaderLogging &reader, std::string name);
~SubByteReaderLoggingSubLevel();

void updateSubLevelName(const std::string &name);

private:
SubByteReaderLogging *r{};
};
Expand Down
2 changes: 2 additions & 0 deletions YUViewLib/src/parser/common/TreeItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class TreeItem : public std::enable_shared_from_this<TreeItem>
return ss.str();
}

void setName(const std::string &name) { this->name = name; }

int getStreamIndex() const
{
if (this->streamIndex >= 0)
Expand Down

0 comments on commit b56c923

Please sign in to comment.