camera-streaming

작성자: facebook

스트리밍, 비디오 프레임, 사진 캡처, 해상도/프레임 속도 구성

npx skills add https://github.com/facebook/meta-wearables-dat-ios --skill camera-streaming

Camera Streaming (iOS)

Guide for implementing camera streaming and photo capture with the DAT SDK.

Key concepts

  • Stream: Main interface for camera streaming
  • VideoFrame: Individual video frames — call .makeUIImage() to render
  • StreamConfiguration: Configure resolution, frame rate, and codec
  • PhotoData: Still image captured from glasses

Creating a DeviceSession

import MWDATCamera
import MWDATCore

let wearables = Wearables.shared
let deviceSelector = AutoDeviceSelector(wearables: wearables)
// Or for a specific device: SpecificDeviceSelector(device: deviceId)
let deviceSession = try wearables.createSession(deviceSelector: deviceSelector)
try deviceSession.start()

// Wait for the device session to reach the started state
for await state in deviceSession.stateStream() {
    if state == .started { break }
}

Adding a Camera

Once the DeviceSession is started, add a Camera capability and get its stream:

let config = StreamConfiguration(
    videoCodec: .raw,
    resolution: .medium,  // 504x896
    frameRate: 24
)

guard let camera = try deviceSession.addCamera(config: config) else {
    // DeviceSession must be in the started state before adding a camera
    return
}
let stream = camera.stream

Resolution options

ResolutionSize
.high720 x 1280
.medium504 x 896
.low360 x 640

Frame rate options

Valid values: 2, 7, 15, 24, 30 FPS.

Lower resolution and frame rate yield higher visual quality due to less Bluetooth compression.

Observing stream state

StreamState transitions: stoppingstoppedwaitingForDevicestartingstreamingpaused

let stateToken = stream.statePublisher.listen { state in
    Task { @MainActor in
        switch state {
        case .streaming:
            // Stream is active, frames are flowing
        case .waitingForDevice:
            // Waiting for glasses to connect
        case .stopped:
            // Stream ended — release resources
        case .paused:
            // Temporarily suspended — keep connection, wait
        default:
            break
        }
    }
}

Receiving video frames

let frameToken = stream.videoFramePublisher.listen { frame in
    guard let image = frame.makeUIImage() else { return }
    Task { @MainActor in
        self.previewImage = image
    }
}

Starting and stopping

// Start the stream capability
stream.start()

// Stop the camera (teardown cascades to the stream)
camera.stop()

// Stop the parent device session when you're done with all capabilities
deviceSession.stop()

Photo capture

Capture a still photo while streaming:

// Listen for photo data
let photoToken = stream.photoDataPublisher.listen { photoData in
    let imageData = photoData.data
    // Convert to UIImage or save
}

// Trigger capture
stream.capturePhoto(format: .jpeg)

Bandwidth and quality

Resolution and frame rate are constrained by Bluetooth Classic bandwidth. The SDK automatically reduces quality when bandwidth is limited:

  1. First lowers resolution (e.g., High → Medium)
  2. Then reduces frame rate (e.g., 30 → 24), never below 15 FPS

Request lower settings for higher visual quality per frame.

Links

facebook의 다른 스킬

binary-size-analysis
facebook
git 커밋 범위에 걸쳐 hermesvm 공유 라이브러리의 커밋별 바이너리 크기 변화를 분석합니다. 커밋별 크기와 주요 증가 및 감소 요약 테이블이 포함된 마크다운 보고서를 생성합니다.
official
modify-jsi-features
facebook
JavaScript Interface (JSI) 레이어에 새로운 JSI 기능을 추가하기 위한 가이드입니다. 사용자가 새로운 메서드나 기능을 추가, 생성 또는 구현하도록 요청할 때 사용하세요.
official
non-interactive-git-rebase
facebook
최상위 커밋이 아닌 git 커밋을 재정렬, 분할, 삭제 또는 수정해야 하며 대화형 편집기 접근이 불가능할 때 사용합니다. 프로그래밍 방식의 리베이스를 다룹니다…
official
click-target
facebook
XR에서 대상 객체를 찾아 클릭합니다. UI 상호작용 테스트, 버튼 클릭, 또는 상호작용 가능한 요소가 올바르게 작동하는지 확인할 때 사용하세요.
official
iwsdk-planner
facebook
IWSDK 프로젝트 계획 및 모범 사례 가이드. 새로운 IWSDK 기능을 계획하거나, 시스템/컴포넌트를 설계하거나, IWSDK 코드 아키텍처를 검토할 때, 또는...
official
iwsdk-ui-panel
facebook
IWSDK UI 패널을 효율적으로 개발하고 반복 개선합니다. PanelUI 구성 요소 작업, UI 레이아웃 디버깅, 또는 IWSDK 애플리케이션의 UI 디자인 개선 시 사용하세요.
official
test-all
facebook
병렬 테스트 오케스트레이터. Task 하위 에이전트와 iwsdk CLI를 통해 9개의 모든 테스트 스위트를 동시에 실행합니다. 빌드, 예제 설정, 개발 서버, 에이전트 실행 등을 처리합니다.
official
test-audio
facebook
iwsdk CLI를 사용하여 오디오 예제에 대해 오디오 시스템(AudioSource 로딩, 재생 상태, 정지, 공간 오디오)을 테스트합니다.
official