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

本讲是Android Camera专题系列的第25讲,我们介绍Android Camera2 API专题的获取Physical Camera数据流,包括如下内容:

  • 判断是否支持Logical MultiCamera
  • 创建Physical Camera Jpeg Stream
  • 创建Physical Camera Capture Session
  • 读取Physical Camera CaptureResult

视频在线观看:

加入知识星球与更多Camera同学交流
– 星球名称:深入浅出Android Camera
– 星球ID: 17296815

判断是否支持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));
}
赞(0)
未经允许不得转载:极客笔记 » 第25讲 Android Camera2 API 获取Physical Camera数据流
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

Android Camera2 API