Skip to content

Commit 527b2ee

Browse files
authored
Merge pull request #8 from Uralstech/unstable
UXR.QuestCamera v3.1.0
2 parents 1e166d4 + 322cfec commit 527b2ee

21 files changed

Lines changed: 307 additions & 289 deletions

Documentation/DocSource/QuickStart.md

Lines changed: 89 additions & 105 deletions
Large diffs are not rendered by default.

Documentation/DocSource/V3Migration.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Migrating to UXR.QuestCamera V3
22

3-
UXR.QuestCamera v3 introduces a soft rewrite of the package with several breaking changes. It's highly recommended to update to v3, as it includes fixes for many crashes and stutters.
4-
This page documents all changes to the **public API** in v3.0.0 compared to v2.6.1.
3+
UXR.QuestCamera v3 introduces a soft rewrite of the package with several breaking changes. It's highly recommended to update to v3, as it includes fixes for many crashes and stutters. This page documents all changes to the **public API** in v3.0.0 and v3.1.0 compared to v2.6.1.
54

65
## Basic Sample
76

@@ -84,6 +83,9 @@ _rawImage.texture = sessionObject.TextureConverter.FrameRenderTexture;
8483
- `CreateSurfaceTextureCaptureSession()` and `CreateOnDemandSurfaceTextureCaptureSession()` now have nullable return types and throw `ObjectDisposedException` if the `CameraDevice` was disposed at the time of calling.
8584
- `CameraId` is no longer a property and is now a cached value.
8685

86+
- **v3.1.0 Specific Changes**
87+
- `WaitForInitializationAsync()` now returns `Task<bool>` representing the open state of the device.
88+
8789
---
8890

8991
## CaptureSessionObject<T>
@@ -111,6 +113,9 @@ _rawImage.texture = sessionObject.TextureConverter.FrameRenderTexture;
111113
- `WaitForInitialization()` now returns a `WaitUntil` object and throws `ObjectDisposedException` if the `ContinuousCaptureSession` was disposed at the time of calling.
112114
- `WaitForInitializationAsync()` now accepts an optional `CancellationToken` and throws `ObjectDisposedException` if the `ContinuousCaptureSession` was disposed at the time of calling.
113115

116+
- **v3.1.0 Specific Changes**
117+
- `WaitForInitializationAsync()` now returns `Task<bool>` representing the open state of the session.
118+
114119
---
115120

116121
## OnDemandCaptureSession
@@ -154,6 +159,9 @@ _rawImage.texture = sessionObject.TextureConverter.FrameRenderTexture;
154159
- `WaitForInitialization()` now returns a `WaitUntil` object and throws `ObjectDisposedException` if the `SurfaceTextureCaptureSession` was disposed at the time of calling.
155160
- `WaitForInitializationAsync()` now accepts an optional `CancellationToken` and throws `ObjectDisposedException` if the `SurfaceTextureCaptureSession` was disposed at the time of calling.
156161

162+
- **v3.1.0 Specific Changes**
163+
- `WaitForInitializationAsync()` now returns `Task<bool>` representing the open state of the session.
164+
157165
---
158166

159167
## OnDemandSurfaceTextureCaptureSession
@@ -165,6 +173,9 @@ _rawImage.texture = sessionObject.TextureConverter.FrameRenderTexture;
165173
- `RequestCapture()` now returns a `WaitUntil?` object (`null` when the capture fails) and throws `ObjectDisposedException` if the `OnDemandSurfaceTextureCaptureSession` was disposed at the time of calling.
166174
- `RequestCaptureAsync()` is now `Awaitable<(Texture2D?, long)> RequestCaptureAsync()` (`Texture2D` is `null` when the capture fails), accepts an optional `CancellationToken`, and throws `ObjectDisposedException` if the `OnDemandSurfaceTextureCaptureSession` was disposed at the time of calling.
167175

176+
- **v3.1.0 Specific Changes**
177+
- `RequestCaptureAsync()` now returns `Task<(Texture2D?, long)>`.
178+
168179
---
169180

170181
## CameraInfo
@@ -198,13 +209,13 @@ _rawImage.texture = sessionObject.TextureConverter.FrameRenderTexture;
198209

199210
---
200211

201-
## UCameraManager
212+
## CaptureTemplate
202213

203-
All methods and properties in [`UCameraManager`](~/api/Uralstech.UXR.QuestCamera.UCameraManager.yml) are now nullable-aware with no breaking changes.
214+
- **Removed**
215+
- `ZeroShutterLag` — not compatible with capture sessions created by the plugin.
204216

205217
---
206218

207-
## CaptureTemplate
219+
## UCameraManager
208220

209-
- **Removed**
210-
- `ZeroShutterLag` — not compatible with capture sessions created by the plugin.
221+
All methods and properties in [`UCameraManager`](~/api/Uralstech.UXR.QuestCamera.UCameraManager.yml) are now nullable-aware with no breaking changes.
Binary file not shown.
Binary file not shown.

UXR.QuestCamera/Packages/com.uralstech.uxr.questcamera/Editor/Scripts.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

UXR.QuestCamera/Packages/com.uralstech.uxr.questcamera/Editor/Scripts/AssetMenuExtensions.cs

Lines changed: 0 additions & 83 deletions
This file was deleted.

UXR.QuestCamera/Packages/com.uralstech.uxr.questcamera/Editor/Scripts/AssetMenuExtensions.cs.meta

Lines changed: 0 additions & 2 deletions
This file was deleted.

UXR.QuestCamera/Packages/com.uralstech.uxr.questcamera/Editor/UXR.QuestCamera.Editor.asmdef

Lines changed: 0 additions & 16 deletions
This file was deleted.

UXR.QuestCamera/Packages/com.uralstech.uxr.questcamera/Editor/UXR.QuestCamera.Editor.asmdef.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.

UXR.QuestCamera/Packages/com.uralstech.uxr.questcamera/Runtime/Scripts/CameraDevice.cs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,46 @@ public WaitUntil WaitForInitialization()
143143
return new(() => CurrentState != NativeWrapperState.Initializing);
144144
}
145145

146-
#if UNITY_6000_0_OR_NEWER
147146
/// <summary>
148147
/// Waits until the CameraDevice opens or errs out.
149148
/// </summary>
150-
/// <returns>The current state of the CameraDevice.</returns>
151-
public async Awaitable<NativeWrapperState> WaitForInitializationAsync(CancellationToken token = default)
149+
/// <param name="timeout">Maximum time to wait.</param>
150+
/// <param name="onTimeout">The action to perform when the <paramref name="timeout"/> is reached.</param>
151+
/// <param name="timeoutMode">Mode in which to measure time to determine <paramref name="timeout"/>.</param>
152+
public WaitUntil WaitForInitialization(TimeSpan timeout, Action onTimeout, WaitTimeoutMode timeoutMode = WaitTimeoutMode.Realtime)
152153
{
153154
ThrowIfDisposed();
154-
await Awaitable.MainThreadAsync();
155-
while (CurrentState == NativeWrapperState.Initializing && !token.IsCancellationRequested)
156-
await Awaitable.NextFrameAsync(token);
155+
return new(() => CurrentState != NativeWrapperState.Initializing, timeout, onTimeout, timeoutMode);
156+
}
157+
158+
/// <summary>
159+
/// Waits until the CameraDevice opens or errs out.
160+
/// </summary>
161+
/// <returns><see langword="true"/> if the device was opened successfully, <see langword="false"/> otherwise.</returns>
162+
public async Task<bool> WaitForInitializationAsync(CancellationToken token = default)
163+
{
164+
ThrowIfDisposed();
165+
if (CurrentState != NativeWrapperState.Initializing)
166+
return CurrentState == NativeWrapperState.Opened;
157167

158-
return CurrentState;
168+
TaskCompletionSource<bool> wrapperState = new();
169+
void OnOpened(string _) => wrapperState.SetResult(true);
170+
void OnClosed(string? _) => wrapperState.SetResult(false);
171+
172+
OnDeviceOpened += OnOpened;
173+
OnDeviceClosed += OnClosed;
174+
175+
try
176+
{
177+
using CancellationTokenRegistration _ = token.Register(wrapperState.SetCanceled);
178+
return await wrapperState.Task;
179+
}
180+
finally
181+
{
182+
OnDeviceOpened -= OnOpened;
183+
OnDeviceClosed -= OnClosed;
184+
}
159185
}
160-
#endif
161186

162187
private bool _disposed = false;
163188

@@ -174,13 +199,13 @@ public async ValueTask DisposeAsync()
174199
if (_cameraDevice != null)
175200
{
176201
TaskCompletionSource<bool> tcs = new();
177-
void OnDisposed(string? _) => tcs.SetResult(true);
202+
void OnDisposed(string? _) => tcs.TrySetResult(true);
178203

179204
OnDeviceClosed += OnDisposed;
180-
bool isClosing = _cameraDevice.Call<bool>("close");
205+
if (!_cameraDevice.Call<bool>("close"))
206+
tcs.TrySetResult(true);
181207

182-
if (isClosing)
183-
await tcs.Task;
208+
await tcs.Task;
184209

185210
OnDeviceClosed -= OnDisposed;
186211
_cameraDevice.Dispose();

0 commit comments

Comments
 (0)