Skip to content

Commit

Permalink
Effect: Rename TextureProcessor to ShaderProgram.
Browse files Browse the repository at this point in the history
Also, replace instances of "texture processor" to "shader program", with capitalization retained.

PiperOrigin-RevId: 507515655
  • Loading branch information
dway123 authored and microkatz committed Feb 8, 2023
1 parent af25905 commit 659b107
Show file tree
Hide file tree
Showing 41 changed files with 531 additions and 550 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

import android.content.Context;
import android.opengl.GLES20;
import com.google.android.exoplayer2.effect.SingleFrameGlTextureProcessor;
import com.google.android.exoplayer2.effect.SingleFrameGlShaderProgram;
import com.google.android.exoplayer2.util.FrameProcessingException;
import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil;
import com.google.android.exoplayer2.util.Size;
import java.io.IOException;

/**
* A {@link SingleFrameGlTextureProcessor} that periodically dims the frames such that pixels are
* A {@link SingleFrameGlShaderProgram} that periodically dims the frames such that pixels are
* darker the further they are away from the frame center.
*/
/* package */ final class PeriodicVignetteProcessor extends SingleFrameGlTextureProcessor {
/* package */ final class PeriodicVignetteShaderProgram extends SingleFrameGlShaderProgram {

private static final String VERTEX_SHADER_PATH = "vertex_shader_copy_es2.glsl";
private static final String FRAGMENT_SHADER_PATH = "fragment_shader_vignette_es2.glsl";
Expand Down Expand Up @@ -61,7 +61,7 @@
* @param outerRadius The radius after which all pixels are black.
* @throws FrameProcessingException If a problem occurs while reading shader files.
*/
public PeriodicVignetteProcessor(
public PeriodicVignetteShaderProgram(
Context context,
boolean useHdr,
float centerX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import com.google.android.exoplayer2.effect.Contrast;
import com.google.android.exoplayer2.effect.DrawableOverlay;
import com.google.android.exoplayer2.effect.GlEffect;
import com.google.android.exoplayer2.effect.GlTextureProcessor;
import com.google.android.exoplayer2.effect.GlShaderProgram;
import com.google.android.exoplayer2.effect.HslAdjustment;
import com.google.android.exoplayer2.effect.OverlayEffect;
import com.google.android.exoplayer2.effect.OverlaySettings;
Expand Down Expand Up @@ -415,7 +415,7 @@ private ImmutableList<Effect> createVideoEffectsFromBundle(Bundle bundle)
(GlEffect)
(Context context, boolean useHdr) -> {
try {
return (GlTextureProcessor)
return (GlShaderProgram)
constructor.newInstance(
context,
useHdr,
Expand All @@ -425,7 +425,7 @@ private ImmutableList<Effect> createVideoEffectsFromBundle(Bundle bundle)
/* outputStreamName= */ "output_video");
} catch (Exception e) {
runOnUiThread(() -> showToast(R.string.no_media_pipe_error));
throw new RuntimeException("Failed to load MediaPipe processor", e);
throw new RuntimeException("Failed to load MediaPipeShaderProgram", e);
}
});
} catch (Exception e) {
Expand Down Expand Up @@ -496,7 +496,7 @@ private ImmutableList<Effect> createVideoEffectsFromBundle(Bundle bundle)
effects.add(
(GlEffect)
(Context context, boolean useHdr) ->
new PeriodicVignetteProcessor(
new PeriodicVignetteShaderProgram(
context,
useHdr,
bundle.getFloat(ConfigurationActivity.PERIODIC_VIGNETTE_CENTER_X),
Expand Down
2 changes: 1 addition & 1 deletion demos/transformer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<string name="select_audio_effects" translatable="false">Add audio effects</string>
<string name="select_video_effects" translatable="false">Add video effects</string>
<string name="periodic_vignette_options" translatable="false">Periodic vignette options</string>
<string name="no_media_pipe_error" translatable="false">Failed to load MediaPipe processor. Check the README for instructions.</string>
<string name="no_media_pipe_error" translatable="false">Failed to load MediaPipeShaderProgram. Check the README for instructions.</string>
<string name="transform" translatable="false">Transform</string>
<string name="debug_preview" translatable="false">Debug preview:</string>
<string name="debug_preview_not_available" translatable="false">No debug preview available.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import android.opengl.EGL14;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.effect.GlTextureProcessor;
import com.google.android.exoplayer2.effect.GlShaderProgram;
import com.google.android.exoplayer2.effect.TextureInfo;
import com.google.android.exoplayer2.util.FrameProcessingException;
import com.google.android.exoplayer2.util.LibraryLoader;
Expand All @@ -43,9 +43,9 @@
import java.util.concurrent.Future;

/** Runs a MediaPipe graph on input frames. */
/* package */ final class MediaPipeProcessor implements GlTextureProcessor {
/* package */ final class MediaPipeShaderProgram implements GlShaderProgram {

private static final String THREAD_NAME = "Demo:MediaPipeProcessor";
private static final String THREAD_NAME = "Demo:MediaPipeShaderProgram";
private static final long RELEASE_WAIT_TIME_MS = 100;
private static final long RETRY_WAIT_TIME_MS = 1;

Expand Down Expand Up @@ -80,11 +80,11 @@ protected void loadLibrary(String name) {
private boolean acceptedFrame;

/**
* Creates a new texture processor that wraps a MediaPipe graph.
* Creates a new shader program that wraps a MediaPipe graph.
*
* <p>If {@code isSingleFrameGraph} is {@code false}, the {@code MediaPipeProcessor} may waste CPU
* time by continuously attempting to queue input frames to MediaPipe until they are accepted or
* waste memory if MediaPipe accepts and stores many frames internally.
* <p>If {@code isSingleFrameGraph} is {@code false}, the {@code MediaPipeShaderProgram} may waste
* CPU time by continuously attempting to queue input frames to MediaPipe until they are accepted
* or waste memory if MediaPipe accepts and stores many frames internally.
*
* @param context The {@link Context}.
* @param useHdr Whether input textures come from an HDR source. If {@code true}, colors will be
Expand All @@ -95,16 +95,16 @@ protected void loadLibrary(String name) {
* @param inputStreamName Name of the input video stream in the graph.
* @param outputStreamName Name of the input video stream in the graph.
*/
public MediaPipeProcessor(
public MediaPipeShaderProgram(
Context context,
boolean useHdr,
String graphName,
boolean isSingleFrameGraph,
String inputStreamName,
String outputStreamName) {
checkState(LOADER.isAvailable());
// TODO(b/227624622): Confirm whether MediaPipeProcessor could support HDR colors.
checkArgument(!useHdr, "MediaPipeProcessor does not support HDR colors.");
// TODO(b/227624622): Confirm whether MediaPipeShaderProgram could support HDR colors.
checkArgument(!useHdr, "MediaPipeShaderProgram does not support HDR colors.");

this.isSingleFrameGraph = isSingleFrameGraph;
singleThreadExecutorService =
Expand Down Expand Up @@ -233,7 +233,7 @@ public void releaseOutputFrame(TextureInfo outputTexture) {

@Override
public void flush() {
// TODO(b/238302341) Support seeking in MediaPipeProcessor.
// TODO(b/238302341) Support seeking in MediaPipeShaderProgram.
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public static void checkGlError() throws GlException {
*/
private static void assertValidTextureSize(int width, int height) throws GlException {
// TODO(b/201293185): Consider handling adjustments for sizes > GL_MAX_TEXTURE_SIZE
// (ex. downscaling appropriately) in a texture processor instead of asserting incorrect
// (ex. downscaling appropriately) in a shader program instead of asserting incorrect
// values.
// For valid GL sizes, see:
// https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glTexImage2D.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.junit.runner.RunWith;

/**
* Pixel test for contrast adjustment via {@link ContrastProcessor}.
* Pixel test for contrast adjustment via {@link ContrastShaderProgram}.
*
* <p>Expected images are taken from an emulator, so tests on different emulators or physical
* devices may fail. To test on other devices, please increase the {@link
Expand All @@ -71,7 +71,7 @@ public class ContrastPixelTest {
private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull EGLSurface placeholderEglSurface;
private @MonotonicNonNull SingleFrameGlTextureProcessor contrastProcessor;
private @MonotonicNonNull SingleFrameGlShaderProgram contrastShaderProgram;
private int inputTexId;
private int inputWidth;
private int inputHeight;
Expand All @@ -90,22 +90,22 @@ public void createGlObjects() throws Exception {

@After
public void release() throws GlUtil.GlException, FrameProcessingException {
if (contrastProcessor != null) {
contrastProcessor.release();
if (contrastShaderProgram != null) {
contrastShaderProgram.release();
}
GlUtil.destroyEglContext(eglDisplay, eglContext);
}

@Test
public void drawFrame_noContrastChange_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_noContrastChange";
contrastProcessor =
new Contrast(/* contrast= */ 0.0f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
contrastShaderProgram =
new Contrast(/* contrast= */ 0.0f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);

contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
contrastShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

Expand All @@ -118,9 +118,9 @@ public void drawFrame_noContrastChange_leavesFrameUnchanged() throws Exception {
@Test
public void drawFrame_minimumContrast_producesAllGrayFrame() throws Exception {
String testId = "drawFrame_minimumContrast";
contrastProcessor =
new Contrast(/* contrast= */ -1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
contrastShaderProgram =
new Contrast(/* contrast= */ -1.0f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Bitmap expectedBitmap =
createArgb8888BitmapWithSolidColor(
Expand All @@ -129,7 +129,7 @@ public void drawFrame_minimumContrast_producesAllGrayFrame() throws Exception {
Color.rgb(
OPENGL_NEUTRAL_RGB_VALUE, OPENGL_NEUTRAL_RGB_VALUE, OPENGL_NEUTRAL_RGB_VALUE));

contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
contrastShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

Expand All @@ -143,13 +143,13 @@ public void drawFrame_minimumContrast_producesAllGrayFrame() throws Exception {
public void drawFrame_decreaseContrast_decreasesPixelsGreaterEqual128IncreasesBelow()
throws Exception {
String testId = "drawFrame_decreaseContrast";
contrastProcessor =
new Contrast(/* contrast= */ -0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
contrastShaderProgram =
new Contrast(/* contrast= */ -0.75f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Bitmap expectedBitmap = readBitmap(DECREASE_CONTRAST_PNG_ASSET_PATH);

contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
contrastShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

Expand All @@ -163,13 +163,13 @@ public void drawFrame_decreaseContrast_decreasesPixelsGreaterEqual128IncreasesBe
public void drawFrame_increaseContrast_increasesPixelsGreaterEqual128DecreasesBelow()
throws Exception {
String testId = "drawFrame_increaseContrast";
contrastProcessor =
new Contrast(/* contrast= */ 0.75f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
contrastShaderProgram =
new Contrast(/* contrast= */ 0.75f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Bitmap expectedBitmap = readBitmap(INCREASE_CONTRAST_PNG_ASSET_PATH);

contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
contrastShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

Expand All @@ -182,13 +182,13 @@ public void drawFrame_increaseContrast_increasesPixelsGreaterEqual128DecreasesBe
@Test
public void drawFrame_maximumContrast_pixelEither0or255() throws Exception {
String testId = "drawFrame_maximumContrast";
contrastProcessor =
new Contrast(/* contrast= */ 1.0f).toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = contrastProcessor.configure(inputWidth, inputHeight);
contrastShaderProgram =
new Contrast(/* contrast= */ 1.0f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = contrastShaderProgram.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Bitmap expectedBitmap = readBitmap(MAXIMUM_CONTRAST_PNG_ASSET_PATH);

contrastProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
contrastShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public final class CropPixelTest {

private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlTextureProcessor cropTextureProcessor;
private @MonotonicNonNull SingleFrameGlShaderProgram cropShaderProgram;
private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId;
private int inputWidth;
Expand All @@ -83,8 +83,8 @@ public void createGlObjects() throws IOException, GlUtil.GlException {

@After
public void release() throws GlUtil.GlException, FrameProcessingException {
if (cropTextureProcessor != null) {
cropTextureProcessor.release();
if (cropShaderProgram != null) {
cropShaderProgram.release();
}
if (eglContext != null && eglDisplay != null) {
GlUtil.destroyEglContext(eglDisplay, eglContext);
Expand All @@ -94,14 +94,14 @@ public void release() throws GlUtil.GlException, FrameProcessingException {
@Test
public void drawFrame_noEdits_matchesGoldenFile() throws Exception {
String testId = "drawFrame_noEdits";
cropTextureProcessor =
cropShaderProgram =
new Crop(/* left= */ -1, /* right= */ 1, /* bottom= */ -1, /* top= */ 1)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = cropShaderProgram.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);

cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
cropShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

Expand All @@ -115,14 +115,14 @@ public void drawFrame_noEdits_matchesGoldenFile() throws Exception {
@Test
public void drawFrame_cropSmaller_matchesGoldenFile() throws Exception {
String testId = "drawFrame_cropSmaller";
cropTextureProcessor =
cropShaderProgram =
new Crop(/* left= */ -.9f, /* right= */ .1f, /* bottom= */ -1f, /* top= */ .5f)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = cropShaderProgram.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Bitmap expectedBitmap = readBitmap(CROP_SMALLER_PNG_ASSET_PATH);

cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
cropShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

Expand All @@ -136,14 +136,14 @@ public void drawFrame_cropSmaller_matchesGoldenFile() throws Exception {
@Test
public void drawFrame_cropLarger_matchesGoldenFile() throws Exception {
String testId = "drawFrame_cropLarger";
cropTextureProcessor =
cropShaderProgram =
new Crop(/* left= */ -2f, /* right= */ 2f, /* bottom= */ -1f, /* top= */ 2f)
.toGlTextureProcessor(context, /* useHdr= */ false);
Size outputSize = cropTextureProcessor.configure(inputWidth, inputHeight);
.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = cropShaderProgram.configure(inputWidth, inputHeight);
setupOutputTexture(outputSize.getWidth(), outputSize.getHeight());
Bitmap expectedBitmap = readBitmap(CROP_LARGER_PNG_ASSET_PATH);

cropTextureProcessor.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
cropShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private ImmutableList<Long> waitForFrameReleaseAndGetReleaseTimesNs(int expected
}

/** Produces blank frames with the given timestamps. */
private static final class BlankFrameProducer implements GlTextureProcessor {
private static final class BlankFrameProducer implements GlShaderProgram {

private @MonotonicNonNull TextureInfo blankTexture;
private @MonotonicNonNull OutputListener outputListener;
Expand Down
Loading

0 comments on commit 659b107

Please sign in to comment.