Java Code Examples for android.hardware.camera2.CameraCharacteristics#Key

The following examples show how to use android.hardware.camera2.CameraCharacteristics#Key . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraMetadataNative.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Compare this key against other native keys, request keys, result keys, and
 * characteristics keys.
 *
 * <p>Two keys are considered equal if their name and type reference are equal.</p>
 *
 * <p>Note that the equality against non-native keys is one-way. A native key may be equal
 * to a result key; but that same result key will not be equal to a native key.</p>
 */
@SuppressWarnings("rawtypes")
@Override
public final boolean equals(Object o) {
    if (this == o) {
        return true;
    }

    if (o == null || this.hashCode() != o.hashCode()) {
        return false;
    }

    Key<?> lhs;

    if (o instanceof CaptureResult.Key) {
        lhs = ((CaptureResult.Key)o).getNativeKey();
    } else if (o instanceof CaptureRequest.Key) {
        lhs = ((CaptureRequest.Key)o).getNativeKey();
    } else if (o instanceof CameraCharacteristics.Key) {
        lhs = ((CameraCharacteristics.Key)o).getNativeKey();
    } else if ((o instanceof Key)) {
        lhs = (Key<?>)o;
    } else {
        return false;
    }

    return mName.equals(lhs.mName) && mTypeReference.equals(lhs.mTypeReference);
}
 
Example 2
Source File: OSFragment.java    From DeviceInfo with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private String formatCameraCharacteristics(CameraCharacteristics info) {
    String infoText;
    if (info != null) {
        StringBuilder infoBuilder = new StringBuilder(
                "Camera characteristics:\n\n");

        for (CameraCharacteristics.Key<?> key : info.getKeys()) {
            infoBuilder.append(String.format(Locale.US, "%s:  ",
                    key.getName()));

            Object val = info.get(key);
            if (val.getClass().isArray()) {
                // Iterate an array-type value
                // Assumes camera characteristics won't have arrays of arrays as values
                int len = Array.getLength(val);
                infoBuilder.append("[ ");
                for (int i = 0; i < len; i++) {
                    infoBuilder.append(String.format(Locale.US, "%s%s",
                            Array.get(val, i), (i + 1 == len) ? ""
                                    : ", "));
                }
                infoBuilder.append(" ]\n\n");
            } else {
                // Single value
                infoBuilder.append(String.format(Locale.US, "%s\n\n",
                        val.toString()));
            }
        }
        infoText = infoBuilder.toString();
    } else {
        infoText = "No info";
    }
    return infoText;
}
 
Example 3
Source File: CameraMetadataNative.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * @hide
 */
public <T> T get(CameraCharacteristics.Key<T> key) {
    return get(key.getNativeKey());
}
 
Example 4
Source File: CameraMetadataNative.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public <T> void set(CameraCharacteristics.Key<T> key, T value) {
    set(key.getNativeKey(), value);
}
 
Example 5
Source File: CameraMetadataNative.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private <T> T getBase(CameraCharacteristics.Key<T> key) {
    return getBase(key.getNativeKey());
}
 
Example 6
Source File: CameraMetadataNative.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private <T> void setBase(CameraCharacteristics.Key<T> key, T value) {
    setBase(key.getNativeKey(), value);
}
 
Example 7
Source File: CameraTexture2.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sets up member variables related to camera.
 */
private void setUpCameraOutputs(int width, int height) throws CameraAccessException {
    MLog.d(TAG, "setUpCameraOutputs");

    String[] cameras = mCameraManager.getCameraIdList();

    for (int i = 0; i < cameras.length; i++) {
        MLog.d(TAG, "camera " + cameras[i]);
    }

    String cameraId = cameras[0];
    CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(cameraId);
    List<CameraCharacteristics.Key<?>> keys = characteristics.getKeys();
    for (int i = 0; i < keys.size(); i++) {
        Object val = characteristics.get(keys.get(i));
        MLog.d(TAG, "characteristic " + keys.get(i) + " " + val);
    }

    // is it facingcamera
    Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
    StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

    // For still image captures, we use the largest available size.
    Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea());
    mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2);
    mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, null);

    // 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 rotatedPreviewWidth = 500;
    int rotatedPreviewHeight = 500;
    int maxPreviewWidth = 500;
    int maxPreviewHeight = 500;
    mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
            rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
            maxPreviewHeight, largest);

    //TODO mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());

    mCameraId = cameraId;
}
 
Example 8
Source File: CustomVideoCapturerCamera2.java    From opentok-android-sdk-samples with MIT License 4 votes vote down vote up
public <T> T get(CameraCharacteristics.Key<T> key) {
    return info.get(key);
}