Skip to content

Commit

Permalink
Merge pull request #539 from IENT/bugfix/h264ErrorLeadingPictures
Browse files Browse the repository at this point in the history
Add some logging. Add try around NAL parsing for AVFormat.
  • Loading branch information
ChristianFeldmann committed Sep 4, 2023
2 parents f1e3ae8 + 397ae2e commit 6af09b5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
6 changes: 3 additions & 3 deletions YUViewLib/src/parser/AVC/HRD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ void HRD::addAU(size_t auBits,
const auto SchedSelIdx = 0;

const auto initial_cpb_removal_delay =
lastBufferingPeriodSEI->initial_cpb_removal_delay[SchedSelIdx];
lastBufferingPeriodSEI->initial_cpb_removal_delay.at(SchedSelIdx);
const auto initial_cpb_removal_delay_offset =
lastBufferingPeriodSEI->initial_cpb_removal_delay_offset[SchedSelIdx];
lastBufferingPeriodSEI->initial_cpb_removal_delay_offset.at(SchedSelIdx);

const bool cbr_flag = vuiParam.nalHrdParameters.cbr_flag[SchedSelIdx];
const bool cbr_flag = vuiParam.nalHrdParameters.cbr_flag.at(SchedSelIdx);

// TODO: Investigate the difference between our results and the results from stream-Eye
// I noticed that the results from stream eye differ by a (seemingly random) additional
Expand Down
5 changes: 3 additions & 2 deletions YUViewLib/src/parser/AVC/ParserAnnexBAVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ ParserAnnexBAVC::parseAndAddNALUnit(int
currentSliceIntra = isRandomAccess;
currentSliceType = to_string(newSliceHeader->slice_type);

DEBUG_AVC("ParserAnnexBAVC::parseAndAddNALUnit Parsed Slice POC "
<< newSliceHeader->globalPOC);
DEBUG_AVC("ParserAnnexBAVC::parseAndAddNALUnit Parsed Slice ("
<< QString::fromStdString(NalTypeMapper.getName(nalAVC->header.nal_unit_type))
<< ") POC " << newSliceHeader->globalPOC);
parseResult.nalTypeName = "Slice(POC " + std::to_string(newSliceHeader->globalPOC) + ") ";
}
else if (nalAVC->header.nal_unit_type == NalType::CODED_SLICE_DATA_PARTITION_B)
Expand Down
27 changes: 27 additions & 0 deletions YUViewLib/src/parser/AVC/nal_unit_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#pragma once

#include "common/EnumMapper.h"
#include "parser/common/SubByteReaderLogging.h"

namespace parser::avc
Expand Down Expand Up @@ -66,6 +67,32 @@ enum class NalType
RESERVED_23
};

const EnumMapper<NalType>
NalTypeMapper({{NalType::UNSPECIFIED, "UNSPECIFIED"},
{NalType::CODED_SLICE_NON_IDR, "CODED_SLICE_NON_IDR"},
{NalType::CODED_SLICE_DATA_PARTITION_A, "CODED_SLICE_DATA_PARTITION_A"},
{NalType::CODED_SLICE_DATA_PARTITION_B, "CODED_SLICE_DATA_PARTITION_B"},
{NalType::CODED_SLICE_DATA_PARTITION_C, "CODED_SLICE_DATA_PARTITION_C"},
{NalType::CODED_SLICE_IDR, "CODED_SLICE_IDR"},
{NalType::SEI, "SEI"},
{NalType::SPS, "SPS"},
{NalType::PPS, "PPS"},
{NalType::AUD, "AUD"},
{NalType::END_OF_SEQUENCE, "END_OF_SEQUENCE"},
{NalType::END_OF_STREAM, "END_OF_STREAM"},
{NalType::FILLER, "FILLER"},
{NalType::SPS_EXT, "SPS_EXT"},
{NalType::PREFIX_NAL, "PREFIX_NAL"},
{NalType::SUBSET_SPS, "SUBSET_SPS"},
{NalType::DEPTH_PARAMETER_SET, "DEPTH_PARAMETER_SET"},
{NalType::RESERVED_17, "RESERVED_17"},
{NalType::RESERVED_18, "RESERVED_18"},
{NalType::CODED_SLICE_AUX, "CODED_SLICE_AUX"},
{NalType::CODED_SLICE_EXTENSION, "CODED_SLICE_EXTENSION"},
{NalType::CODED_SLICE_EXTENSION_DEPTH_MAP, "CODED_SLICE_EXTENSION_DEPTH_MAP"},
{NalType::RESERVED_22, "RESERVED_22"},
{NalType::RESERVED_23, "RESERVED_23"}});

class nal_unit_header
{
public:
Expand Down
19 changes: 13 additions & 6 deletions YUViewLib/src/parser/AVFormat/ParserAVFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,19 @@ ParserAVFormat::parseByteVectorAnnexBStartCodes(ByteVector & d
{
auto itNextStartCode = getNextNalStart(itStartCode);
auto nalData = ByteVector(itStartCode + sizeStartCode, itNextStartCode);
auto parseResult =
this->annexBParser->parseAndAddNALUnit(nalID++, nalData, packetBitrateEntry, {}, item);
if (parseResult.success && parseResult.bitrateEntry)
this->bitratePlotModel->addBitratePoint(this->videoStreamIndex, *parseResult.bitrateEntry);
if (parseResult.success && parseResult.nalTypeName)
naNames[*parseResult.nalTypeName]++;
try
{
auto parseResult =
this->annexBParser->parseAndAddNALUnit(nalID++, nalData, packetBitrateEntry, {}, item);
if (parseResult.success && parseResult.bitrateEntry)
this->bitratePlotModel->addBitratePoint(this->videoStreamIndex, *parseResult.bitrateEntry);
if (parseResult.success && parseResult.nalTypeName)
naNames[*parseResult.nalTypeName]++;
}
catch (const std::exception &)
{
DEBUG_AVFORMAT("ParserAVFormat::parseByteVectorAnnexBStartCodes Parsing of NAL failed");
}
itStartCode = itNextStartCode;
}
return naNames;
Expand Down
6 changes: 3 additions & 3 deletions YUViewLib/src/parser/ParserAnnexB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ bool ParserAnnexB::addFrameToList(int poc,
if (f.poc == poc)
return false;

if (pocOfFirstRandomAccessFrame == -1 && randomAccessPoint)
pocOfFirstRandomAccessFrame = poc;
if (poc >= pocOfFirstRandomAccessFrame)
if (!this->pocOfFirstRandomAccessFrame && randomAccessPoint)
this->pocOfFirstRandomAccessFrame = poc;
if (poc >= this->pocOfFirstRandomAccessFrame.value())
{
// We don't add frames which we can not decode because they are before the first RA (I) frame
AnnexBFrame newFrame;
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/parser/ParserAnnexB.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class ParserAnnexB : public Parser
std::shared_ptr<TreeItem> root,
std::optional<pairUint64> nalStartEndPos);

int pocOfFirstRandomAccessFrame{-1};
std::optional<int> pocOfFirstRandomAccessFrame{};

// Save general information about the file here
struct stream_info_type
Expand Down

0 comments on commit 6af09b5

Please sign in to comment.