Search in sources :

Example 36 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project material-camera by afollestad.

the class CameraUtil method hasCamera2.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean hasCamera2(Context context, boolean stillShot) {
    if (context == null)
        return false;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        return false;
    if (stillShot && ManufacturerUtil.isSamsungDevice())
        return false;
    try {
        CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
        String[] idList = manager.getCameraIdList();
        boolean notNull = true;
        if (idList.length == 0) {
            notNull = false;
        } else {
            for (final String str : idList) {
                if (str == null || str.trim().isEmpty()) {
                    notNull = false;
                    break;
                }
                final CameraCharacteristics characteristics = manager.getCameraCharacteristics(str);
                //noinspection ConstantConditions
                final int supportLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
                if (supportLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
                    notNull = false;
                    break;
                }
            }
        }
        return notNull;
    } catch (Throwable t) {
        t.printStackTrace();
        return false;
    }
}
Also used : CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CameraManager(android.hardware.camera2.CameraManager) TargetApi(android.annotation.TargetApi)

Example 37 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project platform_frameworks_base by android.

the class Camera2SurfaceViewTestCase method openDevice.

/**
     * Open a camera device and get the StaticMetadata for a given camera id.
     *
     * @param cameraId The id of the camera device to be opened.
     */
protected void openDevice(String cameraId) throws Exception {
    mCamera = CameraTestUtils.openCamera(mCameraManager, cameraId, mCameraListener, mHandler);
    mCollector.setCameraId(cameraId);
    CameraCharacteristics properties = mCameraManager.getCameraCharacteristics(cameraId);
    mStaticInfo = new StaticMetadata(properties, CheckLevel.ASSERT, /*collector*/
    null);
    StreamConfigurationMap configMap = properties.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    mSupportRAW10 = configMap.isOutputSupportedFor(ImageFormat.RAW10);
    if (mStaticInfo.isColorOutputSupported()) {
        mOrderedPreviewSizes = getSupportedPreviewSizes(cameraId, mCameraManager, getPreviewSizeBound(mWindowManager, PREVIEW_SIZE_BOUND));
        mOrderedVideoSizes = getSupportedVideoSizes(cameraId, mCameraManager, PREVIEW_SIZE_BOUND);
        mOrderedStillSizes = getSupportedStillSizes(cameraId, mCameraManager, null);
        if (mSupportRAW10) {
            mOrderedRAW10Sizes = getSortedSizesForFormat(cameraId, mCameraManager, ImageFormat.RAW10, null);
        }
        mOrderedYUV420888Sizes = getSortedSizesForFormat(cameraId, mCameraManager, ImageFormat.YUV_420_888, null);
        // Use ImageFormat.YUV_420_888 for now. TODO: need figure out what's format for preview
        // in public API side.
        mMinPreviewFrameDurationMap = mStaticInfo.getAvailableMinFrameDurationsForFormatChecked(ImageFormat.YUV_420_888);
    }
}
Also used : CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) StaticMetadata(com.android.mediaframeworktest.helpers.StaticMetadata)

Example 38 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project platform_frameworks_base by android.

the class CameraTestUtils method getSupportedSizeForClass.

/**
     * Get the available output sizes for the given class.
     *
     */
public static Size[] getSupportedSizeForClass(Class klass, String cameraId, CameraManager cameraManager) throws CameraAccessException {
    CameraCharacteristics properties = cameraManager.getCameraCharacteristics(cameraId);
    assertNotNull("Can't get camera characteristics!", properties);
    if (VERBOSE) {
        Log.v(TAG, "get camera characteristics for camera: " + cameraId);
    }
    StreamConfigurationMap configMap = properties.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    Size[] availableSizes = configMap.getOutputSizes(klass);
    assertArrayNotEmpty(availableSizes, "availableSizes should not be empty for class: " + klass);
    Size[] highResAvailableSizes = configMap.getHighResolutionOutputSizes(ImageFormat.PRIVATE);
    if (highResAvailableSizes != null && highResAvailableSizes.length > 0) {
        Size[] allSizes = new Size[availableSizes.length + highResAvailableSizes.length];
        System.arraycopy(availableSizes, 0, allSizes, 0, availableSizes.length);
        System.arraycopy(highResAvailableSizes, 0, allSizes, availableSizes.length, highResAvailableSizes.length);
        availableSizes = allSizes;
    }
    if (VERBOSE)
        Log.v(TAG, "Supported sizes are: " + Arrays.deepToString(availableSizes));
    return availableSizes;
}
Also used : Size(android.util.Size) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap)

Example 39 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project platform_frameworks_base by android.

the class LegacyMetadataMapper method createCharacteristics.

/**
     * Create characteristics for a legacy device by mapping the {@code parameters}
     * and {@code info}
     *
     * @param parameters A string parseable by {@link Camera.Parameters#unflatten}
     * @param info Camera info with camera facing direction and angle of orientation
     * @return static camera characteristics for a camera device
     *
     * @throws NullPointerException if any of the args were {@code null}
     */
public static CameraCharacteristics createCharacteristics(String parameters, android.hardware.CameraInfo info) {
    checkNotNull(parameters, "parameters must not be null");
    checkNotNull(info, "info must not be null");
    checkNotNull(info.info, "info.info must not be null");
    CameraMetadataNative m = new CameraMetadataNative();
    mapCharacteristicsFromInfo(m, info.info);
    Camera.Parameters params = Camera.getEmptyParameters();
    params.unflatten(parameters);
    mapCharacteristicsFromParameters(m, params);
    if (DEBUG) {
        Log.v(TAG, "createCharacteristics metadata:");
        Log.v(TAG, "--------------------------------------------------- (start)");
        m.dumpToLog();
        Log.v(TAG, "--------------------------------------------------- (end)");
    }
    return new CameraCharacteristics(m);
}
Also used : Parameters(android.hardware.Camera.Parameters) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) Camera(android.hardware.Camera)

Example 40 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project platform_frameworks_base by android.

the class CameraManager method getCameraCharacteristics.

/**
     * <p>Query the capabilities of a camera device. These capabilities are
     * immutable for a given camera.</p>
     *
     * @param cameraId The id of the camera device to query
     * @return The properties of the given camera
     *
     * @throws IllegalArgumentException if the cameraId does not match any
     *         known camera device.
     * @throws CameraAccessException if the camera device has been disconnected.
     *
     * @see #getCameraIdList
     * @see android.app.admin.DevicePolicyManager#setCameraDisabled
     */
@NonNull
public CameraCharacteristics getCameraCharacteristics(@NonNull String cameraId) throws CameraAccessException {
    CameraCharacteristics characteristics = null;
    synchronized (mLock) {
        if (!getOrCreateDeviceIdListLocked().contains(cameraId)) {
            throw new IllegalArgumentException(String.format("Camera id %s does not match any" + " currently connected camera device", cameraId));
        }
        int id = Integer.parseInt(cameraId);
        /*
             * Get the camera characteristics from the camera service directly if it supports it,
             * otherwise get them from the legacy shim instead.
             */
        ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
        if (cameraService == null) {
            throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable");
        }
        try {
            if (!supportsCamera2ApiLocked(cameraId)) {
                // Legacy backwards compatibility path; build static info from the camera
                // parameters
                String parameters = cameraService.getLegacyParameters(id);
                CameraInfo info = cameraService.getCameraInfo(id);
                characteristics = LegacyMetadataMapper.createCharacteristics(parameters, info);
            } else {
                // Normal path: Get the camera characteristics directly from the camera service
                CameraMetadataNative info = cameraService.getCameraCharacteristics(id);
                characteristics = new CameraCharacteristics(info);
            }
        } catch (ServiceSpecificException e) {
            throwAsPublicException(e);
        } catch (RemoteException e) {
            // Camera service died - act as if the camera was disconnected
            throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable", e);
        }
    }
    return characteristics;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService) CameraInfo(android.hardware.CameraInfo) NonNull(android.annotation.NonNull)

Aggregations

CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)61 Size (android.util.Size)31 Camera (android.hardware.Camera)25 Rect (android.graphics.Rect)20 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)20 CaptureRequest (android.hardware.camera2.CaptureRequest)16 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)16 Parameters (android.hardware.Camera.Parameters)15 CameraManager (android.hardware.camera2.CameraManager)12 ZoomData (android.hardware.camera2.legacy.ParameterUtils.ZoomData)10 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)10 ServiceSpecificException (android.os.ServiceSpecificException)10 Range (android.util.Range)10 ArrayList (java.util.ArrayList)10 CameraAccessException (android.hardware.camera2.CameraAccessException)8 NonNull (android.annotation.NonNull)5 CameraInfo (android.hardware.Camera.CameraInfo)5 CameraInfo (android.hardware.CameraInfo)5 ICameraService (android.hardware.ICameraService)5 Face (android.hardware.camera2.params.Face)5