public class Camera2Capturer extends Object implements VideoCapturer
LocalVideoTrack from the
provided cameraId. The frames are provided via a CameraCaptureSession. Camera2Capturer must be run on devices Build.VERSION_CODES.LOLLIPOP or higher.
This class represents an implementation of a VideoCapturer interface. Although public,
these methods are not meant to be invoked directly.
Note: This capturer can be reused, but cannot be shared across multiple LocalVideoTracks simultaneously.
| Modifier and Type | Class and Description |
|---|---|
static class |
Camera2Capturer.Exception
Camera2Capturer exception class.
|
static interface |
Camera2Capturer.Listener
Interface that provides events and errors related to
Camera2Capturer. |
| Constructor and Description |
|---|
Camera2Capturer(android.content.Context context,
String cameraId,
Camera2Capturer.Listener listener)
Constructs a Camera2Capturer instance.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getCameraId()
Returns the currently set camera ID.
|
List<VideoFormat> |
getSupportedFormats()
Returns a list of all supported video formats.
|
boolean |
isScreencast()
Indicates that the camera2 capturer is not a screen cast.
|
static boolean |
isSupported(android.content.Context context)
Indicates if Camera2Capturer is compatible with device.
|
void |
startCapture(VideoFormat captureFormat,
VideoCapturer.Listener videoCapturerListener)
Starts capturing frames at the specified format.
|
void |
stopCapture()
Stops all frames being captured.
|
void |
switchCamera(String newCameraId)
Switches the current
cameraId. |
public Camera2Capturer(android.content.Context context,
String cameraId,
Camera2Capturer.Listener listener)
Note: It is possible to construct multiple instances with different camera IDs, but there are often device limitations on how many camera2 sessions can be open.
context - application contextcameraId - unique identifier of the camera device to open that must be specified in
CameraManager.getCameraIdList().listener - listener of camera 2 capturer eventspublic static boolean isSupported(android.content.Context context)
This method checks that all the following conditions are true:
Build.VERSION_CODES.LOLLIPOP.
CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY.
context - application context.public List<VideoFormat> getSupportedFormats()
CameraCharacteristics, so can vary based on a device's
camera capabilities.
Note: This method can be invoked for informational purposes, but is primarily used internally.
getSupportedFormats in interface VideoCapturerpublic boolean isScreencast()
isScreencast in interface VideoCapturerpublic void startCapture(VideoFormat captureFormat, VideoCapturer.Listener videoCapturerListener)
Note: This method is not meant to be invoked directly.
startCapture in interface VideoCapturercaptureFormat - the format in which to capture frames.videoCapturerListener - consumer of available frames.public void stopCapture()
Note: This method is not meant to be invoked directly.
stopCapture in interface VideoCapturerpublic String getCameraId()
4.0.1