mOrientationManager = new OrientationManagerImpl(this, mMainHandler);
mSettingsManager = getServices().getSettingsManager();
mSoundPlayer = new SoundPlayer(mAppContext);
- mFeatureConfig = OneCameraFeatureConfigCreator.createDefault(getContentResolver());
+ mFeatureConfig = OneCameraFeatureConfigCreator.createDefault(getContentResolver(),
+ getServices().getMemoryManager());
profile.mark();
if (!Glide.isSetup()) {
}
profile.mark("Glide.setup");
try {
- mCameraManager = OneCameraManager.get(this, ResolutionUtil.getDisplayMetrics(this),
- mFeatureConfig);
+ mCameraManager = OneCameraManager.get(
+ mFeatureConfig, mAppContext, ResolutionUtil.getDisplayMetrics(this));
} catch (OneCameraException e) {
// Log error and continue. Modules requiring OneCamera should check
// and handle if null by showing error dialog or other treatment.
import com.android.camera.one.OneCamera.OpenCallback;
import com.android.camera.one.OneCamera.PhotoCaptureParameters;
import com.android.camera.one.OneCameraAccessException;
+import com.android.camera.one.OneCameraCaptureSetting;
import com.android.camera.one.OneCameraCharacteristics;
import com.android.camera.one.OneCameraManager;
import com.android.camera.one.v2.OneCameraManagerImpl;
// Only enable GCam on the back camera
boolean useHdr = mHdrPlusEnabled && mCameraFacing == Facing.BACK;
+ OneCameraCaptureSetting captureSetting;
// Read the preferred picture size from the setting.
try {
- mPictureSize = mAppController.getResolutionSetting().getPictureSize(mCameraFacing);
+ captureSetting = OneCameraCaptureSetting.create(
+ mCameraFacing, mAppController.getResolutionSetting(), mSettingsManager,
+ mAppController.getModuleScope(), useHdr);
} catch (OneCameraAccessException ex) {
mAppController.showErrorAndFinish(R.string.cannot_connect_camera);
return;
}
+ mPictureSize = captureSetting.getCaptureSize();
- mCameraManager.open(mCameraFacing, useHdr, mPictureSize,
+ mCameraManager.open(captureSetting, mCameraHandler, mainThread,
+ imageRotationCalculator, mBurstController, mSoundPlayer,
new OpenCallback() {
@Override
public void onFailure() {
}
});
}
- }, mCameraHandler, mainThread, imageRotationCalculator, mBurstController);
+ });
guard.stop("mCameraManager.open()");
}
import com.google.common.base.Optional;
+import com.android.camera.SoundPlayer;
import com.android.camera.async.RefCountBase;
import com.android.camera.burst.BurstFacadeFactory;
import com.android.camera.captureintent.event.Event;
import com.android.camera.debug.Log;
import com.android.camera.one.OneCamera;
import com.android.camera.one.OneCameraAccessException;
+import com.android.camera.one.OneCameraCaptureSetting;
import com.android.camera.one.OneCameraCharacteristics;
import com.android.camera.one.v2.photo.ImageRotationCalculator;
import com.android.camera.one.v2.photo.ImageRotationCalculatorImpl;
return Optional.of((State) StateFatal.from(this, mResourceConstructed));
}
+ OneCameraCaptureSetting captureSetting;
try {
- /** Read the picture size from the setting. */
- mPictureSize = mResourceConstructed.get().getResolutionSetting().getPictureSize(
- mCameraFacing);
+ captureSetting = OneCameraCaptureSetting.create(
+ mCameraFacing,
+ mResourceConstructed.get().getResolutionSetting(),
+ mResourceConstructed.get().getAppController().getSettingsManager(),
+ mResourceConstructed.get().getAppController().getModuleScope(),
+ false);
+ mPictureSize = captureSetting.getCaptureSize();
} catch (OneCameraAccessException ex) {
Log.e(TAG, "Failed while open camera", ex);
return Optional.of((State) StateFatal.from(this, mResourceConstructed));
final ImageRotationCalculator imageRotationCalculator = ImageRotationCalculatorImpl.from(
mResourceConstructed.get().getOrientationManager(), mCameraCharacteristics);
+
mResourceConstructed.get().getCameraManager().open(
- mCameraFacing,
- false,
- mPictureSize,
- mCameraOpenCallback,
+ captureSetting,
mResourceConstructed.get().getCameraHandler(),
mResourceConstructed.get().getMainThread(),
imageRotationCalculator,
- new BurstFacadeFactory.BurstFacadeStub());
+ new BurstFacadeFactory.BurstFacadeStub(),
+ new SoundPlayer(mResourceConstructed.get().getContext()),
+ mCameraOpenCallback);
return Optional.absent();
}
--- /dev/null
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera.one;
+
+import com.android.camera.async.Observable;
+import com.android.camera.settings.Keys;
+import com.android.camera.settings.ResolutionSetting;
+import com.android.camera.settings.SettingObserver;
+import com.android.camera.settings.SettingsManager;
+import com.android.camera.util.Size;
+
+/**
+ * Contains related settings to configure a camera for a particular type of
+ * capture.
+ */
+public class OneCameraCaptureSetting {
+ private final OneCamera.Facing mCameraFacing;
+ private final Size mCaptureSize;
+ private final Observable<OneCamera.PhotoCaptureParameters.Flash> mFlashSetting;
+ private final Observable<Integer> mExposureSetting;
+ private final Observable<Boolean> mHdrSceneSetting;
+ private final boolean mIsHdrPlusEnabled;
+
+ public static OneCameraCaptureSetting create(
+ OneCamera.Facing cameraFacing,
+ ResolutionSetting resolutionSetting,
+ SettingsManager settingsManager,
+ String cameraSettingScope,
+ boolean isHdrPlusEnabled) throws OneCameraAccessException {
+ Observable<OneCamera.PhotoCaptureParameters.Flash> flashSetting = new FlashSetting(
+ SettingObserver.ofString(settingsManager, cameraSettingScope, Keys.KEY_FLASH_MODE));
+ Observable<Integer> exposureSetting = SettingObserver.ofInteger(
+ settingsManager, cameraSettingScope, Keys.KEY_EXPOSURE);
+ Observable<Boolean> hdrSceneSetting = SettingObserver.ofBoolean(
+ settingsManager, SettingsManager.SCOPE_GLOBAL, Keys.KEY_CAMERA_HDR);
+ return new OneCameraCaptureSetting(
+ cameraFacing,
+ resolutionSetting.getPictureSize(cameraFacing),
+ flashSetting,
+ exposureSetting,
+ hdrSceneSetting,
+ isHdrPlusEnabled);
+ }
+
+ private OneCameraCaptureSetting(
+ OneCamera.Facing cameraFacing,
+ Size captureSize,
+ Observable<OneCamera.PhotoCaptureParameters.Flash> flashSetting,
+ Observable<Integer> exposureSetting,
+ Observable<Boolean> hdrSceneSetting,
+ boolean isHdrPlusEnabled) {
+ mCameraFacing = cameraFacing;
+ mCaptureSize = captureSize;
+ mFlashSetting = flashSetting;
+ mExposureSetting = exposureSetting;
+ mHdrSceneSetting = hdrSceneSetting;
+ mIsHdrPlusEnabled = isHdrPlusEnabled;
+ }
+
+ public OneCamera.Facing getCameraFacing() {
+ return mCameraFacing;
+ }
+
+ public Size getCaptureSize() {
+ return mCaptureSize;
+ }
+
+ public Observable<OneCamera.PhotoCaptureParameters.Flash> getFlashSetting() {
+ return mFlashSetting;
+ }
+
+ public Observable<Integer> getExposureSetting() {
+ return mExposureSetting;
+ }
+
+ public Observable<Boolean> getHdrSceneSetting() {
+ return mHdrSceneSetting;
+ }
+
+ public boolean isHdrPlusEnabled() {
+ return mIsHdrPlusEnabled;
+ }
+}
package com.android.camera.one;
+import android.content.Context;
import android.os.Handler;
import android.util.DisplayMetrics;
-import com.android.camera.CameraActivity;
+import com.android.camera.SoundPlayer;
import com.android.camera.async.MainThread;
import com.android.camera.burst.BurstFacade;
import com.android.camera.debug.Log.Tag;
import com.android.camera.one.OneCamera.OpenCallback;
import com.android.camera.one.config.OneCameraFeatureConfig;
import com.android.camera.one.v2.photo.ImageRotationCalculator;
+import com.android.camera.settings.SettingsManager;
import com.android.camera.util.Size;
import com.google.common.base.Optional;
* Exactly one call will always be made to a single method in the provided
* {@link OpenCallback}.
*
- * @param facing which camera to open. The first camera found in the given
- * direction will be opened.
- * @param enableHdr if an HDR feature exists, open a camera that supports it
- * @param captureSize the capture size. This must be one of the supported
- * sizes.
- * @param callback this listener is called when the camera was opened or
- * when it failed to open.
+ * @param captureSetting the related settings to configure the camera for capture.
* @param handler the handler on which callback methods are invoked.
* @param mainThread Main thread executor
* @param imageRotationCalculator Image rotation calculator required for
* Camera Factory initialization
* @param burstController the burst facade to configure
+ * @param soundPlayer the sound player.
+ * @param openCallback this listener is called when the camera was opened or
+ * when it failed to open.
*/
- public abstract void open(Facing facing, boolean enableHdr, Size captureSize,
- OpenCallback callback, Handler handler,
- MainThread mainThread, final ImageRotationCalculator imageRotationCalculator,
- BurstFacade burstController);
+ public abstract void open(
+ OneCameraCaptureSetting captureSetting,
+ Handler handler,
+ MainThread mainThread,
+ ImageRotationCalculator imageRotationCalculator,
+ BurstFacade burstController,
+ SoundPlayer soundPlayer,
+ OpenCallback openCallback);
// TODO: Move this to OneCameraCharacteristics class.
/**
* @throws OneCameraException Thrown if an error occurred while trying to
* access the camera.
*/
- public static OneCameraManager get(CameraActivity activity, DisplayMetrics displayMetrics,
- OneCameraFeatureConfig featureConfig) throws OneCameraException {
- return create(activity, displayMetrics, featureConfig);
+ public static OneCameraManager get(
+ OneCameraFeatureConfig featureConfig,
+ Context context,
+ DisplayMetrics displayMetrics) throws OneCameraException {
+ return create(featureConfig, context, displayMetrics);
}
/**
* @throws OneCameraException Thrown if an error occurred while trying to
* access the camera.
*/
- private static OneCameraManager create(CameraActivity activity, DisplayMetrics displayMetrics,
- OneCameraFeatureConfig featureConfig) throws OneCameraException {
- Optional<OneCameraManager> manager =
- com.android.camera.one.v2.OneCameraManagerImpl.create(activity, displayMetrics,
- featureConfig);
+ private static OneCameraManager create(
+ OneCameraFeatureConfig featureConfig,
+ Context context,
+ DisplayMetrics displayMetrics) throws OneCameraException {
+ Optional<OneCameraManager> manager = com.android.camera.one.v2.OneCameraManagerImpl.create(
+ featureConfig, context, displayMetrics);
if (!manager.isPresent()) {
- manager = com.android.camera.one.v1.OneCameraManagerImpl.create(activity);
+ manager = com.android.camera.one.v1.OneCameraManagerImpl.create();
}
if (!manager.isPresent()) {
throw new OneCameraException("No camera manager is available.");
private final Function<CameraCharacteristics, CaptureSupportLevel> mCaptureModeDetector;
/** The level of HDR+ support. */
private final HdrPlusSupportLevel mHdrPlusSupportLevel;
+ /**
+ * The maximum amount of memory can be consumed by all opened cameras
+ * during capture and processing, in megabytes.
+ */
+ private final int mMaxMemoryMB;
+
+ /**
+ * The maximum number of images the camera should allocate in the image reader.
+ */
+ private final int mMaxAllowedImageReaderCount;
OneCameraFeatureConfig(boolean useCaptureModule,
Function<CameraCharacteristics, CaptureSupportLevel> captureModeDetector,
- HdrPlusSupportLevel hdrPlusSupportLevel) {
+ HdrPlusSupportLevel hdrPlusSupportLevel,
+ int maxMemoryMB,
+ int maxAllowedImageReaderCount) {
mUseCaptureModule = useCaptureModule;
mCaptureModeDetector = captureModeDetector;
mHdrPlusSupportLevel = hdrPlusSupportLevel;
+ mMaxMemoryMB = maxMemoryMB;
+ mMaxAllowedImageReaderCount = maxAllowedImageReaderCount;
}
/**
public HdrPlusSupportLevel getHdrPlusSupportLevel() {
return mHdrPlusSupportLevel;
}
+
+ /**
+ * @return The maximum amount of memory can be consumed by all opened
+ * cameras during capture and processing, in megabytes.
+ */
+ public int getMaxMemoryMB() {
+ return mMaxMemoryMB;
+ }
+
+ /**
+ * @return The maximum number of images the camera should allocate in the
+ * image reader.
+ */
+ public int getMaxAllowedImageReaderCount() {
+ return mMaxAllowedImageReaderCount;
+ }
}
import android.content.ContentResolver;
import android.hardware.camera2.CameraCharacteristics;
+import com.android.camera.app.MemoryManager;
import com.android.camera.debug.Log;
import com.android.camera.one.config.OneCameraFeatureConfig.CaptureSupportLevel;
import com.android.camera.one.config.OneCameraFeatureConfig.HdrPlusSupportLevel;
/**
* Create the default camera feature config.
*/
- public static OneCameraFeatureConfig createDefault(ContentResolver contentResolver) {
+ public static OneCameraFeatureConfig createDefault(ContentResolver contentResolver,
+ MemoryManager memoryManager) {
// Enable CaptureModule on all L devices unless the device is
// black-listed.
boolean useCaptureModule = ApiHelper.HAS_CAMERA_2_API
GcamHelper.determineHdrPlusSupportLevel(contentResolver, useCaptureModule);
return new OneCameraFeatureConfig(useCaptureModule,
buildCaptureModuleDetector(contentResolver),
- hdrPlusSupportLevel);
+ hdrPlusSupportLevel,
+ memoryManager.getMaxAllowedNativeMemoryAllocation(),
+ GservicesHelper.getMaxAllowedImageReaderCount(contentResolver));
}
private static Function<CameraCharacteristics, CaptureSupportLevel> buildCaptureModuleDetector(
import android.os.Handler;
import com.android.camera.CameraActivity;
+import com.android.camera.SoundPlayer;
import com.android.camera.async.MainThread;
import com.android.camera.burst.BurstFacade;
import com.android.camera.debug.Log;
import com.android.camera.one.OneCamera.Facing;
import com.android.camera.one.OneCamera.OpenCallback;
import com.android.camera.one.OneCameraAccessException;
+import com.android.camera.one.OneCameraCaptureSetting;
import com.android.camera.one.OneCameraCharacteristics;
import com.android.camera.one.OneCameraManager;
import com.android.camera.one.v2.photo.ImageRotationCalculator;
+import com.android.camera.settings.SettingsManager;
import com.android.camera.util.Size;
import com.google.common.base.Optional;
/**
private OneCameraCharacteristics mBackCameraCharacteristics;
private OneCameraCharacteristics mFrontCameraCharacteristics;
- public static Optional<OneCameraManager> create(CameraActivity activity) {
+ public static Optional<OneCameraManager> create() {
int numberOfCameras;
Camera.CameraInfo[] cameraInfos;
try {
}
@Override
- public void open(Facing facing, boolean enableHdr, Size pictureSize,
- OpenCallback callback, Handler handler,
+ public void open(
+ OneCameraCaptureSetting captureSetting,
+ Handler handler,
MainThread mainThread,
- ImageRotationCalculator imageRotationCalculator, BurstFacade burstController) {
+ ImageRotationCalculator imageRotationCalculator,
+ BurstFacade burstController,
+ SoundPlayer soundPlayer,
+ OpenCallback openCallback) {
throw new RuntimeException("Not implemented yet.");
}
package com.android.camera.one.v2;
import android.annotation.TargetApi;
+import android.content.Context;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.os.Handler;
import android.util.DisplayMetrics;
-import com.android.camera.CameraActivity;
import com.android.camera.SoundPlayer;
-import com.android.camera.app.AppController;
import com.android.camera.async.MainThread;
import com.android.camera.burst.BurstFacade;
import com.android.camera.debug.Log;
import com.android.camera.one.OneCamera.Facing;
import com.android.camera.one.OneCamera.OpenCallback;
import com.android.camera.one.OneCameraAccessException;
+import com.android.camera.one.OneCameraCaptureSetting;
import com.android.camera.one.OneCameraCharacteristics;
import com.android.camera.one.OneCameraManager;
import com.android.camera.one.config.OneCameraFeatureConfig;
import com.android.camera.one.v2.photo.ImageRotationCalculator;
import com.android.camera.util.AndroidServices;
import com.android.camera.util.ApiHelper;
-import com.android.camera.util.GservicesHelper;
-import com.android.camera.util.Size;
import com.google.common.base.Optional;
public class OneCameraManagerImpl extends OneCameraManager {
private static final Tag TAG = new Tag("OneCameraMgrImpl2");
- private final AppController mAppController;
+ private final Context mContext;
private final OneCameraFeatureConfig mFeatureConfig;
private final CameraManager mCameraManager;
- private final int mMaxMemoryMB;
- private final int mMaxImages;
private final DisplayMetrics mDisplayMetrics;
- private final SoundPlayer mSoundPlayer;
- public static Optional<OneCameraManager> create(CameraActivity activity,
- DisplayMetrics displayMetrics, OneCameraFeatureConfig featureConfig) {
+ public static Optional<OneCameraManager> create(
+ OneCameraFeatureConfig featureConfig,
+ Context context,
+ DisplayMetrics displayMetrics) {
if (!ApiHelper.HAS_CAMERA_2_API) {
return Optional.absent();
}
Log.e(TAG, "camera2.CameraManager is not available.");
return Optional.absent();
}
- final int maxMemoryMB = activity.getServices().getMemoryManager()
- .getMaxAllowedNativeMemoryAllocation();
- final SoundPlayer soundPlayer = activity.getSoundPlayer();
- final int maxImages = GservicesHelper.
- getMaxAllowedImageReaderCount(activity.getContentResolver());
OneCameraManager oneCameraManager = new OneCameraManagerImpl(
- activity, featureConfig, cameraManager, maxMemoryMB, maxImages, displayMetrics,
- soundPlayer);
+ featureConfig, context, cameraManager, displayMetrics);
return Optional.of(oneCameraManager);
}
* 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(AppController appController, OneCameraFeatureConfig featureConfig,
- CameraManager cameraManager, int maxMemoryMB, int maxImages,
- DisplayMetrics displayMetrics, SoundPlayer soundPlayer) {
- mAppController = appController;
+ public OneCameraManagerImpl(OneCameraFeatureConfig featureConfig,
+ Context context,
+ CameraManager cameraManager,
+ DisplayMetrics displayMetrics) {
mFeatureConfig = featureConfig;
+ mContext = context;
mCameraManager = cameraManager;
- mMaxMemoryMB = maxMemoryMB;
- mMaxImages = maxImages;
mDisplayMetrics = displayMetrics;
- mSoundPlayer = soundPlayer;
}
@Override
- public void open(Facing facing, final boolean useHdr, final Size pictureSize,
- final OpenCallback openCallback,
- Handler handler, final MainThread mainThread,
+ public void open(
+ final OneCameraCaptureSetting captureSetting,
+ final Handler handler,
+ final MainThread mainThread,
final ImageRotationCalculator imageRotationCalculator,
- final BurstFacade burstController) {
+ final BurstFacade burstController,
+ final SoundPlayer soundPlayer,
+ final OpenCallback openCallback) {
try {
- final String cameraId = getCameraId(facing);
+ final String cameraId = getCameraId(captureSetting.getCameraFacing());
Log.i(TAG, "Opening Camera ID " + cameraId);
mCameraManager.openCamera(cameraId, new CameraDevice.StateCallback() {
// We may get multiple calls to StateCallback, but only the
.getCameraCharacteristics(device.getId());
// TODO: Set boolean based on whether HDR+ is
// enabled.
- OneCamera oneCamera = OneCameraCreator.create(mAppController, useHdr,
- mFeatureConfig, device, characteristics, pictureSize,
- mMaxMemoryMB, mMaxImages, mDisplayMetrics, mSoundPlayer,
- mainThread, imageRotationCalculator, burstController);
+ OneCamera oneCamera = OneCameraCreator.create(
+ device,
+ characteristics,
+ mFeatureConfig,
+ captureSetting,
+ mDisplayMetrics,
+ mContext,
+ mainThread,
+ imageRotationCalculator,
+ burstController,
+ soundPlayer);
openCallback.onCameraOpened(oneCamera);
} catch (CameraAccessException e) {
Log.d(TAG, "Could not get camera characteristics");
package com.android.camera.one.v2;
+import android.content.Context;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.util.DisplayMetrics;
import com.android.camera.SoundPlayer;
-import com.android.camera.app.AppController;
import com.android.camera.async.MainThread;
import com.android.camera.burst.BurstFacade;
import com.android.camera.one.OneCamera;
+import com.android.camera.one.OneCameraCaptureSetting;
import com.android.camera.one.config.OneCameraFeatureConfig;
import com.android.camera.one.v2.photo.ImageRotationCalculator;
import com.android.camera.util.Size;
public class OneCameraCreator {
- public static OneCamera create(AppController context, boolean useHdr,
- OneCameraFeatureConfig featureConfig, CameraDevice device,
- CameraCharacteristics characteristics, Size pictureSize,
- int maxMemoryMB, int maxImages,
- DisplayMetrics displayMetrics, SoundPlayer soundPlayer,
- MainThread mainThread, ImageRotationCalculator imageRotationCalculator,
- BurstFacade burstController) {
+ public static OneCamera create(
+ CameraDevice device,
+ CameraCharacteristics characteristics,
+ OneCameraFeatureConfig featureConfig,
+ OneCameraCaptureSetting captureSetting,
+ DisplayMetrics displayMetrics,
+ Context context,
+ MainThread mainThread,
+ ImageRotationCalculator imageRotationCalculator,
+ BurstFacade burstController,
+ SoundPlayer soundPlayer) {
// TODO: Might want to switch current camera to vendor HDR.
- return new OneCameraImpl(device, characteristics, pictureSize);
+ return new OneCameraImpl(device, characteristics, captureSetting.getCaptureSize());
}
}