MultiResolutionImageReader
open class MultiResolutionImageReader : AutoCloseable
| kotlin.Any | |
| ↳ | android.hardware.camera2.MultiResolutionImageReader |
The MultiResolutionImageReader class wraps a group of ImageReaders with the same format and different sizes, source camera Id, or camera sensor modes.
The main use case of this class is for a logical or an ultra high resolution sensor camera to output variable-size images. For a logical multi-camera which implements optical zoom, different physical cameras may have different maximum resolutions. As a result, when the camera device switches between physical cameras depending on zoom ratio, the maximum resolution for a particular format may change. For an ultra high resolution sensor camera, the camera device may deem it better or worse to run in maximum resolution mode / default mode depending on lighting conditions. So the application may choose to let the camera device decide on its behalf.
MultiResolutionImageReader should be used for a camera device only if the camera device supports multi-resolution output stream by advertising the specified output format in CameraCharacteristics.SCALER_MULTI_RESOLUTION_STREAM_CONFIGURATION_MAP.
To acquire images from the MultiResolutionImageReader, the application must use the ImageReader object passed by ImageReader.OnImageAvailableListener.onImageAvailable callback to call ImageReader.acquireNextImage or ImageReader.acquireLatestImage. The application must not use the ImageReader passed by an ImageReader.OnImageAvailableListener.onImageAvailable callback to acquire future images because future images may originate from a different ImageReader contained within the MultiResolutionImageReader.
Note that by default, for a MultiResolutionImageReader, each capture request produces only one output buffer from one internal reader. Some devices also support producing from multiple readers for a single CaptureRequest (for example, by running multiple sensors at the same time). Support for this can be queried by MultiResolutionStreamConfigurationMap#isConcurrentReadersSupported and enabled by using android.hardware.camera2.MultiResolutionImageReader.Builder#setConcurrentOutputsEnabled.
Summary
| Public constructors | |
|---|---|
MultiResolutionImageReader(streams: MutableCollection<MultiResolutionStreamInfo!>, format: Int, maxImages: Int)Create a new multi-resolution reader based on a group of camera stream properties returned by a camera device. |
|
MultiResolutionImageReader(streams: MutableCollection<MultiResolutionStreamInfo!>, format: Int, maxImages: Int, usage: Long)Create a new multi-resolution reader based on a group of camera stream properties returned by a camera device, and the desired format, maximum buffer capacity and consumer usage flag. |
|
| Public methods | |
|---|---|
| open Unit |
close()Closes this resource, relinquishing any underlying resources. |
| open Unit |
flush()Flush pending images from all internal ImageReaders |
| open MultiResolutionStreamInfo |
getStreamInfoForImageReader(reader: ImageReader)Get the MultiResolutionStreamInfo describing the ImageReader an image originates from |
| open Surface |
Get the surface that is used as a target for |
| open Unit |
setOnImageAvailableListener(listener: ImageReader.OnImageAvailableListener?, executor: Executor?)Set onImageAvailableListener callback. |
| Protected methods | |
|---|---|
| open Unit |
finalize()Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |
Public constructors
MultiResolutionImageReader
MultiResolutionImageReader(
streams: MutableCollection<MultiResolutionStreamInfo!>,
format: Int,
maxImages: Int)
Create a new multi-resolution reader based on a group of camera stream properties returned by a camera device.
This constructor is the equivalent of #MultiResolutionImageReader(java.util.Collection without specifying usage.
See #MultiResolutionImageReader(java.util.Collection for full details.
MultiResolutionImageReader
MultiResolutionImageReader(
streams: MutableCollection<MultiResolutionStreamInfo!>,
format: Int,
maxImages: Int,
usage: Long)
Create a new multi-resolution reader based on a group of camera stream properties returned by a camera device, and the desired format, maximum buffer capacity and consumer usage flag.
The valid size and formats depend on the camera characteristics. MultiResolutionImageReader for an image format is supported by the camera device if the format is in the supported multi-resolution output stream formats returned by android.hardware.camera2.params.MultiResolutionStreamConfigurationMap#getOutputFormats. If the image format is supported, the MultiResolutionImageReader object can be created with the streams objects returned by android.hardware.camera2.params.MultiResolutionStreamConfigurationMap#getOutputInfo.
The maxImages parameter determines the maximum number of Image objects that can be acquired from each of the ImageReader within the MultiResolutionImageReader. However, requesting more buffers will use up more memory, so it is important to use only the minimum number necessary. The application is strongly recommended to acquire no more than maxImages images from all of the internal ImageReader objects combined. By keeping track of the number of acquired images for the MultiResolutionImageReader, the application doesn't need to do the bookkeeping for each internal ImageReader returned from onImageAvailable callback.
Unlike the normal ImageReader, the MultiResolutionImageReader has a more complex configuration sequence. Instead of passing the same surface to OutputConfiguration and CaptureRequest, the android.hardware.camera2.params.OutputConfiguration#createInstancesForMultiResolutionOutput call needs to be used to create the OutputConfigurations for session creation, and then getSurface is used to get the target for.
Public methods
close
open fun close(): Unit
Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.
| Exceptions | |
|---|---|
java.lang.Exception |
if this resource cannot be closed |
flush
open fun flush(): Unit
Flush pending images from all internal ImageReaders
Acquire and close pending images from all internal ImageReaders. This has the same effect as calling acquireLatestImage() on all internal ImageReaders, and closing all latest images.
getStreamInfoForImageReader
open fun getStreamInfoForImageReader(reader: ImageReader): MultiResolutionStreamInfo
Get the MultiResolutionStreamInfo describing the ImageReader an image originates from
An image from a MultiResolutionImageReader is produced from one of the underlying ImageReaders. This function returns the MultiResolutionStreamInfo to describe the property for that ImageReader, such as width, height, and physical camera Id.
| Parameters | |
|---|---|
reader |
ImageReader: An internal ImageReader within MultiResolutionImageReader. This value cannot be null. |
| Return | |
|---|---|
MultiResolutionStreamInfo |
The stream info describing the internal ImageReader. This value cannot be null. |
getSurface
open fun getSurface(): Surface
Get the surface that is used as a target for CaptureRequest
The application must use the surface returned by this function as a target for CaptureRequest. The camera device makes the decision on which internal ImageReader will receive the output image.
Please note that holding on to the Surface objects returned by this method is not enough to keep their parent MultiResolutionImageReaders from being reclaimed. In that sense, a Surface acts like a weak reference to the MultiResolutionImageReader that provides it.
| Return | |
|---|---|
Surface |
a Surface to use as the target for a capture request. This value cannot be null. |
setOnImageAvailableListener
open fun setOnImageAvailableListener(
listener: ImageReader.OnImageAvailableListener?,
executor: Executor?
): Unit
Set onImageAvailableListener callback.
This function sets the onImageAvailableListener for all the internal ImageReader objects.
For a multi-resolution ImageReader, the timestamps of images acquired in onImageAvailable callback from different internal ImageReaders may become out-of-order due to the asynchronous callbacks between the different resolution image queues.
| Parameters | |
|---|---|
listener |
ImageReader.OnImageAvailableListener?: The listener that will be run. This value may be null. |
executor |
Executor?: The executor which will be used when invoking the callback. This value may be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. |
Protected methods
finalize
protected open fun finalize(): Unit
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.
The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.
The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.
The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.
The finalize method is never invoked more than once by a Java virtual machine for any given object.
Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.
| Exceptions | |
|---|---|
java.lang.Throwable |
the Exception raised by this method |