Skip to content

Commit

Permalink
Merge pull request #370 from asus4/run-async-options
Browse files Browse the repository at this point in the history
Add waitForMainThread option in RunAsync method
  • Loading branch information
asus4 authored Aug 9, 2024
2 parents ac2293d + 96e892e commit e4e5a2e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Packages/com.github.asus4.mediapipe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"license": "Apache License 2.0",
"unity": "2022.3",
"unityRelease": "0f1",
"version": "2.16.1-p1",
"version": "2.16.1-p2",
"hideInEditor": false,
"dependencies": {
"com.github.asus4.tflite": "2.16.1-p1",
"com.github.asus4.tflite.common": "2.16.1-p1"
"com.github.asus4.tflite": "2.16.1-p2",
"com.github.asus4.tflite.common": "2.16.1-p2"
},
"documentationUrl": "https://github.com/asus4/tf-lite-unity-sample",
"changelogUrl": "https://github.com/asus4/tf-lite-unity-sample/releases",
Expand Down
17 changes: 14 additions & 3 deletions Packages/com.github.asus4.tflite.common/Runtime/BaseVisionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,16 @@ protected virtual void PreProcess(Texture texture)
protected abstract void PostProcess();

// Only available when UniTask is installed
#if TFLITE_UNITASK_ENABLED || true
#if TFLITE_UNITASK_ENABLED
public virtual async UniTask RunAsync(Texture texture, CancellationToken cancellationToken)
{
await RunAsync(texture, cancellationToken, true);
}

public virtual async UniTask RunAsync(
Texture texture,
CancellationToken cancellationToken,
bool waitForMainThread)
{
if (isDisposed)
{
Expand Down Expand Up @@ -151,8 +159,11 @@ public virtual async UniTask RunAsync(Texture texture, CancellationToken cancell
semaphore.Release();
}

// Back to main thread
await UniTask.SwitchToMainThread();
if (waitForMainThread)
{
// Back to main thread
await UniTask.SwitchToMainThread();
}
}

protected virtual async UniTask PreProcessAsync(Texture texture, CancellationToken cancellationToken)
Expand Down
4 changes: 2 additions & 2 deletions Packages/com.github.asus4.tflite.common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"license": "Apache License 2.0",
"unity": "2022.3",
"unityRelease": "0f1",
"version": "2.16.1-p1",
"version": "2.16.1-p2",
"hideInEditor": false,
"dependencies": {
"com.unity.burst": "1.8.12",
"com.github.asus4.tflite": "2.16.1-p1"
"com.github.asus4.tflite": "2.16.1-p2"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion Packages/com.github.asus4.tflite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "Apache License 2.0",
"unity": "2022.3",
"unityRelease": "0f1",
"version": "2.16.1-p1",
"version": "2.16.1-p2",
"hideInEditor": false,
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}
],
"dependencies": {
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.5.3",
"com.github.asus4.texture-source": "0.3.0",
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.5.5",
"com.github.asus4.texture-source": "0.3.2",
"com.unity.2d.sprite": "1.0.0",
"com.unity.collections": "2.1.4",
"com.unity.ext.nunit": "1.0.6",
Expand Down
12 changes: 6 additions & 6 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"dependencies": {
"com.cysharp.unitask": {
"version": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.5.3",
"version": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.5.5",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "64792b672d35e43b3412fc74861f8bdbf41e3a6f"
"hash": "cdf88c6a6ac8c9b7e6e5d3c0a360a4af29641c24"
},
"com.github.asus4.mediapipe": {
"version": "file:com.github.asus4.mediapipe",
"depth": 0,
"source": "embedded",
"dependencies": {
"com.github.asus4.tflite": "2.16.1-p1",
"com.github.asus4.tflite.common": "2.16.1-p1"
"com.github.asus4.tflite": "2.16.1-p2",
"com.github.asus4.tflite.common": "2.16.1-p2"
}
},
"com.github.asus4.texture-source": {
"version": "0.3.0",
"version": "0.3.2",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -37,7 +37,7 @@
"source": "embedded",
"dependencies": {
"com.unity.burst": "1.8.12",
"com.github.asus4.tflite": "2.16.1-p1"
"com.github.asus4.tflite": "2.16.1-p2"
}
},
"com.unity.2d.sprite": {
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ Included prebuilt libraries:
],
"dependencies": {
// Core TensorFlow Lite libraries
"com.github.asus4.tflite": "2.16.1-p1",
"com.github.asus4.tflite": "2.16.1-p2",
// Utilities for TFLite
"com.github.asus4.tflite.common": "2.16.1-p1",
"com.github.asus4.tflite.common": "2.16.1-p2",
// Utilities for MediaPipe
"com.github.asus4.mediapipe": "2.16.1-p1",
"com.github.asus4.mediapipe": "2.16.1-p2",
...// other dependencies
}
}
Expand Down

0 comments on commit e4e5a2e

Please sign in to comment.