Effect: Implement isNoOp on GlEffect interfaces.

Also, allow isNoOp to default to false without the TODO, so that implementations
of isNoOp must opt-in to implementing the override in order to be considered for
skipping the effect (ex. for transcoding in Transformer).

PiperOrigin-RevId: 511223540
This commit is contained in:
huangdarwin 2023-02-21 17:32:12 +00:00 committed by Andrew Lewis
parent 17b3a2133b
commit cb7a8d2d03
5 changed files with 24 additions and 4 deletions

View File

@ -21,6 +21,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.opengl.Matrix; import android.opengl.Matrix;
import androidx.annotation.FloatRange; import androidx.annotation.FloatRange;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.util.Arrays;
/** Modifies brightness of an input frame. */ /** Modifies brightness of an input frame. */
public class Brightness implements RgbMatrix { public class Brightness implements RgbMatrix {
@ -31,7 +32,8 @@ public class Brightness implements RgbMatrix {
* Modifies brightness by adding a constant value to red, green, and blue values. * Modifies brightness by adding a constant value to red, green, and blue values.
* *
* @param brightness The constant value to add to red, green, and blue values. Should be greater * @param brightness The constant value to add to red, green, and blue values. Should be greater
* than or equal to -1f, and less than or equal to 1f. * than or equal to {@code -1f}, and less than or equal to {@code 1f}. {@code 0} means to
* leave brightness unchanged.
*/ */
public Brightness(@FloatRange(from = -1, to = 1) float brightness) { public Brightness(@FloatRange(from = -1, to = 1) float brightness) {
checkArgument( checkArgument(
@ -51,4 +53,9 @@ public class Brightness implements RgbMatrix {
checkArgument(!useHdr, "HDR is not supported."); checkArgument(!useHdr, "HDR is not supported.");
return rgbMatrix; return rgbMatrix;
} }
@Override
public boolean isNoOp(int inputWidth, int inputHeight) {
return Arrays.equals(rgbMatrix, GlUtil.create4x4IdentityMatrix());
}
} }

View File

@ -44,4 +44,9 @@ public class Contrast implements GlEffect {
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return new ContrastShaderProgram(context, this, useHdr); return new ContrastShaderProgram(context, this, useHdr);
} }
@Override
public boolean isNoOp(int inputWidth, int inputHeight) {
return contrast == 0f;
}
} }

View File

@ -49,9 +49,6 @@ public interface GlEffect extends Effect {
* @param inputHeight The input frame height, in pixels. * @param inputHeight The input frame height, in pixels.
*/ */
default boolean isNoOp(int inputWidth, int inputHeight) { default boolean isNoOp(int inputWidth, int inputHeight) {
// TODO(b/265927935): Generalize this logic by implementing this method on all
// subclasses, and deleting the default implementation here. Otherwise, some no-op effects may
// not be properly detected or handled.
return false; return false;
} }
} }

View File

@ -116,4 +116,9 @@ public class HslAdjustment implements GlEffect {
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return new HslShaderProgram(context, /* hslAdjustment= */ this, useHdr); return new HslShaderProgram(context, /* hslAdjustment= */ this, useHdr);
} }
@Override
public boolean isNoOp(int inputWidth, int inputHeight) {
return hueAdjustmentDegrees == 0f && saturationAdjustment == 0f && lightnessAdjustment == 0f;
}
} }

View File

@ -22,6 +22,7 @@ import android.opengl.Matrix;
import androidx.annotation.FloatRange; import androidx.annotation.FloatRange;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.Arrays;
/** Scales the red, green, and blue color channels of a frame. */ /** Scales the red, green, and blue color channels of a frame. */
public final class RgbAdjustment implements RgbMatrix { public final class RgbAdjustment implements RgbMatrix {
@ -98,4 +99,9 @@ public final class RgbAdjustment implements RgbMatrix {
public float[] getMatrix(long presentationTimeUs, boolean useHdr) { public float[] getMatrix(long presentationTimeUs, boolean useHdr) {
return rgbMatrix; return rgbMatrix;
} }
@Override
public boolean isNoOp(int inputWidth, int inputHeight) {
return Arrays.equals(rgbMatrix, GlUtil.create4x4IdentityMatrix());
}
} }