MCPcopy Create free account
hub / github.com/MonaSolutions/MonaServer / ParseNAL

Method ParseNAL

MonaCore/sources/MediaContainer.cpp:269–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269UInt32 MPEGTS::ParseNAL(SubstreamMap& reader, const UInt8* data, UInt32 size) {
270
271 // Frame size error
272 UInt32 available = 0;
273 UInt8 offset = (*data==0x17 && *(data+1)==0x00)? 11 : 5; // (to work with FMLE)
274 if (size<offset)
275 return available;
276
277 const UInt8* cur(data + offset);
278 const UInt8* end(data + size);
279 UInt8 twoBytesHeader = (*data==0x17 && *(data+1)==0x00) ? 1 : 0;
280
281 // Parse each NALU
282 while((end-cur) > (twoBytesHeader ? 2 : 4)) {
283
284 if (*cur++ != 0x00) {
285 WARN("H264 NALU Stream first byte not expected : ", *(cur-1))
286 Logs::Dump("MPEGTS NALU with wrong first byte", data, size);
287 break;
288 }
289
290 // Get size to read
291 UInt32 toRead = *cur++;
292 if (!twoBytesHeader) {
293 toRead <<= 16;
294 toRead += *cur++ << 8;
295 toRead += *cur++;
296 }
297
298 if (toRead > (end-cur)) {
299 WARN("H264 NALU Stream size too long : ", toRead)
300 Logs::Dump("MPEGTS too long NALU", data, size);
301 break;
302 }
303
304 reader.addSub(cur-data, toRead);
305 cur += toRead-1;
306
307 // Go to next NALU (two bytes header? need to ignore 0x01 byte)
308 if ((end-cur) > (1 + twoBytesHeader))
309 cur += 1 + twoBytesHeader;
310 }
311
312 // No NALU founded
313 available = reader.totalSize();
314 if (available == 0)
315 return available;
316
317 return available + reader.count()*3; // Add 3 bytes for each NALU start codes
318}
319
320UInt32 MPEGTS::ParseAudio(SubstreamMap& reader, const UInt8* data, UInt32 size) {
321

Callers

nothing calls this directly

Calls 2

totalSizeMethod · 0.80
countMethod · 0.45

Tested by

no test coverage detected