OSDN Git Service

[OC] Gcam OneCamera implementation.
authorSascha Haeberling <haeberling@google.com>
Tue, 5 Aug 2014 17:53:08 +0000 (10:53 -0700)
committerSascha Haeberling <haeberling@google.com>
Wed, 13 Aug 2014 00:28:26 +0000 (17:28 -0700)
  Bug: 16948752

Change-Id: I0160de117c4ff7024e0d546f594b5777847d1833

src/com/android/camera/CaptureModule.java
src/com/android/camera/app/CameraApp.java
src/com/android/camera/one/OneCamera.java
src/com/android/camera/one/OneCameraManager.java
src/com/android/camera/one/v2/OneCameraManagerImpl.java
src/com/android/camera/util/CameraUtil.java
src_pd/com/android/camera/one/v2/OneCameraCreator.java

index 71eba68..30b24cf 100644 (file)
@@ -69,6 +69,8 @@ import com.android.camera.util.UsageStatistics;
 import com.android.camera2.R;
 import com.android.ex.camera2.portability.CameraAgent.CameraProxy;
 
+import java.io.File;
+
 /**
  * New Capture module that is made to support photo and video capture on top of
  * the OneCamera API, to transparently support GCam.
@@ -221,7 +223,7 @@ public class CaptureModule extends CameraModule
     /** Current orientation of the device. */
     private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
     /** Current zoom value. */
-    private float mZoomValue = 1f;
+    private final float mZoomValue = 1f;
 
     /** True if in AF tap-to-focus sequence. */
     private boolean mTapToFocusInProgress = false;
@@ -274,12 +276,8 @@ public class CaptureModule extends CameraModule
     /** TODO: This is N5 specific. */
     public static final float FULLSCREEN_ASPECT_RATIO = 16 / 9f;
 
-    /**
-     * Desires aspect ratio of the final image.
-     * <p>
-     * TODO: Can't we deduct this from the final image's resolution?
-     */
-    private Float mFinalAspectRatio;
+    /** A directory to store debug information in during development. */
+    private final File mDebugDataDir;
 
     /** CLEAN UP START */
     // private SoundPool mSoundPool;
@@ -304,6 +302,7 @@ public class CaptureModule extends CameraModule
         mContext = mAppController.getAndroidContext();
         mSettingsManager = mAppController.getSettingsManager();
         mSettingsManager.addListener(this);
+        mDebugDataDir = mContext.getExternalCacheDir();
     }
 
     @Override
@@ -359,6 +358,7 @@ public class CaptureModule extends CameraModule
         params.orientation = getOrientation();
         params.flashMode = getFlashModeFromSettings();
         params.heading = mHeading;
+        params.debugDataFolder = mDebugDataDir;
 
         // Take the picture.
         mCamera.takePicture(params, session);
@@ -674,6 +674,7 @@ public class CaptureModule extends CameraModule
      * <li>Updates AF UI if tap-to-focus is not in progress.</li>
      * </ol>
      */
+    @Override
     public void onFocusStatusUpdate(final AutoFocusMode mode, final AutoFocusState state) {
         Log.v(TAG, "AF status is mode:" + mode + " state:" + state);
 
@@ -914,10 +915,8 @@ public class CaptureModule extends CameraModule
                 mPreviewTranformationMatrix.postTranslate(wOffset, hOffset);
                 mAppController.updatePreviewTransformFullscreen(mPreviewTranformationMatrix,
                         aspectRatio);
-                mFinalAspectRatio = aspectRatio;
             } else {
                 mAppController.updatePreviewTransform(mPreviewTranformationMatrix);
-                mFinalAspectRatio = null;
                 mAppController.getCameraAppUI().hideLetterboxing();
             }
             // if (mGcamProxy != null) {
index b169b3d..4bcf83c 100644 (file)
@@ -18,12 +18,10 @@ package com.android.camera.app;
 
 import android.app.Application;
 import android.app.NotificationManager;
-import android.content.ContentResolver;
 import android.content.Context;
 
 import com.android.camera.MediaSaverImpl;
 import com.android.camera.debug.LogHelper;
-import com.android.camera.app.MotionManager;
 import com.android.camera.processing.ProcessingServiceManager;
 import com.android.camera.remote.RemoteShutterListener;
 import com.android.camera.session.CaptureSessionManager;
index d179c72..555f6cb 100644 (file)
@@ -23,6 +23,8 @@ import android.view.Surface;
 import com.android.camera.session.CaptureSession;
 import com.android.camera.util.Size;
 
+import java.io.File;
+
 /**
  * OneCamera is a camera API tailored around our Google Camera application
  * needs. It's not a general purpose API but instead offers an API with exactly
@@ -201,6 +203,9 @@ public interface OneCamera {
         public Flash flashMode = Flash.AUTO;
         // TODO: Add Location
 
+        /** Set this to provide a debug folder for this capture. */
+        public File debugDataFolder;
+
         /**
          * Checks whether all required values are set. If one is missing, it
          * throws a {@link RuntimeException}.
index 2440d6a..a61b706 100644 (file)
 
 package com.android.camera.one;
 
-import android.app.Activity;
 import android.content.Context;
 import android.hardware.camera2.CameraAccessException;
 import android.hardware.camera2.CameraCharacteristics;
 import android.hardware.camera2.CameraManager;
 
+import com.android.camera.CameraActivity;
 import com.android.camera.debug.Log;
 import com.android.camera.debug.Log.Tag;
 import com.android.camera.one.OneCamera.Facing;
@@ -65,7 +65,7 @@ public abstract class OneCameraManager {
      * The instance is created the first time this method is called and cached
      * in a singleton thereafter, so successive calls are cheap.
      */
-    public static OneCameraManager get(Activity activity) {
+    public static OneCameraManager get(CameraActivity activity) {
         if (sCameraManager == null) {
             sCameraManager = create(activity);
         }
@@ -76,11 +76,13 @@ public abstract class OneCameraManager {
      * Creates a new camera manager that is based on Camera2 API, if available,
      * or otherwise uses the portability API.
      */
-    private static OneCameraManager create(Activity activity) {
+    private static OneCameraManager create(CameraActivity activity) {
         CameraManager cameraManager = (CameraManager) activity
                 .getSystemService(Context.CAMERA_SERVICE);
+        int maxMemoryMB = activity.getServices().getMemoryManager()
+                .getMaxAllowedNativeMemoryAllocation();
         if (cameraManager != null && isCamera2FullySupported(cameraManager)) {
-            return new com.android.camera.one.v2.OneCameraManagerImpl(cameraManager);
+            return new com.android.camera.one.v2.OneCameraManagerImpl(cameraManager, maxMemoryMB);
         } else {
             return new com.android.camera.one.v1.OneCameraManagerImpl();
         }
index 097abc2..d2a6fee 100644 (file)
@@ -35,14 +35,18 @@ import com.android.camera.util.Size;
 public class OneCameraManagerImpl extends OneCameraManager {
     private static final Tag TAG = new Tag("OneCameraMgrImpl2");
     private final CameraManager mCameraManager;
+    private final int mMaxMemoryMB;
 
     /**
      * Instantiates a new {@link OneCameraManager} for Camera2 API.
      *
      * @param cameraManager the underlying Camera2 camera manager.
+     * @param maxMemoryMB maximum amount of memory opened cameras should consume
+     *            during capture and processing, in megabytes.
      */
-    public OneCameraManagerImpl(CameraManager cameraManager) {
+    public OneCameraManagerImpl(CameraManager cameraManager, int maxMemoryMB) {
         mCameraManager = cameraManager;
+        mMaxMemoryMB = maxMemoryMB;
     }
 
     @Override
@@ -69,7 +73,7 @@ public class OneCameraManagerImpl extends OneCameraManager {
                                 .getCameraCharacteristics(device.getId());
                         // TODO: Set boolean based on whether HDR+ is enabled.
                         OneCamera oneCamera = OneCameraCreator.create(true, device,
-                                characteristics, pictureSize);
+                                characteristics, pictureSize, mMaxMemoryMB);
                         openCallback.onCameraOpened(oneCamera);
                     } catch (CameraAccessException e) {
                         Log.d(TAG, "Could not get camera characteristics");
index 9ff07d6..43ed840 100644 (file)
@@ -32,7 +32,6 @@ import android.graphics.Matrix;
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.graphics.RectF;
-import android.hardware.Camera;
 import android.location.Location;
 import android.net.Uri;
 import android.os.ParcelFileDescriptor;
@@ -55,7 +54,6 @@ import com.android.camera.debug.Log;
 import com.android.camera.filmstrip.ImageData;
 import com.android.camera2.R;
 import com.android.ex.camera2.portability.CameraCapabilities;
-import com.android.ex.camera2.portability.CameraDeviceInfo.Characteristics;
 import com.android.ex.camera2.portability.CameraSettings;
 import com.android.ex.camera2.portability.Size;
 
@@ -355,10 +353,14 @@ public class CameraUtil {
         int rotation = windowManager.getDefaultDisplay()
                 .getRotation();
         switch (rotation) {
-            case Surface.ROTATION_0: return 0;
-            case Surface.ROTATION_90: return 90;
-            case Surface.ROTATION_180: return 180;
-            case Surface.ROTATION_270: return 270;
+            case Surface.ROTATION_0:
+                return 0;
+            case Surface.ROTATION_90:
+                return 90;
+            case Surface.ROTATION_180:
+                return 180;
+            case Surface.ROTATION_270:
+                return 270;
         }
         return 0;
     }
@@ -366,6 +368,7 @@ public class CameraUtil {
     /**
      * Calculate the default orientation of the device based on the width and
      * height of the display when rotation = 0 (i.e. natural width and height)
+     *
      * @param context current context
      * @return whether the default orientation of the device is portrait
      */
@@ -630,7 +633,7 @@ public class CameraUtil {
     }
 
     public static void prepareMatrix(Matrix matrix, boolean mirror, int displayOrientation,
-                                     Rect previewRect) {
+            Rect previewRect) {
         // Need mirror for front camera.
         matrix.setScale(mirror ? -1 : 1, 1);
         // This is the value for android.hardware.Camera.setDisplayOrientation.
@@ -669,6 +672,7 @@ public class CameraUtil {
 
     /**
      * Down-samples a jpeg byte array.
+     *
      * @param data a byte array of jpeg data
      * @param downSampleFactor down-sample factor
      * @return decoded and down-sampled bitmap
@@ -699,7 +703,7 @@ public class CameraUtil {
             // available.
             settings.setGpsData(
                     new CameraSettings.GpsData(0f, 0f, 0f, System.currentTimeMillis() / 1000, null)
-            );
+                    );
         } else {
             Log.d(TAG, "Set gps location");
             // for NETWORK_PROVIDER location provider, we may have
@@ -1022,7 +1026,6 @@ public class CameraUtil {
         return ret;
     }
 
-
     /**
      * Gets the theme color of a specific mode.
      *
@@ -1151,4 +1154,39 @@ public class CameraUtil {
         }
         return cameraModesIcons.getResourceId(modeIndex, 0);
     }
+
+    /**
+     * Gets the number of cores available in this device, across all processors.
+     * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
+     * <p>
+     * Source: http://stackoverflow.com/questions/7962155/
+     *
+     * @return The number of cores, or 1 if failed to get result
+     */
+    public static int getNumCpuCores() {
+        // Private Class to display only CPU devices in the directory listing
+        class CpuFilter implements java.io.FileFilter {
+            @Override
+            public boolean accept(java.io.File pathname) {
+                // Check if filename is "cpu", followed by a single digit number
+                if (java.util.regex.Pattern.matches("cpu[0-9]+", pathname.getName())) {
+                    return true;
+                }
+                return false;
+            }
+        }
+
+        try {
+            // Get directory containing CPU info
+            java.io.File dir = new java.io.File("/sys/devices/system/cpu/");
+            // Filter to only list the devices we care about
+            java.io.File[] files = dir.listFiles(new CpuFilter());
+            // Return the number of cores (virtual CPU devices)
+            return files.length;
+        } catch (Exception e) {
+            // Default to return 1 core
+            Log.e(TAG, "Failed to count number of cores, defaulting to 1", e);
+            return 1;
+        }
+    }
 }
index cc29336..39f14ab 100644 (file)
@@ -24,7 +24,7 @@ import com.android.camera.util.Size;
 
 public class OneCameraCreator {
     public static OneCamera create(boolean enableHdrPlus, CameraDevice device,
-            CameraCharacteristics characteristics, Size pictureSize) {
+            CameraCharacteristics characteristics, Size pictureSize, int maxMemoryMB) {
         return new OneCameraImpl(device, characteristics, pictureSize);
     }
 }