GL: Make ProjectionRenderer's GL Program @MonotonicNonNull.

PiperOrigin-RevId: 406385758
This commit is contained in:
huangdarwin 2021-10-29 17:16:01 +00:00 committed by tonihei
parent fa98935c06
commit c53924326d
5 changed files with 39 additions and 5 deletions

View file

@ -24,6 +24,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** /**
* Utility class to render spherical meshes for video or images. Call {@link #init()} on the GL * Utility class to render spherical meshes for video or images. Call {@link #init()} on the GL
@ -93,9 +94,9 @@ import java.nio.FloatBuffer;
private int stereoMode; private int stereoMode;
@Nullable private MeshData leftMeshData; @Nullable private MeshData leftMeshData;
@Nullable private MeshData rightMeshData; @Nullable private MeshData rightMeshData;
@Nullable private GlUtil.Program program; private GlUtil.@MonotonicNonNull Program program;
// Program related GL items. These are only valid if program is non-null. // Program related GL items. These are only valid if Program is valid.
private int mvpMatrixHandle; private int mvpMatrixHandle;
private int uTexMatrixHandle; private int uTexMatrixHandle;
private int positionHandle; private int positionHandle;
@ -195,11 +196,10 @@ import java.nio.FloatBuffer;
GLES20.glDisableVertexAttribArray(texCoordsHandle); GLES20.glDisableVertexAttribArray(texCoordsHandle);
} }
/** Cleans up the GL resources. */ /** Cleans up GL resources. */
/* package */ void shutdown() { /* package */ void shutdown() {
if (program != null) { if (program != null) {
program.delete(); program.delete();
program = null;
} }
} }

View file

@ -129,7 +129,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
projectionRenderer.draw(textureId, tempMatrix, rightEye); projectionRenderer.draw(textureId, tempMatrix, rightEye);
} }
/** Cleans up the GL resources. */ /** Cleans up GL resources. */
public void shutdown() { public void shutdown() {
projectionRenderer.shutdown(); projectionRenderer.shutdown();
} }

View file

@ -55,6 +55,7 @@ import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.text.TextOutput; import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener; import com.google.android.exoplayer2.video.VideoRendererEventListener;
@ -91,12 +92,16 @@ public final class TranscodingTransformer {
/** A builder for {@link TranscodingTransformer} instances. */ /** A builder for {@link TranscodingTransformer} instances. */
public static final class Builder { public static final class Builder {
// Mandatory field.
private @MonotonicNonNull Context context; private @MonotonicNonNull Context context;
// Optional fields.
private @MonotonicNonNull MediaSourceFactory mediaSourceFactory; private @MonotonicNonNull MediaSourceFactory mediaSourceFactory;
private Muxer.Factory muxerFactory; private Muxer.Factory muxerFactory;
private boolean removeAudio; private boolean removeAudio;
private boolean removeVideo; private boolean removeVideo;
private boolean flattenForSlowMotion; private boolean flattenForSlowMotion;
private int outputHeight;
private String outputMimeType; private String outputMimeType;
@Nullable private String audioMimeType; @Nullable private String audioMimeType;
@Nullable private String videoMimeType; @Nullable private String videoMimeType;
@ -121,6 +126,7 @@ public final class TranscodingTransformer {
this.removeAudio = transcodingTransformer.transformation.removeAudio; this.removeAudio = transcodingTransformer.transformation.removeAudio;
this.removeVideo = transcodingTransformer.transformation.removeVideo; this.removeVideo = transcodingTransformer.transformation.removeVideo;
this.flattenForSlowMotion = transcodingTransformer.transformation.flattenForSlowMotion; this.flattenForSlowMotion = transcodingTransformer.transformation.flattenForSlowMotion;
this.outputHeight = transcodingTransformer.transformation.outputHeight;
this.outputMimeType = transcodingTransformer.transformation.outputMimeType; this.outputMimeType = transcodingTransformer.transformation.outputMimeType;
this.audioMimeType = transcodingTransformer.transformation.audioMimeType; this.audioMimeType = transcodingTransformer.transformation.audioMimeType;
this.videoMimeType = transcodingTransformer.transformation.videoMimeType; this.videoMimeType = transcodingTransformer.transformation.videoMimeType;
@ -213,6 +219,21 @@ public final class TranscodingTransformer {
return this; return this;
} }
/**
* Sets the output resolution for the video, using the output height. The default value is to
* use the same height as the input. Output width will scale to preserve the input video's
* aspect ratio.
*
* <p>For example, a 1920x1440 video can be scaled to 640x480 by calling setResolution(480).
*
* @param outputHeight The output height for the video, in pixels.
* @return This builder.
*/
public Builder setResolution(int outputHeight) {
this.outputHeight = outputHeight;
return this;
}
/** /**
* Sets the MIME type of the output. The default value is {@link MimeTypes#VIDEO_MP4}. Supported * Sets the MIME type of the output. The default value is {@link MimeTypes#VIDEO_MP4}. Supported
* values are: * values are:
@ -356,6 +377,12 @@ public final class TranscodingTransformer {
checkState( checkState(
muxerFactory.supportsOutputMimeType(outputMimeType), muxerFactory.supportsOutputMimeType(outputMimeType),
"Unsupported output MIME type: " + outputMimeType); "Unsupported output MIME type: " + outputMimeType);
// TODO(ME): Test with values of 10, 100, 1000).
Log.e("TranscodingTransformer", "outputHeight = " + outputHeight);
if (outputHeight == 0) {
// TODO(ME): get output height from input video.
outputHeight = 480;
}
if (audioMimeType != null) { if (audioMimeType != null) {
checkSampleMimeType(audioMimeType); checkSampleMimeType(audioMimeType);
} }
@ -367,6 +394,7 @@ public final class TranscodingTransformer {
removeAudio, removeAudio,
removeVideo, removeVideo,
flattenForSlowMotion, flattenForSlowMotion,
outputHeight,
outputMimeType, outputMimeType,
audioMimeType, audioMimeType,
videoMimeType); videoMimeType);
@ -453,6 +481,7 @@ public final class TranscodingTransformer {
checkState( checkState(
!transformation.removeAudio || !transformation.removeVideo, !transformation.removeAudio || !transformation.removeVideo,
"Audio and video cannot both be removed."); "Audio and video cannot both be removed.");
checkState(!(transformation.removeVideo));
this.context = context; this.context = context;
this.mediaSourceFactory = mediaSourceFactory; this.mediaSourceFactory = mediaSourceFactory;
this.muxerFactory = muxerFactory; this.muxerFactory = muxerFactory;

View file

@ -24,6 +24,7 @@ import androidx.annotation.Nullable;
public final boolean removeAudio; public final boolean removeAudio;
public final boolean removeVideo; public final boolean removeVideo;
public final boolean flattenForSlowMotion; public final boolean flattenForSlowMotion;
public final int outputHeight;
public final String outputMimeType; public final String outputMimeType;
@Nullable public final String audioMimeType; @Nullable public final String audioMimeType;
@Nullable public final String videoMimeType; @Nullable public final String videoMimeType;
@ -32,12 +33,14 @@ import androidx.annotation.Nullable;
boolean removeAudio, boolean removeAudio,
boolean removeVideo, boolean removeVideo,
boolean flattenForSlowMotion, boolean flattenForSlowMotion,
int outputHeight,
String outputMimeType, String outputMimeType,
@Nullable String audioMimeType, @Nullable String audioMimeType,
@Nullable String videoMimeType) { @Nullable String videoMimeType) {
this.removeAudio = removeAudio; this.removeAudio = removeAudio;
this.removeVideo = removeVideo; this.removeVideo = removeVideo;
this.flattenForSlowMotion = flattenForSlowMotion; this.flattenForSlowMotion = flattenForSlowMotion;
this.outputHeight = outputHeight;
this.outputMimeType = outputMimeType; this.outputMimeType = outputMimeType;
this.audioMimeType = audioMimeType; this.audioMimeType = audioMimeType;
this.videoMimeType = videoMimeType; this.videoMimeType = videoMimeType;

View file

@ -297,11 +297,13 @@ public final class Transformer {
checkState( checkState(
muxerFactory.supportsOutputMimeType(outputMimeType), muxerFactory.supportsOutputMimeType(outputMimeType),
"Unsupported output MIME type: " + outputMimeType); "Unsupported output MIME type: " + outputMimeType);
int outputHeight = 0; // TODO(ME): How do we get the input height here?
Transformation transformation = Transformation transformation =
new Transformation( new Transformation(
removeAudio, removeAudio,
removeVideo, removeVideo,
flattenForSlowMotion, flattenForSlowMotion,
outputHeight,
outputMimeType, outputMimeType,
/* audioMimeType= */ null, /* audioMimeType= */ null,
/* videoMimeType= */ null); /* videoMimeType= */ null);