Skip to content

Commit

Permalink
Fixes for logging of streams
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Jan 27, 2021
1 parent ccf1a1b commit 59d7d53
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
41 changes: 24 additions & 17 deletions YUViewLib/src/parser/AVFormat/AVFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ bool AVFormat::parseExtradata_AVC(ByteVector &extradata)
{
SubByteReaderLogging reader(
extradata, packetModel->getRootItem(), "Extradata (Raw AVC NAL units)");
reader.disableEmulationPrevention();

reader.readBits("Version", 8);

// The extradata uses the avcc format (see avc.c in libavformat)
Expand All @@ -159,7 +161,7 @@ bool AVFormat::parseExtradata_AVC(ByteVector &extradata)
SubByteReaderLoggingSubLevel spsSubLevel(reader, "SPS " + std::to_string(i));
auto sps_size = reader.readBits("sps_size", 16);
auto spsData = reader.readBytes("", sps_size, Options().withLoggingDisabled());
auto parseResult = this->annexBParser->parseAndAddNALUnit(nalID++, spsData, {}, {});
auto parseResult = this->annexBParser->parseAndAddNALUnit(nalID++, spsData, {}, {}, reader.getCurrentItemTree());
if (parseResult.success && parseResult.bitrateEntry)
this->bitratePlotModel->addBitratePoint(this->videoStreamIndex, *parseResult.bitrateEntry);
}
Expand All @@ -170,7 +172,7 @@ bool AVFormat::parseExtradata_AVC(ByteVector &extradata)
SubByteReaderLoggingSubLevel ppsSubLevel(reader, "PPS " + std::to_string(i));
auto pps_size = reader.readBits("pps_size", 16);
auto pspsData = reader.readBytes("", pps_size, Options().withLoggingDisabled());
auto parseResult = this->annexBParser->parseAndAddNALUnit(nalID++, pspsData, {}, {});
auto parseResult = this->annexBParser->parseAndAddNALUnit(nalID++, pspsData, {}, {}, reader.getCurrentItemTree());
if (parseResult.success && parseResult.bitrateEntry)
this->bitratePlotModel->addBitratePoint(this->videoStreamIndex, *parseResult.bitrateEntry);
}
Expand Down Expand Up @@ -240,7 +242,7 @@ bool AVFormat::parseExtradata_mpeg2(ByteVector &extradata)
return true;
}

std::queue<std::string>
std::map<std::string, unsigned>
AVFormat::parseByteVectorAnnexBStartCodes(ByteVector & data,
packetDataFormat_t dataFormat,
BitratePlotModel::BitrateEntry packetBitrateEntry,
Expand All @@ -256,18 +258,20 @@ AVFormat::parseByteVectorAnnexBStartCodes(ByteVector & data,
auto getNextNalStart = [&data, &dataFormat](ByteVector::iterator searchStart) {
if (dataFormat == packetDataFormat_t::packetFormatRawNAL)
{
auto itStartCode = std::search(searchStart, data.end(), startCode.begin(), startCode.end());
if (std::distance(searchStart, data.end()) <= 3)
return data.end();
auto itStartCode = std::search(searchStart + 3, data.end(), startCode.begin(), startCode.end());
if (itStartCode == data.end())
return data.end();
itStartCode += startCode.size();
return itStartCode;
}
else if (dataFormat == packetDataFormat_t::packetFormatMP4)
{
unsigned size = *searchStart++;
size += ((*searchStart++) << 8);
size += ((*searchStart++) << 16);
size += ((*searchStart++) << 24);
unsigned size = 0;
size += ((*(searchStart++)) << 24);
size += ((*(searchStart++)) << 16);
size += ((*(searchStart++)) << 8);
size += (*(searchStart++));
if (size > std::distance(searchStart, data.end()))
return data.end();
return searchStart + size;
Expand All @@ -287,18 +291,20 @@ AVFormat::parseByteVectorAnnexBStartCodes(ByteVector & data,
}
}

const auto sizeStartCode = (dataFormat == packetDataFormat_t::packetFormatRawNAL ? 3u : 4u );

auto nalID = 0u;
std::queue<std::string> naNames;
std::map<std::string, unsigned> naNames;
while (itStartCode != data.end())
{
auto itNextStartCode = getNextNalStart(itStartCode);
auto nalData = ByteVector(itStartCode, itNextStartCode);
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.push(*parseResult.nalTypeName);
naNames[*parseResult.nalTypeName]++;
itStartCode = itNextStartCode;
}
return naNames;
Expand Down Expand Up @@ -364,7 +370,7 @@ bool AVFormat::parseAVPacket(unsigned int packetID, AVPacketWrapper &packet)
if (packet.getPacketType() == PacketType::VIDEO)
{
// Colloect the types of OBus/NALs to create a good name later
std::queue<std::string> unitNames;
std::map<std::string, unsigned> unitNames;

if (this->annexBParser)
{
Expand Down Expand Up @@ -406,7 +412,7 @@ bool AVFormat::parseAVPacket(unsigned int packetID, AVPacketWrapper &packet)
posInData += nrBytesRead;

if (!obuTypeName.empty())
unitNames.push(obuTypeName);
unitNames[obuTypeName]++;
}
catch (...)
{
Expand All @@ -427,10 +433,11 @@ bool AVFormat::parseAVPacket(unsigned int packetID, AVPacketWrapper &packet)
specificDescription = " - OBUs:";
}

while (!unitNames.empty())
for (const auto entry : unitNames)
{
specificDescription += " " + unitNames.front();
unitNames.pop();
specificDescription += " " + entry.first;
if (entry.second > 1)
specificDescription += "(x" + std::to_string(entry.second) + ")";
}
}
else if (packet.getPacketType() == PacketType::SUBTITLE_DVB)
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/parser/AVFormat/AVFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AVFormat : public Base
bool parseExtradata_mpeg2(ByteVector &extradata);

// Parse all NAL units in data using the AnnexB parser
std::queue<std::string>
std::map<std::string, unsigned>
parseByteVectorAnnexBStartCodes(ByteVector & data,
packetDataFormat_t dataFormat,
BitratePlotModel::BitrateEntry packetBitrateEntry,
Expand Down
5 changes: 5 additions & 0 deletions YUViewLib/src/parser/Mpeg2/AnnexBMpeg2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ AnnexBMpeg2::parseAndAddNALUnit(int na
specificDescription = " Extension";
parseResult.nalTypeName = "Extension";
}
if (nal_mpeg2.header.nal_unit_type == NalType::SLICE)
{
specificDescription = " Slice";
parseResult.nalTypeName = "Slice";
}

const bool isStartOfNewAU =
(nal_mpeg2.header.nal_unit_type == NalType::SEQUENCE_HEADER ||
Expand Down

0 comments on commit 59d7d53

Please sign in to comment.