Skip to content

Commit 60c5b71

Browse files
psanketiAndroid (Google) Code Review
authored andcommitted
Merge "Crash in SurfaceTextureTarget filter open" into jb-dev
2 parents 255cb77 + 22f2a87 commit 60c5b71

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public void prepare(FilterContext context) {
162162
@Override
163163
public synchronized void open(FilterContext context) {
164164
// Set up SurfaceTexture internals
165+
if (mSurfaceTexture == null) {
166+
Log.e(TAG, "SurfaceTexture is null!!");
167+
throw new RuntimeException("Could not register SurfaceTexture: " + mSurfaceTexture);
168+
}
165169
mSurfaceId = context.getGLEnvironment().registerSurfaceTexture(
166170
mSurfaceTexture, mScreenWidth, mScreenHeight);
167171
if (mSurfaceId <= 0) {
@@ -170,19 +174,24 @@ public synchronized void open(FilterContext context) {
170174
}
171175

172176

177+
// Once the surface is unregistered, we still need the surfacetexture reference.
178+
// That is because when the the filter graph stops and starts again, the app
179+
// may not set the mSurfaceTexture again on the filter. In some cases, the app
180+
// may not even know that the graph has re-started. So it is difficult to enforce
181+
// that condition on an app using this filter. The only case where we need
182+
// to let go of the mSurfaceTexure reference is when the app wants to shut
183+
// down the graph on purpose, such as in the disconnect call.
173184
@Override
174185
public synchronized void close(FilterContext context) {
175186
if (mSurfaceId > 0) {
176187
context.getGLEnvironment().unregisterSurfaceId(mSurfaceId);
177188
mSurfaceId = -1;
178-
// Once the surface is unregistered, remove the surfacetexture reference.
179-
// The surfaceId could not have been valid without a valid surfacetexture.
180-
mSurfaceTexture = null;
181189
}
182190
}
183191

184192
// This should be called from the client side when the surfacetexture is no longer
185193
// valid. e.g. from onPause() in the application using the filter graph.
194+
// In this case, we need to let go of our surfacetexture reference.
186195
public synchronized void disconnect(FilterContext context) {
187196
if (mLogVerbose) Log.v(TAG, "disconnect");
188197
if (mSurfaceTexture == null) {

0 commit comments

Comments
 (0)