Rabbit-R1/android (non root)/java/sources/com/google/android/exoplayer2/mediacodec/BatchBuffer.java

85 lines
2.6 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package com.google.android.exoplayer2.mediacodec;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.util.Assertions;
import java.nio.ByteBuffer;
/* loaded from: classes2.dex */
final class BatchBuffer extends DecoderInputBuffer {
public static final int DEFAULT_MAX_SAMPLE_COUNT = 32;
static final int MAX_SIZE_BYTES = 3072000;
private long lastSampleTimeUs;
private int maxSampleCount;
private int sampleCount;
public long getLastSampleTimeUs() {
return this.lastSampleTimeUs;
}
public int getSampleCount() {
return this.sampleCount;
}
public boolean hasSamples() {
return this.sampleCount > 0;
}
public BatchBuffer() {
super(2);
this.maxSampleCount = 32;
}
@Override // com.google.android.exoplayer2.decoder.DecoderInputBuffer, com.google.android.exoplayer2.decoder.Buffer
public void clear() {
super.clear();
this.sampleCount = 0;
}
public void setMaxSampleCount(int i) {
Assertions.checkArgument(i > 0);
this.maxSampleCount = i;
}
public long getFirstSampleTimeUs() {
return this.timeUs;
}
public boolean append(DecoderInputBuffer decoderInputBuffer) {
Assertions.checkArgument(!decoderInputBuffer.isEncrypted());
Assertions.checkArgument(!decoderInputBuffer.hasSupplementalData());
Assertions.checkArgument(!decoderInputBuffer.isEndOfStream());
if (!canAppendSampleBuffer(decoderInputBuffer)) {
return false;
}
int i = this.sampleCount;
this.sampleCount = i + 1;
if (i == 0) {
this.timeUs = decoderInputBuffer.timeUs;
if (decoderInputBuffer.isKeyFrame()) {
setFlags(1);
}
}
if (decoderInputBuffer.isDecodeOnly()) {
setFlags(Integer.MIN_VALUE);
}
ByteBuffer byteBuffer = decoderInputBuffer.data;
if (byteBuffer != null) {
ensureSpaceForWrite(byteBuffer.remaining());
this.data.put(byteBuffer);
}
this.lastSampleTimeUs = decoderInputBuffer.timeUs;
return true;
}
private boolean canAppendSampleBuffer(DecoderInputBuffer decoderInputBuffer) {
if (!hasSamples()) {
return true;
}
if (this.sampleCount >= this.maxSampleCount || decoderInputBuffer.isDecodeOnly() != isDecodeOnly()) {
return false;
}
ByteBuffer byteBuffer = decoderInputBuffer.data;
return byteBuffer == null || this.data == null || this.data.position() + byteBuffer.remaining() <= MAX_SIZE_BYTES;
}
}