fix for packet header split over 2 PES packets

This commit is contained in:
Rohit Singh 2024-04-26 10:38:32 +02:00
parent 3d974793f9
commit c34c3db87f

View file

@ -77,6 +77,7 @@ public final class MpeghReader implements ElementaryStreamReader {
private final ParsableBitArray headerScratchBits; private final ParsableBitArray headerScratchBits;
private final ParsableByteArray dataScratchBytes; private final ParsableByteArray dataScratchBytes;
private boolean headerDataFinished;
private int payloadBytesRead; private int payloadBytesRead;
private int frameBytes; private int frameBytes;
@ -99,6 +100,7 @@ public final class MpeghReader implements ElementaryStreamReader {
standardFrameLength = C.LENGTH_UNSET; standardFrameLength = C.LENGTH_UNSET;
mainStreamLabel = C.INDEX_UNSET; mainStreamLabel = C.INDEX_UNSET;
rapPending = true; rapPending = true;
headerDataFinished = true;
timeUs = C.TIME_UNSET; timeUs = C.TIME_UNSET;
timeUsPending = C.TIME_UNSET; timeUsPending = C.TIME_UNSET;
} }
@ -116,6 +118,7 @@ public final class MpeghReader implements ElementaryStreamReader {
mainStreamLabel = C.INDEX_UNSET; mainStreamLabel = C.INDEX_UNSET;
configFound = false; configFound = false;
dataPending = false; dataPending = false;
headerDataFinished = true;
rapPending = true; rapPending = true;
timeUs = C.TIME_UNSET; timeUs = C.TIME_UNSET;
timeUsPending = C.TIME_UNSET; timeUsPending = C.TIME_UNSET;
@ -134,7 +137,7 @@ public final class MpeghReader implements ElementaryStreamReader {
this.flags = flags; this.flags = flags;
// check if data is pending (an MPEG-H frame could not be completed) // check if data is pending (an MPEG-H frame could not be completed)
if (!rapPending && frameBytes != 0) { if (!rapPending && (frameBytes != 0 || !headerDataFinished)) {
dataPending = true; dataPending = true;
} }
@ -172,11 +175,19 @@ public final class MpeghReader implements ElementaryStreamReader {
// Prepare dataScratchBytes to read new MHAS packet // Prepare dataScratchBytes to read new MHAS packet
dataScratchBytes.reset(header.packetLength); dataScratchBytes.reset(header.packetLength);
// Signalize packet header processed completely
headerDataFinished = true;
// MHAS packet header finished -> obtain the packet payload // MHAS packet header finished -> obtain the packet payload
state = STATE_READING_PACKET_PAYLOAD; state = STATE_READING_PACKET_PAYLOAD;
} else if (headerScratchBytes.limit() < MAX_MHAS_PACKET_HEADER_SIZE) { } else if (headerScratchBytes.limit() < MAX_MHAS_PACKET_HEADER_SIZE) {
headerScratchBytes.setLimit(headerScratchBytes.limit() + 1); headerScratchBytes.setLimit(headerScratchBytes.limit() + 1);
// Signalize pending packet header processing
headerDataFinished = false;
} }
} else {
// Signalize pending packet header processing
headerDataFinished = false;
} }
break; break;
case STATE_READING_PACKET_PAYLOAD: case STATE_READING_PACKET_PAYLOAD: