-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mac] feat: Support screen capture for macOS. (#24) (#36) fix: Get thumbnails asynchronously. (#37) fix: Use CVPixelBuffer to build DesktopCapture Frame, fix the crash caused by non-CVPixelBuffer frame in RTCVideoEncoderH264 that cannot be cropped. (#63) Fix the crash when setting the fps of the virtual camera. (#62)
- Loading branch information
1 parent
0228e1d
commit 8e832d1
Showing
17 changed files
with
1,233 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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 | ||
|
||
RTC_OBJC_EXPORT | ||
@protocol RTC_OBJC_TYPE | ||
(DesktopCapturerDelegate)<NSObject> | ||
-(void)didCaptureVideoFrame:(RTC_OBJC_TYPE(RTCVideoFrame) *) frame; | ||
-(void)didSourceCaptureStart; | ||
-(void)didSourceCapturePaused; | ||
-(void)didSourceCaptureStop; | ||
-(void)didSourceCaptureError; | ||
@end | ||
|
||
@interface RTCDesktopCapturer () | ||
|
||
@property(nonatomic, readonly)std::shared_ptr<webrtc::ObjCDesktopCapturer> nativeCapturer; | ||
|
||
- (void)didCaptureVideoFrame:(RTC_OBJC_TYPE(RTCVideoFrame) *)frame; | ||
|
||
-(void)didSourceCaptureStart; | ||
|
||
-(void)didSourceCapturePaused; | ||
|
||
-(void)didSourceCaptureStop; | ||
|
||
-(void)didSourceCaptureError; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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 | ||
|
||
@class RTCDesktopCapturer; | ||
|
||
RTC_OBJC_EXPORT | ||
@protocol RTC_OBJC_TYPE | ||
(RTCDesktopCapturerDelegate)<NSObject> | ||
-(void)didSourceCaptureStart:(RTCDesktopCapturer *) capturer; | ||
|
||
-(void)didSourceCapturePaused:(RTCDesktopCapturer *) capturer; | ||
|
||
-(void)didSourceCaptureStop:(RTCDesktopCapturer *) capturer; | ||
|
||
-(void)didSourceCaptureError:(RTCDesktopCapturer *) capturer; | ||
@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(RTCDesktopCapturerDelegate)>)delegate captureDelegate:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)captureDelegate; | ||
|
||
- (instancetype)initWithDefaultScreen:(__weak id<RTC_OBJC_TYPE(RTCDesktopCapturerDelegate)>)delegate captureDelegate:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)captureDelegate; | ||
|
||
- (void)startCapture; | ||
|
||
- (void)startCaptureWithFPS:(NSInteger)fps; | ||
|
||
- (void)stopCapture; | ||
|
||
- (void)stopCaptureWithCompletionHandler:(nullable void (^)(void))completionHandler; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* 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) { | ||
__weak id<RTC_OBJC_TYPE(RTCDesktopCapturerDelegate)> _delegate; | ||
} | ||
|
||
@synthesize nativeCapturer = _nativeCapturer; | ||
@synthesize source = _source; | ||
|
||
- (instancetype)initWithSource:(RTCDesktopSource*)source delegate:(__weak id<RTC_OBJC_TYPE(RTCDesktopCapturerDelegate)>)delegate captureDelegate:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)captureDelegate { | ||
if (self = [super initWithDelegate:captureDelegate]) { | ||
webrtc::DesktopType captureType = webrtc::kScreen; | ||
if(source.sourceType == RTCDesktopSourceTypeWindow) { | ||
captureType = webrtc::kWindow; | ||
} | ||
_nativeCapturer = std::make_shared<webrtc::ObjCDesktopCapturer>(captureType, source.nativeMediaSource->id(), self); | ||
_source = source; | ||
_delegate = delegate; | ||
} | ||
return self; | ||
} | ||
|
||
- (instancetype)initWithDefaultScreen:(__weak id<RTC_OBJC_TYPE(RTCDesktopCapturerDelegate)>)delegate captureDelegate:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelegate)>)captureDelegate { | ||
if (self = [super initWithDelegate:captureDelegate]) { | ||
_nativeCapturer = std::make_unique<webrtc::ObjCDesktopCapturer>(webrtc::kScreen, -1, self); | ||
_source = nil; | ||
_delegate = delegate; | ||
} | ||
return self; | ||
} | ||
|
||
|
||
-(void)dealloc { | ||
_nativeCapturer->Stop(); | ||
_nativeCapturer = nullptr; | ||
} | ||
|
||
- (void)startCapture { | ||
[self didSourceCaptureStart]; | ||
_nativeCapturer->Start(30); | ||
} | ||
|
||
- (void)startCaptureWithFPS:(NSInteger)fps { | ||
_nativeCapturer->Start(fps); | ||
} | ||
|
||
- (void)didCaptureVideoFrame | ||
: (RTC_OBJC_TYPE(RTCVideoFrame) *)frame { | ||
[self.delegate capturer:self didCaptureVideoFrame:frame]; | ||
} | ||
|
||
- (void)stopCapture { | ||
_nativeCapturer->Stop(); | ||
} | ||
|
||
- (void)stopCaptureWithCompletionHandler:(nullable void (^)(void))completionHandler { | ||
[self stopCapture]; | ||
if(completionHandler != nil) { | ||
completionHandler(); | ||
} | ||
} | ||
|
||
-(void)didSourceCaptureStart { | ||
[_delegate didSourceCaptureStart:self]; | ||
} | ||
|
||
-(void)didSourceCapturePaused { | ||
[_delegate didSourceCapturePaused:self]; | ||
} | ||
|
||
-(void)didSourceCaptureStop { | ||
[_delegate didSourceCaptureStop:self]; | ||
} | ||
|
||
-(void)didSourceCaptureError { | ||
[_delegate didSourceCaptureError:self]; | ||
} | ||
|
||
@end |
40 changes: 40 additions & 0 deletions
40
sdk/objc/components/capturer/RTCDesktopMediaList+Private.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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; | ||
class MediaSource; | ||
} | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RTCDesktopMediaList () | ||
|
||
@property(nonatomic, readonly)std::shared_ptr<webrtc::ObjCDesktopMediaList> nativeMediaList; | ||
|
||
-(void)mediaSourceAdded:(webrtc::MediaSource *) source; | ||
|
||
-(void)mediaSourceRemoved:(webrtc::MediaSource *) source; | ||
|
||
-(void)mediaSourceNameChanged:(webrtc::MediaSource *) source; | ||
|
||
-(void)mediaSourceThumbnailChanged:(webrtc::MediaSource *) source; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Oops, something went wrong.