-
Couldn't load subscription status.
- Fork 462
Improve camera refresh logic during initialization #2909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4713b19
e86b9ab
b9e9345
9cf7487
8ab0319
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -119,16 +119,6 @@ protected virtual void Dispose(bool disposing) | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| protected virtual async partial Task PlatformConnectCamera(CancellationToken token) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| if (cameraProvider.AvailableCameras is null) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| await cameraProvider.RefreshAvailableCameras(token); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (cameraProvider.AvailableCameras is null) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| throw new CameraException("Unable to refresh cameras"); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| await StartCameraPreview(token); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -139,13 +129,9 @@ protected virtual async partial Task PlatformStartCameraPreview(CancellationToke | |||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| mediaCapture = new MediaCapture(); | ||||||||||||||||||||||||||
| cameraView.SelectedCamera ??= cameraProvider.AvailableCameras?.FirstOrDefault() ?? throw new CameraException("No camera available on device"); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (cameraView.SelectedCamera is null) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| await cameraProvider.RefreshAvailableCameras(token); | ||||||||||||||||||||||||||
| cameraView.SelectedCamera = cameraProvider.AvailableCameras?.FirstOrDefault() ?? throw new CameraException("No camera available on device"); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| mediaCapture = new MediaCapture(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| await mediaCapture.InitializeCameraForCameraView(cameraView.SelectedCamera.DeviceId, token); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -180,22 +166,17 @@ protected virtual partial void PlatformStopCameraPreview() | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| protected async Task PlatformUpdateResolution(Size resolution, CancellationToken token) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| if (!IsInitialized || mediaCapture is null) | ||||||||||||||||||||||||||
| if (!IsInitialized || mediaCapture is null || cameraView.SelectedCamera is null) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (cameraView.SelectedCamera is null) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| await cameraProvider.RefreshAvailableCameras(token); | ||||||||||||||||||||||||||
| cameraView.SelectedCamera = cameraProvider.AvailableCameras?.FirstOrDefault() ?? throw new CameraException("No camera available on device"); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| var filteredPropertiesList = cameraView.SelectedCamera.ImageEncodingProperties.Where(p => p.Width <= resolution.Width && p.Height <= resolution.Height).ToList(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| filteredPropertiesList = filteredPropertiesList.Count is not 0 | ||||||||||||||||||||||||||
| ? filteredPropertiesList | ||||||||||||||||||||||||||
| : [.. cameraView.SelectedCamera.ImageEncodingProperties.OrderByDescending(p => p.Width * p.Height)]; | ||||||||||||||||||||||||||
| if (filteredPropertiesList.Count is 0) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| filteredPropertiesList = [.. cameraView.SelectedCamera.ImageEncodingProperties.OrderByDescending(p => p.Width * p.Height)]; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (filteredPropertiesList.Count is not 0) | ||||||||||||||||||||||||||
|
Comment on lines
+176
to
181
|
||||||||||||||||||||||||||
| if (filteredPropertiesList.Count is 0) | |
| { | |
| filteredPropertiesList = [.. cameraView.SelectedCamera.ImageEncodingProperties.OrderByDescending(p => p.Width * p.Height)]; | |
| } | |
| if (filteredPropertiesList.Count is not 0) | |
| if (filteredPropertiesList.Count == 0) | |
| { | |
| filteredPropertiesList = [.. cameraView.SelectedCamera.ImageEncodingProperties.OrderByDescending(p => p.Width * p.Height)]; | |
| } | |
| if (filteredPropertiesList.Count != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This line combines null-conditional assignment, null-conditional access, null-coalescing, and exception throwing in a single statement, making it difficult to read and debug. Consider breaking this into multiple lines for better clarity.