Rabbit-R1/switch port/java/sources/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter.java

182 lines
7.4 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.media3.exoplayer.mediacodec;
import android.media.MediaCodec;
import android.media.MediaFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
import android.view.Surface;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.TraceUtil;
import androidx.media3.common.util.Util;
import androidx.media3.decoder.CryptoInfo;
import androidx.media3.exoplayer.mediacodec.MediaCodecAdapter;
import java.io.IOException;
import java.nio.ByteBuffer;
/* loaded from: classes2.dex */
public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter {
private final MediaCodec codec;
private ByteBuffer[] inputByteBuffers;
private ByteBuffer[] outputByteBuffers;
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public boolean needsReconfiguration() {
return false;
}
/* loaded from: classes2.dex */
public static class Factory implements MediaCodecAdapter.Factory {
/* JADX WARN: Multi-variable type inference failed */
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.Factory
public MediaCodecAdapter createAdapter(MediaCodecAdapter.Configuration configuration) throws IOException {
MediaCodec mediaCodec = null;
Object[] objArr = 0;
try {
MediaCodec createCodec = createCodec(configuration);
try {
TraceUtil.beginSection("configureCodec");
createCodec.configure(configuration.mediaFormat, configuration.surface, configuration.crypto, configuration.flags);
TraceUtil.endSection();
TraceUtil.beginSection("startCodec");
createCodec.start();
TraceUtil.endSection();
return new SynchronousMediaCodecAdapter(createCodec);
} catch (IOException | RuntimeException e) {
e = e;
mediaCodec = createCodec;
if (mediaCodec != null) {
mediaCodec.release();
}
throw e;
}
} catch (IOException | RuntimeException e2) {
e = e2;
}
}
protected MediaCodec createCodec(MediaCodecAdapter.Configuration configuration) throws IOException {
Assertions.checkNotNull(configuration.codecInfo);
String str = configuration.codecInfo.name;
TraceUtil.beginSection("createCodec:" + str);
MediaCodec createByCodecName = MediaCodec.createByCodecName(str);
TraceUtil.endSection();
return createByCodecName;
}
}
private SynchronousMediaCodecAdapter(MediaCodec mediaCodec) {
this.codec = mediaCodec;
if (Util.SDK_INT < 21) {
this.inputByteBuffers = mediaCodec.getInputBuffers();
this.outputByteBuffers = mediaCodec.getOutputBuffers();
}
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public int dequeueInputBufferIndex() {
return this.codec.dequeueInputBuffer(0L);
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo) {
int dequeueOutputBuffer;
do {
dequeueOutputBuffer = this.codec.dequeueOutputBuffer(bufferInfo, 0L);
if (dequeueOutputBuffer == -3 && Util.SDK_INT < 21) {
this.outputByteBuffers = this.codec.getOutputBuffers();
}
} while (dequeueOutputBuffer == -3);
return dequeueOutputBuffer;
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public MediaFormat getOutputFormat() {
return this.codec.getOutputFormat();
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public ByteBuffer getInputBuffer(int i) {
if (Util.SDK_INT >= 21) {
return this.codec.getInputBuffer(i);
}
return ((ByteBuffer[]) Util.castNonNull(this.inputByteBuffers))[i];
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public ByteBuffer getOutputBuffer(int i) {
if (Util.SDK_INT >= 21) {
return this.codec.getOutputBuffer(i);
}
return ((ByteBuffer[]) Util.castNonNull(this.outputByteBuffers))[i];
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void queueInputBuffer(int i, int i2, int i3, long j, int i4) {
this.codec.queueInputBuffer(i, i2, i3, j, i4);
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void queueSecureInputBuffer(int i, int i2, CryptoInfo cryptoInfo, long j, int i3) {
this.codec.queueSecureInputBuffer(i, i2, cryptoInfo.getFrameworkCryptoInfo(), j, i3);
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void releaseOutputBuffer(int i, boolean z) {
this.codec.releaseOutputBuffer(i, z);
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void releaseOutputBuffer(int i, long j) {
this.codec.releaseOutputBuffer(i, j);
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void flush() {
this.codec.flush();
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void release() {
this.inputByteBuffers = null;
this.outputByteBuffers = null;
this.codec.release();
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void setOnFrameRenderedListener(final MediaCodecAdapter.OnFrameRenderedListener onFrameRenderedListener, Handler handler) {
this.codec.setOnFrameRenderedListener(new MediaCodec.OnFrameRenderedListener() { // from class: androidx.media3.exoplayer.mediacodec.SynchronousMediaCodecAdapter$$ExternalSyntheticLambda0
@Override // android.media.MediaCodec.OnFrameRenderedListener
public final void onFrameRendered(MediaCodec mediaCodec, long j, long j2) {
SynchronousMediaCodecAdapter.this.m5250xe3d0a01f(onFrameRenderedListener, mediaCodec, j, j2);
}
}, handler);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$setOnFrameRenderedListener$0$androidx-media3-exoplayer-mediacodec-SynchronousMediaCodecAdapter, reason: not valid java name */
public /* synthetic */ void m5250xe3d0a01f(MediaCodecAdapter.OnFrameRenderedListener onFrameRenderedListener, MediaCodec mediaCodec, long j, long j2) {
onFrameRenderedListener.onFrameRendered(this, j, j2);
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void setOutputSurface(Surface surface) {
this.codec.setOutputSurface(surface);
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void setParameters(Bundle bundle) {
this.codec.setParameters(bundle);
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public void setVideoScalingMode(int i) {
this.codec.setVideoScalingMode(i);
}
@Override // androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
public PersistableBundle getMetrics() {
return this.codec.getMetrics();
}
}