Skip to content

Commit b33c34c

Browse files
psanketiAndroid (Google) Code Review
authored andcommitted
Merge "Resolving the black screen / crash in effects" into jb-dev
2 parents 73214f6 + 2f708ce commit b33c34c

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)