FrameProcessor: Add checks to ensure width and height are positive.

Negative and zero values should be disallowed.

PiperOrigin-RevId: 441757246
This commit is contained in:
huangdarwin 2022-04-14 15:36:26 +01:00 committed by Ian Baker
parent ef96932ea1
commit 96b501409d
5 changed files with 16 additions and 0 deletions

View File

@ -167,6 +167,9 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor {
@Override @Override
public void initialize(int inputTexId, int inputWidth, int inputHeight) throws IOException { public void initialize(int inputTexId, int inputWidth, int inputHeight) throws IOException {
checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive");
size = new Size(inputWidth, inputHeight); size = new Size(inputWidth, inputHeight);
// TODO(b/205002913): check the loaded program is consistent with the attributes and uniforms // TODO(b/205002913): check the loaded program is consistent with the attributes and uniforms
// expected in the code. // expected in the code.

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.transformer; package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import android.content.Context; import android.content.Context;
@ -61,6 +62,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override @Override
public void initialize(int inputTexId, int inputWidth, int inputHeight) throws IOException { public void initialize(int inputTexId, int inputWidth, int inputHeight) throws IOException {
checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive");
size = new Size(inputWidth, inputHeight); size = new Size(inputWidth, inputHeight);
// TODO(b/205002913): check the loaded program is consistent with the attributes and uniforms // TODO(b/205002913): check the loaded program is consistent with the attributes and uniforms
// expected in the code. // expected in the code.

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.transformer; package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Assertions.checkState; import static com.google.android.exoplayer2.util.Assertions.checkState;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
@ -86,6 +87,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
List<GlFrameProcessor> frameProcessors, List<GlFrameProcessor> frameProcessors,
boolean enableExperimentalHdrEditing) boolean enableExperimentalHdrEditing)
throws TransformationException { throws TransformationException {
checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive");
if (pixelWidthHeightRatio != 1.0f) { if (pixelWidthHeightRatio != 1.0f) {
// TODO(b/211782176): Consider implementing support for non-square pixels. // TODO(b/211782176): Consider implementing support for non-square pixels.
throw TransformationException.createForFrameProcessorChain( throw TransformationException.createForFrameProcessorChain(

View File

@ -282,6 +282,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor {
/* package */ void configureOutputSizeAndTransformationMatrix(int inputWidth, int inputHeight) { /* package */ void configureOutputSizeAndTransformationMatrix(int inputWidth, int inputHeight) {
checkArgument(inputWidth > 0, "inputWidth must be positive"); checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive"); checkArgument(inputHeight > 0, "inputHeight must be positive");
transformationMatrix = new Matrix(); transformationMatrix = new Matrix();
outputWidth = inputWidth; outputWidth = inputWidth;
outputHeight = inputHeight; outputHeight = inputHeight;

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.transformer; package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
@ -146,6 +147,9 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor {
@EnsuresNonNull("adjustedTransformationMatrix") @EnsuresNonNull("adjustedTransformationMatrix")
@VisibleForTesting // Allows robolectric testing of output size calculation without OpenGL. @VisibleForTesting // Allows robolectric testing of output size calculation without OpenGL.
/* package */ void configureOutputSizeAndTransformationMatrix(int inputWidth, int inputHeight) { /* package */ void configureOutputSizeAndTransformationMatrix(int inputWidth, int inputHeight) {
checkArgument(inputWidth > 0, "inputWidth must be positive");
checkArgument(inputHeight > 0, "inputHeight must be positive");
adjustedTransformationMatrix = new Matrix(transformationMatrix); adjustedTransformationMatrix = new Matrix(transformationMatrix);
if (transformationMatrix.isIdentity()) { if (transformationMatrix.isIdentity()) {