Rabbit-R1/original r1/java/sources/androidx/media3/decoder/DecoderInputBuffer.java

139 lines
4.3 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.media3.decoder;
import androidx.media3.common.Format;
import androidx.media3.common.MediaLibraryInfo;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.nio.ByteBuffer;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
/* loaded from: classes2.dex */
public class DecoderInputBuffer extends Buffer {
public static final int BUFFER_REPLACEMENT_MODE_DIRECT = 2;
public static final int BUFFER_REPLACEMENT_MODE_DISABLED = 0;
public static final int BUFFER_REPLACEMENT_MODE_NORMAL = 1;
private final int bufferReplacementMode;
public final CryptoInfo cryptoInfo;
public ByteBuffer data;
public Format format;
private final int paddingSize;
public ByteBuffer supplementalData;
public long timeUs;
public boolean waitingForKeys;
@Target({ElementType.TYPE_USE})
@Documented
@Retention(RetentionPolicy.SOURCE)
/* loaded from: classes2.dex */
public @interface BufferReplacementMode {
}
static {
MediaLibraryInfo.registerModule("media3.decoder");
}
/* loaded from: classes2.dex */
public static final class InsufficientCapacityException extends IllegalStateException {
public final int currentCapacity;
public final int requiredCapacity;
public InsufficientCapacityException(int i, int i2) {
super("Buffer too small (" + i + " < " + i2 + ")");
this.currentCapacity = i;
this.requiredCapacity = i2;
}
}
public static DecoderInputBuffer newNoDataInstance() {
return new DecoderInputBuffer(0);
}
public DecoderInputBuffer(int i) {
this(i, 0);
}
public DecoderInputBuffer(int i, int i2) {
this.cryptoInfo = new CryptoInfo();
this.bufferReplacementMode = i;
this.paddingSize = i2;
}
@EnsuresNonNull({"supplementalData"})
public void resetSupplementalData(int i) {
ByteBuffer byteBuffer = this.supplementalData;
if (byteBuffer == null || byteBuffer.capacity() < i) {
this.supplementalData = ByteBuffer.allocate(i);
} else {
this.supplementalData.clear();
}
}
@EnsuresNonNull({"data"})
public void ensureSpaceForWrite(int i) {
int i2 = i + this.paddingSize;
ByteBuffer byteBuffer = this.data;
if (byteBuffer == null) {
this.data = createReplacementByteBuffer(i2);
return;
}
int capacity = byteBuffer.capacity();
int position = byteBuffer.position();
int i3 = i2 + position;
if (capacity >= i3) {
this.data = byteBuffer;
return;
}
ByteBuffer createReplacementByteBuffer = createReplacementByteBuffer(i3);
createReplacementByteBuffer.order(byteBuffer.order());
if (position > 0) {
byteBuffer.flip();
createReplacementByteBuffer.put(byteBuffer);
}
this.data = createReplacementByteBuffer;
}
public final boolean isEncrypted() {
return getFlag(1073741824);
}
public final void flip() {
ByteBuffer byteBuffer = this.data;
if (byteBuffer != null) {
byteBuffer.flip();
}
ByteBuffer byteBuffer2 = this.supplementalData;
if (byteBuffer2 != null) {
byteBuffer2.flip();
}
}
@Override // androidx.media3.decoder.Buffer
public void clear() {
super.clear();
ByteBuffer byteBuffer = this.data;
if (byteBuffer != null) {
byteBuffer.clear();
}
ByteBuffer byteBuffer2 = this.supplementalData;
if (byteBuffer2 != null) {
byteBuffer2.clear();
}
this.waitingForKeys = false;
}
private ByteBuffer createReplacementByteBuffer(int i) {
int i2 = this.bufferReplacementMode;
if (i2 == 1) {
return ByteBuffer.allocate(i);
}
if (i2 == 2) {
return ByteBuffer.allocateDirect(i);
}
ByteBuffer byteBuffer = this.data;
throw new InsufficientCapacityException(byteBuffer == null ? 0 : byteBuffer.capacity(), i);
}
}