mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
use @IntDef instead of enum
This commit is contained in:
parent
6472ba1194
commit
3aff715824
1 changed files with 78 additions and 59 deletions
|
|
@ -20,11 +20,18 @@
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
package androidx.media3.extractor;
|
package androidx.media3.extractor;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||||
|
|
||||||
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.util.ParsableBitArray;
|
import androidx.media3.common.util.ParsableBitArray;
|
||||||
import androidx.media3.common.util.ParsableByteArray;
|
import androidx.media3.common.util.ParsableByteArray;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
|
@ -59,57 +66,70 @@ public final class MpeghUtil {
|
||||||
* Enumeration of the MHAS packet types.
|
* Enumeration of the MHAS packet types.
|
||||||
* See ISO_IEC_23008-3;2022, 14.3.1, Table 226
|
* See ISO_IEC_23008-3;2022, 14.3.1, Table 226
|
||||||
*/
|
*/
|
||||||
public enum MHASPacketType {
|
@Documented
|
||||||
PACTYP_NONE(-1),
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
PACTYP_FILLDATA(0),
|
@Target(TYPE_USE)
|
||||||
PACTYP_MPEGH3DACFG(1),
|
@IntDef({
|
||||||
PACTYP_MPEGH3DAFRAME(2),
|
PACTYP_FILLDATA,
|
||||||
PACTYP_AUDIOSCENEINFO(3),
|
PACTYP_MPEGH3DACFG,
|
||||||
/* reserved for ISO use 4-5 */
|
PACTYP_MPEGH3DAFRAME,
|
||||||
PACTYP_SYNC(6),
|
PACTYP_AUDIOSCENEINFO,
|
||||||
PACTYP_SYNCGAP(7),
|
PACTYP_SYNC,
|
||||||
PACTYP_MARKER(8),
|
PACTYP_SYNCGAP,
|
||||||
PACTYP_CRC16(9),
|
PACTYP_MARKER,
|
||||||
PACTYP_CRC32(10),
|
PACTYP_CRC16,
|
||||||
PACTYP_DESCRIPTOR(11),
|
PACTYP_CRC32,
|
||||||
PACTYP_USERINTERACTION(12),
|
PACTYP_DESCRIPTOR,
|
||||||
PACTYP_LOUDNESS_DRC(13),
|
PACTYP_USERINTERACTION,
|
||||||
PACTYP_BUFFERINFO(14),
|
PACTYP_LOUDNESS_DRC,
|
||||||
PACTYP_GLOBAL_CRC16(15),
|
PACTYP_BUFFERINFO,
|
||||||
PACTYP_GLOBAL_CRC32(16),
|
PACTYP_GLOBAL_CRC16,
|
||||||
PACTYP_AUDIOTRUNCATION(17),
|
PACTYP_GLOBAL_CRC32,
|
||||||
PACTYPE_EARCON(19),
|
PACTYP_AUDIOTRUNCATION,
|
||||||
PACTYPE_PCMCONFIG(20),
|
PACTYP_GENDATA,
|
||||||
PACTYPE_PCMDATA(21),
|
PACTYPE_EARCON,
|
||||||
PACTYP_LOUDNESS(22);
|
PACTYPE_PCMCONFIG,
|
||||||
|
PACTYPE_PCMDATA,
|
||||||
|
PACTYP_LOUDNESS
|
||||||
|
})
|
||||||
|
private @interface MHASPacketType {}
|
||||||
|
|
||||||
private final int id;
|
private static final int PACTYP_FILLDATA = 0;
|
||||||
|
private static final int PACTYP_MPEGH3DACFG = 1;
|
||||||
|
private static final int PACTYP_MPEGH3DAFRAME = 2;
|
||||||
|
private static final int PACTYP_AUDIOSCENEINFO = 3;
|
||||||
|
private static final int PACTYP_SYNC = 6;
|
||||||
|
private static final int PACTYP_SYNCGAP = 7;
|
||||||
|
private static final int PACTYP_MARKER = 8;
|
||||||
|
private static final int PACTYP_CRC16 = 9;
|
||||||
|
private static final int PACTYP_CRC32 = 10;
|
||||||
|
private static final int PACTYP_DESCRIPTOR = 11;
|
||||||
|
private static final int PACTYP_USERINTERACTION = 12;
|
||||||
|
private static final int PACTYP_LOUDNESS_DRC = 13;
|
||||||
|
private static final int PACTYP_BUFFERINFO = 14;
|
||||||
|
private static final int PACTYP_GLOBAL_CRC16 = 15;
|
||||||
|
private static final int PACTYP_GLOBAL_CRC32 = 16;
|
||||||
|
private static final int PACTYP_AUDIOTRUNCATION = 17;
|
||||||
|
private static final int PACTYP_GENDATA = 18;
|
||||||
|
private static final int PACTYPE_EARCON = 19;
|
||||||
|
private static final int PACTYPE_PCMCONFIG = 20;
|
||||||
|
private static final int PACTYPE_PCMDATA = 21;
|
||||||
|
private static final int PACTYP_LOUDNESS = 22;
|
||||||
|
|
||||||
MHASPacketType(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MHASPacketType getById(int id) {
|
@Documented
|
||||||
for (MHASPacketType e : values()) {
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
if (e.id == id) {
|
@Target(TYPE_USE)
|
||||||
return e;
|
@IntDef({
|
||||||
}
|
END_OUTPUT,
|
||||||
}
|
PARSE_ERROR,
|
||||||
return PACTYP_NONE;
|
SUBSTREAM_UNSUPPORTED
|
||||||
}
|
})
|
||||||
}
|
private @interface ParseState {}
|
||||||
|
|
||||||
public enum ParseState {
|
private static final int END_OUTPUT = 0;
|
||||||
END_OUTPUT(0), /* Input Data needed */
|
private static final int PARSE_ERROR = 1;
|
||||||
PARSE_ERROR(1), /* Parsing error */
|
private static final int SUBSTREAM_UNSUPPORTED = 2;
|
||||||
SUBSTREAM_UNSUPPORTED(2); /* The bitstream has unsupported sub-streams. */
|
|
||||||
|
|
||||||
public final int id;
|
|
||||||
|
|
||||||
ParseState(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static class FrameInfo {
|
public static class FrameInfo {
|
||||||
|
|
@ -200,7 +220,7 @@ public final class MpeghUtil {
|
||||||
* enough data is available in the provided ParsableBitArray.
|
* enough data is available in the provided ParsableBitArray.
|
||||||
*
|
*
|
||||||
* @param data The bit array to parse.
|
* @param data The bit array to parse.
|
||||||
* @return positive value on success, negative value on parse error and zero if not enough data is available
|
* @return Whether a complete MHAS frame could be parsed.
|
||||||
*/
|
*/
|
||||||
public static boolean canParseFrame(ParsableBitArray data) {
|
public static boolean canParseFrame(ParsableBitArray data) {
|
||||||
boolean retVal = false;
|
boolean retVal = false;
|
||||||
|
|
@ -219,7 +239,7 @@ public final class MpeghUtil {
|
||||||
}
|
}
|
||||||
data.skipBytes(header.packetLength);
|
data.skipBytes(header.packetLength);
|
||||||
|
|
||||||
if (header.packetType == MHASPacketType.PACTYP_MPEGH3DAFRAME) {
|
if (header.packetType == PACTYP_MPEGH3DAFRAME) {
|
||||||
// An mpegh3daFrame packet has been found which signals the end of the MHAS frame.
|
// An mpegh3daFrame packet has been found which signals the end of the MHAS frame.
|
||||||
retVal = true;
|
retVal = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -230,11 +250,11 @@ public final class MpeghUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MHASPacketHeader {
|
private static class MHASPacketHeader {
|
||||||
MHASPacketType packetType;
|
@MHASPacketType int packetType;
|
||||||
long packetLabel;
|
long packetLabel;
|
||||||
int packetLength;
|
int packetLength;
|
||||||
|
|
||||||
public MHASPacketHeader(MHASPacketType type, long label, int length) {
|
public MHASPacketHeader(@MHASPacketType int type, long label, int length) {
|
||||||
packetType = type;
|
packetType = type;
|
||||||
packetLabel = label;
|
packetLabel = label;
|
||||||
packetLength = length;
|
packetLength = length;
|
||||||
|
|
@ -250,8 +270,7 @@ public final class MpeghUtil {
|
||||||
* @throws ParseException If parsing failed, i.e. there is not enough data available.
|
* @throws ParseException If parsing failed, i.e. there is not enough data available.
|
||||||
*/
|
*/
|
||||||
private static MHASPacketHeader parseMhasPacketHeader(ParsableBitArray data) throws ParseException {
|
private static MHASPacketHeader parseMhasPacketHeader(ParsableBitArray data) throws ParseException {
|
||||||
int packetTypeVal = (int) readEscapedValue(data, 3, 8, 8);
|
@MHASPacketType int packetType = (int) readEscapedValue(data, 3, 8, 8);
|
||||||
MHASPacketType packetType = MHASPacketType.getById(packetTypeVal);
|
|
||||||
long packetLabel = readEscapedValue(data, 2, 8, 32);
|
long packetLabel = readEscapedValue(data, 2, 8, 32);
|
||||||
int packetLength = (int) readEscapedValue(data, 11, 24, 24);
|
int packetLength = (int) readEscapedValue(data, 11, 24, 24);
|
||||||
return new MHASPacketHeader(packetType, packetLabel, packetLength);
|
return new MHASPacketHeader(packetType, packetLabel, packetLength);
|
||||||
|
|
@ -739,7 +758,7 @@ public final class MpeghUtil {
|
||||||
checkBitsAvailable(data, 1);
|
checkBitsAvailable(data, 1);
|
||||||
if (data.readBit()) { // shiftIndex1
|
if (data.readBit()) { // shiftIndex1
|
||||||
checkBitsAvailable(data, nBits);
|
checkBitsAvailable(data, nBits);
|
||||||
data.readBits(nBits); // shiftChannel1
|
data.skipBits(nBits); // shiftChannel1
|
||||||
}
|
}
|
||||||
if (sbrRatioIndex == 0 && qceIndex == 0) {
|
if (sbrRatioIndex == 0 && qceIndex == 0) {
|
||||||
checkBitsAvailable(data, 1);
|
checkBitsAvailable(data, 1);
|
||||||
|
|
@ -819,24 +838,24 @@ public final class MpeghUtil {
|
||||||
|
|
||||||
public static class ParseException extends IOException {
|
public static class ParseException extends IOException {
|
||||||
|
|
||||||
public final ParseState parseState;
|
public final @ParseState int parseState;
|
||||||
|
|
||||||
public static ParseException createForNotEnoughData() {
|
public static ParseException createForNotEnoughData() {
|
||||||
return new ParseException(null, null, ParseState.END_OUTPUT);
|
return new ParseException(null, null, END_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ParseException createForUnsupportedSubstream(@Nullable String message) {
|
public static ParseException createForUnsupportedSubstream(@Nullable String message) {
|
||||||
return new ParseException(message, null, ParseState.SUBSTREAM_UNSUPPORTED);
|
return new ParseException(message, null, SUBSTREAM_UNSUPPORTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ParseException createForParsingError(@Nullable String message) {
|
public static ParseException createForParsingError(@Nullable String message) {
|
||||||
return new ParseException(message, null, ParseState.PARSE_ERROR);
|
return new ParseException(message, null, PARSE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ParseException(
|
protected ParseException(
|
||||||
@Nullable String message,
|
@Nullable String message,
|
||||||
@Nullable Throwable cause,
|
@Nullable Throwable cause,
|
||||||
ParseState parseState) {
|
@ParseState int parseState) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
this.parseState = parseState;
|
this.parseState = parseState;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue