summaryrefslogtreecommitdiffstats
path: root/media/mca
diff options
context:
space:
mode:
authorPannag Sanketi <psanketi@google.com>2012-05-07 22:51:58 -0700
committerPannag Sanketi <psanketi@google.com>2012-05-09 18:51:48 -0700
commitb939760679caa9fdd06c862cf8218cc8f4a90ef1 (patch)
tree753cfa4e05019fcb9c0a990fefd0bc2b24bc5814 /media/mca
parentd72ad2ac88ae8477a95e18a800062446a58c524d (diff)
downloadframeworks_base-b939760679caa9fdd06c862cf8218cc8f4a90ef1.zip
frameworks_base-b939760679caa9fdd06c862cf8218cc8f4a90ef1.tar.gz
frameworks_base-b939760679caa9fdd06c862cf8218cc8f4a90ef1.tar.bz2
Adding disconnect call to the SurfaceTextureTarget
Related to b/5873421. When an app using the SurfaceTextureTarget filter and the activity goes out of focus such as onPause(), the underlying surfacetexture might not be available anymore to the filter. The filter needs to be told about that so that it does try to render into the surface corresponding to the surfacetexture. For example, in Camera app, the VideoCamera activity has to let the underlying effects graph know about the disconnect in the onPause() method. Change-Id: Iee3af16715432d84fef4438d1671f4d6d261b3d7
Diffstat (limited to 'media/mca')
-rw-r--r--media/mca/filterpacks/java/android/filterpacks/videosrc/SurfaceTextureTarget.java39
1 files changed, 31 insertions, 8 deletions
diff --git a/media/mca/filterpacks/java/android/filterpacks/videosrc/SurfaceTextureTarget.java b/media/mca/filterpacks/java/android/filterpacks/videosrc/SurfaceTextureTarget.java
index 20e4b32..b023e42 100644
--- a/media/mca/filterpacks/java/android/filterpacks/videosrc/SurfaceTextureTarget.java
+++ b/media/mca/filterpacks/java/android/filterpacks/videosrc/SurfaceTextureTarget.java
@@ -110,7 +110,7 @@ public class SurfaceTextureTarget extends Filter {
}
@Override
- public void setupPorts() {
+ public synchronized void setupPorts() {
// Make sure we have a SurfaceView
if (mSurfaceTexture == null) {
throw new RuntimeException("Null SurfaceTexture passed to SurfaceTextureTarget");
@@ -158,7 +158,7 @@ public class SurfaceTextureTarget extends Filter {
}
@Override
- public void open(FilterContext context) {
+ public synchronized void open(FilterContext context) {
// Set up SurfaceTexture internals
mSurfaceId = context.getGLEnvironment().registerSurfaceTexture(
mSurfaceTexture, mScreenWidth, mScreenHeight);
@@ -169,17 +169,42 @@ public class SurfaceTextureTarget extends Filter {
@Override
- public void close(FilterContext context) {
+ public synchronized void close(FilterContext context) {
if (mSurfaceId > 0) {
context.getGLEnvironment().unregisterSurfaceId(mSurfaceId);
+ mSurfaceId = -1;
+ // Once the surface is unregistered, remove the surfacetexture reference.
+ // The surfaceId could not have been valid without a valid surfacetexture.
+ mSurfaceTexture = null;
}
}
+ // This should be called from the client side when the surfacetexture is no longer
+ // valid. e.g. from onPause() in the application using the filter graph.
+ public synchronized void disconnect(FilterContext context) {
+ if (mLogVerbose) Log.v(TAG, "disconnect");
+ if (mSurfaceTexture == null) {
+ Log.d(TAG, "SurfaceTexture is already null. Nothing to disconnect.");
+ return;
+ }
+ mSurfaceTexture = null;
+ // Make sure we unregister the surface as well if a surface was registered.
+ // There can be a situation where the surface was not registered but the
+ // surfacetexture was valid. For example, the disconnect can be called before
+ // the filter was opened. Hence, the surfaceId may not be a valid one here,
+ // and need to check for its validity.
+ if (mSurfaceId > 0) {
+ context.getGLEnvironment().unregisterSurfaceId(mSurfaceId);
+ mSurfaceId = -1;
+ }
+ }
@Override
- public void process(FilterContext context) {
- if (mLogVerbose) Log.v(TAG, "Starting frame processing");
-
+ public synchronized void process(FilterContext context) {
+ // Surface is not registered. Nothing to render into.
+ if (mSurfaceId <= 0) {
+ return;
+ }
GLEnvironment glEnv = context.getGLEnvironment();
// Get input frame
@@ -197,8 +222,6 @@ public class SurfaceTextureTarget extends Filter {
// See if we need to copy to GPU
Frame gpuFrame = null;
- if (mLogVerbose) Log.v("SurfaceTextureTarget", "Got input format: " + input.getFormat());
-
int target = input.getFormat().getTarget();
if (target != FrameFormat.TARGET_GPU) {
gpuFrame = context.getFrameManager().duplicateFrameToTarget(input,