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

182 lines
7.5 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package com.google.android.exoplayer2.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 com.google.android.exoplayer2.decoder.CryptoInfo;
import com.google.android.exoplayer2.mediacodec.MediaCodecAdapter;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.TraceUtil;
import com.google.android.exoplayer2.util.Util;
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 // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public int dequeueInputBufferIndex() {
return this.codec.dequeueInputBuffer(0L);
}
@Override // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public MediaFormat getOutputFormat() {
return this.codec.getOutputFormat();
}
@Override // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public void queueInputBuffer(int i, int i2, int i3, long j, int i4) {
this.codec.queueInputBuffer(i, i2, i3, j, i4);
}
@Override // com.google.android.exoplayer2.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 // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public void releaseOutputBuffer(int i, boolean z) {
this.codec.releaseOutputBuffer(i, z);
}
@Override // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public void releaseOutputBuffer(int i, long j) {
this.codec.releaseOutputBuffer(i, j);
}
@Override // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public void flush() {
this.codec.flush();
}
@Override // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public void release() {
this.inputByteBuffers = null;
this.outputByteBuffers = null;
this.codec.release();
}
@Override // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public void setOnFrameRenderedListener(final MediaCodecAdapter.OnFrameRenderedListener onFrameRenderedListener, Handler handler) {
this.codec.setOnFrameRenderedListener(new MediaCodec.OnFrameRenderedListener() { // from class: com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter$$ExternalSyntheticLambda0
@Override // android.media.MediaCodec.OnFrameRenderedListener
public final void onFrameRendered(MediaCodec mediaCodec, long j, long j2) {
SynchronousMediaCodecAdapter.this.m5430x143bf9f7(onFrameRenderedListener, mediaCodec, j, j2);
}
}, handler);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$setOnFrameRenderedListener$0$com-google-android-exoplayer2-mediacodec-SynchronousMediaCodecAdapter, reason: not valid java name */
public /* synthetic */ void m5430x143bf9f7(MediaCodecAdapter.OnFrameRenderedListener onFrameRenderedListener, MediaCodec mediaCodec, long j, long j2) {
onFrameRenderedListener.onFrameRendered(this, j, j2);
}
@Override // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public void setOutputSurface(Surface surface) {
this.codec.setOutputSurface(surface);
}
@Override // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public void setParameters(Bundle bundle) {
this.codec.setParameters(bundle);
}
@Override // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public void setVideoScalingMode(int i) {
this.codec.setVideoScalingMode(i);
}
@Override // com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
public PersistableBundle getMetrics() {
return this.codec.getMetrics();
}
}