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