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.
/** 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;
/** 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;
mContext = mAppController.getAndroidContext();
mSettingsManager = mAppController.getSettingsManager();
mSettingsManager.addListener(this);
+ mDebugDataDir = mContext.getExternalCacheDir();
}
@Override
params.orientation = getOrientation();
params.flashMode = getFlashModeFromSettings();
params.heading = mHeading;
+ params.debugDataFolder = mDebugDataDir;
// Take the picture.
mCamera.takePicture(params, session);
* <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);
mPreviewTranformationMatrix.postTranslate(wOffset, hOffset);
mAppController.updatePreviewTransformFullscreen(mPreviewTranformationMatrix,
aspectRatio);
- mFinalAspectRatio = aspectRatio;
} else {
mAppController.updatePreviewTransform(mPreviewTranformationMatrix);
- mFinalAspectRatio = null;
mAppController.getCameraAppUI().hideLetterboxing();
}
// if (mGcamProxy != null) {
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;
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
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}.
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;
* 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);
}
* 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();
}
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
.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");
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;
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;
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;
}
/**
* 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
*/
}
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.
/**
* 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
// 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
return ret;
}
-
/**
* Gets the theme color of a specific mode.
*
}
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;
+ }
+ }
}
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);
}
}