第22讲 Android Camera2 API SessionParameter实战

本讲是Android Camera专题系列的第22讲,我们介绍Android Camera2 API专题的Session Parameter实战,包括如下内容:

  • 如何避免re-configure session

视频在线观看:

如何避免re-configure session

对App而言(创建Session时带上Session Parameter)

  • 获取Available Session Keys
  • 如果Session Keys不为Null,创建Session时将这些Session Keys进行赋值,并尽量保持Session使用过程中不去更改

对HAL而言

  • 防止三方App发生re-configuration
  • 使用Vendor Tag来定义Session Parameter,不要在默认的CaptureRequest里面带Session Keys

Camera App使用Session Parameter

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    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());
    mCameraDevice.createCaptureSession(mSessionConfiguration);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
很抱歉,我之前的回答中提到的 `SessionConfiguration` 是与自然语言处理相关的,与 Android 相机开发无关。如果您要在 Android Camera2 中创建会话(Session),可以使用 `CameraCaptureSession` 类。下面是一个示例代码片段,用于创建一个 `CameraCaptureSession` 对象: ```java private CameraCaptureSession mCameraCaptureSession; private void createCameraSession() { try { Surface surface = mPreviewSurface; mImageReader = ImageReader.newInstance(mPreviewSize.getWidth(), mPreviewSize.getHeight(), ImageFormat.JPEG, 1); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); List<Surface> outputSurfaces = new ArrayList<>(); outputSurfaces.add(surface); outputSurfaces.add(mImageReader.getSurface()); mCameraDevice.createCaptureSession(outputSurfaces, mStateCallback, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } } private CameraCaptureSession.StateCallback mStateCallback = new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mCameraCaptureSession = cameraCaptureSession; try { mCameraCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Log.e(TAG, "onConfigureFailed: CameraCaptureSession configuration failed"); } }; ``` 在上面的代码中,我们使用 `CameraDevice` 的 `createCaptureSession()` 方法来创建一个会话。我们在 `createCaptureSession()` 方法中指定了要输出的 `Surface` 列表,包括预览 `Surface` 和图像读取器 `Surface`。在 `onConfigured()` 方法中,我们将创建的 `CameraCaptureSession` 对象保存在变量 `mCameraCaptureSession` 中,并将预览请求设置为重复请求,这样就可以实时预览相机输出了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

deepinout_camera

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值