第25讲 获取Physical Camera数据流 - Android Camera2 API

本讲是Android Camera专题系列的第25讲,我们介绍Android Camera2 API专题的获取Physical Camera数据流。

更多资源:

资源 描述
在线课程 极客笔记在线课程
知识星球 星球名称:深入浅出Android Camera
星球ID: 17296815
Wechat 极客笔记圈

判断是否支持Logical MultiCamera

mIsLogicalMultiCamera = mStaticMetadata.isCapabilitySupported(
        CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA);
Set<String> physicalCameraIds = manager.getCameraCharacteristics(cameraIdS).getPhysicalCameraIds();

创建Physical Camera Jpeg Stream

private void setupPhysicalCameraStreamImageReader() {
    if (mEnableCapturePhysicalStream) {
        mPhysical0ImageReader = ImageReader.newInstance(mPhysical0JpegSize.getWidth(),
                mPhysical0JpegSize.getHeight(), ImageFormat.JPEG, 2);
        mPhysical0ImageReader.setOnImageAvailableListener(
                new OnImageAvailableListener(), mCameraBackgroundHandler);
        mPhysical1ImageReader = ImageReader.newInstance(mPhysical1JpegSize.getWidth(),
                mPhysical1JpegSize.getHeight(), ImageFormat.JPEG, 2);
        mPhysical1ImageReader.setOnImageAvailableListener(
                new OnImageAvailableListener(), mCameraBackgroundHandler);
    }
}

创建Physical Camera Capture Session

if (mEnableCapturePhysicalStream) {
    OutputConfiguration physical0OutputConfiguration = new OutputConfiguration(mPhysical0ImageReader.getSurface());
    physical0OutputConfiguration.setPhysicalCameraId(mPhysicalCameraIds[0]);
    outputConfigurations.add(physical0OutputConfiguration);

    OutputConfiguration physical1OutputConfiguration = new OutputConfiguration(mPhysical1ImageReader.getSurface());
    physical1OutputConfiguration.setPhysicalCameraId(mPhysicalCameraIds[1]);
    outputConfigurations.add(physical1OutputConfiguration);

    mSessionConfiguration = new SessionConfiguration(
            is_video_high_speed ?
                    SessionConfiguration.SESSION_HIGH_SPEED : SessionConfiguration.SESSION_REGULAR,
            outputConfigurations,
            new CameraTestUtils.HandlerExecutor(mCameraBackgroundHandler),
            myStateCallback
    );
    if (inputConfiguration != null) {
        mSessionConfiguration.setInputConfiguration(inputConfiguration);
    }
    mSessionConfiguration.setSessionParameters(mPreviewBuilder.build());
    if (!mCameraDevice.isSessionConfigurationSupported(mSessionConfiguration)) {
        outputConfigurations.remove(physical0OutputConfiguration);
        outputConfigurations.remove(physical1OutputConfiguration);
        Log.i(TAG, "Physical_Camera session configuration not supported!");
        mEnableCapturePhysicalStream = false;
    }
}

读取Physical Camera CaptureResult

Map<String, CaptureResult> physicalCameraResults = result.getPhysicalCameraResults();
if (mEnableCapturePhysicalStream &&
        physicalCameraResults.get(mPhysicalCameraIds[0]) != null &&
        physicalCameraResults.get(mPhysicalCameraIds[1]) != null) {
    Log.i(TAG, "Physical_Camera" + mPhysicalCameraIds[0] + "'s result timestamp:" +
            physicalCameraResults.get(mPhysicalCameraIds[0]).get(CaptureResult.SENSOR_TIMESTAMP));
    Log.i(TAG, "Physical_Camera" + mPhysicalCameraIds[1] + "'s result timestamp:" +
            physicalCameraResults.get(mPhysicalCameraIds[1]).get(CaptureResult.SENSOR_TIMESTAMP));
}

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程

Android Camera2 API