Move output modes to constants file

PiperOrigin-RevId: 261295173
This commit is contained in:
sofijajvc 2019-08-02 11:44:48 +01:00 committed by Oliver Woodman
parent 39317048e9
commit 4482db40e1
4 changed files with 37 additions and 24 deletions

View File

@ -137,7 +137,7 @@ public class LibvpxVideoRenderer extends BaseRenderer {
private long joiningDeadlineMs;
private Surface surface;
private VpxOutputBufferRenderer outputBufferRenderer;
private int outputMode;
@C.VideoOutputMode private int outputMode;
private boolean waitingForKeys;
private boolean inputStreamEnded;
@ -275,7 +275,7 @@ public class LibvpxVideoRenderer extends BaseRenderer {
formatQueue = new TimedValueQueue<>();
flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
outputMode = VpxDecoder.OUTPUT_MODE_NONE;
outputMode = C.VIDEO_OUTPUT_MODE_NONE;
decoderReinitializationState = REINITIALIZATION_STATE_NONE;
}
@ -349,8 +349,9 @@ public class LibvpxVideoRenderer extends BaseRenderer {
if (waitingForKeys) {
return false;
}
if (format != null && (isSourceReady() || outputBuffer != null)
&& (renderedFirstFrame || outputMode == VpxDecoder.OUTPUT_MODE_NONE)) {
if (format != null
&& (isSourceReady() || outputBuffer != null)
&& (renderedFirstFrame || outputMode == C.VIDEO_OUTPUT_MODE_NONE)) {
// Ready. If we were joining then we've now joined, so clear the joining deadline.
joiningDeadlineMs = C.TIME_UNSET;
return true;
@ -628,8 +629,8 @@ public class LibvpxVideoRenderer extends BaseRenderer {
*/
protected void renderOutputBuffer(VpxOutputBuffer outputBuffer) throws VpxDecoderException {
int bufferMode = outputBuffer.mode;
boolean renderSurface = bufferMode == VpxDecoder.OUTPUT_MODE_SURFACE_YUV && surface != null;
boolean renderYuv = bufferMode == VpxDecoder.OUTPUT_MODE_YUV && outputBufferRenderer != null;
boolean renderSurface = bufferMode == C.VIDEO_OUTPUT_MODE_SURFACE_YUV && surface != null;
boolean renderYuv = bufferMode == C.VIDEO_OUTPUT_MODE_YUV && outputBufferRenderer != null;
lastRenderTimeUs = SystemClock.elapsedRealtime() * 1000;
if (!renderYuv && !renderSurface) {
dropOutputBuffer(outputBuffer);
@ -713,12 +714,12 @@ public class LibvpxVideoRenderer extends BaseRenderer {
this.surface = surface;
this.outputBufferRenderer = outputBufferRenderer;
if (surface != null) {
outputMode = VpxDecoder.OUTPUT_MODE_SURFACE_YUV;
outputMode = C.VIDEO_OUTPUT_MODE_SURFACE_YUV;
} else {
outputMode =
outputBufferRenderer != null ? VpxDecoder.OUTPUT_MODE_YUV : VpxDecoder.OUTPUT_MODE_NONE;
outputBufferRenderer != null ? C.VIDEO_OUTPUT_MODE_YUV : C.VIDEO_OUTPUT_MODE_NONE;
}
if (outputMode != VpxDecoder.OUTPUT_MODE_NONE) {
if (outputMode != C.VIDEO_OUTPUT_MODE_NONE) {
if (decoder != null) {
decoder.setOutputMode(outputMode);
}
@ -735,7 +736,7 @@ public class LibvpxVideoRenderer extends BaseRenderer {
clearReportedVideoSize();
clearRenderedFirstFrame();
}
} else if (outputMode != VpxDecoder.OUTPUT_MODE_NONE) {
} else if (outputMode != C.VIDEO_OUTPUT_MODE_NONE) {
// The output is unchanged and non-null. If we know the video size and/or have already
// rendered to the output, report these again immediately.
maybeRenotifyVideoSizeChanged();
@ -915,7 +916,7 @@ public class LibvpxVideoRenderer extends BaseRenderer {
}
long earlyUs = outputBuffer.timeUs - positionUs;
if (outputMode == VpxDecoder.OUTPUT_MODE_NONE) {
if (outputMode == C.VIDEO_OUTPUT_MODE_NONE) {
// Skip frames in sync with playback, so we'll be at the right frame if the mode changes.
if (isBufferLate(earlyUs)) {
skipOutputBuffer(outputBuffer);

View File

@ -29,10 +29,6 @@ import java.nio.ByteBuffer;
/* package */ final class VpxDecoder
extends SimpleDecoder<VideoDecoderInputBuffer, VpxOutputBuffer, VpxDecoderException> {
public static final int OUTPUT_MODE_NONE = -1;
public static final int OUTPUT_MODE_YUV = 0;
public static final int OUTPUT_MODE_SURFACE_YUV = 1;
private static final int NO_ERROR = 0;
private static final int DECODE_ERROR = 1;
private static final int DRM_ERROR = 2;
@ -40,7 +36,7 @@ import java.nio.ByteBuffer;
private final ExoMediaCrypto exoMediaCrypto;
private final long vpxDecContext;
private volatile int outputMode;
@C.VideoOutputMode private volatile int outputMode;
/**
* Creates a VP9 decoder.
@ -87,10 +83,9 @@ import java.nio.ByteBuffer;
/**
* Sets the output mode for frames rendered by the decoder.
*
* @param outputMode The output mode. One of {@link #OUTPUT_MODE_NONE} and {@link
* #OUTPUT_MODE_YUV}.
* @param outputMode The output mode.
*/
public void setOutputMode(int outputMode) {
public void setOutputMode(@C.VideoOutputMode int outputMode) {
this.outputMode = outputMode;
}
@ -108,7 +103,7 @@ import java.nio.ByteBuffer;
protected void releaseOutputBuffer(VpxOutputBuffer buffer) {
// Decode only frames do not acquire a reference on the internal decoder buffer and thus do not
// require a call to vpxReleaseFrame.
if (outputMode == OUTPUT_MODE_SURFACE_YUV && !buffer.isDecodeOnly()) {
if (outputMode == C.VIDEO_OUTPUT_MODE_SURFACE_YUV && !buffer.isDecodeOnly()) {
vpxReleaseFrame(vpxDecContext, buffer);
}
super.releaseOutputBuffer(buffer);

View File

@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.ext.vp9;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.decoder.OutputBuffer;
import com.google.android.exoplayer2.video.ColorInfo;
import java.nio.ByteBuffer;
@ -31,7 +32,8 @@ public final class VpxOutputBuffer extends OutputBuffer {
/** Decoder private data. */
public int decoderPrivate;
public int mode;
/** Output mode. */
@C.VideoOutputMode public int mode;
/**
* RGB buffer for RGB mode.
*/
@ -60,10 +62,10 @@ public final class VpxOutputBuffer extends OutputBuffer {
* Initializes the buffer.
*
* @param timeUs The presentation timestamp for the buffer, in microseconds.
* @param mode The output mode. One of {@link VpxDecoder#OUTPUT_MODE_NONE}, {@link
* VpxDecoder#OUTPUT_MODE_YUV} and {@link VpxDecoder#OUTPUT_MODE_SURFACE_YUV}.
* @param mode The output mode. One of {@link C#VIDEO_OUTPUT_MODE_NONE}, {@link
* C#VIDEO_OUTPUT_MODE_YUV} and {@link C#VIDEO_OUTPUT_MODE_SURFACE_YUV}.
*/
public void init(long timeUs, int mode) {
public void init(long timeUs, @C.VideoOutputMode int mode) {
this.timeUs = timeUs;
this.mode = mode;
}

View File

@ -499,6 +499,21 @@ public final class C {
/** Indicates that a buffer should be decoded but not rendered. */
public static final int BUFFER_FLAG_DECODE_ONLY = 1 << 31; // 0x80000000
/**
* Video decoder output modes. Possible modes are {@link #VIDEO_OUTPUT_MODE_NONE}, {@link
* #VIDEO_OUTPUT_MODE_YUV} and {@link #VIDEO_OUTPUT_MODE_SURFACE_YUV}.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef(value = {VIDEO_OUTPUT_MODE_NONE, VIDEO_OUTPUT_MODE_YUV, VIDEO_OUTPUT_MODE_SURFACE_YUV})
public @interface VideoOutputMode {}
/** Video decoder output mode is not set. */
public static final int VIDEO_OUTPUT_MODE_NONE = -1;
/** Video decoder output mode that outputs raw 4:2:0 YUV planes. */
public static final int VIDEO_OUTPUT_MODE_YUV = 0;
/** Video decoder output mode that renders 4:2:0 YUV planes directly to a surface. */
public static final int VIDEO_OUTPUT_MODE_SURFACE_YUV = 1;
/**
* Video scaling modes for {@link MediaCodec}-based {@link Renderer}s. One of {@link
* #VIDEO_SCALING_MODE_SCALE_TO_FIT} or {@link #VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING}.