Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mac] feat: Support screen capture for macOS. #24

Merged
merged 23 commits into from
Aug 1, 2022

Conversation

cloudwebrtc
Copy link
Member

@cloudwebrtc cloudwebrtc commented May 8, 2022

Try adding screen sharing for macOS:
TODO: (1/5)

  • Screen capture
  • select screen
  • Window capture
  • Select window
  • Get thumbnail for preview

@cloudwebrtc cloudwebrtc changed the title feat: Add screen capture support for macOS. feat: Support screen capture for macOS. May 8, 2022
@cloudwebrtc cloudwebrtc changed the title feat: Support screen capture for macOS. [macOS] feat: Support screen capture for macOS. May 8, 2022
@cloudwebrtc cloudwebrtc changed the title [macOS] feat: Support screen capture for macOS. [Mac] feat: Support screen capture for macOS. May 8, 2022
@cloudwebrtc cloudwebrtc marked this pull request as ready for review June 10, 2022 14:19
@cloudwebrtc
Copy link
Member Author

cloudwebrtc commented Jun 13, 2022

The windows can now be enumerated.
image

But have some issues here, when I drag the captured window and change the size, the image will crack. There may be a bug in libwebrtc. @hiroshihorie @davidliu @davidzhao Have any ideas? xD
image
image

This problem has been bothering me for two days.

Copy link
Member

@hiroshihorie hiroshihorie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow great work. I'll think about the resize issue.

@cloudwebrtc
Copy link
Member Author

Here is some code showing how to call it, maybe it can help you to test on swift sdk
https://github.com/flutter-webrtc/flutter-webrtc/pull/940/files#diff-dff3e74bce71fb4d131c17ba1af18ac75e9b370124e392da2518866db2a9386c

@davidliu
Copy link
Contributor

Haven't digged into the code, but just from the looks of the image, it seems like the frame isn't updated with the correct dimensions. Since the video frame is a continguous array, if the width isn't updated, the pixels would spill into the next/previous row. That explains why there's a slant and the image is seemingly wrapping around. (I assume the slant gets worse as you expand/contract the window.)

@davidzhao
Copy link
Member

@hiroshihorie your MacOS version didn't have this issue IIRC. Perhaps there are some insights there?

@cloudwebrtc
Copy link
Member Author

okay, everything is working fine now, a story about the width not being divisible by 32.
image

@cloudwebrtc cloudwebrtc force-pushed the feat/support-screen-capture-for-mac branch from 2ac2d6e to 0d02085 Compare June 16, 2022 13:52
@hiroshihorie
Copy link
Member

wow nice find, needs to multiple of 32 ?

@cloudwebrtc
Copy link
Member Author

cloudwebrtc commented Jun 16, 2022

Yes, When the width can be divisible by 32, the picture is fine. Other widths must be added with some numbers, which can be divisible by 32, But at this time, you need to remove the extra width, a black edge xD, It may be related to the capture mechanism of CGWindowListCreateImage. For now, it works perfectly. I still need to do some testing in intel mac, to make sure it works 100%.

https://github.com/webrtc-sdk/webrtc/pull/24/files#diff-0cd0a6ae24c482adb040d158c9b2e162f20c03741100c9036083360d7d1be694R81

Copy link
Member

@davidzhao davidzhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work tracking this one down!

@cloudwebrtc cloudwebrtc force-pushed the feat/support-screen-capture-for-mac branch from cffc13f to 2baa397 Compare June 17, 2022 04:00
davidliu pushed a commit that referenced this pull request Jul 17, 2022
…efptr.

Updates all webrtc code, to have a small followup cl to just add the
"explicit" keyword. Patchset #24 passed all webrtc tests, with explicit.

Bug: webrtc:13464
Change-Id: I39863d3752f73209b531120f66916dc9177bf63a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/242363
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35718}
@cloudwebrtc
Copy link
Member Author

cloudwebrtc commented Jul 28, 2022

hey @vickyleu, Thanks for reporting the issue, and are there any steps to reproduce?
BTW, macOS version and cpu (m1 or intel) is useful info.

@cloudwebrtc cloudwebrtc merged commit 4315ec5 into m97_release Aug 1, 2022
@cloudwebrtc cloudwebrtc deleted the feat/support-screen-capture-for-mac branch August 1, 2022 02:26
cloudwebrtc added a commit that referenced this pull request Aug 3, 2022
* feat: Add screen capture support for macOS.

* chore: rename files.

* chore: update.

* chore: Implement DesktopSource, DesktopMediaList ojbc interface.

* chore: add license.

* fix: capture_state.

* update.

* update.

* Hide private delegate declaration.

* Re-generate thumbnail for all sources when call UpdateSourceList.

* fix: Fix window resize issue.

* update.

* update.

* fix for intel mac.

* cleanup.

* update.

* Add Window/Screen change listener.

* Add force reload for MediaListUpdate and capture cursor.

* fix: Fix the screen freeze caused by the desktop frame not setting the timestamp.

* update.

* fix issue for screen sharing.

* Fixed H264 profile-level-id limitation that could not encode desktop frames with resolutions higher than 720p.
cloudwebrtc added a commit that referenced this pull request Aug 3, 2022
* feat: Add screen capture support for macOS.

* chore: rename files.

* chore: update.

* chore: Implement DesktopSource, DesktopMediaList ojbc interface.

* chore: add license.

* fix: capture_state.

* update.

* update.

* Hide private delegate declaration.

* Re-generate thumbnail for all sources when call UpdateSourceList.

* fix: Fix window resize issue.

* update.

* update.

* fix for intel mac.

* cleanup.

* update.

* Add Window/Screen change listener.

* Add force reload for MediaListUpdate and capture cursor.

* fix: Fix the screen freeze caused by the desktop frame not setting the timestamp.

* update.

* fix issue for screen sharing.

* Fixed H264 profile-level-id limitation that could not encode desktop frames with resolutions higher than 720p.
cloudwebrtc added a commit that referenced this pull request Jan 18, 2023
* feat: Add screen capture support for macOS.

* chore: rename files.

* chore: update.

* chore: Implement DesktopSource, DesktopMediaList ojbc interface.

* chore: add license.

* fix: capture_state.

* update.

* update.

* Hide private delegate declaration.

* Re-generate thumbnail for all sources when call UpdateSourceList.

* fix: Fix window resize issue.

* update.

* update.

* fix for intel mac.

* cleanup.

* update.

* Add Window/Screen change listener.

* Add force reload for MediaListUpdate and capture cursor.

* fix: Fix the screen freeze caused by the desktop frame not setting the timestamp.

* update.

* fix issue for screen sharing.

* Fixed H264 profile-level-id limitation that could not encode desktop frames with resolutions higher than 720p.
cloudwebrtc added a commit that referenced this pull request Jun 6, 2023
* feat: Add screen capture support for macOS.

* chore: rename files.

* chore: update.

* chore: Implement DesktopSource, DesktopMediaList ojbc interface.

* chore: add license.

* fix: capture_state.

* update.

* update.

* Hide private delegate declaration.

* Re-generate thumbnail for all sources when call UpdateSourceList.

* fix: Fix window resize issue.

* update.

* update.

* fix for intel mac.

* cleanup.

* update.

* Add Window/Screen change listener.

* Add force reload for MediaListUpdate and capture cursor.

* fix: Fix the screen freeze caused by the desktop frame not setting the timestamp.

* update.

* fix issue for screen sharing.

* Fixed H264 profile-level-id limitation that could not encode desktop frames with resolutions higher than 720p.
cloudwebrtc added a commit that referenced this pull request Jun 12, 2023
[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)
@cloudwebrtc cloudwebrtc mentioned this pull request Jun 12, 2023
cloudwebrtc added a commit that referenced this pull request Jun 12, 2023
[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)
cloudwebrtc added a commit that referenced this pull request Jun 12, 2023
[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)
cloudwebrtc added a commit that referenced this pull request Jul 12, 2023
[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)
cloudwebrtc added a commit that referenced this pull request Jul 13, 2023
[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)
cloudwebrtc added a commit that referenced this pull request Jul 13, 2023
[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)
cloudwebrtc added a commit that referenced this pull request May 22, 2024
[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)
@cloudwebrtc cloudwebrtc mentioned this pull request May 22, 2024
cloudwebrtc added a commit that referenced this pull request May 30, 2024
[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)
cloudwebrtc added a commit that referenced this pull request Jun 12, 2024
[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)
cloudwebrtc added a commit that referenced this pull request Jun 12, 2024
Use M125 as the latest version and migrate historical patches to m125

Patches Group:

## 1. Update README.md
b6c65fc
* Add Apache-2.0 license and some note to README.md. (#9)
* Updated readme detailing changes from original (#42)
* Adding membrane framework (#51)
* Updated readme (#83)

## 2. Audio Device Optimization
7454824
* allow listen-only mode in AudioUnit, adjust when category changes
(#2)
* release mic when category changes
(#5)
* Change defaults to iOS defaults
(#7)
* Sync audio session config
(#8)
* feat: support bypass voice processing for iOS.
(#15)
* Remove MacBookPro audio pan right code
(#22)
* fix: Fix can't open mic alone when built-in AEC is enabled.
(#29)
* feat: add audio device changes detect for windows.
(#41)
* fix Linux compile (#47)
* AudioUnit: Don't rely on category switch for mic indicator to turn off
(#52)
* Stop recording on mute (turn off mic indicator)
(#55)
* Cherry pick audio selection from m97 release
(#35)
* [Mac] Allow audio device selection
(#21)
* RTCAudioDeviceModule.outputDevice / inputDevice getter and setter
(#80)
* Allow custom audio processing by exposing AudioProcessingModule
(#85)
* Expose audio sample buffers for Android
(#89)
* feat: add external audio processor for android.
(#103)
* android: make audio output attributes modifiable
(#118)
* Fix external audio processor sample rate calculation
(#108)
* Expose remote audio sample buffers on RTCAudioTrack
(#84)
* Fix memory leak when creating audio CMSampleBuffer
#86

## 3. Simulcast/SVC support for iOS/Android.
b0b9fe9
    
- Simulcast support for iOS SDK (#4)
- Support for simulcast in Android SDK (#3)
- include simulcast headers for mac also (#10)
- Fix simulcast using hardware encoder on Android (#48)
- Add scalabilityMode support for AV1/VP9. (#90)

## 4. Android improvements.
9aaaab5
- Start/Stop receiving stream method for VideoTrack (#25)
- Properly remove observer upon deconstruction (#26)
- feat: Expose setCodecPreferences/getCapabilities for android. (#61)
- fix: add WrappedVideoDecoderFactory.java. (#74)

## 5. Darwin improvements
a13ea17
- [Mac/iOS] feat: Add RTCYUVHelper for darwin. (#28)
- Cross-platform `RTCMTLVideoView` for both iOS / macOS (#40)
- rotationOverride should not be assign (#44)
- [ObjC] Expose properties / methods required for AV1 codec support
(#60)
- Workaround: Render PixelBuffer in RTCMTLVideoView (#58)
- Improve iOS/macOS H264 encoder (#70)
- fix: fix video encoder not resuming correctly upon foregrounding
(#75).
- add PrivacyInfo.xcprivacy to darwin frameworks. (#112)
- Add NSPrivacyCollectedDataTypes key to xcprivacy file (#114)
- Thread-safe `RTCInitFieldTrialDictionary` (#116)
- Set RTCCameraVideoCapturer initial zoom factor (#121)
- Unlock configuration before starting capture session (#122)

## 6. Desktop Capture for macOS.
841d78f
- [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)

## 7. Frame Cryptor Support.
fc08745
- feat: Frame Cryptor (aes gcm/cbc). (#54)
- feat: key ratchet/derive. (#66)
- fix: skip invalid key when decryption failed. (#81)
- Improve e2ee, add setSharedKey to KeyProvider. (#88)
- add failure tolerance for framecryptor. (#91)
- fix h264 freeze. (#93)
- Fix/send frame cryptor events from signaling thread (#95)
- more improvements for E2EE. (#96)
- remove too verbose logs (#107)
- Add key ring size to keyProviderOptions. (#109)

## 8. Other improvements.
eed6c8a
- Added yuv_helper (#57)
- ABGRToI420, ARGBToI420 & ARGBToRGB24 (#65)
- more yuv wrappers (#87)
- Fix naming for yuv helper (#113)
- Fix missing `RTC_OBJC_TYPE` macros (#100)

---------

Co-authored-by: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com>
Co-authored-by: David Zhao <dz@livekit.io>
Co-authored-by: davidliu <davidliu@deviange.net>
Co-authored-by: Angelika Serwa <angelika.serwa@gmail.com>
Co-authored-by: Théo Monnom <theo.monnom@outlook.com>
npazkevich pushed a commit to npazkevich/webrtc that referenced this pull request Jun 24, 2024
[Mac] feat: Support screen capture for macOS. (webrtc-sdk#24) (webrtc-sdk#36)
fix: Get thumbnails asynchronously. (webrtc-sdk#37)
fix: Use CVPixelBuffer to build DesktopCapture Frame, fix the crash caused by non-CVPixelBuffer frame in RTCVideoEncoderH264 that cannot be cropped. (webrtc-sdk#63)
Fix the crash when setting the fps of the virtual camera. (webrtc-sdk#62)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants