Commit 51228fc7 by huangdarwin Committed by Ian Baker

Effects: Output to texture without surface in VFP.

Allow the VideoFrameProcessor to output to a texture without an output surface.

Tested by updating texture output tests to no longer output to a surface.

PiperOrigin-RevId: 527244605
parent 9842fbab
...@@ -122,7 +122,8 @@ public interface VideoFrameProcessor { ...@@ -122,7 +122,8 @@ public interface VideoFrameProcessor {
void onOutputSizeChanged(int width, int height); void onOutputSizeChanged(int width, int height);
/** /**
* Called when an output frame with the given {@code presentationTimeUs} becomes available. * Called when an output frame with the given {@code presentationTimeUs} becomes available for
* rendering.
* *
* @param presentationTimeUs The presentation time of the frame, in microseconds. * @param presentationTimeUs The presentation time of the frame, in microseconds.
*/ */
......
...@@ -112,6 +112,9 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -112,6 +112,9 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
* *
* <p>If set, the {@link VideoFrameProcessor} will output to an OpenGL texture, accessible via * <p>If set, the {@link VideoFrameProcessor} will output to an OpenGL texture, accessible via
* {@link TextureOutputListener#onTextureRendered}. Otherwise, no texture will be rendered to. * {@link TextureOutputListener#onTextureRendered}. Otherwise, no texture will be rendered to.
*
* <p>If an {@linkplain #setOutputSurfaceInfo output surface} is set, the texture output will
* be be adjusted as needed, to match the output surface's output.
*/ */
@VisibleForTesting @VisibleForTesting
@CanIgnoreReturnValue @CanIgnoreReturnValue
......
...@@ -31,7 +31,6 @@ import static com.google.common.truth.Truth.assertThat; ...@@ -31,7 +31,6 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.view.Surface; import android.view.Surface;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
...@@ -52,6 +51,7 @@ import com.google.android.exoplayer2.util.VideoFrameProcessingException; ...@@ -52,6 +51,7 @@ import com.google.android.exoplayer2.util.VideoFrameProcessingException;
import com.google.android.exoplayer2.video.ColorInfo; import com.google.android.exoplayer2.video.ColorInfo;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -306,16 +306,10 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest { ...@@ -306,16 +306,10 @@ public final class DefaultVideoFrameProcessorTextureOutputPixelTest {
private @MonotonicNonNull Bitmap outputBitmap; private @MonotonicNonNull Bitmap outputBitmap;
@Override @Override
@Nullable
public Surface getSurface(int width, int height, boolean useHighPrecisionColorComponents) { public Surface getSurface(int width, int height, boolean useHighPrecisionColorComponents) {
this.useHighPrecisionColorComponents = useHighPrecisionColorComponents; this.useHighPrecisionColorComponents = useHighPrecisionColorComponents;
int texId; return null;
try {
texId = GlUtil.createExternalTexture();
} catch (GlUtil.GlException e) {
throw new RuntimeException(e);
}
SurfaceTexture surfaceTexture = new SurfaceTexture(texId);
return new Surface(surfaceTexture);
} }
@Override @Override
......
...@@ -279,15 +279,18 @@ public final class VideoFrameProcessorTestRunner { ...@@ -279,15 +279,18 @@ public final class VideoFrameProcessorTestRunner {
new VideoFrameProcessor.Listener() { new VideoFrameProcessor.Listener() {
@Override @Override
public void onOutputSizeChanged(int width, int height) { public void onOutputSizeChanged(int width, int height) {
@Nullable
Surface outputSurface = Surface outputSurface =
bitmapReader.getSurface( bitmapReader.getSurface(
width, width,
height, height,
/* useHighPrecisionColorComponents= */ ColorInfo.isTransferHdr( /* useHighPrecisionColorComponents= */ ColorInfo.isTransferHdr(
outputColorInfo)); outputColorInfo));
if (outputSurface != null) {
checkNotNull(videoFrameProcessor) checkNotNull(videoFrameProcessor)
.setOutputSurfaceInfo(new SurfaceInfo(outputSurface, width, height)); .setOutputSurfaceInfo(new SurfaceInfo(outputSurface, width, height));
} }
}
@Override @Override
public void onOutputFrameAvailable(long presentationTimeUs) { public void onOutputFrameAvailable(long presentationTimeUs) {
...@@ -366,7 +369,8 @@ public final class VideoFrameProcessorTestRunner { ...@@ -366,7 +369,8 @@ public final class VideoFrameProcessorTestRunner {
/** Reads a {@link Bitmap} from {@link VideoFrameProcessor} output. */ /** Reads a {@link Bitmap} from {@link VideoFrameProcessor} output. */
public interface BitmapReader { public interface BitmapReader {
/** Returns the {@link VideoFrameProcessor} output {@link Surface}. */ /** Returns the {@link VideoFrameProcessor} output {@link Surface}, if one is needed. */
@Nullable
Surface getSurface(int width, int height, boolean useHighPrecisionColorComponents); Surface getSurface(int width, int height, boolean useHighPrecisionColorComponents);
/** Returns the output {@link Bitmap}. */ /** Returns the output {@link Bitmap}. */
...@@ -386,6 +390,7 @@ public final class VideoFrameProcessorTestRunner { ...@@ -386,6 +390,7 @@ public final class VideoFrameProcessorTestRunner {
@Override @Override
@SuppressLint("WrongConstant") @SuppressLint("WrongConstant")
@Nullable
public Surface getSurface(int width, int height, boolean useHighPrecisionColorComponents) { public Surface getSurface(int width, int height, boolean useHighPrecisionColorComponents) {
imageReader = imageReader =
ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, /* maxImages= */ 1); ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, /* maxImages= */ 1);
......
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