Android SurfaceTextureHelper: Avoid crashing if size hasn't been set

SurfaceTextureHelper currently crashes if an OES texture is produced
before setTextureSize() has been called. This is annoying if the texture
size is not easily known beforehand. A real world example is MediaPlayer
that provides the video size with an asynchronous call to
setOnVideoSizeChangedListener(), but that might happen after the first
texture is produced on some devices.

This CL waits with delivering frames until the size has been sent,
rather than crashing.

Bug: webrtc:10709
Change-Id: I5d9ce542e0edaafe1153fd5fe7d64dba86d7e33c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/140080
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28151}
This commit is contained in:
Magnus Jedvert 2019-06-04 11:11:11 +02:00 committed by Commit Bot
parent f4c7ab1bb2
commit 31f18e164e

View file

@ -205,6 +205,7 @@ public class SurfaceTextureHelper {
handler.post(() -> {
this.textureWidth = textureWidth;
this.textureHeight = textureHeight;
tryDeliverTextureFrame();
});
}
@ -286,6 +287,12 @@ public class SurfaceTextureHelper {
if (isQuitting || !hasPendingTexture || isTextureInUse || listener == null) {
return;
}
if (textureWidth == 0 || textureHeight == 0) {
// Information about the resolution needs to be provided by a call to setTextureSize() before
// frames are produced.
Logging.w(TAG, "Texture size has not been set.");
return;
}
isTextureInUse = true;
hasPendingTexture = false;
@ -297,9 +304,6 @@ public class SurfaceTextureHelper {
if (timestampAligner != null) {
timestampNs = timestampAligner.translateTimestamp(timestampNs);
}
if (textureWidth == 0 || textureHeight == 0) {
throw new RuntimeException("Texture size has not been set.");
}
final VideoFrame.Buffer buffer =
new TextureBufferImpl(textureWidth, textureHeight, TextureBuffer.Type.OES, oesTextureId,
RendererCommon.convertMatrixToAndroidGraphicsMatrix(transformMatrix), handler,