package com.mbridge.msdk.playercommon.exoplayer2.video; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Point; import android.media.MediaCodec; import android.media.MediaCrypto; import android.media.MediaFormat; import android.os.Handler; import android.os.SystemClock; import android.util.Log; import android.view.Surface; import androidx.annotation.CallSuper; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.work.WorkRequest; import com.ironsource.v8; import com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer; import com.mbridge.msdk.playercommon.exoplayer2.C; import com.mbridge.msdk.playercommon.exoplayer2.ExoPlaybackException; import com.mbridge.msdk.playercommon.exoplayer2.Format; import com.mbridge.msdk.playercommon.exoplayer2.decoder.DecoderCounters; import com.mbridge.msdk.playercommon.exoplayer2.decoder.DecoderInputBuffer; import com.mbridge.msdk.playercommon.exoplayer2.drm.DrmInitData; import com.mbridge.msdk.playercommon.exoplayer2.drm.DrmSessionManager; import com.mbridge.msdk.playercommon.exoplayer2.drm.FrameworkMediaCrypto; import com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecInfo; import com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer; import com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecSelector; import com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecUtil; import com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaFormatUtil; import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions; import com.mbridge.msdk.playercommon.exoplayer2.util.MimeTypes; import com.mbridge.msdk.playercommon.exoplayer2.util.TraceUtil; import com.mbridge.msdk.playercommon.exoplayer2.util.Util; import com.mbridge.msdk.playercommon.exoplayer2.video.VideoRendererEventListener; import com.unity3d.ads.core.domain.HandleInvocationsFromAdViewer; import java.nio.ByteBuffer; @TargetApi(16) /* loaded from: classes4.dex */ public class MediaCodecVideoRenderer extends MediaCodecRenderer { private static final String KEY_CROP_BOTTOM = "crop-bottom"; private static final String KEY_CROP_LEFT = "crop-left"; private static final String KEY_CROP_RIGHT = "crop-right"; private static final String KEY_CROP_TOP = "crop-top"; private static final int MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT = 10; private static final int[] STANDARD_LONG_EDGE_VIDEO_PX = {1920, 1600, 1440, 1280, 960, 854, 640, 540, 480}; private static final String TAG = "MediaCodecVideoRenderer"; private static boolean deviceNeedsSetOutputSurfaceWorkaround; private static boolean evaluatedDeviceNeedsSetOutputSurfaceWorkaround; private final long allowedJoiningTimeMs; private int buffersInCodecCount; private CodecMaxValues codecMaxValues; private boolean codecNeedsSetOutputSurfaceWorkaround; private int consecutiveDroppedFrameCount; private final Context context; private int currentHeight; private float currentPixelWidthHeightRatio; private int currentUnappliedRotationDegrees; private int currentWidth; private final boolean deviceNeedsAutoFrcWorkaround; private long droppedFrameAccumulationStartTimeMs; private int droppedFrames; private Surface dummySurface; private final VideoRendererEventListener.EventDispatcher eventDispatcher; private final VideoFrameReleaseTimeHelper frameReleaseTimeHelper; private long initialPositionUs; private long joiningDeadlineMs; private long lastInputTimeUs; private long lastRenderTimeUs; private final int maxDroppedFramesToNotify; private long outputStreamOffsetUs; private int pendingOutputStreamOffsetCount; private final long[] pendingOutputStreamOffsetsUs; private final long[] pendingOutputStreamSwitchTimesUs; private float pendingPixelWidthHeightRatio; private int pendingRotationDegrees; private boolean renderedFirstFrame; private int reportedHeight; private float reportedPixelWidthHeightRatio; private int reportedUnappliedRotationDegrees; private int reportedWidth; private int scalingMode; private Surface surface; private boolean tunneling; private int tunnelingAudioSessionId; OnFrameRenderedListenerV23 tunnelingOnFrameRenderedListener; private void clearReportedVideoSize() { this.reportedWidth = -1; this.reportedHeight = -1; this.reportedPixelWidthHeightRatio = -1.0f; this.reportedUnappliedRotationDegrees = -1; } private static boolean isBufferLate(long j) { return j < -30000; } private static boolean isBufferVeryLate(long j) { return j < -500000; } public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector) { this(context, mediaCodecSelector, 0L); } public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, long j) { this(context, mediaCodecSelector, j, null, null, -1); } public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, long j, @Nullable Handler handler, @Nullable VideoRendererEventListener videoRendererEventListener, int i) { this(context, mediaCodecSelector, j, null, false, handler, videoRendererEventListener, i); } public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, long j, @Nullable DrmSessionManager drmSessionManager, boolean z, @Nullable Handler handler, @Nullable VideoRendererEventListener videoRendererEventListener, int i) { super(2, mediaCodecSelector, drmSessionManager, z); this.allowedJoiningTimeMs = j; this.maxDroppedFramesToNotify = i; Context applicationContext = context.getApplicationContext(); this.context = applicationContext; this.frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(applicationContext); this.eventDispatcher = new VideoRendererEventListener.EventDispatcher(handler, videoRendererEventListener); this.deviceNeedsAutoFrcWorkaround = deviceNeedsAutoFrcWorkaround(); this.pendingOutputStreamOffsetsUs = new long[10]; this.pendingOutputStreamSwitchTimesUs = new long[10]; this.outputStreamOffsetUs = C.TIME_UNSET; this.lastInputTimeUs = C.TIME_UNSET; this.joiningDeadlineMs = C.TIME_UNSET; this.currentWidth = -1; this.currentHeight = -1; this.currentPixelWidthHeightRatio = -1.0f; this.pendingPixelWidthHeightRatio = -1.0f; this.scalingMode = 1; clearReportedVideoSize(); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer public int supportsFormat(MediaCodecSelector mediaCodecSelector, DrmSessionManager drmSessionManager, Format format) throws MediaCodecUtil.DecoderQueryException { boolean z; int i; int i2; String str = format.sampleMimeType; if (!MimeTypes.isVideo(str)) { return 0; } DrmInitData drmInitData = format.drmInitData; if (drmInitData != null) { z = false; for (int i3 = 0; i3 < drmInitData.schemeDataCount; i3++) { z |= drmInitData.get(i3).requiresSecureDecryption; } } else { z = false; } MediaCodecInfo decoderInfo = mediaCodecSelector.getDecoderInfo(str, z); if (decoderInfo == null) { return (!z || mediaCodecSelector.getDecoderInfo(str, false) == null) ? 1 : 2; } if (!BaseRenderer.supportsFormatDrm(drmSessionManager, drmInitData)) { return 2; } boolean isCodecSupported = decoderInfo.isCodecSupported(format.codecs); if (isCodecSupported && (i = format.width) > 0 && (i2 = format.height) > 0) { if (Util.SDK_INT >= 21) { isCodecSupported = decoderInfo.isVideoSizeAndRateSupportedV21(i, i2, format.frameRate); } else { boolean z2 = i * i2 <= MediaCodecUtil.maxH264DecodableFrameSize(); if (!z2) { StringBuilder sb = new StringBuilder(); sb.append("FalseCheck [legacyFrameSize, "); sb.append(format.width); sb.append("x"); sb.append(format.height); sb.append("] ["); sb.append(Util.DEVICE_DEBUG_INFO); sb.append(v8.i.e); } isCodecSupported = z2; } } return (isCodecSupported ? 4 : 3) | (decoderInfo.adaptive ? 16 : 8) | (decoderInfo.tunneling ? 32 : 0); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer, com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer public void onEnabled(boolean z) throws ExoPlaybackException { super.onEnabled(z); int i = getConfiguration().tunnelingAudioSessionId; this.tunnelingAudioSessionId = i; this.tunneling = i != 0; this.eventDispatcher.enabled(this.decoderCounters); this.frameReleaseTimeHelper.enable(); } @Override // com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer public void onStreamChanged(Format[] formatArr, long j) throws ExoPlaybackException { if (this.outputStreamOffsetUs == C.TIME_UNSET) { this.outputStreamOffsetUs = j; } else { int i = this.pendingOutputStreamOffsetCount; if (i == this.pendingOutputStreamOffsetsUs.length) { Log.w(TAG, "Too many stream changes, so dropping offset: " + this.pendingOutputStreamOffsetsUs[this.pendingOutputStreamOffsetCount - 1]); } else { this.pendingOutputStreamOffsetCount = i + 1; } long[] jArr = this.pendingOutputStreamOffsetsUs; int i2 = this.pendingOutputStreamOffsetCount; jArr[i2 - 1] = j; this.pendingOutputStreamSwitchTimesUs[i2 - 1] = this.lastInputTimeUs; } super.onStreamChanged(formatArr, j); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer, com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer public void onPositionReset(long j, boolean z) throws ExoPlaybackException { super.onPositionReset(j, z); clearRenderedFirstFrame(); this.initialPositionUs = C.TIME_UNSET; this.consecutiveDroppedFrameCount = 0; this.lastInputTimeUs = C.TIME_UNSET; int i = this.pendingOutputStreamOffsetCount; if (i != 0) { this.outputStreamOffsetUs = this.pendingOutputStreamOffsetsUs[i - 1]; this.pendingOutputStreamOffsetCount = 0; } if (z) { setJoiningDeadlineMs(); } else { this.joiningDeadlineMs = C.TIME_UNSET; } } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer, com.mbridge.msdk.playercommon.exoplayer2.Renderer public boolean isReady() { Surface surface; if (super.isReady() && (this.renderedFirstFrame || (((surface = this.dummySurface) != null && this.surface == surface) || getCodec() == null || this.tunneling))) { this.joiningDeadlineMs = C.TIME_UNSET; return true; } if (this.joiningDeadlineMs == C.TIME_UNSET) { return false; } if (SystemClock.elapsedRealtime() < this.joiningDeadlineMs) { return true; } this.joiningDeadlineMs = C.TIME_UNSET; return false; } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer, com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer public void onStarted() { super.onStarted(); this.droppedFrames = 0; this.droppedFrameAccumulationStartTimeMs = SystemClock.elapsedRealtime(); this.lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000; } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer, com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer public void onStopped() { this.joiningDeadlineMs = C.TIME_UNSET; maybeNotifyDroppedFrames(); super.onStopped(); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer, com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer public void onDisabled() { this.currentWidth = -1; this.currentHeight = -1; this.currentPixelWidthHeightRatio = -1.0f; this.pendingPixelWidthHeightRatio = -1.0f; this.outputStreamOffsetUs = C.TIME_UNSET; this.lastInputTimeUs = C.TIME_UNSET; this.pendingOutputStreamOffsetCount = 0; clearReportedVideoSize(); clearRenderedFirstFrame(); this.frameReleaseTimeHelper.disable(); this.tunnelingOnFrameRenderedListener = null; this.tunneling = false; try { super.onDisabled(); } finally { this.decoderCounters.ensureUpdated(); this.eventDispatcher.disabled(this.decoderCounters); } } @Override // com.mbridge.msdk.playercommon.exoplayer2.BaseRenderer, com.mbridge.msdk.playercommon.exoplayer2.PlayerMessage.Target public void handleMessage(int i, Object obj) throws ExoPlaybackException { if (i == 1) { setSurface((Surface) obj); return; } if (i == 4) { this.scalingMode = ((Integer) obj).intValue(); MediaCodec codec = getCodec(); if (codec != null) { codec.setVideoScalingMode(this.scalingMode); return; } return; } super.handleMessage(i, obj); } private void setSurface(Surface surface) throws ExoPlaybackException { if (surface == null) { Surface surface2 = this.dummySurface; if (surface2 != null) { surface = surface2; } else { MediaCodecInfo codecInfo = getCodecInfo(); if (codecInfo != null && shouldUseDummySurface(codecInfo)) { surface = DummySurface.newInstanceV17(this.context, codecInfo.secure); this.dummySurface = surface; } } } if (this.surface == surface) { if (surface == null || surface == this.dummySurface) { return; } maybeRenotifyVideoSizeChanged(); maybeRenotifyRenderedFirstFrame(); return; } this.surface = surface; int state = getState(); if (state == 1 || state == 2) { MediaCodec codec = getCodec(); if (Util.SDK_INT >= 23 && codec != null && surface != null && !this.codecNeedsSetOutputSurfaceWorkaround) { setOutputSurfaceV23(codec, surface); } else { releaseCodec(); maybeInitCodec(); } } if (surface != null && surface != this.dummySurface) { maybeRenotifyVideoSizeChanged(); clearRenderedFirstFrame(); if (state == 2) { setJoiningDeadlineMs(); return; } return; } clearReportedVideoSize(); clearRenderedFirstFrame(); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer public boolean shouldInitCodec(MediaCodecInfo mediaCodecInfo) { return this.surface != null || shouldUseDummySurface(mediaCodecInfo); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer public void configureCodec(MediaCodecInfo mediaCodecInfo, MediaCodec mediaCodec, Format format, MediaCrypto mediaCrypto) throws MediaCodecUtil.DecoderQueryException { CodecMaxValues codecMaxValues = getCodecMaxValues(mediaCodecInfo, format, getStreamFormats()); this.codecMaxValues = codecMaxValues; MediaFormat mediaFormat = getMediaFormat(format, codecMaxValues, this.deviceNeedsAutoFrcWorkaround, this.tunnelingAudioSessionId); if (this.surface == null) { Assertions.checkState(shouldUseDummySurface(mediaCodecInfo)); if (this.dummySurface == null) { this.dummySurface = DummySurface.newInstanceV17(this.context, mediaCodecInfo.secure); } this.surface = this.dummySurface; } mediaCodec.configure(mediaFormat, this.surface, mediaCrypto, 0); if (Util.SDK_INT < 23 || !this.tunneling) { return; } this.tunnelingOnFrameRenderedListener = new OnFrameRenderedListenerV23(mediaCodec); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer public int canKeepCodec(MediaCodec mediaCodec, MediaCodecInfo mediaCodecInfo, Format format, Format format2) { if (!areAdaptationCompatible(mediaCodecInfo.adaptive, format, format2)) { return 0; } int i = format2.width; CodecMaxValues codecMaxValues = this.codecMaxValues; if (i > codecMaxValues.width || format2.height > codecMaxValues.height || getMaxInputSize(mediaCodecInfo, format2) > this.codecMaxValues.inputSize) { return 0; } return format.initializationDataEquals(format2) ? 1 : 3; } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer @CallSuper public void releaseCodec() { try { super.releaseCodec(); this.buffersInCodecCount = 0; Surface surface = this.dummySurface; if (surface != null) { if (this.surface == surface) { this.surface = null; } surface.release(); this.dummySurface = null; } } catch (Throwable th) { this.buffersInCodecCount = 0; if (this.dummySurface != null) { Surface surface2 = this.surface; Surface surface3 = this.dummySurface; if (surface2 == surface3) { this.surface = null; } surface3.release(); this.dummySurface = null; } throw th; } } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer @CallSuper public void flushCodec() throws ExoPlaybackException { super.flushCodec(); this.buffersInCodecCount = 0; } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer public void onCodecInitialized(String str, long j, long j2) { this.eventDispatcher.decoderInitialized(str, j, j2); this.codecNeedsSetOutputSurfaceWorkaround = codecNeedsSetOutputSurfaceWorkaround(str); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer public void onInputFormatChanged(Format format) throws ExoPlaybackException { super.onInputFormatChanged(format); this.eventDispatcher.inputFormatChanged(format); this.pendingPixelWidthHeightRatio = format.pixelWidthHeightRatio; this.pendingRotationDegrees = format.rotationDegrees; } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer @CallSuper public void onQueueInputBuffer(DecoderInputBuffer decoderInputBuffer) { this.buffersInCodecCount++; this.lastInputTimeUs = Math.max(decoderInputBuffer.timeUs, this.lastInputTimeUs); if (Util.SDK_INT >= 23 || !this.tunneling) { return; } maybeNotifyRenderedFirstFrame(); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer public void onOutputFormatChanged(MediaCodec mediaCodec, MediaFormat mediaFormat) { int integer; int integer2; boolean z = mediaFormat.containsKey(KEY_CROP_RIGHT) && mediaFormat.containsKey(KEY_CROP_LEFT) && mediaFormat.containsKey(KEY_CROP_BOTTOM) && mediaFormat.containsKey(KEY_CROP_TOP); if (z) { integer = (mediaFormat.getInteger(KEY_CROP_RIGHT) - mediaFormat.getInteger(KEY_CROP_LEFT)) + 1; } else { integer = mediaFormat.getInteger("width"); } this.currentWidth = integer; if (z) { integer2 = (mediaFormat.getInteger(KEY_CROP_BOTTOM) - mediaFormat.getInteger(KEY_CROP_TOP)) + 1; } else { integer2 = mediaFormat.getInteger("height"); } this.currentHeight = integer2; float f = this.pendingPixelWidthHeightRatio; this.currentPixelWidthHeightRatio = f; if (Util.SDK_INT >= 21) { int i = this.pendingRotationDegrees; if (i == 90 || i == 270) { int i2 = this.currentWidth; this.currentWidth = integer2; this.currentHeight = i2; this.currentPixelWidthHeightRatio = 1.0f / f; } } else { this.currentUnappliedRotationDegrees = this.pendingRotationDegrees; } mediaCodec.setVideoScalingMode(this.scalingMode); } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer public boolean processOutputBuffer(long j, long j2, MediaCodec mediaCodec, ByteBuffer byteBuffer, int i, int i2, long j3, boolean z) throws ExoPlaybackException { if (this.initialPositionUs == C.TIME_UNSET) { this.initialPositionUs = j; } long j4 = j3 - this.outputStreamOffsetUs; if (z) { skipOutputBuffer(mediaCodec, i, j4); return true; } long j5 = j3 - j; if (this.surface == this.dummySurface) { if (!isBufferLate(j5)) { return false; } skipOutputBuffer(mediaCodec, i, j4); return true; } long elapsedRealtime = SystemClock.elapsedRealtime() * 1000; boolean z2 = getState() == 2; if (!this.renderedFirstFrame || (z2 && shouldForceRenderOutputBuffer(j5, elapsedRealtime - this.lastRenderTimeUs))) { if (Util.SDK_INT >= 21) { renderOutputBufferV21(mediaCodec, i, j4, System.nanoTime()); return true; } renderOutputBuffer(mediaCodec, i, j4); return true; } if (z2 && j != this.initialPositionUs) { long nanoTime = System.nanoTime(); long adjustReleaseTime = this.frameReleaseTimeHelper.adjustReleaseTime(j3, ((j5 - (elapsedRealtime - j2)) * 1000) + nanoTime); long j6 = (adjustReleaseTime - nanoTime) / 1000; if (shouldDropBuffersToKeyframe(j6, j2) && maybeDropBuffersToKeyframe(mediaCodec, i, j4, j)) { return false; } if (shouldDropOutputBuffer(j6, j2)) { dropOutputBuffer(mediaCodec, i, j4); return true; } if (Util.SDK_INT >= 21) { if (j6 < 50000) { renderOutputBufferV21(mediaCodec, i, j4, adjustReleaseTime); return true; } } else if (j6 < WorkRequest.DEFAULT_BACKOFF_DELAY_MILLIS) { if (j6 > 11000) { try { Thread.sleep((j6 - WorkRequest.MIN_BACKOFF_MILLIS) / 1000); } catch (InterruptedException unused) { Thread.currentThread().interrupt(); return false; } } renderOutputBuffer(mediaCodec, i, j4); return true; } } return false; } @Override // com.mbridge.msdk.playercommon.exoplayer2.mediacodec.MediaCodecRenderer @CallSuper public void onProcessedOutputBuffer(long j) { this.buffersInCodecCount--; while (true) { int i = this.pendingOutputStreamOffsetCount; if (i == 0 || j < this.pendingOutputStreamSwitchTimesUs[0]) { return; } long[] jArr = this.pendingOutputStreamOffsetsUs; this.outputStreamOffsetUs = jArr[0]; int i2 = i - 1; this.pendingOutputStreamOffsetCount = i2; System.arraycopy(jArr, 1, jArr, 0, i2); long[] jArr2 = this.pendingOutputStreamSwitchTimesUs; System.arraycopy(jArr2, 1, jArr2, 0, this.pendingOutputStreamOffsetCount); } } public boolean shouldDropOutputBuffer(long j, long j2) { return isBufferLate(j); } public boolean shouldDropBuffersToKeyframe(long j, long j2) { return isBufferVeryLate(j); } public boolean shouldForceRenderOutputBuffer(long j, long j2) { return isBufferLate(j) && j2 > 100000; } public void skipOutputBuffer(MediaCodec mediaCodec, int i, long j) { TraceUtil.beginSection("skipVideoBuffer"); mediaCodec.releaseOutputBuffer(i, false); TraceUtil.endSection(); this.decoderCounters.skippedOutputBufferCount++; } public void dropOutputBuffer(MediaCodec mediaCodec, int i, long j) { TraceUtil.beginSection("dropVideoBuffer"); mediaCodec.releaseOutputBuffer(i, false); TraceUtil.endSection(); updateDroppedBufferCounters(1); } public boolean maybeDropBuffersToKeyframe(MediaCodec mediaCodec, int i, long j, long j2) throws ExoPlaybackException { int skipSource = skipSource(j2); if (skipSource == 0) { return false; } this.decoderCounters.droppedToKeyframeCount++; updateDroppedBufferCounters(this.buffersInCodecCount + skipSource); flushCodec(); return true; } public void updateDroppedBufferCounters(int i) { DecoderCounters decoderCounters = this.decoderCounters; decoderCounters.droppedBufferCount += i; this.droppedFrames += i; int i2 = this.consecutiveDroppedFrameCount + i; this.consecutiveDroppedFrameCount = i2; decoderCounters.maxConsecutiveDroppedBufferCount = Math.max(i2, decoderCounters.maxConsecutiveDroppedBufferCount); if (this.droppedFrames >= this.maxDroppedFramesToNotify) { maybeNotifyDroppedFrames(); } } public void renderOutputBuffer(MediaCodec mediaCodec, int i, long j) { maybeNotifyVideoSizeChanged(); TraceUtil.beginSection("releaseOutputBuffer"); mediaCodec.releaseOutputBuffer(i, true); TraceUtil.endSection(); this.lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000; this.decoderCounters.renderedOutputBufferCount++; this.consecutiveDroppedFrameCount = 0; maybeNotifyRenderedFirstFrame(); } @TargetApi(21) public void renderOutputBufferV21(MediaCodec mediaCodec, int i, long j, long j2) { maybeNotifyVideoSizeChanged(); TraceUtil.beginSection("releaseOutputBuffer"); mediaCodec.releaseOutputBuffer(i, j2); TraceUtil.endSection(); this.lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000; this.decoderCounters.renderedOutputBufferCount++; this.consecutiveDroppedFrameCount = 0; maybeNotifyRenderedFirstFrame(); } private boolean shouldUseDummySurface(MediaCodecInfo mediaCodecInfo) { return Util.SDK_INT >= 23 && !this.tunneling && !codecNeedsSetOutputSurfaceWorkaround(mediaCodecInfo.name) && (!mediaCodecInfo.secure || DummySurface.isSecureSupported(this.context)); } private void setJoiningDeadlineMs() { this.joiningDeadlineMs = this.allowedJoiningTimeMs > 0 ? SystemClock.elapsedRealtime() + this.allowedJoiningTimeMs : C.TIME_UNSET; } private void clearRenderedFirstFrame() { MediaCodec codec; this.renderedFirstFrame = false; if (Util.SDK_INT < 23 || !this.tunneling || (codec = getCodec()) == null) { return; } this.tunnelingOnFrameRenderedListener = new OnFrameRenderedListenerV23(codec); } public void maybeNotifyRenderedFirstFrame() { if (this.renderedFirstFrame) { return; } this.renderedFirstFrame = true; this.eventDispatcher.renderedFirstFrame(this.surface); } private void maybeRenotifyRenderedFirstFrame() { if (this.renderedFirstFrame) { this.eventDispatcher.renderedFirstFrame(this.surface); } } private void maybeNotifyVideoSizeChanged() { int i = this.currentWidth; if (i == -1 && this.currentHeight == -1) { return; } if (this.reportedWidth == i && this.reportedHeight == this.currentHeight && this.reportedUnappliedRotationDegrees == this.currentUnappliedRotationDegrees && this.reportedPixelWidthHeightRatio == this.currentPixelWidthHeightRatio) { return; } this.eventDispatcher.videoSizeChanged(i, this.currentHeight, this.currentUnappliedRotationDegrees, this.currentPixelWidthHeightRatio); this.reportedWidth = this.currentWidth; this.reportedHeight = this.currentHeight; this.reportedUnappliedRotationDegrees = this.currentUnappliedRotationDegrees; this.reportedPixelWidthHeightRatio = this.currentPixelWidthHeightRatio; } private void maybeRenotifyVideoSizeChanged() { int i = this.reportedWidth; if (i == -1 && this.reportedHeight == -1) { return; } this.eventDispatcher.videoSizeChanged(i, this.reportedHeight, this.reportedUnappliedRotationDegrees, this.reportedPixelWidthHeightRatio); } private void maybeNotifyDroppedFrames() { if (this.droppedFrames > 0) { long elapsedRealtime = SystemClock.elapsedRealtime(); this.eventDispatcher.droppedFrames(this.droppedFrames, elapsedRealtime - this.droppedFrameAccumulationStartTimeMs); this.droppedFrames = 0; this.droppedFrameAccumulationStartTimeMs = elapsedRealtime; } } @TargetApi(23) private static void setOutputSurfaceV23(MediaCodec mediaCodec, Surface surface) { mediaCodec.setOutputSurface(surface); } @TargetApi(21) private static void configureTunnelingV21(MediaFormat mediaFormat, int i) { mediaFormat.setFeatureEnabled("tunneled-playback", true); mediaFormat.setInteger("audio-session-id", i); } @SuppressLint({"InlinedApi"}) public MediaFormat getMediaFormat(Format format, CodecMaxValues codecMaxValues, boolean z, int i) { MediaFormat mediaFormat = new MediaFormat(); mediaFormat.setString("mime", format.sampleMimeType); mediaFormat.setInteger("width", format.width); mediaFormat.setInteger("height", format.height); MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData); MediaFormatUtil.maybeSetFloat(mediaFormat, "frame-rate", format.frameRate); MediaFormatUtil.maybeSetInteger(mediaFormat, "rotation-degrees", format.rotationDegrees); MediaFormatUtil.maybeSetColorInfo(mediaFormat, format.colorInfo); mediaFormat.setInteger("max-width", codecMaxValues.width); mediaFormat.setInteger("max-height", codecMaxValues.height); MediaFormatUtil.maybeSetInteger(mediaFormat, "max-input-size", codecMaxValues.inputSize); if (Util.SDK_INT >= 23) { mediaFormat.setInteger(HandleInvocationsFromAdViewer.KEY_DOWNLOAD_PRIORITY, 0); } if (z) { mediaFormat.setInteger("auto-frc", 0); } if (i != 0) { configureTunnelingV21(mediaFormat, i); } return mediaFormat; } public CodecMaxValues getCodecMaxValues(MediaCodecInfo mediaCodecInfo, Format format, Format[] formatArr) throws MediaCodecUtil.DecoderQueryException { int i = format.width; int i2 = format.height; int maxInputSize = getMaxInputSize(mediaCodecInfo, format); if (formatArr.length == 1) { return new CodecMaxValues(i, i2, maxInputSize); } boolean z = false; for (Format format2 : formatArr) { if (areAdaptationCompatible(mediaCodecInfo.adaptive, format, format2)) { int i3 = format2.width; z |= i3 == -1 || format2.height == -1; i = Math.max(i, i3); i2 = Math.max(i2, format2.height); maxInputSize = Math.max(maxInputSize, getMaxInputSize(mediaCodecInfo, format2)); } } if (z) { Log.w(TAG, "Resolutions unknown. Codec max resolution: " + i + "x" + i2); Point codecMaxSize = getCodecMaxSize(mediaCodecInfo, format); if (codecMaxSize != null) { i = Math.max(i, codecMaxSize.x); i2 = Math.max(i2, codecMaxSize.y); maxInputSize = Math.max(maxInputSize, getMaxInputSize(mediaCodecInfo, format.sampleMimeType, i, i2)); Log.w(TAG, "Codec max resolution adjusted to: " + i + "x" + i2); } } return new CodecMaxValues(i, i2, maxInputSize); } private static Point getCodecMaxSize(MediaCodecInfo mediaCodecInfo, Format format) throws MediaCodecUtil.DecoderQueryException { int i = format.height; int i2 = format.width; boolean z = i > i2; int i3 = z ? i : i2; if (z) { i = i2; } float f = i / i3; for (int i4 : STANDARD_LONG_EDGE_VIDEO_PX) { int i5 = (int) (i4 * f); if (i4 <= i3 || i5 <= i) { break; } if (Util.SDK_INT >= 21) { int i6 = z ? i5 : i4; if (!z) { i4 = i5; } Point alignVideoSizeV21 = mediaCodecInfo.alignVideoSizeV21(i6, i4); if (mediaCodecInfo.isVideoSizeAndRateSupportedV21(alignVideoSizeV21.x, alignVideoSizeV21.y, format.frameRate)) { return alignVideoSizeV21; } } else { int ceilDivide = Util.ceilDivide(i4, 16) * 16; int ceilDivide2 = Util.ceilDivide(i5, 16) * 16; if (ceilDivide * ceilDivide2 <= MediaCodecUtil.maxH264DecodableFrameSize()) { int i7 = z ? ceilDivide2 : ceilDivide; if (!z) { ceilDivide = ceilDivide2; } return new Point(i7, ceilDivide); } } } return null; } private static int getMaxInputSize(MediaCodecInfo mediaCodecInfo, Format format) { if (format.maxInputSize != -1) { int size = format.initializationData.size(); int i = 0; for (int i2 = 0; i2 < size; i2++) { i += format.initializationData.get(i2).length; } return format.maxInputSize + i; } return getMaxInputSize(mediaCodecInfo, format.sampleMimeType, format.width, format.height); } /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */ private static int getMaxInputSize(MediaCodecInfo mediaCodecInfo, String str, int i, int i2) { char c; int i3; if (i == -1 || i2 == -1) { return -1; } str.hashCode(); int i4 = 4; switch (str.hashCode()) { case -1664118616: if (str.equals(MimeTypes.VIDEO_H263)) { c = 0; break; } c = 65535; break; case -1662541442: if (str.equals("video/hevc")) { c = 1; break; } c = 65535; break; case 1187890754: if (str.equals(MimeTypes.VIDEO_MP4V)) { c = 2; break; } c = 65535; break; case 1331836730: if (str.equals("video/avc")) { c = 3; break; } c = 65535; break; case 1599127256: if (str.equals(MimeTypes.VIDEO_VP8)) { c = 4; break; } c = 65535; break; case 1599127257: if (str.equals(MimeTypes.VIDEO_VP9)) { c = 5; break; } c = 65535; break; default: c = 65535; break; } switch (c) { case 0: case 2: case 4: i3 = i * i2; i4 = 2; break; case 1: case 5: i3 = i * i2; break; case 3: String str2 = Util.MODEL; if (!"BRAVIA 4K 2015".equals(str2) && (!"Amazon".equals(Util.MANUFACTURER) || (!"KFSOWI".equals(str2) && (!"AFTS".equals(str2) || !mediaCodecInfo.secure)))) { i3 = Util.ceilDivide(i, 16) * Util.ceilDivide(i2, 16) * 256; i4 = 2; break; } break; } return -1; } private static boolean areAdaptationCompatible(boolean z, Format format, Format format2) { return format.sampleMimeType.equals(format2.sampleMimeType) && format.rotationDegrees == format2.rotationDegrees && (z || (format.width == format2.width && format.height == format2.height)) && Util.areEqual(format.colorInfo, format2.colorInfo); } private static boolean deviceNeedsAutoFrcWorkaround() { return Util.SDK_INT <= 22 && "foster".equals(Util.DEVICE) && "NVIDIA".equals(Util.MANUFACTURER); } /* JADX WARN: Removed duplicated region for block: B:23:0x05cb A[ADDED_TO_REGION] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public boolean codecNeedsSetOutputSurfaceWorkaround(java.lang.String r7) { /* Method dump skipped, instructions count: 2212 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: com.mbridge.msdk.playercommon.exoplayer2.video.MediaCodecVideoRenderer.codecNeedsSetOutputSurfaceWorkaround(java.lang.String):boolean"); } public static final class CodecMaxValues { public final int height; public final int inputSize; public final int width; public CodecMaxValues(int i, int i2, int i3) { this.width = i; this.height = i2; this.inputSize = i3; } } @TargetApi(23) public final class OnFrameRenderedListenerV23 implements MediaCodec.OnFrameRenderedListener { private OnFrameRenderedListenerV23(MediaCodec mediaCodec) { mediaCodec.setOnFrameRenderedListener(this, new Handler()); } @Override // android.media.MediaCodec.OnFrameRenderedListener public final void onFrameRendered(@NonNull MediaCodec mediaCodec, long j, long j2) { MediaCodecVideoRenderer mediaCodecVideoRenderer = MediaCodecVideoRenderer.this; if (this != mediaCodecVideoRenderer.tunnelingOnFrameRenderedListener) { return; } mediaCodecVideoRenderer.maybeNotifyRenderedFirstFrame(); } } }