Class CameraDevice¶
- java.lang.Object
-
- com.iristick.smartglass.core.camera.CameraDevice
public abstract class CameraDevice extends Object
This class represents a single camera of an Iristick headset, allowing for fine-grain control of image capture.
Opening a camera happens asynchronously by calling Headset.openCamera(java.lang.String, com.iristick.smartglass.core.camera.CameraDevice.Listener, android.os.Handler)
and passing a
CameraDevice.Listener
object. When opened, the CameraDevice.Listener.onOpened(com.iristick.smartglass.core.camera.CameraDevice)
method will be called with
a ready-to-use CameraDevice
object.
Nested Class Summary¶
Modifier and Type | Class and Description |
---|---|
static interface |
CameraDevice.Listener
Listener interface for receiving updates about the state of a camera device.
|
Field Summary¶
Modifier and Type | Field and Description |
---|---|
static int |
TEMPLATE_BARCODE
Creates a request suitable for scanning barcodes.
|
static int |
TEMPLATE_PREVIEW
Creates a request suitable for a camera preview window.
|
static int |
TEMPLATE_RECORD
Creates a request suitable for video recording.
|
static int |
TEMPLATE_STILL_CAPTURE
Creates a request suitable for still image capture.
|
Constructor Summary¶
Constructor and Description |
---|
CameraDevice() |
Method Summary¶
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Close the connection to this camera as quickly as possible.
|
abstract CaptureRequest.Builder |
createCaptureRequest(int templateType)
Creates a
CaptureRequest builder for new capture requests,
initialized with template for a target use case. |
abstract void |
createCaptureSession(List<Surface> outputs,
CaptureSession.Listener listener,
Handler handler)
Create a new capture session by providing the target output set of Surfaces to the
camera device.
|
abstract String |
getId()
Gets the identifier of the camera.
|
Methods inherited from class java.lang.Object¶
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail¶
TEMPLATE_PREVIEW¶
public static final int TEMPLATE_PREVIEW
setRepeatingRequest
method.- See Also:
createCaptureRequest(int)
TEMPLATE_STILL_CAPTURE¶
public static final int TEMPLATE_STILL_CAPTURE
capture
method.- See Also:
createCaptureRequest(int)
TEMPLATE_RECORD¶
public static final int TEMPLATE_RECORD
setRepeatingRequest
method.- See Also:
createCaptureRequest(int)
TEMPLATE_BARCODE¶
public static final int TEMPLATE_BARCODE
setRepeatingRequest
method.Constructor Detail¶
CameraDevice¶
public CameraDevice()
Method Detail¶
getId¶
@CheckResult @NonNull public abstract String getId()
Gets the identifier of the camera.
This matches the ID given to Headset.openCamera(java.lang.String, com.iristick.smartglass.core.camera.CameraDevice.Listener, android.os.Handler)
to instantiate this camera session.
Attention
Camera identifiers are not part of the stable API.
They may vary across versions of the Iristick Services, device models or even Headset
objects. You should always discover the camera identifiers of a connected headset using
Headset.findCamera(int)
or Headset.getCameraIdList()
.
- Returns:
- The identifier for the camera.
- See Also:
Headset.findCamera(int)
,Headset.getCameraIdList()
close¶
public abstract void close()
Close the connection to this camera as quickly as possible.
Once the camera has fully shut down, the CameraDevice.Listener.onClosed(com.iristick.smartglass.core.camera.CameraDevice)
callback
will be called, and the camera is free to be re-opened.
Immediately after this call, besides the final CameraDevice.Listener.onClosed(com.iristick.smartglass.core.camera.CameraDevice)
call,
no further callbacks from the device or the active session will occur,
and any remaining submitted capture requests will be discarded,
as if CaptureSession.abortCaptures()
had been called, except that no success or
failure callbacks will be invoked.
createCaptureRequest¶
@CheckResult @NonNull public abstract CaptureRequest.Builder createCaptureRequest(int templateType)
Creates a CaptureRequest
builder for new capture requests,
initialized with template for a target use case. The settings are chosen
to be the best options for the specific camera, so it is not
recommended to reuse the same request for a different camera;
create a builder specific for that camera and template and override the
settings as desired, instead.
- Parameters:
templateType
- An enumeration selecting the use case for this request; one of theTEMPLATE_*
values. See the documentation for each template type for details.- Returns:
- A builder for a capture request, initialized with default settings for that template, and no output streams.
- Throws:
IllegalArgumentException
- if the templateType is unknown or unsupported by this camera.- See Also:
TEMPLATE_PREVIEW
,TEMPLATE_RECORD
,TEMPLATE_STILL_CAPTURE
createCaptureSession¶
public abstract void createCaptureSession(@NonNull List<Surface> outputs, @NonNull CaptureSession.Listener listener, @Nullable Handler handler)
Create a new capture session by providing the target output set of Surfaces to the camera device.
The active capture session determines the set of potential output Surfaces for
the camera device for each capture request. A given request may use all
or only some of the outputs. Once the CaptureSession is created, requests can be
submitted with capture
,
captureBurst
, or
setRepeatingRequest
.
Surfaces suitable for inclusion as a camera output can be created for various use cases and targets:
- For drawing to a
SurfaceView
: Once the SurfaceView's Surface iscreated
, set the size of the Surface withSurfaceHolder.setFixedSize(int, int)
to be one of the sizes returned byCameraCharacteristics.StreamConfigurationMap.getSizes()
and then obtain the Surface by callingSurfaceHolder.getSurface()
. - For accessing through an OpenGL texture via a
SurfaceTexture
: Set the size of the SurfaceTexture withSurfaceTexture.setDefaultBufferSize(int, int)
to be one of the sizes returned byCameraCharacteristics.StreamConfigurationMap.getSizes()
before creating a Surface from the SurfaceTexture withSurface(android.graphics.SurfaceTexture)
. - For recording with
MediaCodec
: CallMediaCodec.createInputSurface()
after configuring the media codec to use one of the sizes returned byCameraCharacteristics.StreamConfigurationMap.getSizes()
- For recording with
MediaRecorder
: CallMediaRecorder.getSurface()
after configuring the media recorder to use one of the sizes returned byCameraCharacteristics.StreamConfigurationMap.getSizes()
, or configuring it to use one of the supportedCamcorderProfiles
. - For access to uncompressed YUV or compressed JPEG data in the application: Create an
ImageReader
object with formatImageFormat.YV12
orImageFormat.JPEG
, setting its size to one of the supported sizes returned byCameraCharacteristics.StreamConfigurationMap.getSizes()
. Then obtain aSurface
from it withImageReader.getSurface()
.
The camera device will query each Surface's size and formats upon this call, so they must be set to a valid setting at this time. If the size of an output is changed, a new capture session must be created for the new size to become effective.
It can take several hundred milliseconds for the session's configuration to complete,
since camera hardware may need to be powered on or reconfigured. Once the configuration is
complete and the session is ready to actually capture data, the provided
CaptureSession.Listener
's
CaptureSession.Listener.onConfigured(com.iristick.smartglass.core.camera.CaptureSession)
callback will be called.
If a prior CaptureSession already exists when this method is called, the previous
session will no longer be able to accept new capture requests and will be closed. Any
in-progress capture requests made on the prior session will be completed before it's closed.
Once the new session is configured
,
it is able to start capturing its own requests. To minimize the transition time,
the CaptureSession.abortCaptures()
call can be used to discard the remaining
requests for the prior capture session before a new one is created. Note that once the new
session is created, the old one can no longer have its captures aborted.
Using larger resolution outputs, or more outputs, can result in slower output rate from the device.
- Parameters:
outputs
- The new set of Surfaces that should be made available as targets for captured image data.listener
- The callback to notify about the status of the new capture session.handler
- The handler on which the callback should be invoked, ornull
to use the current thread'slooper
.- Throws:
IllegalArgumentException
- if the set of output Surfaces do not meet the requirements, or the handler is null but the current thread has no looper.NullPointerException
- iflistener
isnull
.- See Also:
CaptureSession