Package com.banuba.sdk.offscreen
Class OffscreenEffectPlayer
- java.lang.Object
-
- com.banuba.sdk.offscreen.OffscreenEffectPlayer
-
public class OffscreenEffectPlayer extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description OffscreenEffectPlayer(android.content.Context context, com.banuba.sdk.effect_player.EffectPlayer player, android.util.Size size, OffscreenSimpleConfig config)
OffscreenEffectPlayer(android.content.Context context, OffscreenEffectPlayerConfig config, java.lang.String key)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
callJsMethod(java.lang.String method, java.lang.String parameter)
Allows calling methods defined in the script of the active effect to configure the effect or manage its state.void
enableAudio(boolean enable)
Switch on/off audio in effects.void
evalJs(java.lang.String script, com.banuba.sdk.effect_player.JsCallback resultCallback)
Allows execute scripts (calling methods) or load JS modules to the environment of active effectOffscreenSimpleConfig
getConfig()
Return the current OEP configurationvoid
loadEffect(java.lang.String effectName)
Loads an effect to the effect player asynchronously by default.void
loadEffect(java.lang.String effectName, boolean async)
Loads an effect to the effect player asynchronously or synchronously.void
playbackPause()
Suspend current playback attempt.void
playbackPlay()
Switching to active state attempt.void
playbackStop()
Switch to inactive state.void
processFullImageData(com.banuba.sdk.types.FullImageData fullImageData, ReleaseCallback releaseCallback, long timestamp)
Send FullImageData to process.void
processFullImageData(com.banuba.sdk.types.FullImageData fullImageData, ReleaseCallback releaseCallback, OEPImageFormat outputImageFormat, long timestamp)
Send FullImageData to process.void
processFullImageDataNoSkip(com.banuba.sdk.types.FullImageData fullImageData, ReleaseCallback releaseCallback, long timestamp)
Meaning and parameters are the same as for processFullImageData but in that case the image will wait in the queue until processed, i.e.void
processImage(android.media.Image image, ImageOrientation orientation)
Send Image to process Image will be closed inside OffscreenEffectPlayervoid
processImage(android.media.Image image, ImageOrientation orientation, OEPImageFormat outputImageFormat)
Send Image to process Image will be closed inside OffscreenEffectPlayervoid
release()
Stop processing and release OffscreenEffectPlayer resourcesvoid
setImageProcessListener(ImageProcessedListener listener, android.os.Handler handler)
Sets ImageProcessListener The callback will be invoked on handler's thread.void
setSurfaceTexture(android.graphics.SurfaceTexture surfaceTexture)
Sets SurfaceTexture Can be used together with ImageProcessListener.void
unloadEffect()
Unload active effect.
-
-
-
Constructor Detail
-
OffscreenEffectPlayer
public OffscreenEffectPlayer(@NonNull android.content.Context context, @NonNull OffscreenEffectPlayerConfig config, @NonNull java.lang.String key)
-
OffscreenEffectPlayer
public OffscreenEffectPlayer(@NonNull android.content.Context context, @NonNull com.banuba.sdk.effect_player.EffectPlayer player, @NonNull android.util.Size size, @NonNull OffscreenSimpleConfig config)
-
-
Method Detail
-
setImageProcessListener
public void setImageProcessListener(@Nullable ImageProcessedListener listener, @Nullable android.os.Handler handler)
Sets ImageProcessListener The callback will be invoked on handler's thread. Can be used together with surfaceTexture. In this case, OffscreenEffectPlayer will render to SurfaceTexture and send image to listenerPassing NULL/NULL will disable prepare and send Buffers to listener
- Parameters:
listener
- The listener to use, or null to remove the listener.handler
- The handler on which the listener should be invoked, or null to remove the listener
-
setSurfaceTexture
public void setSurfaceTexture(@Nullable android.graphics.SurfaceTexture surfaceTexture)
Sets SurfaceTexture Can be used together with ImageProcessListener. In this case OffscreenEffectPlayer will render to SurfaceTexture and send image to listenerPassing NULL will disable render to SurfaceTexture
- Parameters:
surfaceTexture
- The surfaceTexture to use, or null to remove.
-
processImage
public void processImage(@NonNull android.media.Image image, @NonNull ImageOrientation orientation)
Send Image to process Image will be closed inside OffscreenEffectPlayer- Parameters:
image
- Android image to processorientation
- describes current image orientation
-
processImage
public void processImage(@NonNull android.media.Image image, @NonNull ImageOrientation orientation, @NonNull OEPImageFormat outputImageFormat)
Send Image to process Image will be closed inside OffscreenEffectPlayer- Parameters:
image
- Android image to processorientation
- describes current image orientationoutputImageFormat
- describes output Image Format
-
processFullImageData
public void processFullImageData(@NonNull com.banuba.sdk.types.FullImageData fullImageData, @Nullable ReleaseCallback releaseCallback, long timestamp)
Send FullImageData to process. FullImageData is a container for the Image object or buffers representing image in a specific format.- Parameters:
fullImageData
- Instance of FullImageData objectreleaseCallback
- is called by OEP when image stored in fullImageData can be released. If releaseCallback is passed then Image data isn't copied to improve performance. If a releaseCallback is passed and an Image is used, undefined behavior may occur when the ImageReader is closed and then opened again. In order to avoid this, it is necessary to call playbackStop before closing the camera and playbackPlay after opening it.timestamp
- lets you associate frame with the timestamp in order to identify it at ImageProcessedListener call
-
processFullImageData
public void processFullImageData(@NonNull com.banuba.sdk.types.FullImageData fullImageData, @Nullable ReleaseCallback releaseCallback, @NonNull OEPImageFormat outputImageFormat, long timestamp)
Send FullImageData to process. FullImageData is a container for the Image object or buffers representing image in a specific format.- Parameters:
fullImageData
- Instance of FullImageData objectreleaseCallback
- is called by OEP when image stored in fullImageData can be released. If releaseCallback is passed then Image data isn't copied to improve performance. If a releaseCallback is passed and an Image is used, undefined behavior may occur when the ImageReader is closed and then opened again. In order to avoid this, it is necessary to call playbackStop before closing the camera and playbackPlay after opening it.outputImageFormat
- OEPImageFormattimestamp
- lets you associate frame with the timestamp in order to identify it at ImageProcessedListener call
-
processFullImageDataNoSkip
@VisibleForTesting public void processFullImageDataNoSkip(@NonNull com.banuba.sdk.types.FullImageData fullImageData, @Nullable ReleaseCallback releaseCallback, long timestamp)
Meaning and parameters are the same as for processFullImageData but in that case the image will wait in the queue until processed, i.e. every image is processed without drops even if another image is being processed at this moment.
-
loadEffect
public void loadEffect(@NonNull java.lang.String effectName)
Loads an effect to the effect player asynchronously by default. Please use another loadEffect method to decide which mode of effect loading appropriates you.- Parameters:
effectName
- the name of an effect (folder) in the app resource storage
-
loadEffect
public void loadEffect(@NonNull java.lang.String effectName, boolean async)
Loads an effect to the effect player asynchronously or synchronously. In the case of synchronous loading, the effect will be loaded and activated as a single step, while for asynchronous loading the activation of effect will be postponed to the rendering phase. The loading of the effect in synchronous mode is practical when you need to be sure that the effect is wholly loaded and activated before the first frame rendering.- Parameters:
effectName
- the name of an effect (folder) in the app resource storageasync
- if true the effect will be loaded asynchronously, else synchronously
-
unloadEffect
public void unloadEffect()
Unload active effect. The effect stays in the cache so that another loading of the same effect is faster.
-
callJsMethod
public void callJsMethod(@NonNull java.lang.String method, @NonNull java.lang.String parameter)
Allows calling methods defined in the script of the active effect to configure the effect or manage its state. This method is obsolete, see evalJs.- Parameters:
method
- - the name of the js methodparameter
- - the parameter to pass to the method
-
evalJs
public void evalJs(@NonNull java.lang.String script, @Nullable com.banuba.sdk.effect_player.JsCallback resultCallback)
Allows execute scripts (calling methods) or load JS modules to the environment of active effect- Parameters:
script
- - js script with escaped quotesresultCallback
- - the callback called after script's execution completed
-
release
public void release()
Stop processing and release OffscreenEffectPlayer resources
-
playbackPlay
public void playbackPlay()
Switching to active state attempt. Possible from paused or stopped state and has no effect if effect playback is already active. Playback resumes from the position saved before `playbackPause` call.
-
playbackPause
public void playbackPause()
Suspend current playback attempt. The recognizer thread is stopped and all the video textures and audio units playback is stopped as well. Effect player doesn't react on processImage or processFullImageData calls in suspended state except asynchronous-inconsistent mode.
-
playbackStop
public void playbackStop()
Switch to inactive state. In addition to pause clears recognizer's buffer. The next switch to active state will result in total rerun of active effect which means that it will be started from the very beginning. Call this method when you stop input from camera (e.g. went in background or switch).
-
getConfig
@NonNull public OffscreenSimpleConfig getConfig()
Return the current OEP configuration
-
enableAudio
public void enableAudio(boolean enable)
Switch on/off audio in effects.- Parameters:
enable
-
-
-