-
- All Implemented Interfaces:
-
com.twilio.video.VideoCapturer,tvi.webrtc.VideoCapturer
public class Camera2Capturer implements VideoCapturer
The Camera2Capturer class is used to provide video frames for a LocalVideoTrack from the provided cameraId. The frames are provided via a . Camera2Capturer must be run on devices or higher.
This class represents an implementation of a VideoCapturer interface. Although public, these methods are not meant to be invoked directly.
This capturer can be reused, but cannot be shared across multiple LocalVideoTracks simultaneously. It is possible to construct multiple instances with different camera IDs, but there are device specific limitations on how many camera2 sessions can be open.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classCamera2Capturer.ExceptionCamera2Capturer exception class.
public interfaceCamera2Capturer.ListenerInterface that provides events and errors related to Camera2Capturer.
-
Constructor Summary
Constructors Constructor Description Camera2Capturer(Context context, String cameraId)Constructs a Camera2Capturer instance. Camera2Capturer(Context context, String cameraId, Camera2Capturer.Listener listener)Constructs a Camera2Capturer instance.
-
Method Summary
Modifier and Type Method Description synchronized StringgetCameraId()Returns the currently set camera ID. static booleanisSupported(@NonNull() Context context)Indicates if Camera2Capturer is compatible with device. booleanisScreencast()Indicates that the camera2 capturer is not a screen cast. voidinitialize(@NonNull() SurfaceTextureHelper surfaceTextureHelper, @NonNull() Context context, @NonNull() CapturerObserver capturerObserver)voidstartCapture(int width, int height, int framerate)voidstopCapture()Stops all frames being captured. voiddispose()This method provides an optional step to perform a final cleanup. synchronized voidswitchCamera(@NonNull() String newCameraId)Switches the current cameraId. synchronized booleanupdateCaptureRequest(@NonNull() CaptureRequestUpdater captureRequestUpdater)Schedules a capture request update. -
Methods inherited from class com.twilio.video.VideoCapturer
changeCaptureFormat, getCaptureFormat -
Methods inherited from class tvi.webrtc.VideoCapturer
changeCaptureFormat, dispose, initialize, isScreencast, startCapture, stopCapture -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
Camera2Capturer
Camera2Capturer(Context context, String cameraId)
Constructs a Camera2Capturer instance.- Parameters:
context- application contextcameraId- unique identifier of the camera device to open that must be specified ingetCameraIdList
-
Camera2Capturer
Camera2Capturer(Context context, String cameraId, Camera2Capturer.Listener listener)
Constructs a Camera2Capturer instance.- Parameters:
context- application contextcameraId- unique identifier of the camera device to open that must be specified ingetCameraIdListlistener- an optional listener of camera2 capturer events
-
-
Method Detail
-
getCameraId
@NonNull() synchronized String getCameraId()
Returns the currently set camera ID.
-
isSupported
static boolean isSupported(@NonNull() Context context)
Indicates if Camera2Capturer is compatible with device.
This method checks that all the following conditions are true:
- The device API level is at least LOLLIPOP.
- All device cameras have hardware support level greater than .
- Parameters:
context- application context.
-
isScreencast
boolean isScreencast()
Indicates that the camera2 capturer is not a screen cast.
-
initialize
void initialize(@NonNull() SurfaceTextureHelper surfaceTextureHelper, @NonNull() Context context, @NonNull() CapturerObserver capturerObserver)
-
startCapture
void startCapture(int width, int height, int framerate)
-
stopCapture
void stopCapture()
Stops all frames being captured.
Note: This method is not meant to be invoked directly.
-
dispose
void dispose()
This method provides an optional step to perform a final cleanup.
-
switchCamera
synchronized void switchCamera(@NonNull() String newCameraId)
Switches the current cameraId.
- Parameters:
newCameraId- the new camera id.
-
updateCaptureRequest
synchronized boolean updateCaptureRequest(@NonNull() CaptureRequestUpdater captureRequestUpdater)
Schedules a capture request update.
A CaptureRequest.Builder optimal for capturing video for streaming will beprovided for modification to the provided CaptureRequestUpdater. Modifications to the CaptureRequest.Builder will be applied to the after the invocation of . can be invoked while capturing frames or not.If the Camera2Capturer is not capturing the CaptureRequestUpdater will becalled when capturer resumes.
The following snippet demonstrates how to turn on the flash of a camera while capturing.
// Create the camera2 capturer Camera2Capturer camera2Capturer = new Camera2Capturer(context, cameraId, camera2Listener); // Start the camera2 capturer LocalVideoTrack camera2VideoTrack = LocalVideoTrack.create(context, true, camera2Capturer); // Schedule the capture request update camera2Capturer.updateCaptureRequest(new CaptureRequestUpdater() {{@literal @}Override public void apply(@NonNull CaptureRequest.Builder captureRequestBuilder) { captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH); } }The camera2 capturer will raise an Exception to the provided Listener withthe code CAPTURE_REQUEST_UPDATE_FAILED if a successfully scheduled capturerequest update failed to be applied.
- Parameters:
captureRequestUpdater- capture request updater that receives the capture requestbuilder that can be modified.
-
-
-
-