Revert "Android: Generalize and make TextureBufferImpl public"
This reverts commit 28111d7fa0b94e37a5eeba616eb806c65b12560e. Reason for revert: Crashes video_quality_loopback_test. Original change's description: > Android: Generalize and make TextureBufferImpl public > > This CL generalizes TextureBufferImpl so it's useful from other contexts than > from a SurfaceTextureHelper, and fixes a bug in cropAndScale(). It also exposes > the class in the api so that clients don't have to duplicate the logic. > > Bug: None > Change-Id: Ib82aa8bee025ec14de74a7be9d91fd4e5298a248 > Reviewed-on: https://webrtc-review.googlesource.com/69819 > Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> > Commit-Queue: Magnus Jedvert <magjed@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22875} TBR=magjed@webrtc.org,sakal@webrtc.org Change-Id: Ica7fc181fec70b8b79f39f0e114eef81a03aa116 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: None Reviewed-on: https://webrtc-review.googlesource.com/70240 Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22878}
This commit is contained in:

committed by
Commit Bot

parent
f7ffd94ad2
commit
64051d4975
@ -766,11 +766,11 @@ rtc_android_library("video_api_java") {
|
||||
"api/org/webrtc/JavaI420Buffer.java",
|
||||
"api/org/webrtc/RendererCommon.java",
|
||||
"api/org/webrtc/SurfaceTextureHelper.java",
|
||||
"api/org/webrtc/TextureBufferImpl.java",
|
||||
"api/org/webrtc/YuvConverter.java",
|
||||
"api/org/webrtc/YuvHelper.java",
|
||||
"src/java/org/webrtc/EglBase10.java",
|
||||
"src/java/org/webrtc/EglBase14.java",
|
||||
"src/java/org/webrtc/TextureBufferImpl.java",
|
||||
]
|
||||
|
||||
deps = [
|
||||
|
@ -320,7 +320,12 @@ public class SurfaceTextureHelper {
|
||||
* buffer calls returnTextureFrame() when it is released.
|
||||
*/
|
||||
public TextureBuffer createTextureBuffer(int width, int height, Matrix transformMatrix) {
|
||||
return new TextureBufferImpl(width, height, TextureBuffer.Type.OES, oesTextureId,
|
||||
transformMatrix, handler, yuvConverter, this ::returnTextureFrame);
|
||||
return new TextureBufferImpl(
|
||||
width, height, TextureBuffer.Type.OES, oesTextureId, transformMatrix, this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
returnTextureFrame();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -171,10 +171,10 @@ public class VideoRenderer {
|
||||
yuvStrides[1], yuvPlanes[2], yuvStrides[2],
|
||||
() -> { VideoRenderer.renderFrameDone(this); });
|
||||
} else {
|
||||
// Note: No Handler or YuvConverter means calling toI420 will crash.
|
||||
// Note: surfaceTextureHelper being null means calling toI420 will crash.
|
||||
buffer = new TextureBufferImpl(width, height, VideoFrame.TextureBuffer.Type.OES, textureId,
|
||||
RendererCommon.convertMatrixToAndroidGraphicsMatrix(samplingMatrix), null /* handler */,
|
||||
null /* yuvConverter */, () -> VideoRenderer.renderFrameDone(this));
|
||||
RendererCommon.convertMatrixToAndroidGraphicsMatrix(samplingMatrix),
|
||||
null /* surfaceTextureHelper */, () -> { VideoRenderer.renderFrameDone(this); });
|
||||
}
|
||||
return new VideoFrame(buffer, rotationDegree, 0 /* timestampNs */);
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ import org.webrtc.VideoFrame.I420Buffer;
|
||||
import org.webrtc.VideoFrame.TextureBuffer;
|
||||
|
||||
/**
|
||||
* Class for converting OES textures to a YUV ByteBuffer. It can be constructed on any thread, but
|
||||
* should only be operated from a single thread with an active EGL context.
|
||||
* Class for converting OES textures to a YUV ByteBuffer. It should be constructed on a thread with
|
||||
* an active EGL context, and only be used from that thread.
|
||||
*/
|
||||
public class YuvConverter {
|
||||
// Vertex coordinates in Normalized Device Coordinates, i.e.
|
||||
@ -111,7 +111,7 @@ public class YuvConverter {
|
||||
// clang-format on
|
||||
|
||||
private final ThreadUtils.ThreadChecker threadChecker = new ThreadUtils.ThreadChecker();
|
||||
private final GlTextureFrameBuffer textureFrameBuffer = new GlTextureFrameBuffer(GLES20.GL_RGBA);
|
||||
private final GlTextureFrameBuffer textureFrameBuffer;
|
||||
private TextureBuffer.Type shaderTextureType;
|
||||
private GlShader shader;
|
||||
private int texMatrixLoc;
|
||||
@ -123,7 +123,8 @@ public class YuvConverter {
|
||||
* This class should be constructed on a thread that has an active EGL context.
|
||||
*/
|
||||
public YuvConverter() {
|
||||
threadChecker.detachThread();
|
||||
threadChecker.checkIsOnValidThread();
|
||||
textureFrameBuffer = new GlTextureFrameBuffer(GLES20.GL_RGBA);
|
||||
}
|
||||
|
||||
/** Converts the texture buffer to I420. */
|
||||
|
@ -11,32 +11,31 @@
|
||||
package org.webrtc;
|
||||
|
||||
import android.graphics.Matrix;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.annotation.Nullable;
|
||||
import android.os.Handler;
|
||||
|
||||
/**
|
||||
* Android texture buffer that glues together the necessary information together with a generic
|
||||
* release callback. ToI420() is implemented by providing a Handler and a YuvConverter.
|
||||
* Android texture buffer backed by a SurfaceTextureHelper's texture. The buffer calls
|
||||
* |releaseCallback| when it is released.
|
||||
*/
|
||||
public class TextureBufferImpl implements VideoFrame.TextureBuffer {
|
||||
class TextureBufferImpl implements VideoFrame.TextureBuffer {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final Type type;
|
||||
private final int id;
|
||||
private final Matrix transformMatrix;
|
||||
private final Handler toI420Handler;
|
||||
private final YuvConverter yuvConverter;
|
||||
private final SurfaceTextureHelper surfaceTextureHelper;
|
||||
private final RefCountDelegate refCountDelegate;
|
||||
|
||||
public TextureBufferImpl(int width, int height, Type type, int id, Matrix transformMatrix,
|
||||
Handler toI420Handler, YuvConverter yuvConverter, @Nullable Runnable releaseCallback) {
|
||||
SurfaceTextureHelper surfaceTextureHelper, @Nullable Runnable releaseCallback) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.transformMatrix = transformMatrix;
|
||||
this.toI420Handler = toI420Handler;
|
||||
this.yuvConverter = yuvConverter;
|
||||
this.surfaceTextureHelper = surfaceTextureHelper;
|
||||
this.refCountDelegate = new RefCountDelegate(releaseCallback);
|
||||
}
|
||||
|
||||
@ -67,8 +66,7 @@ public class TextureBufferImpl implements VideoFrame.TextureBuffer {
|
||||
|
||||
@Override
|
||||
public VideoFrame.I420Buffer toI420() {
|
||||
return ThreadUtils.invokeAtFrontUninterruptibly(
|
||||
toI420Handler, () -> yuvConverter.convert(this));
|
||||
return surfaceTextureHelper.textureToYuv(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,12 +82,17 @@ public class TextureBufferImpl implements VideoFrame.TextureBuffer {
|
||||
@Override
|
||||
public VideoFrame.Buffer cropAndScale(
|
||||
int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) {
|
||||
final Matrix newMatrix = new Matrix(transformMatrix);
|
||||
newMatrix.preTranslate(cropX / (float) width, cropY / (float) height);
|
||||
newMatrix.preScale(cropWidth / (float) width, cropHeight / (float) height);
|
||||
|
||||
retain();
|
||||
Matrix newMatrix = new Matrix(transformMatrix);
|
||||
newMatrix.postScale(cropWidth / (float) width, cropHeight / (float) height);
|
||||
newMatrix.postTranslate(cropX / (float) width, cropY / (float) height);
|
||||
|
||||
return new TextureBufferImpl(
|
||||
scaleWidth, scaleHeight, type, id, newMatrix, toI420Handler, yuvConverter, this ::release);
|
||||
scaleWidth, scaleHeight, type, id, newMatrix, surfaceTextureHelper, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
release();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user