[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Concurrent camera streaming\n\nAndroid allows devices to support concurrent streaming of camera devices. For\nexample, this allows a device to have both the front and back cameras operating\nat the same time. From Android 11, the Camera2 API\nincludes the following methods\nthat apps can call to determine if the cameras support concurrent streaming and\nthe stream configurations that are supported.\n\n- [`getConcurrentCameraIds`](https://developer.android.com/reference/android/hardware/camera2/CameraManager#getConcurrentCameraIds()): Gets the set of combinations of currently connected camera device identifiers that support configuring camera device sessions concurrently.\n- [`isConcurrentSessionConfigurationSupported`](https://developer.android.com/reference/android/hardware/camera2/CameraManager?hl=id#isConcurrentSessionConfigurationSupported(java.util.Map%3Cjava.lang.String,%20android.hardware.camera2.params.SessionConfiguration%3E)): Checks whether the provided set of camera devices and their corresponding session configurations can be configured concurrently.\n\nA set of mandatory stream combinations that must be supported during concurrent\nstreaming are included through a camera device's camera characteristics in the\n[`SCALER_MANDATORY_CONCURRENT_STREAM_COMBINATIONS`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#SCALER_MANDATORY_CONCURRENT_STREAM_COMBINATIONS)\nproperty.\n\nEach camera device advertised through `getConcurrentStreamingCameraIds()` must\nsupport the following guaranteed configurations for concurrent streams.\n\n| Target 1 || Target 2 || |\n| Type | Max size | Type | Max size | Sample use cases |\n|------------|----------|------------|----------|-----------------------------------------|\n| YUV | s1440p | | | In-app video or image processing |\n| PRIV | s1440p | | | In-app viewfinder analysis |\n| JPEG | s1440p | | | No viewfinder still image capture |\n| YUV / PRIV | s720p | JPEG | s1440p | Standard still imaging |\n| YUV / PRIV | s720p | YUV / PRIV | s1440p | In-app video or processing with preview |\n\nDevices with the `MONOCHROME` capability\n([`CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES`](https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES)\nincludes\n[`CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MONOCHROME`](https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MONOCHROME))\nsupporting Y8 must support substituting YUV streams with Y8 in all guaranteed\nstream combinations.\n\n`s720p` refers to 720p (1280 x 720) or the maximum supported resolution for the\nparticular format returned by\n[`StreamConfigurationMap.getOutputSizes()`](https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap#getOutputSizes(int)).\n`s1440p` refers to 1440p (1920 x 1440) or the maximum supported resolution for\nthe particular format returned by\n[`StreamConfigurationMap.getOutputSizes()`](https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap#getOutputSizes(int)).\nDevices whose capabilities don't include\n[`ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE`](https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE)\nmust support at least a single Y16 stream, `Dataspace::DEPTH` with sVGA\nresolution, during concurrent operation, where sVGA is the smaller of the two\nfollowing resolutions:\n\n- maximum output resolution for the given format\n- 640 x 480\n\nImplementation\n--------------\n\nTo allow apps to query a device to determine if its\ncameras support concurrent streaming, implement the\n[`ICameraProvider@2.6`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/camera/provider/2.6/ICameraProvider.hal)\nHAL interface, which includes the following methods:\n\n- [`getConcurrentStreamingCameraIds`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/camera/provider/2.6/ICameraProvider.hal#101)\n- [`isConcurrentStreamCombinationSupported`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/camera/provider/2.6/ICameraProvider.hal#149)\n\nFor a reference implementation of the `ICameraProvider@2.6`HAL interface, see\nthe emulated camera HAL library at\n[`EmulatedCameraProviderHWLImpl.cpp`](https://android.googlesource.com/platform/hardware/google/camera/+/refs/heads/android16-release/devices/EmulatedCamera/hwl/EmulatedCameraProviderHWLImpl.cpp#256).\n\nValidation\n----------\n\nTo test that your implementation of this feature works as intended, use the\n[`ConcurrentCameraTest.java`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/ConcurrentCameraTest.java)\nCTS test. Also, test using an app that opens up multiple cameras and operates\nthem concurrently.\n\nResource allocations problems\n-----------------------------\n\nIf camera HALs advertise support for concurrent operation of\ncamera devices, they might run into resource allocation problems, especially in\nthe case where there are enough image signal processor (ISP) resources on the\nphone to stream both front and back (or other) cameras concurrently, but not to\ntheir full capacity. In this case, the camera HAL must allocate limited\nhardware resources to each camera device.\n\n### Example scenario\n\nThe following scenario demonstrates this problem.\n\n#### Problem\n\nThe device has the following configuration:\n\n- Camera ID `0` is a logical camera backed by a wide and ultra-wide camera, which each take one ISP resource.\n- Camera ID `1` is a camera which takes one ISP resource.\n\nThe device (phone) has two ISPs. If camera ID `0` is opened and a session is\nconfigured, it's possible that the camera HAL reserves two ISPs anticipating\nboth ultrawide and wide camera use.\n\nIf that's the case, the front camera (ID `1`) can't configure any\nstreams because both ISPs are in use.\n\n#### Solution\n\nTo address this problem, the framework can open both camera IDs `0` and `1`\nbefore configuring sessions to provide a hint to the camera HAL about how to\nallocate resources (because it now expects concurrent operation of cameras).\nHowever, this can lead to limited capabilities, for example, zoom might not be\nable to handle the full zoom range ratio (because switching physical camera\nIDs might be problematic).\n\nTo implement this solution, make the following updates to\n`provider@2.6::ICameraProvider::getConcurrentCameraStreamingCameraIds`.\n\n- Mandate that for concurrent operation of cameras, the camera\n framework must open camera devices (`@3.2::ICameraDevice::open`) before\n configuring any sessions on the camera devices. This allows camera\n providers to allocate resources accordingly.\n\n- To address the issue of not being able to handle the full\n zoom range ratio, ensure that camera apps, when using cameras concurrently,\n are guaranteed to use the `ZOOM_RATIO` control setting between only 1x and\n `MAX_DIGITAL_ZOOM` instead of the complete `ZOOM_RATIO_RANGE` (this\n prevents the switching of physical cameras internally, which potentially\n requires more ISPs).\n\n| **Note:** Camera IDs advertised in a combination through `getConcurrenStreamingCameraIds` must not conflict. For example if `getConcurrentStreamingCameraIds` advertises {0,1}, {2,1}, camera IDs `0` and `2` are allowed to conflict, however camera IDs `0` and `1`, and `1` and `2` must not conflict.\n\n#### Problem with testDualCameraPreview\n\nWhen you make the updates above, it can create a problem with a behavior allowed\nby the `MultiViewTest.java#testDualCameraPreview` test.\n\nThe test `testDualCameraPreview` doesn't configure sessions only after opening\nall cameras. It follows this sequence: \n\n for each camera in cameraDevices :\n device = openCamera(camera)\n createCaptureSession(device);\n\nIt does, however, tolerate camera open failures with\n`ERROR_MAX_CAMERAS_IN_USE [1]`. Third-party apps might depend on this behavior.\n\nBecause the camera HAL won't know the complete set of camera IDs being opened\nfor concurrent operation before configuring sessions, it could be hard for it to\nallocate hardware resources (assuming there is some competition for them).\n\nTo address this problem, maintaining backward compatibility in addition to\nsupporting concurrent streaming, camera HALs should fail `openCamera` calls with\n`ERROR_MAX_CAMERAS_IN_USE` if they can't support full stream configuration for\nall cameras running concurrently."]]