JNI utils for Task API.
interface | TaskJniUtils.EmptyHandleProvider | Syntax sugar to get nativeHandle from empty param list. | |
interface | TaskJniUtils.FdAndOptionsHandleProvider<T> | Syntax sugar to get nativeHandle from file descriptor and options. | |
interface | TaskJniUtils.MultipleBuffersHandleProvider | Syntax sugar to get nativeHandle from an array of ByteBuffer s. |
long | INVALID_POINTER |
static <T> long |
createHandleFromFdAndOptions(Context context, FdAndOptionsHandleProvider<T> provider, String libName, String filePath, T options)
Initializes the JNI and returns C++ handle with file descriptor and options for task API.
|
static long |
createHandleFromLibrary(TaskJniUtils.EmptyHandleProvider provider, String libName)
Initializes the JNI and returns C++ handle by first loading the C++ library and then invokes
TaskJniUtils.EmptyHandleProvider.createHandle() . |
static long |
createHandleWithMultipleAssetFilesFromLibrary(Context context, TaskJniUtils.MultipleBuffersHandleProvider provider, String libName, String... filePaths)
Initializes the JNI and returns C++ handle by first loading the C++ library and then invokes
TaskJniUtils.MultipleBuffersHandleProvider.createHandle(ByteBuffer) . |
static long |
createProtoBaseOptionsHandle(BaseOptions baseOptions)
|
static long |
createProtoBaseOptionsHandleWithLegacyNumThreads(BaseOptions baseOptions, int legacyNumThreads)
|
static MappedByteBuffer |
loadMappedFile(Context context, String filePath)
Loads a file from the asset folder through memory mapping.
|
static void |
tryLoadLibrary(String libName)
Try loading a native library, if it's already loaded return directly.
|
Initializes the JNI and returns C++ handle with file descriptor and options for task API.
context | the Android app context |
---|---|
provider | provider to get C++ handle, usually returned from native call |
libName | name of C++ lib to be loaded |
filePath | path of the file to be loaded |
options | options to set up the task API, used by the provider |
IOException | If model file fails to load. |
---|
Initializes the JNI and returns C++ handle by first loading the C++ library and then invokes
TaskJniUtils.EmptyHandleProvider.createHandle()
.
provider | provider to get C++ handle, usually returned from native call |
---|---|
libName |
Initializes the JNI and returns C++ handle by first loading the C++ library and then invokes
TaskJniUtils.MultipleBuffersHandleProvider.createHandle(ByteBuffer)
.
context | app context |
---|---|
provider | provider to get C++ pointer, usually returned from native call |
libName | name of C++ lib to load |
filePaths | file paths to load |
IOException | If model file fails to load. |
---|
baseOptions | |
---|---|
legacyNumThreads |
Loads a file from the asset folder through memory mapping.
context | Application context to access assets. |
---|---|
filePath | Asset path of the file. |
IOException | If model file fails to load. |
---|
Try loading a native library, if it's already loaded return directly.
libName | name of the lib |
---|