Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,43 @@ if (is_ios || is_mac) {
"../rtc_base/system:gcd_helpers",
]
}

rtc_library("desktopcapture_objc") {
visibility = [ "*" ]
sources = [
"objc/components/capturer/RTCDesktopCapturer+Prvate.h",
"objc/components/capturer/RTCDesktopCapturer.h",
"objc/components/capturer/RTCDesktopCapturer.mm",
"objc/components/capturer/RTCDesktopSource+Prvate.h",
"objc/components/capturer/RTCDesktopSource.h",
"objc/components/capturer/RTCDesktopSource.mm",
"objc/components/capturer/RTCDesktopMediaList+Prvate.h",
"objc/components/capturer/RTCDesktopMediaList.h",
"objc/components/capturer/RTCDesktopMediaList.mm",
"objc/native/src/objc_desktop_capture.h",
"objc/native/src/objc_desktop_capture.mm",
"objc/native/src/objc_desktop_media_list.h",
"objc/native/src/objc_desktop_media_list.mm",
]
frameworks = [
"AppKit.framework",
]

configs += [ "..:common_objc" ]

public_configs = [ ":common_config_objc" ]

deps = [
":base_objc",
":helpers_objc",
":videoframebuffer_objc",
"../rtc_base/system:gcd_helpers",
"../modules/desktop_capture",
]
if(is_mac) {
deps += [ "//third_party:jpeg", ]
}
}

rtc_library("videocodec_objc") {
visibility = [ "*" ]
Expand Down Expand Up @@ -1455,6 +1492,9 @@ if (is_ios || is_mac) {
"objc/base/RTCYUVPlanarBuffer.h",
"objc/components/capturer/RTCCameraVideoCapturer.h",
"objc/components/capturer/RTCFileVideoCapturer.h",
"objc/components/capturer/RTCDesktopCapturer.h",
"objc/components/capturer/RTCDesktopSource.h",
"objc/components/capturer/RTCDesktopMediaList.h",
"objc/components/renderer/metal/RTCMTLNSVideoView.h",
"objc/components/renderer/opengl/RTCNSGLVideoView.h",
"objc/components/renderer/opengl/RTCVideoViewShading.h",
Expand Down Expand Up @@ -1488,6 +1528,7 @@ if (is_ios || is_mac) {
":opengl_ui_objc",
":peerconnectionfactory_base_objc",
":videocapture_objc",
":desktopcapture_objc",
":videocodec_objc",
":videotoolbox_objc",
"../rtc_base:rtc_base_approved",
Expand Down
29 changes: 29 additions & 0 deletions sdk/objc/components/capturer/RTCDesktopCapturer+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2022 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.
*/

#import "RTCDesktopCapturer.h"

#include "sdk/objc/native/src/objc_desktop_capture.h"

NS_ASSUME_NONNULL_BEGIN

@interface RTCDesktopCapturer ()

@property(nonatomic, readonly)std::shared_ptr<webrtc::ObjCDesktopCapturer> nativeCapturer;

@end

NS_ASSUME_NONNULL_END
54 changes: 54 additions & 0 deletions sdk/objc/components/capturer/RTCDesktopCapturer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2022 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.
*/

#import <AVFoundation/AVFoundation.h>
#import <Foundation/Foundation.h>

#import "RTCMacros.h"
#import "RTCVideoCapturer.h"
#import "RTCDesktopSource.h"

NS_ASSUME_NONNULL_BEGIN

RTC_OBJC_EXPORT
@protocol RTC_OBJC_TYPE
(DesktopCapturerDelegate)<NSObject>
- (void)didCaptureVideoFrame:(RTC_OBJC_TYPE(RTCVideoFrame) *) frame;
@end

RTC_OBJC_EXPORT
// Screen capture that implements RTCVideoCapturer. Delivers frames to a
// RTCVideoCapturerDelegate (usually RTCVideoSource).
@interface RTC_OBJC_TYPE (RTCDesktopCapturer) : RTC_OBJC_TYPE(RTCVideoCapturer)

@property(nonatomic, readonly) RTCDesktopSource *source;

- (instancetype)initWithSource:(RTCDesktopSource*)source delegate:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)delegate;

- (instancetype)initWithDefaultScreen:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)delegate;

// Starts the capture session asynchronously.
- (void)startCapture:(NSInteger)fps;

// Stops the capture session asynchronously.
- (void)stopCapture;

- (void)didCaptureVideoFrame
: (RTC_OBJC_TYPE(RTCVideoFrame) *)frame;

@end

NS_ASSUME_NONNULL_END
73 changes: 73 additions & 0 deletions sdk/objc/components/capturer/RTCDesktopCapturer.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2022 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.
*/

#import <Foundation/Foundation.h>

#import "base/RTCLogging.h"
#import "base/RTCVideoFrameBuffer.h"

#import "components/video_frame_buffer/RTCCVPixelBuffer.h"

#import "RTCDesktopCapturer.h"
#import "RTCDesktopCapturer+Private.h"
#import "RTCDesktopSource+Private.h"

@implementation RTC_OBJC_TYPE (RTCDesktopCapturer) {
}

@synthesize nativeCapturer = _nativeCapturer;
@synthesize source = _source;

- (instancetype)initWithSource:(RTCDesktopSource*)source delegate:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)delegate {
if (self = [super initWithDelegate:delegate]) {
webrtc::ObjCDesktopCapturer::DesktopType captureType = webrtc::ObjCDesktopCapturer::kScreen;
if(source.sourceType == RTCDesktopSourceTypeWindow) {
captureType = webrtc::ObjCDesktopCapturer::kWindow;
}
_nativeCapturer = std::make_shared<webrtc::ObjCDesktopCapturer>(captureType, source.nativeMediaSource->id(), self);
_source = source;
}
return self;
}

- (instancetype)initWithDefaultScreen:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)delegate {
if (self = [super initWithDelegate:delegate]) {
_nativeCapturer = std::make_unique<webrtc::ObjCDesktopCapturer>(webrtc::ObjCDesktopCapturer::kScreen, -1, self);
_source = nil;
}
return self;
}


-(void)dealloc {
_nativeCapturer->Stop();
_nativeCapturer = nullptr;
}

- (void)startCapture:(NSInteger)fps {
_nativeCapturer->Start();
}

- (void)didCaptureVideoFrame
: (RTC_OBJC_TYPE(RTCVideoFrame) *)frame {
[self.delegate capturer:self didCaptureVideoFrame:frame];
}

- (void)stopCapture {
_nativeCapturer->Stop();
}

@end
41 changes: 41 additions & 0 deletions sdk/objc/components/capturer/RTCDesktopMediaList+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2022 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.
*/

#import "RTCDesktopMediaList.h"

namespace webrtc {
class ObjCDesktopMediaList;
}

NS_ASSUME_NONNULL_BEGIN

@interface RTCDesktopMediaList ()

@property(nonatomic, readonly)std::shared_ptr<webrtc::ObjCDesktopMediaList> nativeMediaList;

-(void)mediaSourceAdded:(int)index;

-(void)mediaSourceRemoved:(int)index;

-(void)mediaSourceMoved:(int) oldIndex newIndex:(int) newIndex;

-(void)mediaSourceNameChanged:(int)index;

-(void)mediaSourceThumbnailChanged:(int)index;

@end

NS_ASSUME_NONNULL_END
47 changes: 47 additions & 0 deletions sdk/objc/components/capturer/RTCDesktopMediaList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2022 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.
*/

#import <AVFoundation/AVFoundation.h>
#import <Foundation/Foundation.h>

#import "RTCMacros.h"
#import "RTCDesktopSource.h"

NS_ASSUME_NONNULL_BEGIN

RTC_OBJC_EXPORT
@protocol RTC_OBJC_TYPE(RTCDesktopMediaListDelegate)<NSObject>
-(void)mediaSourceAdded:(int)index fromSource:(RTCDesktopSource *) source;
-(void)mediaSourceRemoved:(int)index fromSource:(RTCDesktopSource *) source;
-(void)mediaSourceMoved:(int) oldIndex newIndex:(int) newIndex fromSource:(RTCDesktopSource *) source;
-(void)mediaSourceNameChanged:(int)index fromSource:(RTCDesktopSource *) source;
-(void)mediaSourceThumbnailChanged:(int)index fromSource:(RTCDesktopSource *) source;
@end

RTC_OBJC_EXPORT
@interface RTC_OBJC_TYPE (RTCDesktopMediaList) : NSObject

-(instancetype)initWithDelegate:(__weak id<RTC_OBJC_TYPE(RTCDesktopMediaListDelegate)>)delegate type:(RTCDesktopSourceType)type;

@property(nonatomic, readonly) RTCDesktopSourceType sourceType;

- (int32_t)UpdateSourceList;

- (NSArray<RTCDesktopSource *>*) getSources;

@end

NS_ASSUME_NONNULL_END
Loading