List of usage examples for android.hardware.camera2 CameraCharacteristics INFO_SUPPORTED_HARDWARE_LEVEL
Key INFO_SUPPORTED_HARDWARE_LEVEL
To view the source code for android.hardware.camera2 CameraCharacteristics INFO_SUPPORTED_HARDWARE_LEVEL.
Click Source Link
Generally classifies the overall set of the camera device functionality.
The supported hardware level is a high-level description of the camera device's capabilities, summarizing several capabilities into one field.
From source file:Main.java
/** * Returns {@code true} if this device only supports {@code LEGACY} mode operation in the * Camera2 API for the given camera ID./*from w ww . j ava2s .c om*/ * * @param context {@link Context} to access the {@link CameraManager} in. * @param cameraId the ID of the camera device to check. * @return {@code true} if this device only supports {@code LEGACY} mode. */ public static boolean isLegacyHAL(Context context, int cameraId) throws Exception { CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); CameraCharacteristics characteristics = manager.getCameraCharacteristics(Integer.toString(cameraId)); return characteristics.get( CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY; }
From source file:com.askjeffreyliu.camera2barcode.camera.CameraSource.java
public boolean isCamera2Native() { try {//from ww w .ja v a 2s. c om if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { return false; } manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE); mCameraId = manager.getCameraIdList()[mFacing]; CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId); //CHECK CAMERA HARDWARE LEVEL. int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); return (deviceLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY); } catch (CameraAccessException ex) { return false; } }
From source file:com.example.android.hdrviewfinder.HdrViewfinderActivity.java
private void findAndOpenCamera() { boolean cameraPermissions = checkCameraPermissions(); if (cameraPermissions) { String errorMessage = "Unknown error"; boolean foundCamera = false; initializeCamera();/*from ww w.j ava2 s . c om*/ if (cameraPermissions && mCameraOps != null) { try { // Find first back-facing camera that has necessary capability. String[] cameraIds = mCameraManager.getCameraIdList(); for (String id : cameraIds) { CameraCharacteristics info = mCameraManager.getCameraCharacteristics(id); int facing = info.get(CameraCharacteristics.LENS_FACING); int level = info.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); boolean hasFullLevel = (level == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL); int[] capabilities = info.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES); int syncLatency = info.get(CameraCharacteristics.SYNC_MAX_LATENCY); boolean hasManualControl = hasCapability(capabilities, CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR); boolean hasEnoughCapability = hasManualControl && syncLatency == CameraCharacteristics.SYNC_MAX_LATENCY_PER_FRAME_CONTROL; // All these are guaranteed by // CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL, but checking // for only the things we care about expands range of devices we can run on. // We want: // - Back-facing camera // - Manual sensor control // - Per-frame synchronization (so that exposure can be changed every frame) if (facing == CameraCharacteristics.LENS_FACING_BACK && (hasFullLevel || hasEnoughCapability)) { // Found suitable camera - get info, open, and set up outputs mCameraInfo = info; mCameraOps.openCamera(id); configureSurfaces(); foundCamera = true; break; } } if (!foundCamera) { errorMessage = getString(R.string.camera_no_good); } } catch (CameraAccessException e) { errorMessage = getErrorString(e); } if (!foundCamera) { showErrorDialog(errorMessage); } } } }
From source file:com.manufacton.cordova.MyCameraManager.java
/** * Sets up member variables related to camera. * * @param width The width of available size for camera preview * @param height The height of available size for camera preview *//* ww w . ja v a2s . c om*/ private void setUpCameraOutputs(int width, int height) { CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { continue; } StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { continue; } // For still image captures, we use the largest available size. Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); // Find out if we need to swap dimension to get the preview size relative to sensor // coordinate. int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); //noinspection ConstantConditions mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); boolean swappedDimensions = false; switch (displayRotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: if (mSensorOrientation == 90 || mSensorOrientation == 270) { swappedDimensions = true; } break; case Surface.ROTATION_90: case Surface.ROTATION_270: if (mSensorOrientation == 0 || mSensorOrientation == 180) { swappedDimensions = true; } break; default: Log.e(TAG, "Display rotation is invalid: " + displayRotation); } Point displaySize = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(displaySize); int rotatedPreviewWidth = width; int rotatedPreviewHeight = height; int maxPreviewWidth = displaySize.x; int maxPreviewHeight = displaySize.y; if (swappedDimensions) { rotatedPreviewWidth = height; rotatedPreviewHeight = width; maxPreviewWidth = displaySize.y; maxPreviewHeight = displaySize.x; } if (maxPreviewWidth > MAX_PREVIEW_WIDTH) { maxPreviewWidth = MAX_PREVIEW_WIDTH; } if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) { maxPreviewHeight = MAX_PREVIEW_HEIGHT; } // Danger, W.R.! Attempting to use too large a preview size could exceed the camera // bus' bandwidth limitation, resulting in gorgeous previews but the storage of // garbage capture data. int cameraLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); if (cameraLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY && android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.LOLLIPOP) { Log.d(TAG, "LEGACY CAMERA DETECTED & OLD OS DETECTED"); Size[] sizes = map.getOutputSizes(SurfaceTexture.class); for (Size option : sizes) { Log.d(TAG, "available : WIDTH: " + option.getWidth() + " HEIGHT: " + option.getHeight()); } mImageReader = ImageReader.newInstance(640, 480, ImageFormat.JPEG, 2); } else { Log.d(TAG, "LEGACY CAMERA NOT DETECTED"); mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest); mImageReader = ImageReader.newInstance(mPreviewSize.getWidth(), mPreviewSize.getHeight(), ImageFormat.JPEG, 2); Log.d(TAG, "For mPreviewSize: WIDTH: " + mPreviewSize.getWidth() + " HEIGHT: " + mPreviewSize.getHeight()); } mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // We fit the aspect ratio of TextureView to the size of preview we picked. // int orientation = getResources().getConfiguration().orientation; // if (orientation == Configuration.ORIENTATION_LANDSCAPE) { // mTextureView.setAspectRatio( // mPreviewSize.getWidth(), mPreviewSize.getHeight()); // } else { // mTextureView.setAspectRatio( // mPreviewSize.getHeight(), mPreviewSize.getWidth()); // } // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; mCameraId = cameraId; return; } } catch (CameraAccessException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } }
From source file:com.ape.camera2raw.Camera2RawFragment.java
/** * Check if we are using a device that only supports the LEGACY hardware level. * <p/>//from ww w . j a v a 2 s. c o m * Call this only with {@link #mCameraStateLock} held. * * @return true if this is a legacy device. */ private boolean isLegacyLocked() { return mCharacteristics.get( CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY; }