Package com.twilio.video
Class CameraCapturer
- java.lang.Object
-
- com.twilio.video.CameraCapturer
-
- All Implemented Interfaces:
VideoCapturer,VideoCapturer
public class CameraCapturer extends java.lang.Object implements VideoCapturer
The CameraCapturer class is used to provide video frames for aLocalVideoTrackfrom a givencameraId. The frames are provided via the preview API ofCamera.This class represents an implementation of a
VideoCapturerinterface. 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCameraCapturer.Errorstatic interfaceCameraCapturer.ListenerInterface that provides events and errors related toCameraCapturer.
-
Field Summary
Fields Modifier and Type Field Description static intERROR_CAMERA_FREEZEstatic intERROR_CAMERA_PERMISSION_NOT_GRANTEDstatic intERROR_CAMERA_SERVER_STOPPEDstatic intERROR_CAMERA_SWITCH_FAILEDstatic intERROR_UNKNOWNstatic intERROR_UNSUPPORTED_SOURCE
-
Constructor Summary
Constructors Constructor Description CameraCapturer(android.content.Context context, java.lang.String cameraId)Constructs a CameraCapturer instance.CameraCapturer(android.content.Context context, java.lang.String cameraId, CameraCapturer.Listener listener)Constructs a CameraCapturer instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()This method provides an optional step to perform a final cleanup.java.lang.StringgetCameraId()Returns the currently set cameraID.voidinitialize(SurfaceTextureHelper surfaceTextureHelper, android.content.Context context, CapturerObserver capturerObserver)This function is used to initialize the camera thread, the android application context, and the capture observer.booleanisScreencast()Indicates that the camera capturer is not a screen cast.voidstartCapture(int width, int height, int framerate)Start capturing frames in a format that is as close as possible towidth x heightandframerate.voidstopCapture()Stops all frames being captured.voidswitchCamera(java.lang.String newCameraId)Switches the currentcameraId.booleanupdateCameraParameters(CameraParameterUpdater cameraParameterUpdater)Schedules a camera parameter update.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.twilio.video.VideoCapturer
changeCaptureFormat, getCaptureFormat
-
-
-
-
Field Detail
-
ERROR_CAMERA_FREEZE
public static final int ERROR_CAMERA_FREEZE
- See Also:
- Constant Field Values
-
ERROR_CAMERA_SERVER_STOPPED
public static final int ERROR_CAMERA_SERVER_STOPPED
- See Also:
- Constant Field Values
-
ERROR_UNSUPPORTED_SOURCE
public static final int ERROR_UNSUPPORTED_SOURCE
- See Also:
- Constant Field Values
-
ERROR_CAMERA_PERMISSION_NOT_GRANTED
public static final int ERROR_CAMERA_PERMISSION_NOT_GRANTED
- See Also:
- Constant Field Values
-
ERROR_CAMERA_SWITCH_FAILED
public static final int ERROR_CAMERA_SWITCH_FAILED
- See Also:
- Constant Field Values
-
ERROR_UNKNOWN
public static final int ERROR_UNKNOWN
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CameraCapturer
public CameraCapturer(@NonNull android.content.Context context, @NonNull java.lang.String cameraId)Constructs a CameraCapturer instance.- Parameters:
context- application contextcameraId- unique identifier of the camera device to open that must be specified inCamera1Enumerator.getDeviceNames()
-
CameraCapturer
public CameraCapturer(@NonNull android.content.Context context, @NonNull java.lang.String cameraId, @Nullable CameraCapturer.Listener listener)Constructs a CameraCapturer instance.- Parameters:
context- application contextcameraId- unique identifier of the camera device to open that must be specified inCamera1Enumerator.getDeviceNames()listener- an optional listener of camera capturer events
-
-
Method Detail
-
isScreencast
public boolean isScreencast()
Indicates that the camera capturer is not a screen cast.- Specified by:
isScreencastin interfaceVideoCapturer- Returns:
- true if-and-only-if this is a screen capturer.
-
initialize
public void initialize(@NonNull SurfaceTextureHelper surfaceTextureHelper, @NonNull android.content.Context context, @NonNull CapturerObserver capturerObserver)Description copied from interface:VideoCapturerThis function is used to initialize the camera thread, the android application context, and the capture observer. It will be called only once and before any startCapture() request. The camera thread is guaranteed to be valid until dispose() is called. If the VideoCapturer wants to deliver texture frames, it should do this by rendering on the SurfaceTexture insurfaceTextureHelper, register itself as a listener, and forward the frames to CapturerObserver.onFrameCaptured(). The caller still has ownership ofsurfaceTextureHelperand is responsible for making sure surfaceTextureHelper.dispose() is called. This also means that the caller can reuse the SurfaceTextureHelper to initialize a new VideoCapturer once the previous VideoCapturer has been disposed.- Specified by:
initializein interfaceVideoCapturer
-
startCapture
public void startCapture(int width, int height, int framerate)Description copied from interface:VideoCapturerStart capturing frames in a format that is as close as possible towidth x heightandframerate.- Specified by:
startCapturein interfaceVideoCapturer
-
stopCapture
public void stopCapture()
Stops all frames being captured. TheCamerainterface should be available for use upon completion.Note: This method is not meant to be invoked directly.
- Specified by:
stopCapturein interfaceVideoCapturer
-
dispose
public void dispose()
Description copied from interface:VideoCapturerThis method provides an optional step to perform a final cleanup.- Specified by:
disposein interfaceVideoCapturer- Specified by:
disposein interfaceVideoCapturer
-
getCameraId
@NonNull public java.lang.String getCameraId()
Returns the currently set cameraID.
-
switchCamera
public void switchCamera(@NonNull java.lang.String newCameraId)Switches the currentcameraId. This method can be invoked while capturing frames or not.- Parameters:
newCameraId- the new camera id.
-
updateCameraParameters
public boolean updateCameraParameters(@NonNull CameraParameterUpdater cameraParameterUpdater)Schedules a camera parameter update. The current camera'sCamera.Parameterswill be provided for modification viaCameraParameterUpdater.apply(Camera.Parameters). Any changes to the parameters will be applied after the invocation of this callback. This method can be invoked while capturing frames 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() { @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 camera parameters for modification.- Returns:
- true if update was scheduled or false if an update is pending or could not be scheduled.
-
-