package com.mbridge.msdk.playercommon.exoplayer2.decoder; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.nio.ByteBuffer; /* loaded from: classes4.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 = new CryptoInfo(); public ByteBuffer data; public long timeUs; @Retention(RetentionPolicy.SOURCE) public @interface BufferReplacementMode { } public final boolean isFlagsOnly() { return this.data == null && this.bufferReplacementMode == 0; } public static DecoderInputBuffer newFlagsOnlyInstance() { return new DecoderInputBuffer(0); } public DecoderInputBuffer(int i) { this.bufferReplacementMode = i; } public void ensureSpaceForWrite(int i) throws IllegalStateException { ByteBuffer byteBuffer = this.data; if (byteBuffer == null) { this.data = createReplacementByteBuffer(i); return; } int capacity = byteBuffer.capacity(); int position = this.data.position(); int i2 = i + position; if (capacity >= i2) { return; } ByteBuffer createReplacementByteBuffer = createReplacementByteBuffer(i2); if (position > 0) { this.data.position(0); this.data.limit(position); createReplacementByteBuffer.put(this.data); } this.data = createReplacementByteBuffer; } public final boolean isEncrypted() { return getFlag(1073741824); } public final void flip() { this.data.flip(); } @Override // com.mbridge.msdk.playercommon.exoplayer2.decoder.Buffer public void clear() { super.clear(); ByteBuffer byteBuffer = this.data; if (byteBuffer != null) { byteBuffer.clear(); } } 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 IllegalStateException("Buffer too small (" + (byteBuffer == null ? 0 : byteBuffer.capacity()) + " < " + i + ")"); } }