Commit d4725838 by olly Committed by kim-vde

Remove reflection and call Surface.setFrameRate directly

PiperOrigin-RevId: 336838201
parent 5e1c96ad
...@@ -60,7 +60,6 @@ import com.google.android.exoplayer2.util.MimeTypes; ...@@ -60,7 +60,6 @@ import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.util.TraceUtil;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener.EventDispatcher; import com.google.android.exoplayer2.video.VideoRendererEventListener.EventDispatcher;
import java.lang.reflect.Method;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -104,24 +103,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -104,24 +103,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
/** Magic frame render timestamp that indicates the EOS in tunneling mode. */ /** Magic frame render timestamp that indicates the EOS in tunneling mode. */
private static final long TUNNELING_EOS_PRESENTATION_TIME_US = Long.MAX_VALUE; private static final long TUNNELING_EOS_PRESENTATION_TIME_US = Long.MAX_VALUE;
// TODO: Remove reflection once we target API level 30.
@Nullable private static final Method surfaceSetFrameRateMethod;
static {
@Nullable Method setFrameRateMethod = null;
if (Util.SDK_INT >= 30) {
try {
setFrameRateMethod = Surface.class.getMethod("setFrameRate", float.class, int.class);
} catch (NoSuchMethodException e) {
// Do nothing.
}
}
surfaceSetFrameRateMethod = setFrameRateMethod;
}
// TODO: Remove these constants and use those defined by Surface once we target API level 30.
private static final int SURFACE_FRAME_RATE_COMPATIBILITY_DEFAULT = 0;
private static final int SURFACE_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE = 1;
private static boolean evaluatedDeviceNeedsSetOutputSurfaceWorkaround; private static boolean evaluatedDeviceNeedsSetOutputSurfaceWorkaround;
private static boolean deviceNeedsSetOutputSurfaceWorkaround; private static boolean deviceNeedsSetOutputSurfaceWorkaround;
...@@ -136,9 +117,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -136,9 +117,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
private boolean codecNeedsSetOutputSurfaceWorkaround; private boolean codecNeedsSetOutputSurfaceWorkaround;
private boolean codecHandlesHdr10PlusOutOfBandMetadata; private boolean codecHandlesHdr10PlusOutOfBandMetadata;
private Surface surface; @Nullable private Surface surface;
private float surfaceFrameRate; private float surfaceFrameRate;
private Surface dummySurface; @Nullable private Surface dummySurface;
private boolean haveReportedFirstFrameRenderedForCurrentSurface; private boolean haveReportedFirstFrameRenderedForCurrentSurface;
@VideoScalingMode private int scalingMode; @VideoScalingMode private int scalingMode;
private boolean renderedFirstFrameAfterReset; private boolean renderedFirstFrameAfterReset;
...@@ -1116,19 +1097,12 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -1116,19 +1097,12 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
@RequiresApi(30) @RequiresApi(30)
private void setSurfaceFrameRateV30(Surface surface, float frameRate) { private static void setSurfaceFrameRateV30(Surface surface, float frameRate) {
if (surfaceSetFrameRateMethod == null) {
Log.e(TAG, "Failed to call Surface.setFrameRate (method does not exist)");
}
int compatibility = int compatibility =
frameRate == 0 frameRate == 0
? SURFACE_FRAME_RATE_COMPATIBILITY_DEFAULT ? Surface.FRAME_RATE_COMPATIBILITY_DEFAULT
: SURFACE_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE; : Surface.FRAME_RATE_COMPATIBILITY_FIXED_SOURCE;
try { surface.setFrameRate(frameRate, compatibility);
surfaceSetFrameRateMethod.invoke(surface, frameRate, compatibility);
} catch (Exception e) {
Log.e(TAG, "Failed to call Surface.setFrameRate", e);
}
} }
private boolean shouldUseDummySurface(MediaCodecInfo codecInfo) { private boolean shouldUseDummySurface(MediaCodecInfo codecInfo) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment