mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Minor refactoring based on internal review
This commit is contained in:
parent
c34c3db87f
commit
6aa80b334a
1 changed files with 8 additions and 7 deletions
|
|
@ -40,6 +40,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||||
|
|
||||||
/** Parses a continuous MPEG-H audio byte stream and extracts MPEG-H frames. */
|
/** Parses a continuous MPEG-H audio byte stream and extracts MPEG-H frames. */
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
|
|
@ -59,6 +60,10 @@ public final class MpeghReader implements ElementaryStreamReader {
|
||||||
private static final int MIN_MHAS_PACKET_HEADER_SIZE = 2;
|
private static final int MIN_MHAS_PACKET_HEADER_SIZE = 2;
|
||||||
private static final int MAX_MHAS_PACKET_HEADER_SIZE = 15;
|
private static final int MAX_MHAS_PACKET_HEADER_SIZE = 15;
|
||||||
|
|
||||||
|
private final ParsableByteArray headerScratchBytes;
|
||||||
|
private final ParsableBitArray headerScratchBits;
|
||||||
|
private final ParsableByteArray dataScratchBytes;
|
||||||
|
|
||||||
private @State int state;
|
private @State int state;
|
||||||
|
|
||||||
private @MonotonicNonNull String formatId;
|
private @MonotonicNonNull String formatId;
|
||||||
|
|
@ -73,10 +78,6 @@ public final class MpeghReader implements ElementaryStreamReader {
|
||||||
|
|
||||||
private int syncBytes;
|
private int syncBytes;
|
||||||
|
|
||||||
private final ParsableByteArray headerScratchBytes;
|
|
||||||
private final ParsableBitArray headerScratchBits;
|
|
||||||
private final ParsableByteArray dataScratchBytes;
|
|
||||||
|
|
||||||
private boolean headerDataFinished;
|
private boolean headerDataFinished;
|
||||||
private int payloadBytesRead;
|
private int payloadBytesRead;
|
||||||
private int frameBytes;
|
private int frameBytes;
|
||||||
|
|
@ -175,18 +176,15 @@ 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;
|
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;
|
headerDataFinished = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Signalize pending packet header processing
|
|
||||||
headerDataFinished = false;
|
headerDataFinished = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -309,6 +307,7 @@ public final class MpeghReader implements ElementaryStreamReader {
|
||||||
*
|
*
|
||||||
* @param data A {@link ParsableByteArray} from which to read the sample data.
|
* @param data A {@link ParsableByteArray} from which to read the sample data.
|
||||||
*/
|
*/
|
||||||
|
@RequiresNonNull("output")
|
||||||
private void writeSampleData(ParsableByteArray data) {
|
private void writeSampleData(ParsableByteArray data) {
|
||||||
// read bytes from input data and write them into the output
|
// read bytes from input data and write them into the output
|
||||||
int bytesToRead = min(data.bytesLeft(), header.packetLength - payloadBytesRead);
|
int bytesToRead = min(data.bytesLeft(), header.packetLength - payloadBytesRead);
|
||||||
|
|
@ -323,6 +322,7 @@ public final class MpeghReader implements ElementaryStreamReader {
|
||||||
* MpeghUtil.Mpegh3daConfig} field. Must be byte-aligned.
|
* MpeghUtil.Mpegh3daConfig} field. Must be byte-aligned.
|
||||||
* @throws ParserException if a valid {@link MpeghUtil.Mpegh3daConfig} cannot be parsed.
|
* @throws ParserException if a valid {@link MpeghUtil.Mpegh3daConfig} cannot be parsed.
|
||||||
*/
|
*/
|
||||||
|
@RequiresNonNull("output")
|
||||||
private void parseConfig(ParsableBitArray bitArray) throws ParserException {
|
private void parseConfig(ParsableBitArray bitArray) throws ParserException {
|
||||||
MpeghUtil.Mpegh3daConfig config = MpeghUtil.parseMpegh3daConfig(bitArray);
|
MpeghUtil.Mpegh3daConfig config = MpeghUtil.parseMpegh3daConfig(bitArray);
|
||||||
samplingRate = config.samplingFrequency;
|
samplingRate = config.samplingFrequency;
|
||||||
|
|
@ -355,6 +355,7 @@ public final class MpeghReader implements ElementaryStreamReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Finalizes an MPEG-H frame. */
|
/** Finalizes an MPEG-H frame. */
|
||||||
|
@RequiresNonNull("output")
|
||||||
private void finalizeFrame() {
|
private void finalizeFrame() {
|
||||||
@C.BufferFlags int flag = 0;
|
@C.BufferFlags int flag = 0;
|
||||||
// if we have a frame with an mpegh3daConfig, set the obtained AU to a key frame
|
// if we have a frame with an mpegh3daConfig, set the obtained AU to a key frame
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue