From 59d7d53bf97008c0b551cfede98da087fd350986 Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Wed, 27 Jan 2021 23:10:30 +0100 Subject: [PATCH] Fixes for logging of streams --- YUViewLib/src/parser/AVFormat/AVFormat.cpp | 41 +++++++++++++--------- YUViewLib/src/parser/AVFormat/AVFormat.h | 2 +- YUViewLib/src/parser/Mpeg2/AnnexBMpeg2.cpp | 5 +++ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/YUViewLib/src/parser/AVFormat/AVFormat.cpp b/YUViewLib/src/parser/AVFormat/AVFormat.cpp index 0d69874d9..8f64dcca7 100644 --- a/YUViewLib/src/parser/AVFormat/AVFormat.cpp +++ b/YUViewLib/src/parser/AVFormat/AVFormat.cpp @@ -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) @@ -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); } @@ -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); } @@ -240,7 +242,7 @@ bool AVFormat::parseExtradata_mpeg2(ByteVector &extradata) return true; } -std::queue +std::map AVFormat::parseByteVectorAnnexBStartCodes(ByteVector & data, packetDataFormat_t dataFormat, BitratePlotModel::BitrateEntry packetBitrateEntry, @@ -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; @@ -287,18 +291,20 @@ AVFormat::parseByteVectorAnnexBStartCodes(ByteVector & data, } } + const auto sizeStartCode = (dataFormat == packetDataFormat_t::packetFormatRawNAL ? 3u : 4u ); + auto nalID = 0u; - std::queue naNames; + std::map 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; @@ -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 unitNames; + std::map unitNames; if (this->annexBParser) { @@ -406,7 +412,7 @@ bool AVFormat::parseAVPacket(unsigned int packetID, AVPacketWrapper &packet) posInData += nrBytesRead; if (!obuTypeName.empty()) - unitNames.push(obuTypeName); + unitNames[obuTypeName]++; } catch (...) { @@ -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) diff --git a/YUViewLib/src/parser/AVFormat/AVFormat.h b/YUViewLib/src/parser/AVFormat/AVFormat.h index 72d62e244..ec04c7f23 100644 --- a/YUViewLib/src/parser/AVFormat/AVFormat.h +++ b/YUViewLib/src/parser/AVFormat/AVFormat.h @@ -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::map parseByteVectorAnnexBStartCodes(ByteVector & data, packetDataFormat_t dataFormat, BitratePlotModel::BitrateEntry packetBitrateEntry, diff --git a/YUViewLib/src/parser/Mpeg2/AnnexBMpeg2.cpp b/YUViewLib/src/parser/Mpeg2/AnnexBMpeg2.cpp index 63c6b071a..886e529e7 100644 --- a/YUViewLib/src/parser/Mpeg2/AnnexBMpeg2.cpp +++ b/YUViewLib/src/parser/Mpeg2/AnnexBMpeg2.cpp @@ -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 ||