/// <summary> /// Opens a <seealso cref="com.samsung.android.sdk.camera.SCameraDevice"/>. /// </summary> private void openCamera() { try { if (!mCameraOpenCloseLock.tryAcquire(3000, TimeUnit.MILLISECONDS)) { showAlertDialog("Time out waiting to lock camera opening.", true); } mSCameraManager = mSCamera.SCameraManager; SCameraCharacteristics characteristics = mSCameraManager.getCameraCharacteristics(mCameraId); StreamConfigurationMap streamConfigurationMap = characteristics.get(SCameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); // Acquires supported preview size list that supports YUV420_888. // Input Surface from panorama processor will have a format of ImageFormat.YUV420_888 mPreviewSize = streamConfigurationMap.getOutputSizes(ImageFormat.YUV_420_888)[0]; foreach (Size option in streamConfigurationMap.getOutputSizes(ImageFormat.YUV_420_888)) { // preview size must be supported by panorama processor if (!contains(mProcessor.Parameters.get(SCameraPanoramaProcessor.STREAM_SIZE_LIST), option)) { continue; } int areaCurrent = Math.Abs((mPreviewSize.Width * mPreviewSize.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT)); int areaNext = Math.Abs((option.Width * option.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT)); if (areaCurrent > areaNext) { mPreviewSize = option; } } int orientation = Resources.Configuration.orientation; if (Configuration.ORIENTATION_LANDSCAPE == orientation) { mTextureView.setAspectRatio(mPreviewSize.Width, mPreviewSize.Height); } else { mTextureView.setAspectRatio(mPreviewSize.Height, mPreviewSize.Width); } initProcessor(); mSCameraManager.openCamera(mCameraId, new StateCallbackAnonymousInnerClassHelper(this), mBackgroundHandler); } catch (CameraAccessException e) { showAlertDialog("Cannot open the camera.", true); Log.e(TAG, "Cannot open the camera.", e); } catch (InterruptedException e) { throw new Exception("Interrupted while trying to lock camera opening.", e); } }
/// <returns> true, If device supports required feature. </returns> private bool checkRequiredFeatures() { try { mCameraId = null; foreach (string id in mSCamera.SCameraManager.CameraIdList) { SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(id); if (cameraCharacteristics.get(SCameraCharacteristics.LENS_FACING) == SCameraCharacteristics.LENS_FACING_BACK) { mCameraId = id; break; } } if (null == mCameraId) { showAlertDialog("No back-facing camera exist.", true); return(false); } SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(mCameraId); if (!contains(cameraCharacteristics.get(SCameraCharacteristics.CONTROL_AF_AVAILABLE_MODES), SCameraCharacteristics.CONTROL_AF_MODE_CONTINUOUS_PICTURE)) { showAlertDialog("Required AF mode is not supported.", true); return(false); } if (!mSCamera.isFeatureEnabled(SCamera.SCAMERA_PROCESSOR)) { showAlertDialog("This device does not support SCamera Processor feature.", true); return(false); } SCameraProcessorManager processorManager = mSCamera.SCameraProcessorManager; if (!processorManager.isProcessorAvailable(SCameraProcessorManager.PROCESSOR_TYPE_PANORAMA)) { showAlertDialog("This device does not support Panorama Processor.", true); return(false); } } catch (CameraAccessException e) { showAlertDialog("Cannot access the camera.", true); Log.e(TAG, "Cannot access the camera.", e); return(false); } return(true); }
private bool checkRequiredFeatures() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { showAlertDialog("Device running Android prior to M is not compatible with the reprocessing APIs.", true); Log.e(TAG, "Device running Android prior to M is not compatible with the reprocessing APIs."); return(false); } try { mCameraId = null; foreach (string id in mSCamera.SCameraManager.CameraIdList) { SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(id); if (cameraCharacteristics.get(SCameraCharacteristics.LENS_FACING) == SCameraCharacteristics.LENS_FACING_BACK) { mCameraId = id; break; } } if (mCameraId == null) { showAlertDialog("No back-facing camera exist.", true); return(false); } mCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(mCameraId); if (!asList(mCharacteristics.get(SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)).Contains(SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING)) { showAlertDialog("YUV reprocessing capability is not supported.", true); Log.e(TAG, "YUV reprocessing capability is not supported."); return(false); } } catch (CameraAccessException e) { showAlertDialog("Cannot access the camera.", true); Log.e(TAG, "Cannot access the camera.", e); return(false); } return(true); }
private bool checkRequiredFeatures() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { showAlertDialog("Device running Android prior to M is not compatible with torch mode control APIs.", true); Log.e(TAG, "Device running Android prior to M is not compatible with torch mode control APIs."); return(false); } try { bool flashFound = false; foreach (string id in mSCamera.SCameraManager.CameraIdList) { SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(id); if (cameraCharacteristics.get(SCameraCharacteristics.FLASH_INFO_AVAILABLE)) { flashFound = true; break; } } // no camera device with flash unit. if (!flashFound) { showAlertDialog("Device does not have a camera device with flash unit.", true); Log.e(TAG, "Device does not have a camera device with flash unit."); return(false); } } catch (CameraAccessException e) { showAlertDialog("Cannot access the camera.", true); Log.e(TAG, "Cannot access the camera.", e); return(false); } return(true); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("deprecation") private boolean checkRequiredFeatures() private bool checkRequiredFeatures() { try { mCameraId = null; // Find camera device that facing to given facing parameter. foreach (string id in mSCamera.SCameraManager.CameraIdList) { SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(id); if (cameraCharacteristics.get(SCameraCharacteristics.LENS_FACING) == SCameraCharacteristics.LENS_FACING_BACK) { mCameraId = id; break; } } if (mCameraId == null) { showAlertDialog("No back-facing camera exist.", true); return(false); } // acquires camera characteristics mCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(mCameraId); if (!contains(mCharacteristics.get(SCameraCharacteristics.CONTROL_AF_AVAILABLE_MODES), SCameraCharacteristics.CONTROL_AF_MODE_CONTINUOUS_PICTURE)) { showAlertDialog("Required AF mode is not supported.", true); return(false); } if (!contains(mCharacteristics.get(SCameraCharacteristics.CONTROL_AVAILABLE_SCENE_MODES), SCameraCharacteristics.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO) || mCharacteristics.get(SCameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).HighSpeedVideoSizes.length == 0 || mCharacteristics.get(SCameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).HighSpeedVideoFpsRanges.length == 0) { showAlertDialog("High speed video recording scene mode is not supported.", true); return(false); } mVideoParameterList.Clear(); foreach (Size videoSize in mCharacteristics.get(SCameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).HighSpeedVideoSizes) { foreach (Range <int?> fpsRange in mCharacteristics.get(SCameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).getHighSpeedVideoFpsRangesFor(videoSize)) { //we will record constant fps video if (fpsRange.Lower.Equals(fpsRange.Upper)) { mVideoParameterList.Add(new VideoParameter(videoSize, fpsRange)); } } } } catch (CameraAccessException e) { showAlertDialog("Cannot access the camera.", true); Log.e(TAG, "Cannot access the camera.", e); return(false); } return(true); }
private bool checkRequiredFeatures() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { showAlertDialog("Device running Android prior to M is not compatible with the reprocessing APIs.", true); Log.e(TAG, "Device running Android prior to M is not compatible with the reprocessing APIs."); return false; } try { mCameraId = null; foreach (string id in mSCamera.SCameraManager.CameraIdList) { SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(id); if (cameraCharacteristics.get(SCameraCharacteristics.LENS_FACING) == SCameraCharacteristics.LENS_FACING_BACK) { mCameraId = id; break; } } if (mCameraId == null) { showAlertDialog("No back-facing camera exist.", true); return false; } mCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(mCameraId); if (!asList(mCharacteristics.get(SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)).Contains(SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING)) { showAlertDialog("YUV reprocessing capability is not supported.", true); Log.e(TAG, "YUV reprocessing capability is not supported."); return false; } } catch (CameraAccessException e) { showAlertDialog("Cannot access the camera.", true); Log.e(TAG, "Cannot access the camera.", e); return false; } return true; }
private void openCamera() { lock (this) { try { if (!mCameraOpenCloseLock.tryAcquire(3000, TimeUnit.MILLISECONDS)) { showAlertDialog("Time out waiting to lock camera opening.", true); } // acquires camera characteristics mCharacteristics = mSCameraManager.getCameraCharacteristics(mSCameraManager.CameraIdList[0]); StreamConfigurationMap streamConfigurationMap = mCharacteristics.get(SCameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); // Acquires supported preview size list that supports SurfaceTexture mPreviewSize = streamConfigurationMap.getOutputSizes(typeof(SurfaceTexture))[0]; foreach (Size option in streamConfigurationMap.getOutputSizes(typeof(SurfaceTexture))) { // Find maximum preview size that is not larger than MAX_PREVIEW_WIDTH/MAX_PREVIEW_HEIGHT int areaCurrent = Math.Abs((mPreviewSize.Width * mPreviewSize.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT)); int areaNext = Math.Abs((option.Width * option.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT)); if (areaCurrent > areaNext) { mPreviewSize = option; } } // Acquires supported input size for YUV_420_888 format. Size yuvSize = streamConfigurationMap.getInputSizes(ImageFormat.YUV_420_888)[0]; // Configures an ImageReader mYUVReader = ImageReader.newInstance(yuvSize.Width, yuvSize.Height, ImageFormat.YUV_420_888, 2); mJpegReader = ImageReader.newInstance(mYUVReader.Width, mYUVReader.Height, ImageFormat.JPEG, 2); mYUVReader.setOnImageAvailableListener(mYUVImageListener, mReaderHandler); mJpegReader.setOnImageAvailableListener(mJpegImageListener, mReaderHandler); // Set the aspect ratio to TextureView int orientation = Resources.Configuration.orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.Width, mPreviewSize.Height); } else { mTextureView.setAspectRatio(mPreviewSize.Height, mPreviewSize.Width); } // Opening the camera device here mSCameraManager.openCamera(mCameraId, new StateCallbackAnonymousInnerClassHelper(this), mBackgroundHandler); } catch (CameraAccessException e) { showAlertDialog("Cannot open the camera.", true); Log.e(TAG, "Cannot open the camera.", e); } catch (InterruptedException e) { throw new Exception("Interrupted while trying to lock camera opening.", e); } } }
private bool checkRequiredFeatures() { try { mCameraId = null; foreach (string id in mSCamera.SCameraManager.CameraIdList) { SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(id); if (cameraCharacteristics.get(SCameraCharacteristics.LENS_FACING) == SCameraCharacteristics.LENS_FACING_BACK) { mCameraId = id; break; } } if (mCameraId == null) { showAlertDialog("No back-facing camera exist.", true); return false; } mCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(mCameraId); if (!mCharacteristics.AvailableCaptureRequestKeys.contains(SCaptureRequest.LENS_FOCUS_DISTANCE) || !contains(mCharacteristics.get(SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES), SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR) || !(mCharacteristics.get(SCameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE) > 0.0f)) { showAlertDialog("Required SCaptureRequest.Key is not supported.", true); return false; } if (!contains(mCharacteristics.get(SCameraCharacteristics.CONTROL_AF_AVAILABLE_MODES), SCameraCharacteristics.CONTROL_AF_MODE_AUTO) || !contains(mCharacteristics.get(SCameraCharacteristics.CONTROL_AF_AVAILABLE_MODES), SCameraCharacteristics.CONTROL_AF_MODE_OFF)) { showAlertDialog("Required AF mode is not supported.", true); return false; } if (!mSCamera.isFeatureEnabled(SCamera.SCAMERA_PROCESSOR)) { showAlertDialog("This device does not support SCamera Processor feature.", true); return false; } SCameraProcessorManager processorManager = mSCamera.SCameraProcessorManager; if (!processorManager.isProcessorAvailable(SCameraProcessorManager.PROCESSOR_TYPE_DEPTH_OF_FIELD)) { showAlertDialog("This device does not support DOF Processor.", true); return false; } } catch (CameraAccessException e) { showAlertDialog("Cannot access the camera.", true); Log.e(TAG, "Cannot access the camera.", e); return false; } return true; }
private bool checkRequiredFeatures() { try { mCameraId = null; foreach (string id in mSCamera.SCameraManager.CameraIdList) { SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(id); if (cameraCharacteristics.get(SCameraCharacteristics.LENS_FACING) == SCameraCharacteristics.LENS_FACING_BACK) { mCameraId = id; break; } } if (mCameraId == null) { showAlertDialog("No back-facing camera exist.", true); return false; } mCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(mCameraId); if (!contains(mCharacteristics.get(SCameraCharacteristics.CONTROL_AF_AVAILABLE_MODES), SCameraCharacteristics.CONTROL_AF_MODE_CONTINUOUS_PICTURE)) { showAlertDialog("Required AF mode is not supported.", true); return false; } if (!mSCamera.isFeatureEnabled(SCamera.SCAMERA_PROCESSOR)) { showAlertDialog("This device does not support SCamera Processor feature.", true); return false; } SCameraProcessorManager processorManager = mSCamera.SCameraProcessorManager; if (!processorManager.isProcessorAvailable(SCameraProcessorManager.PROCESSOR_TYPE_HDR)) { showAlertDialog("This device does not support HDR Processor.", true); return false; } } catch (CameraAccessException e) { showAlertDialog("Cannot access the camera.", true); Log.e(TAG, "Cannot access the camera.", e); return false; } return true; }
/// <summary> /// Opens a <seealso cref="com.samsung.android.sdk.camera.SCameraDevice"/>. /// </summary> private void openCamera(int facing) { lock (this) { try { if (!mCameraOpenCloseLock.tryAcquire(3000, TimeUnit.MILLISECONDS)) { showAlertDialog("Time out waiting to lock camera opening.", true); } mSCameraManager = mSCamera.SCameraManager; mCameraId = null; // Find camera device that facing to given facing parameter. foreach (string id in mSCamera.SCameraManager.CameraIdList) { SCameraCharacteristics cameraCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(id); if (cameraCharacteristics.get(SCameraCharacteristics.LENS_FACING) == facing) { mCameraId = id; break; } } if (mCameraId == null) { showAlertDialog("No camera exist with given facing: " + facing, true); return; } // acquires camera characteristics mCharacteristics = mSCamera.SCameraManager.getCameraCharacteristics(mCameraId); StreamConfigurationMap streamConfigurationMap = mCharacteristics.get(SCameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); // Acquires supported preview size list that supports SurfaceTexture mPreviewSize = streamConfigurationMap.getOutputSizes(typeof(SurfaceTexture))[0]; foreach (Size option in streamConfigurationMap.getOutputSizes(typeof(SurfaceTexture))) { // Find maximum preview size that is not larger than MAX_PREVIEW_WIDTH/MAX_PREVIEW_HEIGHT int areaCurrent = Math.Abs((mPreviewSize.Width * mPreviewSize.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT)); int areaNext = Math.Abs((option.Width * option.Height) - (MAX_PREVIEW_WIDTH * MAX_PREVIEW_HEIGHT)); if (areaCurrent > areaNext) { mPreviewSize = option; } } // Acquires supported size for JPEG format Size[] jpegSizeList = null; jpegSizeList = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 0 == jpegSizeList.Length) { // If device has 'SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE' getOutputSizes can return zero size list // for a format value in getOutputFormats. jpegSizeList = streamConfigurationMap.getHighResolutionOutputSizes(ImageFormat.JPEG); } Size jpegSize = jpegSizeList[0]; // Configures an ImageReader mJpegReader = ImageReader.newInstance(jpegSize.Width, jpegSize.Height, ImageFormat.JPEG, 1); mJpegReader.setOnImageAvailableListener(mImageCallback, mImageSavingHandler); if (contains(mCharacteristics.get(SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES), SCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) { Size[] rawSizeList = streamConfigurationMap.getOutputSizes(ImageFormat.RAW_SENSOR); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 0 == rawSizeList.Length) { rawSizeList = streamConfigurationMap.getHighResolutionOutputSizes(ImageFormat.RAW_SENSOR); } Size rawSize = rawSizeList[0]; mRawReader = ImageReader.newInstance(rawSize.Width, rawSize.Height, ImageFormat.RAW_SENSOR, 1); mRawReader.setOnImageAvailableListener(mImageCallback, mImageSavingHandler); mImageFormatList = Arrays.asList(ImageFormat.JPEG, ImageFormat.RAW_SENSOR); } else { if (mRawReader != null) { mRawReader.close(); mRawReader = null; } mImageFormatList = Arrays.asList(ImageFormat.JPEG); } mImageFormat = ImageFormat.JPEG; // Set the aspect ratio to TextureView int orientation = Resources.Configuration.orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.Width, mPreviewSize.Height); mFaceRectView.setAspectRatio(mPreviewSize.Width, mPreviewSize.Height); } else { mTextureView.setAspectRatio(mPreviewSize.Height, mPreviewSize.Width); mFaceRectView.setAspectRatio(mPreviewSize.Height, mPreviewSize.Width); } // calculate transform matrix for face rect view configureFaceRectTransform(); // Opening the camera device here mSCameraManager.openCamera(mCameraId, new StateCallbackAnonymousInnerClassHelper(this), mBackgroundHandler); } catch (CameraAccessException e) { showAlertDialog("Cannot open the camera.", true); Log.e(TAG, "Cannot open the camera.", e); } catch (InterruptedException e) { throw new Exception("Interrupted while trying to lock camera opening.", e); } } }