mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Adjust image input ForPixelWidthHeightRatio
PiperOrigin-RevId: 532463400
(cherry picked from commit 63ee5ccb28)
This commit is contained in:
parent
5a72333554
commit
7fdae1ad0d
4 changed files with 17 additions and 21 deletions
|
|
@ -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 androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
|
import androidx.media3.common.FrameInfo;
|
||||||
import androidx.media3.common.GlTextureInfo;
|
import androidx.media3.common.GlTextureInfo;
|
||||||
import androidx.media3.common.VideoFrameProcessingException;
|
import androidx.media3.common.VideoFrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
|
|
@ -81,10 +82,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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -126,9 +127,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(
|
||||||
|
|
@ -141,7 +143,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,7 +156,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) {
|
||||||
|
|
@ -161,8 +164,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);
|
||||||
|
|
@ -175,8 +178,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--;
|
||||||
|
|
@ -196,14 +199,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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -362,7 +362,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 androidx.media3.effect;
|
||||||
import static androidx.media3.common.util.Assertions.checkState;
|
import static androidx.media3.common.util.Assertions.checkState;
|
||||||
import static androidx.media3.common.util.Assertions.checkStateNotNull;
|
import static androidx.media3.common.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;
|
||||||
|
|
@ -115,12 +114,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
surfaceTexture.setDefaultBufferSize(width, height);
|
surfaceTexture.setDefaultBufferSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void queueInputBitmap(
|
|
||||||
Bitmap inputBitmap, long durationUs, long offsetUs, float frameRate, boolean useHdr) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Surface getInputSurface() {
|
public Surface getInputSurface() {
|
||||||
return surface;
|
return surface;
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ import androidx.media3.common.VideoFrameProcessor.OnInputFrameProcessedListener;
|
||||||
* @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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue