Commit 944b51f0 by tofunmi Committed by Tofunmi Adigun-Hameed

Adjust image input ForPixelWidthHeightRatio

PiperOrigin-RevId: 532463400
(cherry picked from commit a6f5d386955225c9c6f409276c4acbe00e48bd01)
parent 749dcef1
...@@ -24,6 +24,7 @@ import android.opengl.GLES20; ...@@ -24,6 +24,7 @@ import android.opengl.GLES20;
import android.opengl.GLUtils; import android.opengl.GLUtils;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.FrameInfo;
import com.google.android.exoplayer2.util.GlTextureInfo; import com.google.android.exoplayer2.util.GlTextureInfo;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -79,10 +80,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -79,10 +80,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override @Override
public void queueInputBitmap( public void queueInputBitmap(
Bitmap inputBitmap, long durationUs, long offsetUs, float frameRate, boolean useHdr) { Bitmap inputBitmap, long durationUs, FrameInfo frameInfo, float frameRate, boolean useHdr) {
videoFrameProcessingTaskExecutor.submit( videoFrameProcessingTaskExecutor.submit(
() -> { () -> {
setupBitmap(inputBitmap, durationUs, offsetUs, frameRate, useHdr); setupBitmap(inputBitmap, durationUs, frameInfo, frameRate, useHdr);
currentInputStreamEnded = false; currentInputStreamEnded = false;
}); });
} }
...@@ -124,9 +125,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -124,9 +125,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
}); });
} }
// Methods that must be called on the GL thread. // Methods that must be called on the GL thread.
private void setupBitmap( private void setupBitmap(
Bitmap bitmap, long durationUs, long offsetUs, float frameRate, boolean useHdr) Bitmap bitmap, long durationUs, FrameInfo frameInfo, float frameRate, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
if (Util.SDK_INT >= 26) { if (Util.SDK_INT >= 26) {
checkState( checkState(
...@@ -139,7 +141,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -139,7 +141,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
this.useHdr = useHdr; this.useHdr = useHdr;
int framesToAdd = round(frameRate * (durationUs / (float) C.MICROS_PER_SECOND)); int framesToAdd = round(frameRate * (durationUs / (float) C.MICROS_PER_SECOND));
double frameDurationUs = C.MICROS_PER_SECOND / frameRate; double frameDurationUs = C.MICROS_PER_SECOND / frameRate;
pendingBitmaps.add(new BitmapFrameSequenceInfo(bitmap, offsetUs, frameDurationUs, framesToAdd)); pendingBitmaps.add(
new BitmapFrameSequenceInfo(bitmap, frameInfo, frameDurationUs, framesToAdd));
maybeQueueToShaderProgram(); maybeQueueToShaderProgram();
} }
...@@ -151,7 +154,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -151,7 +154,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (framesToQueueForCurrentBitmap == 0) { if (framesToQueueForCurrentBitmap == 0) {
Bitmap bitmap = currentBitmapInfo.bitmap; Bitmap bitmap = currentBitmapInfo.bitmap;
framesToQueueForCurrentBitmap = currentBitmapInfo.numberOfFrames; framesToQueueForCurrentBitmap = currentBitmapInfo.numberOfFrames;
currentPresentationTimeUs = currentBitmapInfo.offsetUs; currentPresentationTimeUs = currentBitmapInfo.frameInfo.offsetToAddUs;
int currentTexId; int currentTexId;
try { try {
if (currentGlTextureInfo != null) { if (currentGlTextureInfo != null) {
...@@ -159,8 +162,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -159,8 +162,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
currentTexId = currentTexId =
GlUtil.createTexture( GlUtil.createTexture(
bitmap.getWidth(), currentBitmapInfo.frameInfo.width,
bitmap.getHeight(), currentBitmapInfo.frameInfo.height,
/* useHighPrecisionColorComponents= */ useHdr); /* useHighPrecisionColorComponents= */ useHdr);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, currentTexId); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, currentTexId);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, /* level= */ 0, bitmap, /* border= */ 0); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, /* level= */ 0, bitmap, /* border= */ 0);
...@@ -173,8 +176,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -173,8 +176,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
currentTexId, currentTexId,
/* fboId= */ C.INDEX_UNSET, /* fboId= */ C.INDEX_UNSET,
/* rboId= */ C.INDEX_UNSET, /* rboId= */ C.INDEX_UNSET,
bitmap.getWidth(), currentBitmapInfo.frameInfo.width,
bitmap.getHeight()); currentBitmapInfo.frameInfo.height);
} }
framesToQueueForCurrentBitmap--; framesToQueueForCurrentBitmap--;
downstreamShaderProgramCapacity--; downstreamShaderProgramCapacity--;
...@@ -194,14 +197,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -194,14 +197,14 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** Information to generate all the frames associated with a specific {@link Bitmap}. */ /** Information to generate all the frames associated with a specific {@link Bitmap}. */
private static final class BitmapFrameSequenceInfo { private static final class BitmapFrameSequenceInfo {
public final Bitmap bitmap; public final Bitmap bitmap;
public final long offsetUs; public final FrameInfo frameInfo;
public final double frameDurationUs; public final double frameDurationUs;
public final int numberOfFrames; public final int numberOfFrames;
public BitmapFrameSequenceInfo( public BitmapFrameSequenceInfo(
Bitmap bitmap, long offsetUs, double frameDurationUs, int numberOfFrames) { Bitmap bitmap, FrameInfo frameInfo, double frameDurationUs, int numberOfFrames) {
this.bitmap = bitmap; this.bitmap = bitmap;
this.offsetUs = offsetUs; this.frameInfo = frameInfo;
this.frameDurationUs = frameDurationUs; this.frameDurationUs = frameDurationUs;
this.numberOfFrames = numberOfFrames; this.numberOfFrames = numberOfFrames;
} }
......
...@@ -360,7 +360,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -360,7 +360,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
.queueInputBitmap( .queueInputBitmap(
inputBitmap, inputBitmap,
durationUs, durationUs,
checkNotNull(nextInputFrameInfo).offsetToAddUs, checkNotNull(nextInputFrameInfo),
frameRate, frameRate,
/* useHdr= */ false); /* useHdr= */ false);
hasRefreshedNextInputFrameInfo = false; hasRefreshedNextInputFrameInfo = false;
......
...@@ -18,7 +18,6 @@ package com.google.android.exoplayer2.effect; ...@@ -18,7 +18,6 @@ package com.google.android.exoplayer2.effect;
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;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
import android.view.Surface; import android.view.Surface;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -116,12 +115,6 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -116,12 +115,6 @@ import java.util.concurrent.atomic.AtomicInteger;
} }
@Override @Override
public void queueInputBitmap(
Bitmap inputBitmap, long durationUs, long offsetUs, float frameRate, boolean useHdr) {
throw new UnsupportedOperationException();
}
@Override
public Surface getInputSurface() { public Surface getInputSurface() {
return surface; return surface;
} }
......
...@@ -49,7 +49,7 @@ import com.google.android.exoplayer2.util.VideoFrameProcessor.OnInputFrameProces ...@@ -49,7 +49,7 @@ import com.google.android.exoplayer2.util.VideoFrameProcessor.OnInputFrameProces
* @param useHdr Whether input and/or output colors are HDR. * @param useHdr Whether input and/or output colors are HDR.
*/ */
default void queueInputBitmap( default void queueInputBitmap(
Bitmap inputBitmap, long durationUs, long offsetUs, float frameRate, boolean useHdr) { Bitmap inputBitmap, long durationUs, FrameInfo frameInfo, float frameRate, boolean useHdr) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
......
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