Skip to content

Commit

Permalink
fix: Set up depth stream properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Dec 13, 2024
1 parent 7d2b43b commit 66d0a62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package/ios/Core/CameraSession+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ extension CameraSession {
let depthOutput = AVCaptureDepthDataOutput()
depthOutput.alwaysDiscardsLateDepthData = true
depthOutput.isFilteringEnabled = false
// 3.2. Set up a synchronizer between video and depth data
// 3.2. Add depth output to session
captureSession.addOutput(depthOutput)
// 3.3. Set up a synchronizer between video and depth data
outputSynchronizer = AVCaptureDataOutputSynchronizer(dataOutputs: [depthOutput, videoOutput])
outputSynchronizer!.setDelegate(self, queue: CameraQueues.videoQueue)
// 3.3. Add depth output to session
captureSession.addOutput(depthOutput)
self.depthOutput = depthOutput
} else {
// Video is the only output - use it's own delegate
Expand Down
10 changes: 10 additions & 0 deletions package/src/devices/getCameraFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export interface FormatFilter {
* you might want to choose a different auto-focus system.
*/
autoFocusSystem?: AutoFocusSystem
/**
* Specifies whether to prefer formats that support depth data capture.
*/
depth?: boolean
}

type FilterWithPriority<T> = {
Expand Down Expand Up @@ -236,6 +240,12 @@ export function getCameraFormat(device: CameraDevice, filters: FormatFilter[]):
if (format.autoFocusSystem === filter.autoFocusSystem.target) rightPoints += filter.autoFocusSystem.priority
}

// Find depth data
if (filter.depth != null) {
if (bestFormat.supportsDepthCapture) leftPoints += filter.depth.priority
if (format.supportsDepthCapture) rightPoints += filter.depth.priority
}

if (rightPoints > leftPoints) bestFormat = format
}

Expand Down

0 comments on commit 66d0a62

Please sign in to comment.