public class CameraCapturer extends java.lang.Object implements VideoCapturer
LocalVideoTrack
from a
given cameraId
. The frames are provided via the preview API of Camera
.
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 LocalVideoTrack
s simultaneously.
Modifier and Type | Class and Description |
---|---|
static interface |
CameraCapturer.Error |
static interface |
CameraCapturer.Listener
Interface that provides events and errors related to
CameraCapturer . |
Modifier and Type | Field and Description |
---|---|
static int |
ERROR_CAMERA_FREEZE |
static int |
ERROR_CAMERA_PERMISSION_NOT_GRANTED |
static int |
ERROR_CAMERA_SERVER_STOPPED |
static int |
ERROR_CAMERA_SWITCH_FAILED |
static int |
ERROR_UNKNOWN |
static int |
ERROR_UNSUPPORTED_SOURCE |
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
void |
dispose()
This method provides an optional step to perform a final cleanup.
|
java.lang.String |
getCameraId()
Returns the currently set cameraID.
|
void |
initialize(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.
|
boolean |
isScreencast()
Indicates that the camera capturer is not a screen cast.
|
void |
startCapture(int width,
int height,
int framerate)
Start capturing frames in a format that is as close as possible to
width x height and
framerate . |
void |
stopCapture()
Stops all frames being captured.
|
void |
switchCamera(java.lang.String newCameraId)
Switches the current
cameraId . |
boolean |
updateCameraParameters(CameraParameterUpdater cameraParameterUpdater)
Schedules a camera parameter update.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
changeCaptureFormat, getCaptureFormat
public static final int ERROR_CAMERA_FREEZE
public static final int ERROR_CAMERA_SERVER_STOPPED
public static final int ERROR_UNSUPPORTED_SOURCE
public static final int ERROR_CAMERA_PERMISSION_NOT_GRANTED
public static final int ERROR_CAMERA_SWITCH_FAILED
public static final int ERROR_UNKNOWN
public CameraCapturer(@NonNull android.content.Context context, @NonNull java.lang.String cameraId)
context
- application contextcameraId
- unique identifier of the camera device to open that must be specified in
Camera1Enumerator.getDeviceNames()
public CameraCapturer(@NonNull android.content.Context context, @NonNull java.lang.String cameraId, @Nullable CameraCapturer.Listener listener)
context
- application contextcameraId
- unique identifier of the camera device to open that must be specified in
Camera1Enumerator.getDeviceNames()
listener
- an optional listener of camera capturer eventspublic boolean isScreencast()
isScreencast
in interface VideoCapturer
public void initialize(@NonNull SurfaceTextureHelper surfaceTextureHelper, @NonNull android.content.Context context, @NonNull CapturerObserver capturerObserver)
VideoCapturer
surfaceTextureHelper
, register itself as a listener, and forward the frames to
CapturerObserver.onFrameCaptured(). The caller still has ownership of surfaceTextureHelper
and 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.initialize
in interface VideoCapturer
public void startCapture(int width, int height, int framerate)
VideoCapturer
width x height
and
framerate
.startCapture
in interface VideoCapturer
public void stopCapture()
Camera
interface should be
available for use upon completion.
Note: This method is not meant to be invoked directly.
stopCapture
in interface VideoCapturer
public void dispose()
VideoCapturer
dispose
in interface VideoCapturer
@NonNull public java.lang.String getCameraId()
public void switchCamera(@NonNull java.lang.String newCameraId)
cameraId
. This method can be invoked while capturing frames or
not.newCameraId
- the new camera id.public boolean updateCameraParameters(@NonNull CameraParameterUpdater cameraParameterUpdater)
Camera.Parameters
will be provided for modification via CameraParameterUpdater.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);
}
}
});
cameraParameterUpdater
- camera parameter updater that receives current camera
parameters for modification.6.0.0