@@ -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