Skip to content

Commit 6bb47f5

Browse files
Support for Vision Pro (#131)
TODO: - [x] fix compile for RTCCameraVideoCapturer - [ ] fix RTCMTLRenderer ? --------- Co-authored-by: Hiroshi Horie <[email protected]>
1 parent 5778782 commit 6bb47f5

File tree

6 files changed

+62
-29
lines changed

6 files changed

+62
-29
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ deps = {
5454
'src/base':
5555
'https://chromium.googlesource.com/chromium/src/base@738cf0c976fd3d07c5f1853f050594c5295300d8',
5656
'src/build':
57-
'https://chromium.googlesource.com/chromium/src/build@cab574b350bc82dc3e7a1f634fedeb3079bf9e9d',
57+
'https://github.com/webrtc-sdk/build@1367989663b6cd7873ec606d0ed1f7878dd3ea7d',
5858
'src/buildtools':
5959
'https://chromium.googlesource.com/chromium/src/buildtools@5eb927f0a922dfacf10cfa84ee76f39dcf2a7311',
6060
# Gradle 6.6.1. Used for testing Android Studio project generation for WebRTC.

sdk/BUILD.gn

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,15 @@ if (is_ios || is_mac) {
172172

173173
if (is_ios) {
174174
sources += [
175-
"objc/helpers/RTCCameraPreviewView.h",
176-
"objc/helpers/RTCCameraPreviewView.m",
177175
"objc/helpers/UIDevice+RTCDevice.h",
178176
"objc/helpers/UIDevice+RTCDevice.mm",
179177
]
178+
if (target_environment != "xrdevice" && target_environment != "xrsimulator") {
179+
sources += [
180+
"objc/helpers/RTCCameraPreviewView.h",
181+
"objc/helpers/RTCCameraPreviewView.m",
182+
]
183+
}
180184
frameworks += [ "UIKit.framework" ]
181185
}
182186
}
@@ -274,11 +278,14 @@ if (is_ios || is_mac) {
274278
deps = [
275279
":base_objc",
276280
":helpers_objc",
277-
":metal_objc",
278281
":opengl_objc",
279282
":videocapture_objc",
280283
":videoframebuffer_objc",
281284
]
285+
286+
if (target_environment != "xrdevice" && target_environment != "xrsimulator") {
287+
deps += [ ":metal_objc" ]
288+
}
282289
}
283290

284291
rtc_library("audio_device") {
@@ -625,7 +632,7 @@ if (is_ios || is_mac) {
625632
"Metal.framework",
626633
"MetalKit.framework",
627634
]
628-
if (is_ios || is_mac) {
635+
if ((is_ios || is_mac) && !(target_environment == "xrsimulator" || target_environment == "xrdevice")) {
629636
sources += [
630637
"objc/components/renderer/metal/RTCMTLVideoView.h",
631638
"objc/components/renderer/metal/RTCMTLVideoView.m",
@@ -667,9 +674,13 @@ if (is_ios || is_mac) {
667674
sources = [
668675
"objc/components/capturer/RTCCameraVideoCapturer.h",
669676
"objc/components/capturer/RTCCameraVideoCapturer.m",
670-
"objc/components/capturer/RTCFileVideoCapturer.h",
671-
"objc/components/capturer/RTCFileVideoCapturer.m",
672677
]
678+
if (target_environment != "xrdevice" && target_environment != "xrsimulator") {
679+
sources += [
680+
"objc/components/capturer/RTCFileVideoCapturer.h",
681+
"objc/components/capturer/RTCFileVideoCapturer.m",
682+
]
683+
}
673684
frameworks = [
674685
"AVFoundation.framework",
675686
"CoreVideo.framework",
@@ -687,7 +698,7 @@ if (is_ios || is_mac) {
687698
"../rtc_base/system:gcd_helpers",
688699
]
689700
}
690-
701+
691702
rtc_library("desktopcapture_objc") {
692703
visibility = [ "*" ]
693704
sources = [
@@ -705,7 +716,7 @@ if (is_ios || is_mac) {
705716
"objc/native/src/objc_desktop_media_list.h",
706717
"objc/native/src/objc_desktop_media_list.mm",
707718
]
708-
frameworks = [
719+
frameworks = [
709720
"AppKit.framework",
710721
]
711722

@@ -720,7 +731,7 @@ if (is_ios || is_mac) {
720731
"../rtc_base/system:gcd_helpers",
721732
"../modules/desktop_capture",
722733
]
723-
if(is_mac) {
734+
if (is_mac) {
724735
deps += [ "//third_party:jpeg", ]
725736
}
726737
}
@@ -879,7 +890,7 @@ if (is_ios || is_mac) {
879890
"../media:rtc_simulcast_encoder_adapter",
880891
]
881892
}
882-
893+
883894
rtc_library("mediaconstraints_objc") {
884895
configs += [ "..:no_global_constructors" ]
885896
sources = [
@@ -1242,7 +1253,6 @@ if (is_ios || is_mac) {
12421253
":framework_objc",
12431254
":helpers_objc",
12441255
":mediaconstraints_objc",
1245-
":metal_objc",
12461256
":native_api",
12471257
":native_api_audio_device_module",
12481258
":native_video",
@@ -1275,7 +1285,11 @@ if (is_ios || is_mac) {
12751285
"../system_wrappers",
12761286
"//third_party/libyuv",
12771287
]
1278-
1288+
if (target_environment != "xrdevice" && target_environment != "xrsimulator") {
1289+
deps += [
1290+
":metal_objc",
1291+
]
1292+
}
12791293
if (rtc_ios_use_opengl_rendering) {
12801294
deps += [ ":opengl_objc" ]
12811295
}
@@ -1375,7 +1389,6 @@ if (is_ios || is_mac) {
13751389
"objc/components/capturer/RTCCameraVideoCapturer.h",
13761390
"objc/components/capturer/RTCFileVideoCapturer.h",
13771391
"objc/components/network/RTCNetworkMonitor.h",
1378-
"objc/components/renderer/metal/RTCMTLVideoView.h",
13791392
"objc/components/renderer/opengl/RTCEAGLVideoView.h",
13801393
"objc/components/renderer/opengl/RTCVideoViewShading.h",
13811394
"objc/components/video_codec/RTCCodecSpecificInfoH264.h",
@@ -1387,7 +1400,6 @@ if (is_ios || is_mac) {
13871400
"objc/components/video_codec/RTCVideoEncoderFactoryH264.h",
13881401
"objc/components/video_codec/RTCVideoEncoderH264.h",
13891402
"objc/components/video_frame_buffer/RTCCVPixelBuffer.h",
1390-
"objc/helpers/RTCCameraPreviewView.h",
13911403
"objc/helpers/RTCDispatcher.h",
13921404
"objc/helpers/RTCYUVHelper.h",
13931405
"objc/helpers/UIDevice+RTCDevice.h",
@@ -1452,6 +1464,13 @@ if (is_ios || is_mac) {
14521464
"objc/components/audio/RTCAudioCustomProcessingDelegate.h",
14531465
]
14541466

1467+
if (target_environment != "xrdevice" && target_environment != "xrsimulator") {
1468+
common_objc_headers += [
1469+
"objc/helpers/RTCCameraPreviewView.h",
1470+
"objc/components/renderer/metal/RTCMTLVideoView.h",
1471+
]
1472+
}
1473+
14551474
if (!build_with_chromium) {
14561475
common_objc_headers += [
14571476
"objc/api/logging/RTCCallbackLogger.h",
@@ -1472,7 +1491,6 @@ if (is_ios || is_mac) {
14721491
":audio_objc",
14731492
":base_objc",
14741493
":default_codec_factory_objc",
1475-
":metal_objc",
14761494
":native_api",
14771495
":native_video",
14781496
":peerconnectionfactory_base_objc",
@@ -1481,6 +1499,9 @@ if (is_ios || is_mac) {
14811499
":videotoolbox_objc",
14821500
":darwin_privacy_info",
14831501
]
1502+
if (target_environment != "xrdevice" && target_environment != "xrsimulator") {
1503+
deps += [ ":metal_objc" ]
1504+
}
14841505
if (!build_with_chromium) {
14851506
deps += [
14861507
":callback_logger_objc",
@@ -1626,7 +1647,6 @@ if (is_ios || is_mac) {
16261647
deps = [
16271648
":base_objc",
16281649
":default_codec_factory_objc",
1629-
":metal_objc",
16301650
":native_api",
16311651
":native_video",
16321652
":peerconnectionfactory_base_objc",
@@ -1636,6 +1656,9 @@ if (is_ios || is_mac) {
16361656
":videotoolbox_objc",
16371657
":darwin_privacy_info",
16381658
]
1659+
if (target_environment != "xrdevice" && target_environment != "xrsimulator") {
1660+
deps += [ ":metal_objc" ]
1661+
}
16391662
if (!build_with_chromium) {
16401663
deps += [
16411664
":callback_logger_objc",

sdk/objc/components/capturer/RTCCameraVideoCapturer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ NS_EXTENSION_UNAVAILABLE_IOS("Camera not available in app extensions.")
2727

2828
// Returns list of available capture devices that support video capture.
2929
+ (NSArray<AVCaptureDevice *> *)captureDevices;
30+
3031
// Returns list of formats that are supported by this class for this device.
3132
+ (NSArray<AVCaptureDeviceFormat *> *)supportedFormatsForDevice:(AVCaptureDevice *)device;
3233

34+
#if !TARGET_OS_VISION
3335
+ (CGFloat)defaultZoomFactorForDeviceType:(AVCaptureDeviceType)deviceType;
36+
#endif
3437

3538
- (instancetype)initWithDelegate:
3639
(nullable __weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)delegate;

sdk/objc/components/capturer/RTCCameraVideoCapturer.m

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ - (instancetype)initWithDelegate:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelega
7474
return nil;
7575
}
7676
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
77-
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST
77+
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST && !TARGET_OS_VISION
7878
_orientation = UIInterfaceOrientationPortrait;
7979
_rotation = RTCVideoRotation_90;
8080
[center addObserver:self
@@ -118,11 +118,16 @@ - (void)dealloc {
118118
}
119119

120120
+ (NSArray<AVCaptureDevice *> *)captureDevices {
121+
#if TARGET_OS_VISION
122+
// Simply return an empty array.
123+
return [NSArray array];
124+
#else
121125
AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession
122126
discoverySessionWithDeviceTypes:@[ AVCaptureDeviceTypeBuiltInWideAngleCamera ]
123127
mediaType:AVMediaTypeVideo
124128
position:AVCaptureDevicePositionUnspecified];
125129
return session.devices;
130+
#endif
126131
}
127132

128133
+ (NSArray<AVCaptureDeviceFormat *> *)supportedFormatsForDevice:(AVCaptureDevice *)device {
@@ -131,6 +136,7 @@ - (void)dealloc {
131136
return device.formats;
132137
}
133138

139+
#if !TARGET_OS_VISION
134140
+ (CGFloat)defaultZoomFactorForDeviceType:(AVCaptureDeviceType)deviceType {
135141
// AVCaptureDeviceTypeBuiltInTripleCamera, Virtual, switchOver: [2, 6], default: 2
136142
// AVCaptureDeviceTypeBuiltInDualCamera, Virtual, switchOver: [3], default: 1
@@ -150,6 +156,7 @@ + (CGFloat)defaultZoomFactorForDeviceType:(AVCaptureDeviceType)deviceType {
150156

151157
return 1.0;
152158
}
159+
#endif
153160

154161
- (FourCharCode)preferredOutputPixelFormat {
155162
return _preferredOutputPixelFormat;
@@ -175,7 +182,7 @@ - (void)startCaptureWithDevice:(AVCaptureDevice *)device
175182
block:^{
176183
RTCLogInfo("startCaptureWithDevice %@ @ %ld fps", format, (long)fps);
177184

178-
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST
185+
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST && !TARGET_OS_VISION
179186
dispatch_async(dispatch_get_main_queue(), ^{
180187
if (!self->_generatingOrientationNotifications) {
181188
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
@@ -224,7 +231,7 @@ - (void)stopCaptureWithCompletionHandler:(nullable void (^)(void))completionHand
224231
}
225232
[self.captureSession stopRunning];
226233

227-
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST
234+
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST && !TARGET_OS_VISION
228235
dispatch_async(dispatch_get_main_queue(), ^{
229236
if (self->_generatingOrientationNotifications) {
230237
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
@@ -241,7 +248,7 @@ - (void)stopCaptureWithCompletionHandler:(nullable void (^)(void))completionHand
241248

242249
#pragma mark iOS notifications
243250

244-
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST
251+
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST && !TARGET_OS_VISION
245252
- (void)deviceOrientationDidChange:(NSNotification *)notification {
246253
[self updateOrientation];
247254
}
@@ -264,7 +271,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput
264271
return;
265272
}
266273

267-
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST
274+
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST && !TARGET_OS_VISION
268275
// Default to portrait orientation on iPhone.
269276
BOOL usingFrontCamera = NO;
270277
// Check the image's EXIF for the camera the image came from as the image could have been
@@ -442,7 +449,7 @@ - (dispatch_queue_t)frameQueue {
442449
- (BOOL)setupCaptureSession:(AVCaptureSession *)captureSession {
443450
NSAssert(_captureSession == nil, @"Setup capture session called twice.");
444451
_captureSession = captureSession;
445-
#if defined(WEBRTC_IOS)
452+
#if defined(WEBRTC_IOS) && !TARGET_OS_VISION
446453
_captureSession.sessionPreset = AVCaptureSessionPresetInputPriority;
447454
_captureSession.usesApplicationAudioSession = NO;
448455
#endif
@@ -519,7 +526,7 @@ - (void)updateZoomFactor {
519526
NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeCaptureSession],
520527
@"updateZoomFactor must be called on the capture queue.");
521528

522-
#if TARGET_OS_IOS || TARGET_OS_TV
529+
#if (TARGET_OS_IOS || TARGET_OS_TV) && !TARGET_OS_VISION
523530
CGFloat videoZoomFactor = [[self class] defaultZoomFactorForDeviceType:_currentDevice.deviceType];
524531
[_currentDevice setVideoZoomFactor:videoZoomFactor];
525532
#endif
@@ -529,8 +536,8 @@ - (void)reconfigureCaptureSessionInput {
529536
NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeCaptureSession],
530537
@"reconfigureCaptureSessionInput must be called on the capture queue.");
531538
NSError *error = nil;
532-
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:_currentDevice
533-
error:&error];
539+
AVCaptureDeviceInput *input = [[AVCaptureDeviceInput alloc] initWithDevice:_currentDevice
540+
error:&error];
534541
if (!input) {
535542
RTCLogError(@"Failed to create front camera input: %@", error.localizedDescription);
536543
return;
@@ -547,7 +554,7 @@ - (void)reconfigureCaptureSessionInput {
547554
[_captureSession commitConfiguration];
548555
}
549556

550-
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST
557+
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST && !TARGET_OS_VISION
551558
- (void)updateOrientation {
552559
NSAssert([RTC_OBJC_TYPE(RTCDispatcher) isOnQueueForType:RTCDispatcherTypeMain],
553560
@"statusBarOrientation must be called on the main queue.");

sdk/objc/components/video_codec/RTCVideoDecoderH264.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ - (int)resetDecompressionSession {
206206
NSDictionary *attributes = @{
207207
#if defined(WEBRTC_IOS) && (TARGET_OS_MACCATALYST || TARGET_OS_SIMULATOR)
208208
(NSString *)kCVPixelBufferMetalCompatibilityKey : @(YES),
209-
#elif defined(WEBRTC_IOS)
209+
#elif defined(WEBRTC_IOS) && !defined(TARGET_OS_VISION)
210210
(NSString *)kCVPixelBufferOpenGLESCompatibilityKey : @(YES),
211211
#elif defined(WEBRTC_MAC) && !defined(WEBRTC_ARCH_ARM64)
212212
(NSString *)kCVPixelBufferOpenGLCompatibilityKey : @(YES),

sdk/objc/components/video_codec/RTCVideoEncoderH264.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ - (int)resetCompressionSessionWithPixelFormat:(OSType)framePixelFormat {
685685
NSDictionary *sourceAttributes = @{
686686
#if defined(WEBRTC_IOS) && (TARGET_OS_MACCATALYST || TARGET_OS_SIMULATOR)
687687
(NSString *)kCVPixelBufferMetalCompatibilityKey : @(YES),
688-
#elif defined(WEBRTC_IOS)
688+
#elif defined(WEBRTC_IOS) && !defined(TARGET_OS_VISION)
689689
(NSString *)kCVPixelBufferOpenGLESCompatibilityKey : @(YES),
690690
#elif defined(WEBRTC_MAC) && !defined(WEBRTC_ARCH_ARM64)
691691
(NSString *)kCVPixelBufferOpenGLCompatibilityKey : @(YES),

0 commit comments

Comments
 (0)