Rabbit-R1/android (non root)/java/sources/androidx/media3/extractor/mp4/SefReader.java
2024-05-21 17:08:36 -04:00

199 lines
8.6 KiB
Java

package androidx.media3.extractor.mp4;
import androidx.media3.common.Metadata;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.extractor.ExtractorInput;
import androidx.media3.extractor.PositionHolder;
import androidx.media3.extractor.metadata.mp4.SlowMotionData;
import com.google.common.base.Splitter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/* loaded from: classes2.dex */
final class SefReader {
private static final int LENGTH_OF_ONE_SDR = 12;
private static final int SAMSUNG_TAIL_SIGNATURE = 1397048916;
private static final int STATE_CHECKING_FOR_SEF = 1;
private static final int STATE_READING_SDRS = 2;
private static final int STATE_READING_SEF_DATA = 3;
private static final int STATE_SHOULD_CHECK_FOR_SEF = 0;
private static final String TAG = "SefReader";
private static final int TAIL_FOOTER_LENGTH = 8;
private static final int TAIL_HEADER_LENGTH = 12;
private static final int TYPE_SLOW_MOTION_DATA = 2192;
private static final int TYPE_SUPER_SLOW_DEFLICKERING_ON = 2820;
private static final int TYPE_SUPER_SLOW_MOTION_BGM = 2817;
private static final int TYPE_SUPER_SLOW_MOTION_DATA = 2816;
private static final int TYPE_SUPER_SLOW_MOTION_EDIT_DATA = 2819;
private final List<DataReference> dataReferences = new ArrayList();
private int readerState = 0;
private int tailLength;
private static final Splitter COLON_SPLITTER = Splitter.on(':');
private static final Splitter ASTERISK_SPLITTER = Splitter.on('*');
public void reset() {
this.dataReferences.clear();
this.readerState = 0;
}
public int read(ExtractorInput extractorInput, PositionHolder positionHolder, List<Metadata.Entry> list) throws IOException {
int i = this.readerState;
long j = 0;
if (i == 0) {
long length = extractorInput.getLength();
if (length != -1 && length >= 8) {
j = length - 8;
}
positionHolder.position = j;
this.readerState = 1;
} else if (i == 1) {
checkForSefData(extractorInput, positionHolder);
} else if (i == 2) {
readSdrs(extractorInput, positionHolder);
} else if (i == 3) {
readSefData(extractorInput, list);
positionHolder.position = 0L;
} else {
throw new IllegalStateException();
}
return 1;
}
private void checkForSefData(ExtractorInput extractorInput, PositionHolder positionHolder) throws IOException {
ParsableByteArray parsableByteArray = new ParsableByteArray(8);
extractorInput.readFully(parsableByteArray.getData(), 0, 8);
this.tailLength = parsableByteArray.readLittleEndianInt() + 8;
if (parsableByteArray.readInt() != SAMSUNG_TAIL_SIGNATURE) {
positionHolder.position = 0L;
} else {
positionHolder.position = extractorInput.getPosition() - (this.tailLength - 12);
this.readerState = 2;
}
}
private void readSdrs(ExtractorInput extractorInput, PositionHolder positionHolder) throws IOException {
long length = extractorInput.getLength();
int i = this.tailLength - 20;
ParsableByteArray parsableByteArray = new ParsableByteArray(i);
extractorInput.readFully(parsableByteArray.getData(), 0, i);
for (int i2 = 0; i2 < i / 12; i2++) {
parsableByteArray.skipBytes(2);
short readLittleEndianShort = parsableByteArray.readLittleEndianShort();
if (readLittleEndianShort == TYPE_SLOW_MOTION_DATA || readLittleEndianShort == TYPE_SUPER_SLOW_MOTION_DATA || readLittleEndianShort == TYPE_SUPER_SLOW_MOTION_BGM || readLittleEndianShort == TYPE_SUPER_SLOW_MOTION_EDIT_DATA || readLittleEndianShort == TYPE_SUPER_SLOW_DEFLICKERING_ON) {
this.dataReferences.add(new DataReference(readLittleEndianShort, (length - this.tailLength) - parsableByteArray.readLittleEndianInt(), parsableByteArray.readLittleEndianInt()));
} else {
parsableByteArray.skipBytes(8);
}
}
if (this.dataReferences.isEmpty()) {
positionHolder.position = 0L;
} else {
this.readerState = 3;
positionHolder.position = this.dataReferences.get(0).startOffset;
}
}
private void readSefData(ExtractorInput extractorInput, List<Metadata.Entry> list) throws IOException {
long position = extractorInput.getPosition();
int length = (int) ((extractorInput.getLength() - extractorInput.getPosition()) - this.tailLength);
ParsableByteArray parsableByteArray = new ParsableByteArray(length);
extractorInput.readFully(parsableByteArray.getData(), 0, length);
for (int i = 0; i < this.dataReferences.size(); i++) {
DataReference dataReference = this.dataReferences.get(i);
parsableByteArray.setPosition((int) (dataReference.startOffset - position));
parsableByteArray.skipBytes(4);
int readLittleEndianInt = parsableByteArray.readLittleEndianInt();
int nameToDataType = nameToDataType(parsableByteArray.readString(readLittleEndianInt));
int i2 = dataReference.size - (readLittleEndianInt + 8);
if (nameToDataType == TYPE_SLOW_MOTION_DATA) {
list.add(readSlowMotionData(parsableByteArray, i2));
} else if (nameToDataType != TYPE_SUPER_SLOW_MOTION_DATA && nameToDataType != TYPE_SUPER_SLOW_MOTION_BGM && nameToDataType != TYPE_SUPER_SLOW_MOTION_EDIT_DATA && nameToDataType != TYPE_SUPER_SLOW_DEFLICKERING_ON) {
throw new IllegalStateException();
}
}
}
private static SlowMotionData readSlowMotionData(ParsableByteArray parsableByteArray, int i) throws ParserException {
ArrayList arrayList = new ArrayList();
List<String> splitToList = ASTERISK_SPLITTER.splitToList(parsableByteArray.readString(i));
for (int i2 = 0; i2 < splitToList.size(); i2++) {
List<String> splitToList2 = COLON_SPLITTER.splitToList(splitToList.get(i2));
if (splitToList2.size() != 3) {
throw ParserException.createForMalformedContainer(null, null);
}
try {
arrayList.add(new SlowMotionData.Segment(Long.parseLong(splitToList2.get(0)), Long.parseLong(splitToList2.get(1)), 1 << (Integer.parseInt(splitToList2.get(2)) - 1)));
} catch (NumberFormatException e) {
throw ParserException.createForMalformedContainer(null, e);
}
}
return new SlowMotionData(arrayList);
}
private static int nameToDataType(String str) throws ParserException {
str.hashCode();
char c = 65535;
switch (str.hashCode()) {
case -1711564334:
if (str.equals("SlowMotion_Data")) {
c = 0;
break;
}
break;
case -1332107749:
if (str.equals("Super_SlowMotion_Edit_Data")) {
c = 1;
break;
}
break;
case -1251387154:
if (str.equals("Super_SlowMotion_Data")) {
c = 2;
break;
}
break;
case -830665521:
if (str.equals("Super_SlowMotion_Deflickering_On")) {
c = 3;
break;
}
break;
case 1760745220:
if (str.equals("Super_SlowMotion_BGM")) {
c = 4;
break;
}
break;
}
switch (c) {
case 0:
return TYPE_SLOW_MOTION_DATA;
case 1:
return TYPE_SUPER_SLOW_MOTION_EDIT_DATA;
case 2:
return TYPE_SUPER_SLOW_MOTION_DATA;
case 3:
return TYPE_SUPER_SLOW_DEFLICKERING_ON;
case 4:
return TYPE_SUPER_SLOW_MOTION_BGM;
default:
throw ParserException.createForMalformedContainer("Invalid SEF name", null);
}
}
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes2.dex */
public static final class DataReference {
public final int dataType;
public final int size;
public final long startOffset;
public DataReference(int i, long j, int i2) {
this.dataType = i;
this.startOffset = j;
this.size = i2;
}
}
}