Search in sources :

Example 11 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_frameworks_base by AOSPA.

the class CamcorderProfile method hasProfile.

/**
     * Returns true if camcorder profile exists for the first back-facing
     * camera at the given quality level.
     *
     * <p>
     * When using the Camera 2 API in {@code LEGACY} mode (i.e. when
     * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL} is set
     * to
     * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY}),
     * {@link #hasProfile} may return {@code true} for unsupported resolutions.  To ensure a
     * a given resolution is supported in LEGACY mode, the configuration given in
     * {@link android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP}
     * must contain the the resolution in the supported output sizes.  The recommended way to check
     * this is with
     * {@link android.hardware.camera2.params.StreamConfigurationMap#getOutputSizes(Class)} with the
     * class of the desired recording endpoint, and check that the desired resolution is contained
     * in the list returned.
     * </p>
     * @see android.hardware.camera2.CameraManager
     * @see android.hardware.camera2.CameraCharacteristics
     *
     * @param quality the target quality level for the camcorder profile
     */
public static boolean hasProfile(int quality) {
    int numberOfCameras = Camera.getNumberOfCameras();
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
            return hasProfile(i, quality);
        }
    }
    return false;
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo)

Example 12 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_frameworks_base by ResurrectionRemix.

the class CameraDeviceUserShim method connectBinderShim.

public static CameraDeviceUserShim connectBinderShim(ICameraDeviceCallbacks callbacks, int cameraId) {
    if (DEBUG) {
        Log.d(TAG, "Opening shim Camera device");
    }
    /*
         * Put the camera open on a separate thread with its own looper; otherwise
         * if the main thread is used then the callbacks might never get delivered
         * (e.g. in CTS which run its own default looper only after tests)
         */
    CameraLooper init = new CameraLooper(cameraId);
    CameraCallbackThread threadCallbacks = new CameraCallbackThread(callbacks);
    // TODO: Make this async instead of blocking
    int initErrors = init.waitForOpen(OPEN_CAMERA_TIMEOUT_MS);
    Camera legacyCamera = init.getCamera();
    // Check errors old HAL initialization
    LegacyExceptionUtils.throwOnServiceError(initErrors);
    // Disable shutter sounds (this will work unconditionally) for api2 clients
    legacyCamera.disableShutterSound();
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    Camera.Parameters legacyParameters = null;
    try {
        legacyParameters = legacyCamera.getParameters();
    } catch (RuntimeException e) {
        throw new ServiceSpecificException(ICameraService.ERROR_INVALID_OPERATION, "Unable to get initial parameters: " + e.getMessage());
    }
    CameraCharacteristics characteristics = LegacyMetadataMapper.createCharacteristics(legacyParameters, info);
    LegacyCameraDevice device = new LegacyCameraDevice(cameraId, legacyCamera, characteristics, threadCallbacks);
    return new CameraDeviceUserShim(cameraId, device, characteristics, init, threadCallbacks);
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) Camera(android.hardware.Camera) CameraInfo(android.hardware.Camera.CameraInfo)

Example 13 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_frameworks_base by ResurrectionRemix.

the class CameraStreamer method getDefaultFacing.

/**
     * Returns the camera facing that is chosen when DONT_CARE is specified.
     * Returns 0 if neither a front nor back camera could be found.
     */
public static int getDefaultFacing() {
    int camCount = Camera.getNumberOfCameras();
    if (camCount == 0) {
        return 0;
    } else {
        CameraInfo cameraInfo = new CameraInfo();
        Camera.getCameraInfo(0, cameraInfo);
        return (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) ? FACING_FRONT : FACING_BACK;
    }
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo)

Example 14 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android-vision by googlesamples.

the class CameraSource method setRotation.

/**
     * Calculates the correct rotation for the given camera id and sets the rotation in the
     * parameters.  It also sets the camera's display orientation and rotation.
     *
     * @param parameters the camera parameters for which to set the rotation
     * @param cameraId   the camera id to set rotation based on
     */
private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) {
    WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    int degrees = 0;
    int rotation = windowManager.getDefaultDisplay().getRotation();
    switch(rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
        default:
            Log.e(TAG, "Bad rotation value: " + rotation);
    }
    CameraInfo cameraInfo = new CameraInfo();
    Camera.getCameraInfo(cameraId, cameraInfo);
    int angle;
    int displayAngle;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        angle = (cameraInfo.orientation + degrees) % 360;
        // compensate for it being mirrored
        displayAngle = (360 - angle);
    } else {
        // back-facing
        angle = (cameraInfo.orientation - degrees + 360) % 360;
        displayAngle = angle;
    }
    // This corresponds to the rotation constants in {@link Frame}.
    mRotation = angle / 90;
    camera.setDisplayOrientation(displayAngle);
    parameters.setRotation(angle);
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo) SuppressLint(android.annotation.SuppressLint) WindowManager(android.view.WindowManager)

Example 15 with CameraInfo

use of android.hardware.Camera.CameraInfo in project wechat by motianhuo.

the class CameraHelper method startCapture.

/**
	 * 开启相机拍摄
	 */
public void startCapture() {
    if (mCamera == null) {
        // mCamera = Camera.open();
        camera_count = Camera.getNumberOfCameras();
        Log.e(TAG, "camera count:" + camera_count);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
            for (int i = 0; i < camera_count; i++) {
                CameraInfo info = new CameraInfo();
                Camera.getCameraInfo(i, info);
                // find front camera
                if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
                    Log.e(TAG, "to open front camera");
                    mCamera = Camera.open(i);
                }
            }
        }
        if (mCamera == null) {
            Log.e(TAG, "AAAAA OPEN camera");
            mCamera = Camera.open();
        }
    }
    try {
        mCamera.stopPreview();
        mParameters = mCamera.getParameters();
        if (isScreenOriatationPortrait()) {
            mCamera.setDisplayOrientation(90);
        }
        mParameters.setPreviewSize(mwidth, mheight);
        mParameters.setPreviewFrameRate(25);
        mCamera.setParameters(mParameters);
        int mformat = mParameters.getPreviewFormat();
        int bitsperpixel = ImageFormat.getBitsPerPixel(mformat);
        Log.e(TAG, "pzy bitsperpixel: " + bitsperpixel);
        yuv_frame = new byte[mwidth * mheight * bitsperpixel / 8];
        yuv_Rotate90 = new byte[mwidth * mheight * bitsperpixel / 8];
        yuv_Rotate90lr = new byte[mwidth * mheight * bitsperpixel / 8];
        mCamera.addCallbackBuffer(yuv_frame);
        // mCamera.setPreviewDisplay(holder);
        mCamera.setPreviewDisplay(localSurfaceHolder);
        mCamera.setPreviewCallbackWithBuffer(this);
        EMVideoCallHelper.getInstance().setResolution(mwidth, mheight);
        mCamera.startPreview();
        Log.d(TAG, "camera start preview");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo)

Aggregations

CameraInfo (android.hardware.Camera.CameraInfo)56 Camera (android.hardware.Camera)6 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)5 ServiceSpecificException (android.os.ServiceSpecificException)5 SuppressLint (android.annotation.SuppressLint)3 WindowManager (android.view.WindowManager)2 IOException (java.io.IOException)2 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Face (android.hardware.Camera.Face)1 FaceDetectionListener (android.hardware.Camera.FaceDetectionListener)1 MediaRecorder (android.media.MediaRecorder)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Pair (android.util.Pair)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 AppDataDirGuesser (com.google.testing.littlemock.AppDataDirGuesser)1