自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
会话参数
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在捕获会话初始化阶段,会话参数功能使摄像头客户端可以主动配置一部分耗时较长的请求参数(即会话参数),从而减少延迟。借助此功能,您的 HAL 实现会在信息流配置阶段(而不是第一个捕获请求期间)接收客户端参数,并且可以根据它们的值更高效地准备和构建内部流水线。
在 Android 10 中,您可以使用可选的会话重新配置查询功能来更好地控制内部会话参数重新配置逻辑,从而提高性能。如需了解详情,请参阅会话重新配置查询。
示例和源代码
参考会话参数实现已经成为 CameraHal 的一部分。此 HAL 使用旧版 Hal API。实现 Camera HIDL API 的绑定式 CameraHal 必须使用相应的 HIDL sessionParams 条目在信息流配置期间访问所有新的传入会话参数。
摄像头客户端可以通过调用 getAvailableSessionKeys()
来查询所有受支持的会话参数的键,并最终通过 setSessionParameters()
设置它们的初始值。
实现
您的 CameraHal 实现必须在相应的静态摄像头元数据中填充 ANDROID_REQUEST_AVAILABLE_SESSION_KEYS
,并提供 ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS
的一个子集(其中包含难以按帧应用的键的列表,如果在捕获会话生命周期内修改这些键,则可能会导致意外延迟)。
典型示例包括:需要耗费时间重新配置硬件或更改内部摄像头流水线的参数。控制会话参数仍然可以在捕获请求中发挥作用,不过,客户端应意识到并预料到其应用会出现延迟。
框架会监控所有传入请求,如果它检测到会话参数值发生变化,则会在内部重新配置相机。然后,已传递到 CameraHal 的新流配置中会包含更新后的会话参数值(用于更高效地配置相机流水线)。
自定义
您可以在 CameraHal 端填充的可用会话参数列表中定义标记。如果 CameraHal 将可用会话参数列表留空,此功能将无效。
验证
CTS 提供以下用于测试会话参数的新用例:
通常,在某个参数成为会话密钥列表的一部分之后,其当前值就会添加到在信息流配置期间在 HAL 层传递的会话参数中。
选择会话参数时请务必谨慎。不应频繁更改流配置之间的会话参数值(如果有的话)。如果参数频繁更改(例如捕获 intent),其适用性会非常低;如果将此类参数添加到会话参数列表中,则可能会因内部重新配置过多而导致 CTS 问题。
会话重新配置查询
Android 10 引入了可选的会话重新配置查询功能来提高性能,因为会话参数值修改导致的内部信息流重新配置会降低性能。为了解决此问题,HIDL ICameraDeviceSession
3.5 及更高版本支持 isReconfigurationRequired
方法,该方法提供对内部会话参数重新配置逻辑的精细控制。使用此方法,可在需要时精确地进行信息流重新配置。
isReconfigurationRequired
的参数提供有关每个待修改会话参数的必需信息,允许针对各种设备进行自定义。
此功能仅在摄像头服务和相机 HAL 中实现。没有面向公众的 API。如果此功能得以实现,摄像头客户端在使用会话参数时性能应该会有明显的提升。
实现
如需支持会话重新配置查询,您必须实现 isReconfigurationRequired
方法来检查新会话参数值是否需要重新配置完整的信息流。
如果客户端更改任何通告的会话参数的值,相机框架会调用 isReconfigurationRequired
方法。根据具体值,HAL 会决定是否需要重新配置完整的信息流。如果 HAL 返回 false
,则相机框架会跳过内部重新配置。如果 HAL 返回 true
,则该框架会重新配置信息流并相应地传递新的会话参数值。
在使用新参数的请求提交给 HAL 之前,该框架可以调用 isReconfigurationRequired
方法,并且可以在该请求提交之前将其取消。因此,HAL 不得使用此方法调用以任何方式更改其行为。
HAL 实现必须满足以下要求:
- 在配置活跃会话后,该框架必须能够随时调用
isReconfigurationRequired
方法。
- 务必避免对待处理摄像头请求的性能产生影响。特别是,在正常的摄像头流式传输期间,不得有任何故障或延迟。
设备和 HAL 实现必须满足以下性能方面的要求:
- 不得更改硬件和软件摄像头设置。
- 不得对摄像头性能造成用户可见的影响。
isReconfigurationRequired
方法接受以下参数:
oldSessionParams
:上一个会话的会话参数。通常是现有的会话参数。
newSessionParams
:客户端设置的新会话参数。
预期的返回状态代码包括:
OK
:成功重新配置所需的查询。
METHOD_NOT_SUPPORTED
:摄像头设备不支持重新配置查询。
INTERNAL_ERROR
:由于内部错误,重新配置查询无法完成。
返回值包括:
true
:需要重新配置信息流。
false
:不需要重新配置信息流。
如需忽略会话重新配置查询,HAL 应返回 METHOD_NOT_SUPPORTED
或 false
。这会导致默认的摄像头服务行为,其中在每个会话参数更改时触发信息流重新配置。
验证
可以使用 CameraHidlTest#configureStreamsWithSessionParameters
中的 VTS 测试用例验证会话重新配置查询功能。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Session parameters\n\nThe session parameters feature reduces delays by enabling camera clients to\nactively configure the subset of costly request parameters, that is, session\nparameters, as part of the capture session initialization phase. With this\nfeature, your HAL implementations receive the client parameters during the\nstream configuration phase instead of the first capture request and can,\ndepending on their values, prepare and build the internal pipeline more\nefficiently.\n\nIn Android 10, you can improve performance by using\nthe optional session reconfiguration query feature for more control over the\ninternal session parameter reconfiguration logic. For more information, see\n[Session reconfiguration query](#session_reconfiguration_query).\n\nExamples and source\n-------------------\n\nA reference session parameter implementation is already part of the\n[CameraHal](https://android.googlesource.com/platform/hardware/qcom/camera/+/main/msm8998/QCamera2/HAL3/QCamera3HWI.cpp).\nThis HAL uses the legacy Hal API.\nThe [binderized](/docs/core/architecture/hal-types)\nCameraHal that implements the camera HIDL API must use the respective HIDL\n[sessionParams](https://android.googlesource.com/platform/hardware/interfaces/+/android16-release/camera/device/3.4/types.hal#111)\nentry to access any new incoming session parameters during stream configuration.\n\nCamera clients can query the keys of all supported session parameters by calling\n[`getAvailableSessionKeys()`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#getAvailableSessionKeys())\nand eventually set their initial values through\n[`setSessionParameters()`](https://developer.android.com/reference/android/hardware/camera2/params/SessionConfiguration#setSessionParameters(android.hardware.camera2.CaptureRequest)).\n\nImplementation\n--------------\n\nYour CameraHal implementation must populate the\n[`ANDROID_REQUEST_AVAILABLE_SESSION_KEYS`](https://android.googlesource.com/platform/hardware/interfaces/+/android16-release/camera/metadata/3.3/types.hal#98)\nwithin the respective static camera metadata and provide a subset of\n[`ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS`](https://android.googlesource.com/platform/hardware/interfaces/+/android16-release/camera/metadata/3.2/types.hal#1016),\nwhich contains a list of keys that are difficult to apply per-frame and can\nresult in unexpected delays when modified during the capture session lifetime.\n\nTypical examples include parameters that require a time-consuming hardware\nreconfiguration or an internal camera pipeline change. Control over session\nparameters can still be exerted in capture requests but clients should be aware\nof and expect delays in their app.\n\nThe framework monitors all incoming requests and if it detects a change in the\nvalue of a session parameter, it internally reconfigures the camera. The new\nstream configuration passed to CameraHal then includes the updated session\nparameter values, which are used to configure the camera pipeline more\nefficiently.\n\nCustomization\n-------------\n\nYou can define tags in the available session parameter list that is populated on\nthe CameraHal side. This feature is not active if CameraHal leaves the\navailable session parameter list empty.\n\nValidation\n----------\n\nCTS includes the following new cases for testing session parameters:\n\n- [`CameraDeviceTest#testSessionConfiguration`](https://android.googlesource.com/platform/cts/+/a3676a2dfa0630204be80a3c1f1cbbe6db2c3925/tests/camera/src/android/hardware/camera2/cts/CameraDeviceTest.java#793)\n- [`CameraDeviceTest#testCreateSessionWithParameters`](https://android.googlesource.com/platform/cts/+/a3676a2dfa0630204be80a3c1f1cbbe6db2c3925/tests/camera/src/android/hardware/camera2/cts/CameraDeviceTest.java#868)\n- [`CameraDeviceTest#testSessionParametersStateLeak`](https://android.googlesource.com/platform/cts/+/42f4eb187e216363208b96b726ec4287ce512231/tests/camera/src/android/hardware/camera2/cts/CameraDeviceTest.java#870)\n- [`NativeCameraDeviceTest#testCameraDevicePreviewWithSessionParameters`](https://android.googlesource.com/platform/cts/+/a3676a2dfa0630204be80a3c1f1cbbe6db2c3925/tests/camera/libctscamera2jni/native-camera-jni.cpp#2140)\n\nIn general, after a certain parameter is part of the session key list, its\ncurrent value is included as part of the session parameters passed during stream\nconfiguration at the HAL layer.\n\nSession parameters must be carefully selected. The values shouldn't change\nfrequently, if at all, between stream configurations. Parameters that change\nfrequently, such as capture intent, are ill-suited and adding them to the\nsession parameter list could cause CTS failures due to excessive internal\nre-configuration.\n\nSession reconfiguration query\n-----------------------------\n\nAndroid 10 introduces an optional session\nreconfiguration query feature to\nimprove performance as internal stream reconfigurations resulting from session\nparameter value modifications can reduce performance. To address this concern,\nHIDL\n[`ICameraDeviceSession`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/camera/device/3.5/ICameraDeviceSession.hal)\nversion 3.5 and higher supports the\n[`isReconfigurationRequired`](https://android.googlesource.com/platform/hardware/interfaces/+/22eac5f667dfca8de336ddc45ad60a08250f6b30/camera/device/3.5/ICameraDeviceSession.hal#146)\nmethod, which provides fine-grained control over the internal session parameter\nreconfiguration logic. Using this method, stream reconfiguration can occur\nprecisely when required.\n\nThe arguments for `isReconfigurationRequired`\nprovide the required information about every pending session parameter\nmodification, allowing for various kinds of device-specific customizations.\n\nThis feature is implemented only in the camera service and the camera HAL. There\nare no public-facing APIs. If this feature is implemented, camera clients should\nsee performance improvements when working with session parameters.\n\n### Implementation\n\nTo support session reconfiguration queries, you must implement the\n[`isReconfigurationRequired`](https://android.googlesource.com/platform/hardware/interfaces/+/22eac5f667dfca8de336ddc45ad60a08250f6b30/camera/device/3.5/ICameraDeviceSession.hal#146)\nmethod to check whether complete stream reconfiguration is required for new\nsession parameter values.\n\nIf the client changes the value of any advertised session parameter, the camera\nframework calls the `isReconfigurationRequired`\nmethod. Depending on the specific values, the HAL decides whether a complete\nstream reconfiguration is required. If the HAL returns `false`, the camera\nframework skips the internal reconfiguration. If the HAL returns `true`, the\nframework reconfigures the streams and passes the new session parameter values\naccordingly.\n\nThe `isReconfigurationRequired` method can be called by the framework some time\nbefore a request with new parameters is submitted to the HAL, and the request\ncan be cancelled before it is submitted. Therefore, the HAL must not use this\nmethod call to change its behavior in any way.\n\nThe HAL implementation must meet the following requirements:\n\n- The framework must be able to call the `isReconfigurationRequired` method at any time after active session configuration.\n- There must be no impact on the performance of pending camera requests. In particular, there must not be any glitches or delays during normal camera streaming.\n\nThe device and HAL implementation must meet the following performance\nrequirements:\n\n- Hardware and software camera settings must not be changed.\n- There must be no user-visible impact on camera performance.\n\nThe `isReconfigurationRequired`\nmethod takes the following arguments:\n\n- `oldSessionParams`: Session parameters from the previous session. Usually the existing session parameters.\n- `newSessionParams`: New session parameters that are set by the client.\n\nThe expected return status codes are:\n\n- `OK`: Successful reconfiguration required query.\n- `METHOD_NOT_SUPPORTED`: The camera device doesn't support the reconfiguration query.\n- `INTERNAL_ERROR`: The reconfiguration query can't complete due to an internal error.\n\nThe return values are:\n\n- `true`: Stream reconfiguration is required.\n- `false`: Stream reconfiguration isn't required.\n\nTo ignore a session reconfiguration query, the HAL returns\n`METHOD_NOT_SUPPORTED` or `false`. This results in the default camera service\nbehavior where stream reconfiguration is triggered on each session parameter\nchange.\n\n### Validation\n\nThe session reconfiguration query feature can be validated using the VTS test\ncase in\n[`CameraHidlTest#configureStreamsWithSessionParameters`](https://android.googlesource.com/platform/hardware/interfaces/+/e18057b42f1698f33f34d14e86a53934bd337bb8/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp#2653)."]]