Skip to content

Commit 2f708ce

Browse files
committed
Resolving the black screen / crash in effects
b:/6278826 The SurfaceTextureTarget Filter was not unregistering the surface on closing leading to crashes and blank screens. Change-Id: Ia9f6fc69b92d5a5e2e1e3803969152d11528aa3d
1 parent 1b8f499 commit 2f708ce

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

media/mca/filterpacks/java/android/filterpacks/videosrc/SurfaceTextureTarget.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,22 @@ public void prepare(FilterContext context) {
160160
@Override
161161
public void open(FilterContext context) {
162162
// Set up SurfaceTexture internals
163-
mSurfaceId = context.getGLEnvironment().registerSurfaceTexture(mSurfaceTexture, mScreenWidth, mScreenHeight);
163+
mSurfaceId = context.getGLEnvironment().registerSurfaceTexture(
164+
mSurfaceTexture, mScreenWidth, mScreenHeight);
165+
if (mSurfaceId <= 0) {
166+
throw new RuntimeException("Could not register SurfaceTexture: " + mSurfaceTexture);
167+
}
164168
}
165169

170+
171+
@Override
172+
public void close(FilterContext context) {
173+
if (mSurfaceId > 0) {
174+
context.getGLEnvironment().unregisterSurfaceId(mSurfaceId);
175+
}
176+
}
177+
178+
166179
@Override
167180
public void process(FilterContext context) {
168181
if (mLogVerbose) Log.v(TAG, "Starting frame processing");
@@ -173,9 +186,11 @@ public void process(FilterContext context) {
173186
Frame input = pullInput("frame");
174187
boolean createdFrame = false;
175188

176-
float currentAspectRatio = (float)input.getFormat().getWidth() / input.getFormat().getHeight();
189+
float currentAspectRatio =
190+
(float)input.getFormat().getWidth() / input.getFormat().getHeight();
177191
if (currentAspectRatio != mAspectRatio) {
178-
if (mLogVerbose) Log.v(TAG, "New aspect ratio: " + currentAspectRatio +", previously: " + mAspectRatio);
192+
if (mLogVerbose) Log.v(TAG, "New aspect ratio: " + currentAspectRatio +
193+
", previously: " + mAspectRatio);
179194
mAspectRatio = currentAspectRatio;
180195
updateTargetRect();
181196
}

0 commit comments

Comments
 (0)