Banuba SDK
|
The EffectPlayer class provides ability to play AR effects on set of images or video. More...
#import <BNBEffectPlayer.h>
Instance Methods | |
(void) | - addFrameDurationListener: |
Add callback to receive FPS information. More... | |
(void) | - removeFrameDurationListener: |
Remove callback to receive FPS information. More... | |
(void) | - addFaceNumberListener: |
Add callback to receive faces count in frame. More... | |
(void) | - removeFaceNumberListener: |
Remove callback to receive faces count in frame. More... | |
(void) | - addFrameDataListener: |
Add callback to receive frame data right after processing in recognizer. More... | |
(void) | - removeFrameDataListener: |
Remove callback to receive frame data right after processing in recognizer. More... | |
(void) | - addCameraPoiListener: |
Add callback to receive center of the face in frame relative to top-left corner in [0, 1] space. More... | |
(void) | - removeCameraPoiListener: |
Remove callback to receive center of the face in frame relative to top-left Thread-safe. More... | |
(void) | - addEffectInfoListener: |
Add callback to receive current effect info from Effect Player. More... | |
(void) | - removeEffectInfoListener: |
Remove callback to receive current effect info from Effect Player. More... | |
(void) | - addEffectActivationCompletionListener: |
Add callback to receive current effect activation notification from Effect Player. More... | |
(void) | - removeEffectActivationCompletionListener: |
Remove callback to receive current effect activation notification from Effect Player. More... | |
(void) | - setMaxFaces: |
Sets maximum allowed face results, if face tracking feature is present. More... | |
(void) | - setExternalCameraTexture:width:height: |
Set OpenGL name of input external texture. More... | |
(void) | - setUseExtCamTex: |
Use external texture as input source. More... | |
(void) | - surfaceCreated:height: |
Use to notify the EffectPlayer that the surface exists and effect can be played. More... | |
(void) | - surfaceChanged:height: |
Notify about rendering surface being resized. More... | |
(void) | - surfaceDestroyed |
This method should be called right before an active context will become invalid. More... | |
(int64_t) | - draw |
Draw the current effect into the current OpenGL framebuffer. More... | |
(int64_t) | - drawWithExternalFrameData: |
Draw the current effect into the current OpenGL framebuffer. More... | |
(void) | - captureBlit:captureHeight: |
Record last rendering ("draw_()") result into current OpenGL framebuffer. More... | |
(nonnull BNBPixelBuffer *) | - readPixels |
Receive the last rendered frame in binary form. More... | |
(void) | - setRenderConsistencyMode: |
Thread-safe. More... | |
(nonnull NSData *) | - processImage:outputPixelFormat: |
Process an image with current effect. More... | |
(nonnull NSData *) | - processImageFrameData:outputPixelFormat: |
Process an image with current effect. More... | |
(nonnull NSData *) | - processImageData:width:height:orientation:isMirrored:inputPixelFormat:outputPixelFormat: |
Process image with current effect. More... | |
(void) | - pushFrame: |
Provides image to process and to play effect. More... | |
(void) | - pushFrameWithNumber:frameNumber: |
Provides image to process and to play effect. More... | |
(void) | - pushFrameData: |
Provides FrameData to process and to play effect. More... | |
(void) | - pushFrameDataWithNumber:frameNumber: |
Provides FrameData with frame number to process and to play effect. More... | |
(void) | - playbackPlay |
MUST be called from the main(render) thread. More... | |
(void) | - playbackPause |
(void) | - playbackStop |
(BNBEffectPlayerPlaybackState) | - getPlaybackState |
Thread-safe. More... | |
(nullable BNBInputManager *) | - getInputManager |
Get interface to control user iterations. More... | |
(void) | - startVideoProcessing:screenHeight:orientation:resetEffect:offlineMode: |
Initialize video processing. More... | |
(void) | - stopVideoProcessing: |
Finish processing and return renderer to normal state. More... | |
(nullable BNBFrameData *) | - processVideoFrameData:recognizerIterations: |
Provide frame data to evaluate video processing. More... | |
(nullable BNBFrameData *) | - processVideoFrame:recognizerIterations: |
Provide frame to evaluate video processing. More... | |
(nonnull NSData *) | - drawVideoFrame:timeNs:outputPixelFormat: |
Draw processed frame to image buffer. More... | |
(nonnull NSData *) | - drawVideoFrameAllocated:timeNs:outputPixelFormat:allocatedBuffer: |
The same as draw_video_frame but accepts preallocated buffer to avoid recreation for every frame. More... | |
(void) | - writeRecordedAudio:lengthMs: |
Save recorded audio. More... | |
(void) | - onVideoRecordStart: |
Trigger record start events in EP and Effect. More... | |
(void) | - onVideoRecordEnd |
Triggers record stop events in EP and Effect. More... | |
(nullable BNBEffectManager *) | - effectManager |
Get effect manager object Thread-safe. More... | |
(void) | - setRecognizerOfflineMode: |
Force recognizer offline mode Thread-safe. More... | |
(void) | - setRecognizerUseFutureFilter: |
Set future frame filtrarion mode. More... | |
(void) | - setRecognizerUseFutureInterpolate: |
Set future frame interpolation mode. More... | |
(void) | - setFrameProcessor: |
Set frame processor as current Thread-safe. More... | |
(nullable BNBFrameProcessor *) | - frameProcessor |
Get current frame processor Thread-safe. More... | |
Class Methods | |
(nullable BNBEffectPlayer *) | + create: |
(void) | + setRenderBackend: |
(BNBRenderBackendType) | + getCurrentRenderBackendType |
The EffectPlayer class provides ability to play AR effects on set of images or video.
In order to support an application lifecycle EffectPlayer provides special methods to control it during application states like pause or losing focus.
Initial playback state of newly created Effect Player instance is active
. With playback control methods described below, the player can be launched/resumed or paused. State of effect player becomes stopped/inactive at the moment of surface loss or by calling the EffectPlayer::playback_stop method. One can use next three methods to control effect playback:
- EffectPlayer.playback_play
. 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 EffectPlayer.playbackPause
call.
- EffectPlayer.playback_pause
. 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 EffectPlayer::pushFrame calls in suspended state except asynchronous-inconsistent mode.
- EffectPlayer.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.
If you want an application to be active on windowed mode and if the focus is on another application you can switch EffectPlayer into active state when onStart
activity callback occurs and switch to paused when onStop
occurs. Otherwise you can suspend EffectPlayer
on onPause
and resume on onResume
callback to make an instance of the EffectPlayer
inactive while activity losing focus.
There are two methods that have to be used to ensure correct operating of the EffectPlayer. Losing context without notifying the EffectPlayer leads to application crash. Methods for context changes notification:
- EffectPlayer.surfaceCreated
- EffectPlayer.surfaceDestroyed
EffectPlayer allows to call some of its methods from several threads (simultaneously) for convenience and increased performance. This is allowed only during normal operation, all invocations from other threads MUST finish before you start destroying the EffectPlayer instance. Most methods belong to one of the two groups:
- MUST be called from the "Main" (also "Render") thread ("Not Reentrant, Not Thread-safe")
- MAY be called from "Any" thread. Most are "Thread-safe" Listener callbacks can be called back from any thread. Generally for best performance and responsiveness you'll have 3 threads:
- Main(render) thread for drawing-related operations
- "Camera" thread for handling and push()-ing frames into EffectPlayer
- UI Thread for handling user interactions and other tasks
Definition at line 78 of file BNBEffectPlayer.h.
- (void) addCameraPoiListener: | (nullable id< BNBCameraPoiListener >) | cameraPoiListener |
Add callback to receive center of the face in frame relative to top-left corner in [0, 1] space.
Thread-safe. May be called from any thread
- (void) addEffectActivationCompletionListener: | (nullable id< BNBEffectActivationCompletionListener >) | effectActivationCompletionListener |
Add callback to receive current effect activation notification from Effect Player.
Thread-safe. May be called from any thread
- (void) addEffectInfoListener: | (nullable id< BNBEffectInfoListener >) | effectInfoListener |
Add callback to receive current effect info from Effect Player.
Thread-safe. May be called from any thread
- (void) addFaceNumberListener: | (nullable id< BNBFaceNumberListener >) | faceNumberListener |
Add callback to receive faces count in frame.
Thread-safe. May be called from any thread
- (void) addFrameDataListener: | (nullable id< BNBFrameDataListener >) | frameDataListener |
Add callback to receive frame data right after processing in recognizer.
Thread-safe. May be called from any thread
- (void) addFrameDurationListener: | (nullable id< BNBFrameDurationListener >) | frameDurationListener |
Add callback to receive FPS information.
Thread-safe. May be called from any thread
- (void) captureBlit: | (int32_t) | captureWidth | |
captureHeight: | (int32_t) | captureHeight | |
Record last rendering ("draw_()") result into current OpenGL framebuffer.
Content is cropped to maintain effect_size() aspect ratio MUST be called from the render thread
+ (nullable BNBEffectPlayer *) create: | (nullable BNBEffectPlayerConfiguration *) | configuration |
- (int64_t) draw |
Draw the current effect into the current OpenGL framebuffer.
Uses internal frame_data object obtained from latest push_frame recognition result.
Return current frame number if drawing was performed and caller should swap buffers otherwise DRAW_SKIPPED
(-1) MUST be called from the render thread
- (nonnull NSData *) drawVideoFrame: | (nullable BNBFrameData *) | inputFrameData | |
timeNs: | (int64_t) | timeNs | |
outputPixelFormat: | (BNBPixelFormat) | outputPixelFormat | |
Draw processed frame to image buffer.
MUST be called from the render thread
inputFrameData | FrameData to draw. |
timeNs | Frame position on timeline. |
outputPixelFormat | Output image format. |
- (nonnull NSData *) drawVideoFrameAllocated: | (nullable BNBFrameData *) | inputFrameData | |
timeNs: | (int64_t) | timeNs | |
outputPixelFormat: | (BNBPixelFormat) | outputPixelFormat | |
allocatedBuffer: | (nonnull NSData *) | allocatedBuffer | |
The same as draw_video_frame but accepts preallocated buffer to avoid recreation for every frame.
MUST be called from the render thread
- (int64_t) drawWithExternalFrameData: | (nullable BNBFrameData *) | frameData |
Draw the current effect into the current OpenGL framebuffer.
Uses externally provided frameData object instead of internal one obtained from latest push_frame recognition result.
Return frame number from provided frameData if drawing was performed and caller should swap buffers otherwise DRAW_SKIPPED
(-1) MUST be called from the render thread
- (nullable BNBEffectManager *) effectManager |
Get effect manager object Thread-safe.
May be called from any thread
- (nullable BNBFrameProcessor *) frameProcessor |
Get current frame processor Thread-safe.
May be called from any thread
+ (BNBRenderBackendType) getCurrentRenderBackendType |
- (nullable BNBInputManager *) getInputManager |
Get interface to control user iterations.
This events will be passed to effect. Thread-safe. May be called from any thread
- (BNBEffectPlayerPlaybackState) getPlaybackState |
Thread-safe.
May be called from any thread
- (void) onVideoRecordEnd |
Triggers record stop events in EP and Effect.
Thread-safe. May be called from any thread
- (void) onVideoRecordStart: | (BOOL) | playAudioWhileRecording |
Trigger record start events in EP and Effect.
Records all sounds during recording to be replayed by processRecordedAudio
. If
playAudioWhileRecording | is true, the audio will continue to play. Otherwise, the audio will be muted. Thread-safe. May be called from any thread |
- (void) playbackPause |
- (void) playbackPlay |
MUST be called from the main(render) thread.
- (void) playbackStop |
- (nonnull NSData *) processImage: | (nonnull BNBFullImageData *) | inputImage | |
outputPixelFormat: | (BNBPixelFormat) | outputPixelFormat | |
Process an image with current effect.
Must be called from the render thread.
inputImage | to avoid conversion recommended to use YUV image |
outputPixelFormat | to avoid conversion recommended to use RGBA |
params | extra image processing arguments |
- (nonnull NSData *) processImageData: | (nonnull NSData *) | inputImage | |
width: | (int32_t) | width | |
height: | (int32_t) | height | |
orientation: | (BNBCameraOrientation) | orientation | |
isMirrored: | (BOOL) | isMirrored | |
inputPixelFormat: | (BNBPixelFormat) | inputPixelFormat | |
outputPixelFormat: | (BNBPixelFormat) | outputPixelFormat | |
Process image with current effect.
Must be called from render thread. NOTE: inputImage have copy overhead, preferable to use process_image method MUST be called from the render thread
inputImage | input image with width * height * 4 size |
outputPixelFormat | to avoid conversion recommended to use RGBA |
- (nonnull NSData *) processImageFrameData: | (nullable BNBFrameData *) | inputFrameData | |
outputPixelFormat: | (BNBPixelFormat) | outputPixelFormat | |
Process an image with current effect.
Prefer this method over processImage
when you have extra input data besides just an input image.
Must be called from render thread.
inputFrameData | FrameData with an image |
outputPixelFormat | to avoid conversion recommended to use RGBA |
params | extra image processing arguments |
- (nullable BNBFrameData *) processVideoFrame: | (nonnull BNBFullImageData *) | inputImage | |
recognizerIterations: | (nullable NSNumber *) | recognizerIterations | |
Provide frame to evaluate video processing.
MUST be called from the render thread
inputImage | Image to process. |
params | Processing params. |
recognizerIterations | Number of processing iterations. Higher number means higher processing quality, but lower speed. Must be greater than 1. Pass null value for default number. |
- (nullable BNBFrameData *) processVideoFrameData: | (nullable BNBFrameData *) | inputFrameData | |
recognizerIterations: | (nullable NSNumber *) | recognizerIterations | |
Provide frame data to evaluate video processing.
MUST be called from the render thread
inputFrameData | Frame Data to process. |
params | Processing params. |
recognizerIterations | Number of processing iterations. Higher number means higher processing quality, but lower speed. Must be greater than 1. Pass null value for default number. |
- (void) pushFrame: | (nonnull BNBFullImageData *) | fullImage |
Provides image to process and to play effect.
Thread-safe. May be called from any thread
- (void) pushFrameData: | (nullable BNBFrameData *) | frameData |
Provides FrameData to process and to play effect.
Must contain full image. Thread-safe. May be called from any thread
- (void) pushFrameDataWithNumber: | (nullable BNBFrameData *) | frameData | |
frameNumber: | (int64_t) | frameNumber | |
Provides FrameData with frame number to process and to play effect.
Must contain full image. Thread-safe. May be called from any thread
- (void) pushFrameWithNumber: | (nonnull BNBFullImageData *) | fullImage | |
frameNumber: | (int64_t) | frameNumber | |
Provides image to process and to play effect.
Thread-safe. May be called from any thread
- (nonnull BNBPixelBuffer *) readPixels |
Receive the last rendered frame in binary form.
fx_width * fx_height * 4
MUST be called from the render thread - (void) removeCameraPoiListener: | (nullable id< BNBCameraPoiListener >) | cameraPoiListener |
Remove callback to receive center of the face in frame relative to top-left Thread-safe.
May be called from any thread
- (void) removeEffectActivationCompletionListener: | (nullable id< BNBEffectActivationCompletionListener >) | effectActivationCompletionListener |
Remove callback to receive current effect activation notification from Effect Player.
Thread-safe. May be called from any thread
- (void) removeEffectInfoListener: | (nullable id< BNBEffectInfoListener >) | effectInfoListener |
Remove callback to receive current effect info from Effect Player.
Thread-safe. May be called from any thread
- (void) removeFaceNumberListener: | (nullable id< BNBFaceNumberListener >) | faceNumberListener |
Remove callback to receive faces count in frame.
Thread-safe. May be called from any thread
- (void) removeFrameDataListener: | (nullable id< BNBFrameDataListener >) | frameDataListener |
Remove callback to receive frame data right after processing in recognizer.
Thread-safe. May be called from any thread
- (void) removeFrameDurationListener: | (nullable id< BNBFrameDurationListener >) | frameDurationListener |
Remove callback to receive FPS information.
Thread-safe. May be called from any thread
- (void) setExternalCameraTexture: | (int32_t) | name | |
width: | (int32_t) | width | |
height: | (int32_t) | height | |
Set OpenGL name of input external texture.
https://developer.android.com/reference/android/graphics/SurfaceTexture . MUST be called from the render thread
name | Texture name |
width | Textute width |
height | Texture height |
Note: This function is Android only.
Note: We use texture size to calculate aspect ratio only.
- (void) setFrameProcessor: | (nullable BNBFrameProcessor *) | processor |
Set frame processor as current Thread-safe.
May be called from any thread
- (void) setMaxFaces: | (int32_t) | maxFaces |
Sets maximum allowed face results, if face tracking feature is present.
Thread-safe. May be called from any thread This option is relevant only for GLFX effects.
- (void) setRecognizerOfflineMode: | (BOOL) | on |
Force recognizer offline mode Thread-safe.
May be called from any thread
- (void) setRecognizerUseFutureFilter: | (BOOL) | on |
Set future frame filtrarion mode.
Produce smoother recognition result (anti jitter), however adds inconsistency in push'ed/draw'ed frames (one frame lag) Example: push frame 1 - draw frame 1, push frame 2 - draw frame 1, push frame 3 - draw frame 2, ...
- (void) setRecognizerUseFutureInterpolate: | (BOOL) | on |
Set future frame interpolation mode.
Produce faster recognition result (skip even frames), however adds inconsistency in push'ed/pop'ed frames (one frame lag) Example: push frame 1 - pop frame 1, push frame 2 - pop frame 1, push frame 3 - pop frame 2, ...
+ (void) setRenderBackend: | (BNBRenderBackendType) | backendType |
- (void) setRenderConsistencyMode: | (BNBConsistencyMode) | value |
Thread-safe.
May be called from any thread
- (void) setUseExtCamTex: | (BOOL) | value |
Use external texture as input source.
MUST be called from the render thread
- (void) startVideoProcessing: | (int64_t) | screenWidth | |
screenHeight: | (int64_t) | screenHeight | |
orientation: | (BNBCameraOrientation) | orientation | |
resetEffect: | (BOOL) | resetEffect | |
offlineMode: | (BOOL) | offlineMode | |
Initialize video processing.
To provide frames use process_video_frame methods. Effect audio is recorded as well and can be accessed using process_recorded_audio and write_recorded_audio. push_frame should not be called during processing. MUST be called from the render thread
Exception | Must be aborted with stop_video_processing() |
- (void) stopVideoProcessing: | (BOOL) | resetEffect |
Finish processing and return renderer to normal state.
MUST be called from the render thread
- (void) surfaceChanged: | (int32_t) | width | |
height: | (int32_t) | height | |
Notify about rendering surface being resized.
MUST be called from the render thread
- (void) surfaceCreated: | (int32_t) | width | |
height: | (int32_t) | height | |
Use to notify the EffectPlayer that the surface exists and effect can be played.
0, 0 for width and height are valid values. MUST be called from the render thread
- (void) surfaceDestroyed |
This method should be called right before an active context will become invalid.
Switches playback state to inactive state. If it's not done an application will be crashed on next draw iteration. After losing the surface effect playback can't be resumed from last position. MUST be called from the render thread
- (void) writeRecordedAudio: | (nonnull NSString *) | filename | |
lengthMs: | (int64_t) | lengthMs | |
Save recorded audio.
Not thread-safe but can be called from any thread.
filename | ".wav" extension must be used. |
lengthMs | Track length. Set to '0' to use full duration. |