MCPcopy Create free account
hub / github.com/IENT/YUView / parseAndAddNALUnit

Method parseAndAddNALUnit

YUViewLib/src/parser/Mpeg2/ParserAnnexBMpeg2.cpp:59–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57using namespace mpeg2;
58
59ParserAnnexB::ParseResult
60ParserAnnexBMpeg2::parseAndAddNALUnit(int nalID,
61 const ByteVector & data,
62 std::optional<BitratePlotModel::BitrateEntry> bitrateEntry,
63 std::optional<pairUint64> nalStartEndPosFile,
64 std::shared_ptr<TreeItem> parent)
65{
66 ParserAnnexB::ParseResult parseResult;
67
68 // Skip the NAL unit header
69 unsigned readOffset = 0;
70 if (data.at(0) == (char)0 && data.at(1) == (char)0 && data.at(2) == (char)1)
71 readOffset = 3;
72 else if (data.at(0) == (char)0 && data.at(1) == (char)0 && data.at(2) == (char)0 &&
73 data.at(3) == (char)1)
74 readOffset = 4;
75 else
76 {
77 ByteVector startCode({char(0), char(0), char(1)});
78 auto itStartCode = std::search(data.begin(), data.end(), startCode.begin(), startCode.end());
79 if (itStartCode == data.end())
80 // No start code found in the whole data. Try to start reading with a header.
81 readOffset = 0;
82 else
83 readOffset = unsigned(itStartCode - data.begin()) + 3;
84 }
85
86 // Use the given tree item. If it is not set, use the nalUnitMode (if active).
87 // We don't set data (a name) for this item yet.
88 // We want to parse the item and then set a good description.
89 std::string specificDescription;
90 std::shared_ptr<TreeItem> nalRoot;
91 if (parent)
92 nalRoot = parent->createChildItem();
93 else if (packetModel->rootItem)
94 nalRoot = packetModel->rootItem->createChildItem();
95
96 reader::SubByteReaderLogging reader(data, nalRoot, "", readOffset);
97
98 if (nalRoot)
99 ParserAnnexB::logNALSize(data, nalRoot, nalStartEndPosFile);
100
101 // Create a nal_unit and read the header
102 NalUnitMpeg2 nal_mpeg2(nalID, nalStartEndPosFile);
103 nal_mpeg2.header.parse(reader);
104
105 bool currentSliceIntra = false;
106 std::string currentSliceType;
107 if (nal_mpeg2.header.nal_unit_type == NalType::SEQUENCE_HEADER)
108 {
109 DEBUG_MPEG2("ParserAnnexBMpeg2::parseAndAddNALUnit Sequence header");
110
111 auto newSequenceHeader = std::make_shared<sequence_header>();
112 newSequenceHeader->parse(reader);
113
114 if (!this->firstSequenceHeader)
115 this->firstSequenceHeader = newSequenceHeader;
116

Callers

nothing calls this directly

Calls 11

createChildItemMethod · 0.80
isIntraPictureMethod · 0.80
getPictureTypeStringMethod · 0.80
getMeaningMethod · 0.80
setPropertiesMethod · 0.80
to_stringFunction · 0.50
atMethod · 0.45
parseMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected