OSDN Git Service

camera2: Release surface in ImageReader#close and fix legacy cleanup
authorRuben Brunk <rubenbrunk@google.com>
Fri, 13 Mar 2015 03:54:03 +0000 (20:54 -0700)
committerRuben Brunk <rubenbrunk@google.com>
Tue, 17 Mar 2015 17:49:29 +0000 (17:49 +0000)
Bug: 19694090
Change-Id: I344ad707dbd414db023e4770769b5237bd3bbb4e

core/java/android/hardware/camera2/legacy/LegacyCameraDevice.java
core/java/android/hardware/camera2/legacy/LegacyExceptionUtils.java
core/java/android/hardware/camera2/legacy/RequestThreadManager.java
core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp
media/java/android/media/ImageReader.java

index 367a078..b5a019d 100644 (file)
@@ -292,6 +292,10 @@ public class LegacyCameraDevice implements AutoCloseable {
                     Log.e(TAG, "configureOutputs - null outputs are not allowed");
                     return BAD_VALUE;
                 }
+                if (!output.isValid()) {
+                    Log.e(TAG, "configureOutputs - invalid output surfaces are not allowed");
+                    return BAD_VALUE;
+                }
                 StreamConfigurationMap streamConfigurations = mStaticCharacteristics.
                         get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
 
@@ -522,7 +526,7 @@ public class LegacyCameraDevice implements AutoCloseable {
      * @return the width and height of the surface
      *
      * @throws NullPointerException if the {@code surface} was {@code null}
-     * @throws IllegalStateException if the {@code surface} was invalid
+     * @throws BufferQueueAbandonedException if the {@code surface} was invalid
      */
     public static Size getSurfaceSize(Surface surface) throws BufferQueueAbandonedException {
         checkNotNull(surface);
index 7e0c01b..4b7cfbf 100644 (file)
@@ -60,7 +60,7 @@ public class LegacyExceptionUtils {
             case CameraBinderDecorator.NO_ERROR: {
                 return CameraBinderDecorator.NO_ERROR;
             }
-            case CameraBinderDecorator.ENODEV: {
+            case CameraBinderDecorator.BAD_VALUE: {
                 throw new BufferQueueAbandonedException();
             }
         }
index f1f2f0c..70471a5 100644 (file)
@@ -501,6 +501,10 @@ public class RequestThreadManager {
             return;
         }
         for(Surface s : surfaces) {
+            if (s == null || !s.isValid()) {
+                Log.w(TAG, "Jpeg surface is invalid, skipping...");
+                continue;
+            }
             try {
                 LegacyCameraDevice.setSurfaceFormat(s, LegacyMetadataMapper.HAL_PIXEL_FORMAT_BLOB);
             } catch (LegacyExceptionUtils.BufferQueueAbandonedException e) {
index 0a6fb9d..8f38ae5 100644 (file)
@@ -373,8 +373,7 @@ static sp<ANativeWindow> getNativeWindow(JNIEnv* env, jobject surface) {
         return NULL;
     }
     if (anw == NULL) {
-        jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
-                "Surface had no valid native window.");
+        ALOGE("%s: Surface had no valid native window.", __FUNCTION__);
         return NULL;
     }
     return anw;
index 8d6a588..a965e2b 100644 (file)
@@ -443,6 +443,7 @@ public class ImageReader implements AutoCloseable {
     @Override
     public void close() {
         setOnImageAvailableListener(null, null);
+        if (mSurface != null) mSurface.release();
         nativeClose();
     }