Skip to content

Commit

Permalink
visionOS Persona camera support (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie authored Aug 12, 2024
1 parent eaf1e24 commit ef5e0fe
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 6 deletions.
2 changes: 1 addition & 1 deletion LiveKitClient.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |spec|

spec.source_files = "Sources/**/*"

spec.dependency("LiveKitWebRTC", "= 125.6422.03")
spec.dependency("LiveKitWebRTC", "= 125.6422.05")
spec.dependency("SwiftProtobuf")
spec.dependency("Logging")

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
],
dependencies: [
// LK-Prefixed Dynamic WebRTC XCFramework
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "125.6422.04"),
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "125.6422.05"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.26.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
// Only used for DocC generation
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let package = Package(
],
dependencies: [
// LK-Prefixed Dynamic WebRTC XCFramework
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "125.6422.04"),
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "125.6422.05"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.26.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
// Only used for DocC generation
Expand Down
7 changes: 6 additions & 1 deletion Sources/LiveKit/Extensions/AVCaptureDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ import AVFoundation

public extension AVCaptureDevice {
/// Helper extension to return the acual direction the camera is facing.
/// In macOS, the Facetime camera's position is .unspecified but this property will return .front for such cases.
var facingPosition: AVCaptureDevice.Position {
#if os(macOS)
/// In macOS, the Facetime camera's position is .unspecified but this property will return .front for such cases.
if deviceType == .builtInWideAngleCamera, position == .unspecified {
return .front
}
#elseif os(visionOS)
/// In visionOS, the Persona camera's position is .unspecified but this property will return .front for such cases.
if position == .unspecified {
return .front
}
#endif

return position
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/TimeInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public extension TimeInterval {
static let defaultPublisherDataChannelOpen: Self = 7
static let resolveSid: Self = 7 + 5 // Join response + 5
static let defaultPublish: Self = 10
static let defaultCaptureStart: Self = 5
static let defaultCaptureStart: Self = 10
}

extension TimeInterval {
Expand Down
4 changes: 4 additions & 0 deletions Sources/LiveKit/Support/DeviceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class DeviceManager: Loggable {
self.devicesCompleter.resume(returning: devices)
}
}
#elseif os(visionOS)
// For visionOS, there is no DiscoverySession so return the Persona camera if available.
let devices: [AVCaptureDevice] = [.systemPreferredCamera].compactMap { $0 }
devicesCompleter.resume(returning: devices)
#endif
}
}
31 changes: 31 additions & 0 deletions Tests/LiveKitTests/DeviceManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@testable import LiveKit
import XCTest

class DeviceManagerTests: XCTestCase {
func testListDevices() async throws {
let devices = try await DeviceManager.shared.devices()
print("Devices: \(devices.map { "(facingPosition: \(String(describing: $0.facingPosition)))" }.joined(separator: ", "))")
XCTAssert(devices.count > 0, "No capture devices found.")

// visionOS will return 0 formats.
guard let firstDevice = devices.first else { return }
let formats = firstDevice.formats
XCTAssert(formats.count > 0, "No formats found for device.")
}
}
14 changes: 13 additions & 1 deletion Tests/LiveKitTests/Support/Tracks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@ extension XCTestCase {
let asset = AVAsset(url: tempLocalUrl)
let assetReader = try AVAssetReader(asset: asset)

guard let track = asset.tracks(withMediaType: .video).first else {
let tracks = try await {
#if os(visionOS)
return try await asset.loadTracks(withMediaType: .video)
#else
if #available(iOS 15.0, macOS 12.0, *) {
return try await asset.loadTracks(withMediaType: .video)
} else {
return asset.tracks(withMediaType: .video)
}
#endif
}()

guard let track = tracks.first else {
XCTFail("No video track found in sample video file")
fatalError()
}
Expand Down

0 comments on commit ef5e0fe

Please sign in to comment.