Skip to content

Commit

Permalink
Merge pull request #437 from IENT/bugfix/434-BitratePlotAV1
Browse files Browse the repository at this point in the history
Fix for bitrate plot in AV1 and packet view
  • Loading branch information
ChristianFeldmann committed Nov 25, 2021
2 parents 17ab838 + d038774 commit 586bec2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
4 changes: 3 additions & 1 deletion YUViewLib/src/parser/AV1/AV1OBU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ std::pair<size_t, std::string> ParserAV1OBU::parseAndAddOBU(int
if (obu.header.obu_type == ObuType::OBU_TEMPORAL_DELIMITER)
{
decValues.SeenFrameHeader = false;
obuTypeName = "Temporal Delimiter";
}
if (obu.header.obu_type == ObuType::OBU_SEQUENCE_HEADER)
else if (obu.header.obu_type == ObuType::OBU_SEQUENCE_HEADER)
{
auto new_sequence_header = std::make_shared<sequence_header_obu>();
new_sequence_header->parse(reader);
Expand All @@ -104,6 +105,7 @@ std::pair<size_t, std::string> ParserAV1OBU::parseAndAddOBU(int
catch (const std::exception &e)
{
errorText = " ERROR " + std::string(e.what());
obuTypeName = "Error";
}

if (obuRoot)
Expand Down
32 changes: 21 additions & 11 deletions YUViewLib/src/parser/AVFormat/AVFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,9 @@ bool AVFormat::parseAVPacket(unsigned packetID, unsigned streamPacketID, AVPacke
auto dataLength = packet.getDataSize();
avpacketData.assign(dataPointer, dataPointer + dataLength);
}
bool addBitrateEntryForPacket = true;

AVRational timeBase = timeBaseAllStreams[packet.getStreamIndex()];
auto timeBase = timeBaseAllStreams[packet.getStreamIndex()];

auto formatTimestamp = [](int64_t timestamp, AVRational timebase) -> std::string {
std::ostringstream ss;
Expand Down Expand Up @@ -390,6 +391,8 @@ bool AVFormat::parseAVPacket(unsigned packetID, unsigned streamPacketID, AVPacke
specificDescription = " - "; // In mpeg2 there is no concept of NAL units
else
specificDescription = " - NALs:";

addBitrateEntryForPacket = false;
}
else if (this->obuParser)
{
Expand All @@ -407,14 +410,14 @@ bool AVFormat::parseAVPacket(unsigned packetID, unsigned streamPacketID, AVPacke
DEBUG_AVFORMAT(
"AVFormat::parseAVPacket parsed OBU %d header %d bytes", obuID, nrBytesRead);

if (!obuTypeName.empty())
unitNames[obuTypeName]++;

constexpr auto minOBUSize = 3u;
auto remaining = std::distance(posInData, avpacketData.end());
if (remaining < 0 || nrBytesRead + minOBUSize >= size_t(std::abs(remaining)))
break;
posInData += nrBytesRead;

if (!obuTypeName.empty())
unitNames[obuTypeName]++;
}
catch (...)
{
Expand Down Expand Up @@ -509,13 +512,17 @@ bool AVFormat::parseAVPacket(unsigned packetID, unsigned streamPacketID, AVPacke
DEBUG_AVFORMAT("AVFormat::parseAVPacket Exception occured while parsing generic packet data: "
<< e.what());
}
}

if (addBitrateEntryForPacket)
{
BitratePlotModel::BitrateEntry entry;
entry.pts = packet.getPTS();
entry.dts = packet.getDTS();
entry.bitrate = packet.getDataSize();
entry.keyframe = packet.getFlagKeyframe();
entry.duration = packet.getDuration();
entry.pts = packet.getPTS();
entry.dts = packet.getDTS();
entry.bitrate = packet.getDataSize();
entry.keyframe = packet.getFlagKeyframe();
entry.frameType = entry.keyframe ? "Keyframe" : "Frame";
entry.duration = packet.getDuration();
if (entry.duration == 0)
{
// Unknown. We have to guess.
Expand All @@ -524,8 +531,11 @@ bool AVFormat::parseAVPacket(unsigned packetID, unsigned streamPacketID, AVPacke
this->videoStreamIndex < this->timeBaseAllStreams.size())
{
auto videoTimeBase = this->timeBaseAllStreams[this->videoStreamIndex];
auto duration = 1.0 / this->framerate * videoTimeBase.den / videoTimeBase.num;
entry.duration = int(std::round(duration));
if (videoTimeBase.num > 0)
{
auto duration = 1.0 / this->framerate * videoTimeBase.den / videoTimeBase.num;
entry.duration = int(std::round(duration));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/parser/common/BitratePlotModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ BitratePlotModel::getPointInfo(unsigned streamIndex, unsigned plotIndex, unsigne
unsigned(this->dataPerStream[streamIndex].size()) <= pointIndex)
return {};

auto & entry = this->dataPerStream[streamIndex][pointIndex];
auto entry = this->dataPerStream[streamIndex][pointIndex];
const auto isAveragePlot = (plotIndex == 1);

if (isAveragePlot)
Expand Down

0 comments on commit 586bec2

Please sign in to comment.