From 36bf4f817b66f01ffad7b155f839b6db3a40ed4b Mon Sep 17 00:00:00 2001 From: Sai Krishna Date: Wed, 6 Jan 2021 16:53:09 +0530 Subject: [PATCH 1/5] wip error handler for surface creation --- sdk/android/api/org/webrtc/EglError.java | 5 +++ sdk/android/api/org/webrtc/EglRenderer.java | 32 +++++++++++++------ .../api/org/webrtc/SurfaceEglRenderer.java | 4 +++ .../api/org/webrtc/SurfaceViewRenderer.java | 8 +++++ .../src/java/org/webrtc/EglBase14.java | 3 ++ 5 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 sdk/android/api/org/webrtc/EglError.java diff --git a/sdk/android/api/org/webrtc/EglError.java b/sdk/android/api/org/webrtc/EglError.java new file mode 100644 index 0000000000..4e61f64bee --- /dev/null +++ b/sdk/android/api/org/webrtc/EglError.java @@ -0,0 +1,5 @@ +package org.webrtc; + +public interface EglError { + public void onSurfaceCreationFailed(Exception exception); +} diff --git a/sdk/android/api/org/webrtc/EglRenderer.java b/sdk/android/api/org/webrtc/EglRenderer.java index d0a1d98b2b..41f4df0ae3 100644 --- a/sdk/android/api/org/webrtc/EglRenderer.java +++ b/sdk/android/api/org/webrtc/EglRenderer.java @@ -64,17 +64,25 @@ public synchronized void setSurface(Object surface) { // TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression. @SuppressWarnings("NoSynchronizedMethodCheck") public synchronized void run() { - if (surface != null && eglBase != null && !eglBase.hasSurface()) { - if (surface instanceof Surface) { - eglBase.createSurface((Surface) surface); - } else if (surface instanceof SurfaceTexture) { - eglBase.createSurface((SurfaceTexture) surface); + try { + if (surface != null && eglBase != null && !eglBase.hasSurface()) { + if (surface instanceof Surface) { + eglBase.createSurface((Surface) surface); + } else if (surface instanceof SurfaceTexture) { + eglBase.createSurface((SurfaceTexture) surface); + } else { + throw new IllegalStateException("Invalid surface: " + surface); + } + eglBase.makeCurrent(); + // Necessary for YUV frames with odd width. + GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); + } + } catch (Exception e) { + if (eglError != null) { + eglError.onSurfaceCreationFailed(e); } else { - throw new IllegalStateException("Invalid surface: " + surface); + throw e; } - eglBase.makeCurrent(); - // Necessary for YUV frames with odd width. - GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); } } } @@ -99,6 +107,7 @@ public synchronized void run() { // EGL and GL resources for drawing YUV/OES textures. After initilization, these are only accessed // from the render thread. @Nullable private EglBase eglBase; + private EglError eglError; private final VideoFrameDrawer frameDrawer = new VideoFrameDrawer(); @Nullable private RendererCommon.GlDrawer drawer; private final Matrix drawMatrix = new Matrix(); @@ -157,6 +166,11 @@ public EglRenderer(String name) { this.name = name; } + public EglRenderer(String name, EglError eglError) { + this.name = name; + this.eglError = eglError; + } + /** * Initialize this class, sharing resources with |sharedContext|. The custom |drawer| will be used * for drawing frames on the EGLSurface. This class is responsible for calling release() on diff --git a/sdk/android/api/org/webrtc/SurfaceEglRenderer.java b/sdk/android/api/org/webrtc/SurfaceEglRenderer.java index 350a4cb51a..9e28eabe1d 100644 --- a/sdk/android/api/org/webrtc/SurfaceEglRenderer.java +++ b/sdk/android/api/org/webrtc/SurfaceEglRenderer.java @@ -41,6 +41,10 @@ public SurfaceEglRenderer(String name) { super(name); } + public SurfaceEglRenderer(String name, EglError eglError) { + super(name, eglError); + } + /** * Initialize this class, sharing resources with |sharedContext|. The custom |drawer| will be used * for drawing frames on the EGLSurface. This class is responsible for calling release() on diff --git a/sdk/android/api/org/webrtc/SurfaceViewRenderer.java b/sdk/android/api/org/webrtc/SurfaceViewRenderer.java index c39416c3e1..3312971125 100644 --- a/sdk/android/api/org/webrtc/SurfaceViewRenderer.java +++ b/sdk/android/api/org/webrtc/SurfaceViewRenderer.java @@ -52,6 +52,14 @@ public SurfaceViewRenderer(Context context) { getHolder().addCallback(eglRenderer); } + public SurfaceViewRenderer(Context context, EglError eglError) { + super(context); + this.resourceName = getResourceName(); + eglRenderer = new SurfaceEglRenderer(resourceName, eglError); + getHolder().addCallback(this); + getHolder().addCallback(eglRenderer); + } + /** * Standard View constructor. In order to render something, you must first call init(). */ diff --git a/sdk/android/src/java/org/webrtc/EglBase14.java b/sdk/android/src/java/org/webrtc/EglBase14.java index 404c3a6e29..f4a50da2af 100644 --- a/sdk/android/src/java/org/webrtc/EglBase14.java +++ b/sdk/android/src/java/org/webrtc/EglBase14.java @@ -93,6 +93,9 @@ private void createSurfaceInternal(Object surface) { throw new RuntimeException("Already has an EGLSurface"); } int[] surfaceAttribs = {EGL14.EGL_NONE}; + //added for testing purpose + throw new RuntimeException( + "Failed to create window surface: 0x0x3004"); eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig, surface, surfaceAttribs, 0); if (eglSurface == EGL14.EGL_NO_SURFACE) { throw new RuntimeException( From 3002ca0a1af83e66cd0ea66f298715431701b7bf Mon Sep 17 00:00:00 2001 From: Sai Krishna Date: Wed, 6 Jan 2021 17:20:06 +0530 Subject: [PATCH 2/5] wip fix unreachable statement --- sdk/android/src/java/org/webrtc/EglBase14.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sdk/android/src/java/org/webrtc/EglBase14.java b/sdk/android/src/java/org/webrtc/EglBase14.java index f4a50da2af..171e662d9f 100644 --- a/sdk/android/src/java/org/webrtc/EglBase14.java +++ b/sdk/android/src/java/org/webrtc/EglBase14.java @@ -19,10 +19,12 @@ import android.opengl.EGLExt; import android.opengl.EGLSurface; import android.os.Build; -import javax.annotation.Nullable; import android.view.Surface; + import org.webrtc.EglBase; +import javax.annotation.Nullable; + /** * Holds EGL state and utility methods for handling an EGL14 EGLContext, an EGLDisplay, * and an EGLSurface. @@ -96,11 +98,11 @@ private void createSurfaceInternal(Object surface) { //added for testing purpose throw new RuntimeException( "Failed to create window surface: 0x0x3004"); - eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig, surface, surfaceAttribs, 0); - if (eglSurface == EGL14.EGL_NO_SURFACE) { - throw new RuntimeException( - "Failed to create window surface: 0x" + Integer.toHexString(EGL14.eglGetError())); - } +// eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig, surface, surfaceAttribs, 0); +// if (eglSurface == EGL14.EGL_NO_SURFACE) { +// throw new RuntimeException( +// "Failed to create window surface: 0x" + Integer.toHexString(EGL14.eglGetError())); +// } } @Override From f64983592b295f3d632bef7ecd33b821126e7fc7 Mon Sep 17 00:00:00 2001 From: Sai Krishna Date: Wed, 6 Jan 2021 17:39:54 +0530 Subject: [PATCH 3/5] added file in gn --- sdk/android/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/android/BUILD.gn b/sdk/android/BUILD.gn index 760fd7a127..40d3a37691 100644 --- a/sdk/android/BUILD.gn +++ b/sdk/android/BUILD.gn @@ -843,6 +843,7 @@ generate_jni("generated_java_audio_jni") { rtc_android_library("video_java") { java_files = [ + "api/org/webrtc/EglError.java", "api/org/webrtc/EglRenderer.java", "api/org/webrtc/GlRectDrawer.java", "api/org/webrtc/VideoDecoderFallback.java", From 57d750869cc531e21fdbb0c8f8448b7e490858df Mon Sep 17 00:00:00 2001 From: Sai Krishna Date: Thu, 7 Jan 2021 15:21:24 +0530 Subject: [PATCH 4/5] reverted testing changes --- sdk/android/src/java/org/webrtc/EglBase14.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sdk/android/src/java/org/webrtc/EglBase14.java b/sdk/android/src/java/org/webrtc/EglBase14.java index 171e662d9f..cbed8ebedd 100644 --- a/sdk/android/src/java/org/webrtc/EglBase14.java +++ b/sdk/android/src/java/org/webrtc/EglBase14.java @@ -95,14 +95,11 @@ private void createSurfaceInternal(Object surface) { throw new RuntimeException("Already has an EGLSurface"); } int[] surfaceAttribs = {EGL14.EGL_NONE}; - //added for testing purpose - throw new RuntimeException( - "Failed to create window surface: 0x0x3004"); -// eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig, surface, surfaceAttribs, 0); -// if (eglSurface == EGL14.EGL_NO_SURFACE) { -// throw new RuntimeException( -// "Failed to create window surface: 0x" + Integer.toHexString(EGL14.eglGetError())); -// } + eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig, surface, surfaceAttribs, 0); + if (eglSurface == EGL14.EGL_NO_SURFACE) { + throw new RuntimeException( + "Failed to create window surface: 0x" + Integer.toHexString(EGL14.eglGetError())); + } } @Override From 17d83cc0b5cf6b9687001f93fbdb1ea5fbb98485 Mon Sep 17 00:00:00 2001 From: Sai Krishna Date: Thu, 7 Jan 2021 15:23:16 +0530 Subject: [PATCH 5/5] import format fix --- sdk/android/src/java/org/webrtc/EglBase14.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sdk/android/src/java/org/webrtc/EglBase14.java b/sdk/android/src/java/org/webrtc/EglBase14.java index cbed8ebedd..404c3a6e29 100644 --- a/sdk/android/src/java/org/webrtc/EglBase14.java +++ b/sdk/android/src/java/org/webrtc/EglBase14.java @@ -19,12 +19,10 @@ import android.opengl.EGLExt; import android.opengl.EGLSurface; import android.os.Build; +import javax.annotation.Nullable; import android.view.Surface; - import org.webrtc.EglBase; -import javax.annotation.Nullable; - /** * Holds EGL state and utility methods for handling an EGL14 EGLContext, an EGLDisplay, * and an EGLSurface.