Minor formatting changes

This commit is contained in:
Rohit Singh 2024-01-18 15:48:05 +00:00
parent b6990c3c5b
commit 6ac888ec3b
2 changed files with 46 additions and 54 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright 2023 The Android Open Source Project * Copyright 2024 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -72,10 +72,10 @@ public final class MpeghUtil {
switch (packetType) { switch (packetType) {
case MhasPacketHeader.PACTYP_MPEGH3DACFG: case MhasPacketHeader.PACTYP_MPEGH3DACFG:
throw ParserException.createForMalformedContainer( throw ParserException.createForMalformedContainer(
"Mpegh3daConfig packet with invalid packet label 0", /* cause= */ null); "Mpegh3daConfig packet with invalid packet label 0", /* cause= */ null);
case MhasPacketHeader.PACTYP_AUDIOTRUNCATION: case MhasPacketHeader.PACTYP_AUDIOTRUNCATION:
throw ParserException.createForMalformedContainer( throw ParserException.createForMalformedContainer(
"AudioTruncation packet with invalid packet label 0", /* cause= */ null); "AudioTruncation packet with invalid packet label 0", /* cause= */ null);
case MhasPacketHeader.PACTYP_MPEGH3DAFRAME: case MhasPacketHeader.PACTYP_MPEGH3DAFRAME:
throw ParserException.createForMalformedContainer( throw ParserException.createForMalformedContainer(
"Mpegh3daFrame packet with invalid packet label 0", /* cause= */ null); "Mpegh3daFrame packet with invalid packet label 0", /* cause= */ null);
@ -612,7 +612,8 @@ public final class MpeghUtil {
public final int packetLength; public final int packetLength;
public final int headerLength; public final int headerLength;
public MhasPacketHeader(@Type int packetType, long packetLabel, int packetLength, int headerLength) { public MhasPacketHeader(
@Type int packetType, long packetLabel, int packetLength, int headerLength) {
this.packetType = packetType; this.packetType = packetType;
this.packetLabel = packetLabel; this.packetLabel = packetLabel;
this.packetLength = packetLength; this.packetLength = packetLength;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright 2023 The Android Open Source Project * Copyright 2024 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -61,7 +61,6 @@ public final class MpeghReader implements ElementaryStreamReader {
private @MonotonicNonNull String formatId; private @MonotonicNonNull String formatId;
private @MonotonicNonNull TrackOutput output; private @MonotonicNonNull TrackOutput output;
// The timestamp to attach to the next sample in the current packet. // The timestamp to attach to the next sample in the current packet.
private double timeUs; private double timeUs;
private double timeUsPending; private double timeUsPending;
@ -79,33 +78,21 @@ public final class MpeghReader implements ElementaryStreamReader {
private int payloadBytesRead; private int payloadBytesRead;
private int frameBytes; private int frameBytes;
@Nullable @Nullable private MpeghUtil.MhasPacketHeader header;
private MpeghUtil.MhasPacketHeader header;
private int samplingRate; private int samplingRate;
private int standardFrameLength; private int standardFrameLength;
private int truncationSamples; private int truncationSamples;
private long mainStreamLabel; private long mainStreamLabel;
private boolean configFound; private boolean configFound;
/** Constructs a new reader for MPEG-H elementary streams. */
/**
* Constructs a new reader for MPEG-H elementary streams.
*/
public MpeghReader() { public MpeghReader() {
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
syncBytes = 0;
headerScratchBytes = new ParsableByteArray(new byte[MpeghUtil.MAX_MHAS_PACKET_HEADER_SIZE]); headerScratchBytes = new ParsableByteArray(new byte[MpeghUtil.MAX_MHAS_PACKET_HEADER_SIZE]);
dataScratchBytes = new ParsableByteArray(); dataScratchBytes = new ParsableByteArray();
header = null;
headerDataFinished = false;
payloadBytesRead = 0;
frameBytes = 0;
samplingRate = C.RATE_UNSET_INT; samplingRate = C.RATE_UNSET_INT;
standardFrameLength = C.LENGTH_UNSET; standardFrameLength = C.LENGTH_UNSET;
truncationSamples = 0;
mainStreamLabel = C.INDEX_UNSET; mainStreamLabel = C.INDEX_UNSET;
configFound = false;
dataPending = false;
rapPending = true; rapPending = true;
timeUs = C.TIME_UNSET; timeUs = C.TIME_UNSET;
timeUsPending = C.TIME_UNSET; timeUsPending = C.TIME_UNSET;
@ -172,10 +159,15 @@ public final class MpeghReader implements ElementaryStreamReader {
} }
break; break;
case STATE_READING_PACKET_HEADER: case STATE_READING_PACKET_HEADER:
// check if the gathering of data in header scratch buffer was finished and adjust remaining bytes // check if the gathering of data in header scratch buffer was finished and adjust
// remaining bytes
if (headerDataFinished && headerScratchBytes.getPosition() > 0) { if (headerDataFinished && headerScratchBytes.getPosition() > 0) {
System.arraycopy(headerScratchBytes.getData(), headerScratchBytes.getPosition(), System.arraycopy(
headerScratchBytes.getData(), 0, headerScratchBytes.bytesLeft()); headerScratchBytes.getData(),
headerScratchBytes.getPosition(),
headerScratchBytes.getData(),
0,
headerScratchBytes.bytesLeft());
headerScratchBytes.setPosition(headerScratchBytes.bytesLeft()); headerScratchBytes.setPosition(headerScratchBytes.bytesLeft());
headerDataFinished = false; headerDataFinished = false;
} }
@ -195,8 +187,8 @@ public final class MpeghReader implements ElementaryStreamReader {
payloadBytesRead = 0; payloadBytesRead = 0;
frameBytes += header.packetLength + header.headerLength; frameBytes += header.packetLength + header.headerLength;
if (header.packetType == MpeghUtil.MhasPacketHeader.PACTYP_AUDIOTRUNCATION || if (header.packetType == MpeghUtil.MhasPacketHeader.PACTYP_AUDIOTRUNCATION
header.packetType == MpeghUtil.MhasPacketHeader.PACTYP_MPEGH3DACFG) { || header.packetType == MpeghUtil.MhasPacketHeader.PACTYP_MPEGH3DACFG) {
dataScratchBytes.ensureCapacity(header.packetLength); dataScratchBytes.ensureCapacity(header.packetLength);
dataScratchBytes.setPosition(0); dataScratchBytes.setPosition(0);
dataScratchBytes.setLimit(header.packetLength); dataScratchBytes.setLimit(header.packetLength);
@ -207,11 +199,8 @@ public final class MpeghReader implements ElementaryStreamReader {
} }
break; break;
case STATE_READING_PACKET_PAYLOAD: case STATE_READING_PACKET_PAYLOAD:
if (header == null) { if (header.packetType == MpeghUtil.MhasPacketHeader.PACTYP_MPEGH3DACFG
throw new IllegalStateException(); || header.packetType == MpeghUtil.MhasPacketHeader.PACTYP_AUDIOTRUNCATION) {
}
if (header.packetType == MpeghUtil.MhasPacketHeader.PACTYP_MPEGH3DACFG ||
header.packetType == MpeghUtil.MhasPacketHeader.PACTYP_AUDIOTRUNCATION) {
// read bytes from header scratch buffer into the data scratch buffer // read bytes from header scratch buffer into the data scratch buffer
headerDataPos = headerScratchBytes.getPosition(); headerDataPos = headerScratchBytes.getPosition();
if (headerDataPos != MpeghUtil.MAX_MHAS_PACKET_HEADER_SIZE) { if (headerDataPos != MpeghUtil.MAX_MHAS_PACKET_HEADER_SIZE) {
@ -228,8 +217,8 @@ public final class MpeghReader implements ElementaryStreamReader {
// read bytes from header scratch buffer and write them into the output // read bytes from header scratch buffer and write them into the output
headerDataPos = headerScratchBytes.getPosition(); headerDataPos = headerScratchBytes.getPosition();
if (headerDataPos != MpeghUtil.MAX_MHAS_PACKET_HEADER_SIZE) { if (headerDataPos != MpeghUtil.MAX_MHAS_PACKET_HEADER_SIZE) {
bytesToRead = min(headerScratchBytes.bytesLeft(), bytesToRead =
header.packetLength - payloadBytesRead); min(headerScratchBytes.bytesLeft(), header.packetLength - payloadBytesRead);
output.sampleData(headerScratchBytes, bytesToRead); output.sampleData(headerScratchBytes, bytesToRead);
payloadBytesRead += bytesToRead; payloadBytesRead += bytesToRead;
} }
@ -255,9 +244,10 @@ public final class MpeghReader implements ElementaryStreamReader {
@Nullable List<byte[]> initializationData = null; @Nullable List<byte[]> initializationData = null;
if (config.compatibleProfileLevelSet != null if (config.compatibleProfileLevelSet != null
&& config.compatibleProfileLevelSet.length > 0) { && config.compatibleProfileLevelSet.length > 0) {
// The first entry in initializationData is reserved for the audio specific config. // The first entry in initializationData is reserved for the audio specific
initializationData = ImmutableList.of(Util.EMPTY_BYTE_ARRAY, // config.
config.compatibleProfileLevelSet); initializationData =
ImmutableList.of(Util.EMPTY_BYTE_ARRAY, config.compatibleProfileLevelSet);
} }
Format format = Format format =
new Format.Builder() new Format.Builder()
@ -280,7 +270,8 @@ public final class MpeghReader implements ElementaryStreamReader {
rapPending = false; rapPending = false;
} }
double sampleDurationUs = double sampleDurationUs =
(double) C.MICROS_PER_SECOND * (standardFrameLength - truncationSamples) (double) C.MICROS_PER_SECOND
* (standardFrameLength - truncationSamples)
/ samplingRate; / samplingRate;
long pts = Math.round(timeUs); long pts = Math.round(timeUs);
if (dataPending) { if (dataPending) {
@ -310,17 +301,16 @@ public final class MpeghReader implements ElementaryStreamReader {
// Do nothing. // Do nothing.
} }
/** /**
* Continues a read from the provided {@code source} into a given {@code target}. * Continues a read from the provided {@code source} into a given {@code target}.
* *
* @param source The source from which to read. * @param source The source from which to read.
* @param target The target into which data is to be read. * @param target The target into which data is to be read.
* @param targetLength The target length of the read. * @param targetLength The target length of the read.
* @return Whether the target length was reached. * @return Whether the target length was reached.
*/ */
private boolean continueRead(ParsableByteArray source, ParsableByteArray target, private boolean continueRead(
int targetLength) { ParsableByteArray source, ParsableByteArray target, int targetLength) {
int bytesToRead = min(source.bytesLeft(), targetLength - target.getPosition()); int bytesToRead = min(source.bytesLeft(), targetLength - target.getPosition());
source.readBytes(target.getData(), target.getPosition(), bytesToRead); source.readBytes(target.getData(), target.getPosition(), bytesToRead);
target.setPosition(target.getPosition() + bytesToRead); target.setPosition(target.getPosition() + bytesToRead);
@ -340,21 +330,22 @@ public final class MpeghReader implements ElementaryStreamReader {
if ((flags & FLAG_RANDOM_ACCESS_INDICATOR) == 0) { if ((flags & FLAG_RANDOM_ACCESS_INDICATOR) == 0) {
// RAI is not signalled -> drop the PES data // RAI is not signalled -> drop the PES data
pesBuffer.setPosition(pesBuffer.limit()); pesBuffer.setPosition(pesBuffer.limit());
} else { return false;
if ((flags & FLAG_DATA_ALIGNMENT_INDICATOR) == 0) { }
// if RAI is signalled but the data is not aligned we need to find the sync packet
while (pesBuffer.bytesLeft() > 0) { if ((flags & FLAG_DATA_ALIGNMENT_INDICATOR) == 0) {
syncBytes <<= C.BITS_PER_BYTE; // if RAI is signalled but the data is not aligned we need to find the sync packet
syncBytes |= pesBuffer.readUnsignedByte(); while (pesBuffer.bytesLeft() > 0) {
if (MpeghUtil.isSyncWord(syncBytes)) { syncBytes <<= C.BITS_PER_BYTE;
pesBuffer.setPosition(pesBuffer.getPosition() - MpeghUtil.MHAS_SYNC_WORD_LENGTH); syncBytes |= pesBuffer.readUnsignedByte();
syncBytes = 0; if (MpeghUtil.isSyncWord(syncBytes)) {
return true; pesBuffer.setPosition(pesBuffer.getPosition() - MpeghUtil.MHAS_SYNC_WORD_LENGTH);
} syncBytes = 0;
return true;
} }
} else {
return true;
} }
} else {
return true;
} }
} else { } else {
pesBuffer.setPosition(pesBuffer.limit()); pesBuffer.setPosition(pesBuffer.limit());