-
- All Implemented Interfaces:
-
com.twilio.video.VideoCapturer,tvi.webrtc.VideoCapturer
public class CameraCapturer implements VideoCapturer
The CameraCapturer class is used to provide video frames for a LocalVideoTrack from a given cameraId. The frames are provided via the preview API of .
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 s simultaneously.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public @interfaceCameraCapturer.Errorpublic interfaceCameraCapturer.ListenerInterface that provides events and errors related to CameraCapturer.
-
Field Summary
Fields Modifier and Type Field Description public final static intERROR_CAMERA_FREEZEpublic final static intERROR_CAMERA_SERVER_STOPPEDpublic final static intERROR_UNSUPPORTED_SOURCEpublic final static intERROR_CAMERA_PERMISSION_NOT_GRANTEDpublic final static intERROR_CAMERA_SWITCH_FAILEDpublic final static intERROR_UNKNOWNprivate StringcameraId
-
Constructor Summary
Constructors Constructor Description CameraCapturer(Context context, String cameraId)Constructs a CameraCapturer instance. CameraCapturer(Context context, String cameraId, CameraCapturer.Listener listener)Constructs a CameraCapturer instance.
-
Method Summary
Modifier and Type Method Description synchronized StringgetCameraId()Returns the currently set cameraID. booleanisScreencast()Indicates that the camera 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 booleanupdateCameraParameters(@NonNull() CameraParameterUpdater cameraParameterUpdater)Schedules a camera parameter 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
-
CameraCapturer
CameraCapturer(Context context, String cameraId)
Constructs a CameraCapturer instance.- Parameters:
context- application contextcameraId- unique identifier of the camera device to open that must be specified ingetDeviceNames
-
CameraCapturer
CameraCapturer(Context context, String cameraId, CameraCapturer.Listener listener)
Constructs a CameraCapturer instance.- Parameters:
context- application contextcameraId- unique identifier of the camera device to open that must be specified ingetDeviceNameslistener- an optional listener of camera capturer events
-
-
Method Detail
-
getCameraId
@NonNull() synchronized String getCameraId()
Returns the currently set cameraID.
-
isScreencast
boolean isScreencast()
Indicates that the camera 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. The android.hardware.Camera interface should beavailable for use upon completion.
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. This method can be invoked while capturing frames ornot.
- Parameters:
newCameraId- the new camera id.
-
updateCameraParameters
synchronized boolean updateCameraParameters(@NonNull() CameraParameterUpdater cameraParameterUpdater)
Schedules a camera parameter update. The current camera's will be provided for modification via . Any changes to the parameters will beapplied after the invocation of this callback. This method can be invoked while capturingframes or not.
The following snippet demonstrates how to turn on the flash of a camera while capturing.
// Create camera capturer CameraCapturer cameraCapturer = new CameraCapturer(context, cameraId, null); // Start camera capturer LocalVideoTrack cameraVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer); // Schedule camera parameter update cameraCapturer.updateCameraParameters(new CameraParameterUpdater() {{@literal @}Override public void apply(Camera.Parameters cameraParameters) { // Ensure camera supports flash and turn on if (cameraParameters.getFlashMode() != null) { cameraParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); } } });- Parameters:
cameraParameterUpdater- camera parameter updater that receives current cameraparameters for modification.
-
-
-
-