CameraEffect
public abstract class CameraEffect
Media3Effect |
A CameraEffect that applies media3 |
OverlayEffect |
A |
An effect for one or multiple camera outputs.
This API allows the implementer to inject code into CameraX pipeline and apply visual effects, such as a portrait effect. The CameraEffect class contains two types of information, the processor and the configuration.
- The processor is an implementation of either
SurfaceProcessororImageProcessor. It consumes original camera frames from CameraX, applies the effect, and returns the processed frames back to CameraX. - The configuration provides information on how the processor should be injected into the pipeline. For example, the target
UseCases where the effect should be applied. It may also contain information about camera configuration. For example, the exposure level.
If CameraX fails to send frames to the CameraEffect, the error will be delivered to the app via error callbacks such as onError. If CameraEffect fails to process and return the frames, for example, unable to allocate the resources for image processing, it must throw Throwable in the processor implementation. The Throwable will be caught and forwarded to the app via error callbacks. Please see the Javadoc of the processor interfaces for details.
Extend this class to create specific effects. The Executor provided in the constructors will be used by CameraX to call the processors.
Code sample for a portrait effect that targets the PreviewUseCase:
class PortraitPreviewEffect extends CameraEffect { PortraitPreviewEffect() { super(PREVIEW, getExecutor(), getSurfaceProcessor()); } private static Executor getExecutor() { // Returns an executor for calling the SurfaceProcessor } private static SurfaceProcessor getSurfaceProcessor() { // Return a SurfaceProcessor implementation that applies a portrait effect. } }
Summary
Constants |
|
|---|---|
static final int |
IMAGE_CAPTURE = 4Bitmask option to indicate that CameraX should apply this effect to |
static final int |
PREVIEW = 1Bitmask option to indicate that CameraX should apply this effect to |
static final int |
VIDEO_CAPTURE = 2Bitmask option to indicate that CameraX should apply this effect to |
Protected constructors |
|---|
CameraEffect( |
CameraEffect( |
Public methods |
|
|---|---|
@NonNull Consumer<Throwable> |
Gets the Error listener associated with this effect. |
@NonNull Executor |
Gets the |
@Nullable SurfaceProcessor |
Gets the |
int |
Ges the target |
Constants
IMAGE_CAPTURE
public static final int IMAGE_CAPTURE = 4
Bitmask option to indicate that CameraX should apply this effect to ImageCapture.
PREVIEW
public static final int PREVIEW = 1
Bitmask option to indicate that CameraX should apply this effect to Preview.
VIDEO_CAPTURE
public static final int VIDEO_CAPTURE = 2
Bitmask option to indicate that CameraX should apply this effect to VideoCapture.
Protected constructors
CameraEffect
protected CameraEffect(
int targets,
@NonNull Executor executor,
@NonNull ImageProcessor imageProcessor,
@NonNull Consumer<Throwable> errorListener
)
| Parameters | |
|---|---|
int targets |
the target |
@NonNull Executor executor |
the |
@NonNull ImageProcessor imageProcessor |
a |
@NonNull Consumer<Throwable> errorListener |
invoked if the effect runs into unrecoverable errors. This is invoked on the provided {@param executor}. |
CameraEffect
protected CameraEffect(
int targets,
@NonNull Executor executor,
@NonNull SurfaceProcessor surfaceProcessor,
@NonNull Consumer<Throwable> errorListener
)
| Parameters | |
|---|---|
int targets |
the target UseCase combinations will throw IllegalArgumentException. |
@NonNull Executor executor |
the |
@NonNull SurfaceProcessor surfaceProcessor |
a |
@NonNull Consumer<Throwable> errorListener |
invoked if the effect runs into unrecoverable errors. The |
Public methods
getErrorListener
public @NonNull Consumer<Throwable> getErrorListener()
Gets the Error listener associated with this effect.
This method returns the value set in the constructor. The Throwable will be the error thrown by this CameraEffect. For example, ProcessingException.
getExecutor
public @NonNull Executor getExecutor()
Gets the Executor associated with this effect.
This method returns the value set in the constructor.
getSurfaceProcessor
public @Nullable SurfaceProcessor getSurfaceProcessor()
Gets the SurfaceProcessor associated with this effect.