Class NativeJavaCVMediaBackend
java.lang.Object
org.episteme.nativ.media.backends.NativeJavaCVMediaBackend
- All Implemented Interfaces:
AudioAlgorithmProvider<AudioBuffer>, AudioBackend, VideoAlgorithmProvider, VideoBackend, VisionAlgorithmProvider<BufferedImage>, VisionBackend, AlgorithmProvider, Backend, ComputeBackend, CPUBackend, NativeBackend
@AutoService({Backend.class,ComputeBackend.class,AudioBackend.class,VideoBackend.class,VisionBackend.class,CPUBackend.class,NativeBackend.class})
public class NativeJavaCVMediaBackend
extends Object
implements AudioBackend, VideoBackend, VisionBackend, CPUBackend, NativeBackend
Native Media Backend using JavaCV (OpenCV/FFmpeg) for multi-purpose tasks.
Covers Audio, Video and Vision with native acceleration through Bytedeco.
- Since:
- 1.2
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(BufferedImage image, ImageOp<BufferedImage> op) Applies a generic operation to an image.apply(AudioBuffer audio, AudioOp<AudioBuffer> op) Applies an operation to audio data.createAudio(Object data, int channels, int sampleRate) Creates and returns the backend instance (or returns self if it is the backend).Creates an execution context for running operations.createImage(Object data, int width, int height) Creates a new image from the given data.detectMotion(float[][] prev, float[][] curr, float threshold) Detects motion between two frames.Returns the type of hardware accelerator used by this backend.Returns the unique category of the algorithm.Returns the friendly name of this backend instance.Returns a description of the backend.doublegetId()Returns the unique identifier for this backend (e.g., "javafx", "jmol", "cuda").getName()Returns the display name for UI presentation.Returns the name of the native library this backend depends on.intReturns the priority for auto-selection (higher = preferred).float[]Returns the current frequency spectrum.doublegetTime()getType()Returns the backend type category (e.g., "plotting", "molecular", "tensor", "math").<T> TGrabs the current frame as an image.booleanChecks if this backend is currently available (libraries loaded, etc.).booleanisLoaded()Checks if the native library is loaded and available.voidLoads an audio resource.voidpause()voidplay()processNative(BufferedImage image, int opCode) voidshutdown()Called when the application is shutting down or the backend is being replaced.voidstop()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AlgorithmProvider
description, getMetadata, scoreMethods inherited from interface Backend
getAlgorithmProviders, getStatusMessage, isExplicitlyDisabledMethods inherited from interface CPUBackend
supportsComplexNumbers, supportsFloatingPoint, supportsParallelOpsMethods inherited from interface VideoAlgorithmProvider
detectTransitions
-
Constructor Details
-
NativeJavaCVMediaBackend
public NativeJavaCVMediaBackend()
-
-
Method Details
-
isLoaded
public boolean isLoaded()Description copied from interface:NativeBackendChecks if the native library is loaded and available.- Specified by:
isLoadedin interfaceNativeBackend- Returns:
- true if the native library has been successfully loaded
-
getNativeLibraryName
Description copied from interface:NativeBackendReturns the name of the native library this backend depends on.- Specified by:
getNativeLibraryNamein interfaceNativeBackend- Returns:
- library name (e.g., "openblas", "cuda", "fftw3")
-
getType
Description copied from interface:BackendReturns the backend type category (e.g., "plotting", "molecular", "tensor", "math").- Specified by:
getTypein interfaceAudioBackend- Specified by:
getTypein interfaceBackend- Specified by:
getTypein interfaceComputeBackend- Specified by:
getTypein interfaceCPUBackend- Specified by:
getTypein interfaceVideoBackend- Specified by:
getTypein interfaceVisionBackend
-
getId
Description copied from interface:BackendReturns the unique identifier for this backend (e.g., "javafx", "jmol", "cuda").- Specified by:
getIdin interfaceAudioBackend- Specified by:
getIdin interfaceBackend- Specified by:
getIdin interfaceComputeBackend- Specified by:
getIdin interfaceVideoBackend- Specified by:
getIdin interfaceVisionBackend
-
getBackendName
Description copied from interface:AudioBackendReturns the friendly name of this backend instance.- Specified by:
getBackendNamein interfaceAudioBackend- Specified by:
getBackendNamein interfaceVideoBackend- Specified by:
getBackendNamein interfaceVisionBackend
-
getDescription
Description copied from interface:BackendReturns a description of the backend.- Specified by:
getDescriptionin interfaceAudioBackend- Specified by:
getDescriptionin interfaceBackend- Specified by:
getDescriptionin interfaceComputeBackend- Specified by:
getDescriptionin interfaceVideoBackend- Specified by:
getDescriptionin interfaceVisionBackend
-
isAvailable
public boolean isAvailable()Description copied from interface:BackendChecks if this backend is currently available (libraries loaded, etc.).Default implementation checks
Backend.isExplicitlyDisabled()and returns false if it is.- Specified by:
isAvailablein interfaceAlgorithmProvider- Specified by:
isAvailablein interfaceAudioBackend- Specified by:
isAvailablein interfaceBackend- Specified by:
isAvailablein interfaceVideoBackend- Specified by:
isAvailablein interfaceVisionBackend
-
shutdown
public void shutdown()Description copied from interface:BackendCalled when the application is shutting down or the backend is being replaced. Use this to release hardware resources, close file handles, or stop background threads.- Specified by:
shutdownin interfaceAlgorithmProvider- Specified by:
shutdownin interfaceAudioBackend- Specified by:
shutdownin interfaceBackend- Specified by:
shutdownin interfaceVideoBackend- Specified by:
shutdownin interfaceVisionBackend
-
getPriority
public int getPriority()Description copied from interface:BackendReturns the priority for auto-selection (higher = preferred). Used when multiple backends are available.- Specified by:
getPriorityin interfaceAlgorithmProvider- Specified by:
getPriorityin interfaceAudioBackend- Specified by:
getPriorityin interfaceBackend- Specified by:
getPriorityin interfaceVideoBackend- Specified by:
getPriorityin interfaceVisionBackend
-
apply
Description copied from interface:VisionAlgorithmProviderApplies a generic operation to an image.- Specified by:
applyin interfaceVisionAlgorithmProvider<BufferedImage>
-
getName
Description copied from interface:BackendReturns the display name for UI presentation.- Specified by:
getNamein interfaceAlgorithmProvider- Specified by:
getNamein interfaceAudioAlgorithmProvider<AudioBuffer>- Specified by:
getNamein interfaceAudioBackend- Specified by:
getNamein interfaceBackend- Specified by:
getNamein interfaceVideoAlgorithmProvider- Specified by:
getNamein interfaceVideoBackend- Specified by:
getNamein interfaceVisionAlgorithmProvider<BufferedImage>- Specified by:
getNamein interfaceVisionBackend
-
processNative
-
createImage
Description copied from interface:VisionAlgorithmProviderCreates a new image from the given data.- Specified by:
createImagein interfaceVisionAlgorithmProvider<BufferedImage>
-
createContext
Description copied from interface:ComputeBackendCreates an execution context for running operations.The context should be used within a try-with-resources block to ensure proper cleanup of resources.
- Specified by:
createContextin interfaceAudioBackend- Specified by:
createContextin interfaceComputeBackend- Specified by:
createContextin interfaceVideoBackend- Specified by:
createContextin interfaceVisionBackend- Returns:
- new execution context
-
createBackend
Description copied from interface:BackendCreates and returns the backend instance (or returns self if it is the backend).- Specified by:
createBackendin interfaceAudioBackend- Specified by:
createBackendin interfaceBackend- Specified by:
createBackendin interfaceComputeBackend- Specified by:
createBackendin interfaceVideoBackend- Specified by:
createBackendin interfaceVisionBackend- Returns:
- The backend implementation object
-
load
Description copied from interface:AudioBackendLoads an audio resource.- Specified by:
loadin interfaceAudioBackend- Specified by:
loadin interfaceVideoBackend- Parameters:
path- File path or URL- Throws:
Exception
-
play
public void play()- Specified by:
playin interfaceAudioBackend- Specified by:
playin interfaceVideoBackend
-
pause
public void pause()- Specified by:
pausein interfaceAudioBackend- Specified by:
pausein interfaceVideoBackend
-
stop
public void stop()- Specified by:
stopin interfaceAudioBackend- Specified by:
stopin interfaceVideoBackend
-
getTime
public double getTime()- Specified by:
getTimein interfaceAudioBackend- Specified by:
getTimein interfaceVideoBackend
-
getDuration
public double getDuration()- Specified by:
getDurationin interfaceAudioBackend- Specified by:
getDurationin interfaceVideoBackend
-
grabFrame
public <T> T grabFrame()Description copied from interface:VideoBackendGrabs the current frame as an image.- Specified by:
grabFramein interfaceVideoBackend- Type Parameters:
T- the image type- Returns:
- the current frame
-
getSpectrum
public float[] getSpectrum()Description copied from interface:AudioBackendReturns the current frequency spectrum.- Specified by:
getSpectrumin interfaceAudioBackend- Returns:
- Array of magnitudes (usually 128 or 256 bands)
-
createAudio
- Specified by:
createAudioin interfaceAudioAlgorithmProvider<AudioBuffer>- Specified by:
createAudioin interfaceAudioBackend
-
apply
Description copied from interface:AudioAlgorithmProviderApplies an operation to audio data.- Specified by:
applyin interfaceAudioAlgorithmProvider<AudioBuffer>- Specified by:
applyin interfaceAudioBackend
-
getAlgorithmType
Description copied from interface:AlgorithmProviderReturns the unique category of the algorithm.- Specified by:
getAlgorithmTypein interfaceAlgorithmProvider- Specified by:
getAlgorithmTypein interfaceAudioAlgorithmProvider<AudioBuffer>- Specified by:
getAlgorithmTypein interfaceVideoAlgorithmProvider- Specified by:
getAlgorithmTypein interfaceVisionAlgorithmProvider<BufferedImage>
-
getAcceleratorType
Description copied from interface:ComputeBackendReturns the type of hardware accelerator used by this backend.- Specified by:
getAcceleratorTypein interfaceAudioBackend- Specified by:
getAcceleratorTypein interfaceComputeBackend- Specified by:
getAcceleratorTypein interfaceCPUBackend- Specified by:
getAcceleratorTypein interfaceVideoBackend- Specified by:
getAcceleratorTypein interfaceVisionBackend- Returns:
- the accelerator type
-
detectMotion
public SceneTransitionDetector.Transition detectMotion(float[][] prev, float[][] curr, float threshold) Description copied from interface:VideoAlgorithmProviderDetects motion between two frames.- Specified by:
detectMotionin interfaceVideoAlgorithmProvider- Parameters:
prev- Gray frame (float[][])curr- Gray frame (float[][])threshold- Sensitivity threshold- Returns:
- Motion result
-