Skip to content

Commit

Permalink
Merge pull request #287 from IENT/feature/HRD-fixes
Browse files Browse the repository at this point in the history
Feature/hrd fixes
  • Loading branch information
ChristianFeldmann authored Oct 27, 2020
2 parents 8a6ff0a + 620766b commit 81b020f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
52 changes: 39 additions & 13 deletions YUViewLib/src/parser/parserAnnexBAVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ parserAnnexB::ParseResult parserAnnexBAVC::parseAndAddNALUnit(int nalID, QByteAr
bool parsingSuccess = true;
bool currentSliceIntra = false;
QString currentSliceType;
QSharedPointer<buffering_period_sei> currentBufferingPeriodSEI;
QSharedPointer<pic_timing_sei> currentPicTimingSEI;
if (nal_avc.nal_unit_type == SPS)
{
// A sequence parameter set
Expand Down Expand Up @@ -347,15 +345,21 @@ parserAnnexB::ParseResult parserAnnexBAVC::parseAndAddNALUnit(int nalID, QByteAr
auto new_buffering_period_sei = QSharedPointer<buffering_period_sei>(new buffering_period_sei(new_sei));
result = new_buffering_period_sei->parse_buffering_period_sei(sub_sei_data, this->active_SPS_list, message_tree);
reparse = new_buffering_period_sei;
currentBufferingPeriodSEI = new_buffering_period_sei;
this->hrd.isFirstAUInBufferingPeriod = true;
if (this->lastBufferingPeriodSEI.isNull())
this->lastBufferingPeriodSEI = new_buffering_period_sei;
else
this->newBufferingPeriodSEI = new_buffering_period_sei;
this->nextAUIsFirstAUInBufferingPeriod = true;
}
else if (new_sei->payloadType == 1)
{
auto new_pic_timing_sei = QSharedPointer<pic_timing_sei>(new pic_timing_sei(new_sei));
result = new_pic_timing_sei->parse_pic_timing_sei(sub_sei_data, this->active_SPS_list, CpbDpbDelaysPresentFlag, message_tree);
reparse = new_pic_timing_sei;
currentPicTimingSEI = new_pic_timing_sei;
if (this->lastPicTimingSEI.isNull())
this->lastPicTimingSEI = new_pic_timing_sei;
else
this->newPicTimingSEI = new_pic_timing_sei;
}
else if (new_sei->payloadType == 4)
{
Expand Down Expand Up @@ -428,6 +432,11 @@ parserAnnexB::ParseResult parserAnnexBAVC::parseAndAddNALUnit(int nalID, QByteAr
parseResult.bitrateEntry = entry;

this->hrd.addAU(this->sizeCurrentAU * 8, curFramePOC, this->active_SPS_list[0], this->lastBufferingPeriodSEI, this->lastPicTimingSEI, this->getHRDPlotModel());

if (this->newBufferingPeriodSEI)
this->lastBufferingPeriodSEI = this->newBufferingPeriodSEI;
if (this->newPicTimingSEI)
this->lastPicTimingSEI = this->newPicTimingSEI;
}
this->sizeCurrentAU = 0;
this->counterAU++;
Expand All @@ -438,18 +447,20 @@ parserAnnexB::ParseResult parserAnnexBAVC::parseAndAddNALUnit(int nalID, QByteAr
this->lastFramePOC = curFramePOC;
this->sizeCurrentAU += data.size();

if (this->nextAUIsFirstAUInBufferingPeriod)
{
if (this->counterAU > 0)
this->hrd.isFirstAUInBufferingPeriod = true;
this->nextAUIsFirstAUInBufferingPeriod = false;
}

if (nal_avc.isSlice())
{
if (!currentSliceIntra)
this->currentAUAllSlicesIntra = false;
this->currentAUSliceTypes[currentSliceType]++;
}

if (currentBufferingPeriodSEI)
this->lastBufferingPeriodSEI = currentBufferingPeriodSEI;
if (currentPicTimingSEI)
this->lastPicTimingSEI = currentPicTimingSEI;

if (nalRoot)
{
// Set a useful name of the TreeItem (the root for this NAL)
Expand Down Expand Up @@ -2256,7 +2267,7 @@ void parserAnnexBAVC::HRD::addAU(unsigned auBits, unsigned poc, QSharedPointer<s
// first AU.
// if (this->au_n == 0)
// {
// auBits += 47 * 8;
// auBits += 49 * 8;
// }

/* Some notation:
Expand Down Expand Up @@ -2370,7 +2381,8 @@ void parserAnnexBAVC::HRD::addAU(unsigned auBits, unsigned poc, QSharedPointer<s
this->addConstantBufferLine(poc, lastFrameTime, (*it).t_r, plotModel);
this->removeFromBufferAndCheck((*it), poc, (*it).t_r, plotModel);
it = this->framesToRemove.erase(it);
lastFrameTime = (*it).t_r;
if (it != this->framesToRemove.end())
lastFrameTime = (*it).t_r;
}
else
break;
Expand Down Expand Up @@ -2409,7 +2421,7 @@ void parserAnnexBAVC::HRD::addAU(unsigned auBits, unsigned poc, QSharedPointer<s
// While bits are coming into the buffer, frames are removed as well.
// For each period, we add the bits (and check the buffer state) and remove the
// frames from the buffer (and check the buffer state).
auto t_ai_sub = t_ai;
auto t_ai_sub = t_ai;
unsigned int buffer_add_sum = 0;
long double buffer_add_remainder = 0;
for (auto frame : relevant_frames)
Expand Down Expand Up @@ -2490,10 +2502,24 @@ QList<parserAnnexBAVC::HRD::HRDFrameToRemove> parserAnnexBAVC::HRD::popRemoveFra
{
QList<parserAnnexBAVC::HRD::HRDFrameToRemove> l;
auto it = this->framesToRemove.begin();
double t_r_previous = 0;
while (it != this->framesToRemove.end())
{
if ((*it).t_r < from)
{
DEBUG_AVC("Warning: Frame " << (*it).poc << " was not removed at the time (" << double((*it).t_r) << ") it should have been. Dropping it now.");
it = this->framesToRemove.erase(it);
continue;
}
if ((*it).t_r < t_r_previous)
{
DEBUG_AVC("Warning: Frame " << (*it).poc << " has a removal time (" << double((*it).t_r) << ") before the previous frame (" << t_r_previous << "). Dropping it now.");
it = this->framesToRemove.erase(it);
continue;
}
if ((*it).t_r >= from && (*it).t_r < to)
{
t_r_previous = (*it).t_r;
l.push_back((*it));
it = this->framesToRemove.erase(it);
continue;
Expand Down
4 changes: 4 additions & 0 deletions YUViewLib/src/parser/parserAnnexBAVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,12 @@ class parserAnnexBAVC : public parserAnnexB
// parameter sets. Here we keep a list of seis that need to be parsed after the parameter sets were recieved.
QList<QSharedPointer<sei>> reparse_sei;

// When new SEIs come in and they don't initialize the HRD, they are not accessed until the current AU is processed by the HRD.
QSharedPointer<buffering_period_sei> lastBufferingPeriodSEI;
QSharedPointer<pic_timing_sei> lastPicTimingSEI;
QSharedPointer<buffering_period_sei> newBufferingPeriodSEI;
QSharedPointer<pic_timing_sei> newPicTimingSEI;
bool nextAUIsFirstAUInBufferingPeriod {false};

// In an SEI, the number of bytes indicated do not consider the emulation prevention. This function
// can determine the real number of bytes that we need to read from the input considering the emulation prevention
Expand Down
2 changes: 2 additions & 0 deletions YUViewLib/src/ui/views/plotViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,8 @@ void PlotViewWidget::drawPlot(QPainter &painter) const
{
unsigned intervalLeft = 0;
unsigned intervalRight = nrpoints;
if (nrpoints == 0)
return intervalLeft;
while (true)
{
unsigned pointToCheck = intervalLeft + (intervalRight - intervalLeft) / 2;
Expand Down

0 comments on commit 81b020f

Please sign in to comment.