Commit d73c0b3c by huangdarwin Committed by tonihei

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
parent 2515e39f
...@@ -22,6 +22,7 @@ import android.opengl.Matrix; ...@@ -22,6 +22,7 @@ import android.opengl.Matrix;
import androidx.annotation.FloatRange; import androidx.annotation.FloatRange;
import androidx.media3.common.util.GlUtil; import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import java.util.Arrays;
/** Modifies brightness of an input frame. */ /** Modifies brightness of an input frame. */
@UnstableApi @UnstableApi
...@@ -33,7 +34,8 @@ public class Brightness implements RgbMatrix { ...@@ -33,7 +34,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(
...@@ -53,4 +55,9 @@ public class Brightness implements RgbMatrix { ...@@ -53,4 +55,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());
}
} }
...@@ -46,4 +46,9 @@ public class Contrast implements GlEffect { ...@@ -46,4 +46,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;
}
} }
...@@ -51,9 +51,6 @@ public interface GlEffect extends Effect { ...@@ -51,9 +51,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;
} }
} }
...@@ -118,4 +118,9 @@ public class HslAdjustment implements GlEffect { ...@@ -118,4 +118,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;
}
} }
...@@ -23,6 +23,7 @@ import androidx.annotation.FloatRange; ...@@ -23,6 +23,7 @@ import androidx.annotation.FloatRange;
import androidx.media3.common.util.GlUtil; import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
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. */
@UnstableApi @UnstableApi
...@@ -100,4 +101,9 @@ public final class RgbAdjustment implements RgbMatrix { ...@@ -100,4 +101,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());
}
} }
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