public class CameraCapturer extends Object implements VideoCapturer
LocalVideoTrack
from a
given CameraCapturer.CameraSource
. 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 class |
CameraCapturer.CameraSource
Camera source types.
|
static interface |
CameraCapturer.Error |
static interface |
CameraCapturer.Listener
Interface that provides events and errors related to
CameraCapturer . |
static interface |
CameraCapturer.PictureListener
Interface that provides events related to taking a picture while capturing.
|
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,
CameraCapturer.CameraSource cameraSource) |
CameraCapturer(android.content.Context context,
CameraCapturer.CameraSource cameraSource,
CameraCapturer.Listener listener) |
Modifier and Type | Method and Description |
---|---|
CameraCapturer.CameraSource |
getCameraSource()
Returns the currently specified camera source.
|
List<VideoFormat> |
getSupportedFormats()
Returns a list of all supported video formats.
|
boolean |
isScreencast()
Indicates that the camera capturer is not a screen cast.
|
static boolean |
isSourceAvailable(CameraCapturer.CameraSource cameraSource)
Indicates if a camera source is available on the device.
|
void |
startCapture(VideoFormat captureFormat,
VideoCapturer.Listener videoCapturerListener)
Starts capturing frames at the specified format.
|
void |
stopCapture()
Stops all frames being captured.
|
void |
switchCamera()
Switches the current
CameraCapturer.CameraSource . |
boolean |
takePicture(CameraCapturer.PictureListener pictureListener)
Schedules an image capture.
|
boolean |
updateCameraParameters(CameraParameterUpdater cameraParameterUpdater)
Schedules a camera parameter update.
|
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(android.content.Context context, CameraCapturer.CameraSource cameraSource)
public CameraCapturer(android.content.Context context, CameraCapturer.CameraSource cameraSource, CameraCapturer.Listener listener)
public static boolean isSourceAvailable(CameraCapturer.CameraSource cameraSource)
cameraSource
- the camera sourcepublic List<VideoFormat> getSupportedFormats()
Camera.Parameters
, 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 VideoCapturer
public boolean isScreencast()
isScreencast
in interface VideoCapturer
public void startCapture(VideoFormat captureFormat, VideoCapturer.Listener videoCapturerListener)
Note: This method is not meant to be invoked directly.
startCapture
in interface VideoCapturer
captureFormat
- the format in which to capture frames.videoCapturerListener
- consumer of available frames.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 CameraCapturer.CameraSource getCameraSource()
public void switchCamera()
CameraCapturer.CameraSource
. This method can be invoked while capturing frames
or not.public boolean updateCameraParameters(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,
CameraCapturer.CameraSource.BACK_CAMERA, 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.public boolean takePicture(CameraCapturer.PictureListener pictureListener)
The following snippet demonstrates how to capture and image and decode to a
Bitmap
.
// Create camera capturer
CameraCapturer cameraCapturer = new CameraCapturer(context,
CameraCapturer.CameraSource.BACK_CAMERA, null);
// Start camera capturer
LocalVideoTrack cameraVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer)
// Schedule an image capture
cameraCapturer.takePicture(new CameraCapturer.PictureListener() {
@Override
public void onShutter() {
// Show some UI or play a sound
}
@Override
public void onPictureTaken(byte[] pictureData) {
Bitmap bitmap = BitmapFactory.decodeByteArray(pictureData, 0,
pictureData.length);
}
});
pictureListener
- listener that that receives the callback for the shutter and picture
taken event.