diff --git a/third_party/libwebrtc/moz-patch-stack/0123.patch b/third_party/libwebrtc/moz-patch-stack/0123.patch new file mode 100644 index 000000000000..16023746d2b2 --- /dev/null +++ b/third_party/libwebrtc/moz-patch-stack/0123.patch @@ -0,0 +1,6141 @@ +From +: +Andreas +Pehrson +< +apehrson +mozilla +. +com +> +Date +: +Thu +12 +Sep +2024 +21 +: +04 +: +00 ++ +0000 +Subject +: +Bug +1918096 +- +Integrate +SCContentSharingPicker +into +ScreenCapturerSck +. +r += +webrtc +- +reviewers +padenot +dbaker +This +works +by +creating +ScreenCapturerSck +with +a +sck_allow_system_picker +DesktopCaptureOptions +flag +. +The +flow +is +similar +to +the +Pipewire +capturer +in +that +SelectSource +has +no +effect +. +Start +( +) +brings +up +the +system +picker +and +: +- +automatically +starts +capture +on +selection +also +reconfigures +on +future +selection +changes +. +- +signals +a +stop +by +setting +the +permanent +error +flag +on +cancel +or +error +. +The +system +picker +is +configured +for +both +single +display +and +multiple +windows +to +give +users +as +much +power +over +what +they +share +as +possible +. +There +is +an +application +mode +also +but +other +browsers +are +not +allowing +access +to +that +as +of +now +. +Differential +Revision +: +https +: +/ +/ +phabricator +. +services +. +mozilla +. +com +/ +D221851 +Mercurial +Revision +: +https +: +/ +/ +hg +. +mozilla +. +org +/ +mozilla +- +central +/ +rev +/ +86a5d2db126efcee95a63e3079cda88747049197 +- +- +- +modules +/ +desktop_capture +/ +BUILD +. +gn +| +2 ++ +. +. +. +/ +desktop_capture +/ +desktop_capture_options +. +h +| +9 ++ +modules +/ +desktop_capture +/ +desktop_capturer +. +cc +| +8 ++ +- +. +. +. +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +h +| +49 ++ ++ ++ +. +. +. +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm +| +68 ++ ++ ++ ++ +. +. +. +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +h +| +7 ++ +. +. +. +/ +mac +/ +screen_capturer_sck +. +mm +| +291 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +- +- +7 +files +changed +415 +insertions +( ++ +) +19 +deletions +( +- +) +create +mode +100644 +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +h +create +mode +100644 +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +BUILD +. +gn +b +/ +modules +/ +desktop_capture +/ +BUILD +. +gn +index +d9276a97f5 +. +. +99253e4c4b +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +BUILD +. +gn ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +BUILD +. +gn +- +601 +6 ++ +601 +8 +if +( +is_mac +) +{ +" +mac +/ +desktop_frame_iosurface +. +mm +" +" +mac +/ +desktop_frame_provider +. +h +" +" +mac +/ +desktop_frame_provider +. +mm +" ++ +" +mac +/ +sck_picker_handle +. +h +" ++ +" +mac +/ +sck_picker_handle +. +mm +" +" +mac +/ +screen_capturer_mac +. +h +" +" +mac +/ +screen_capturer_mac +. +mm +" +" +mac +/ +screen_capturer_sck +. +h +" +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +desktop_capture_options +. +h +b +/ +modules +/ +desktop_capture +/ +desktop_capture_options +. +h +index +c44ec6a9e8 +. +. +51785a4085 +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +desktop_capture_options +. +h ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +desktop_capture_options +. +h +- +79 +6 ++ +79 +14 +class +RTC_EXPORT +DesktopCaptureOptions +{ +/ +/ +new +versions +of +macOS +that +remove +support +for +the +CGDisplay +- +based +APIs +. +bool +allow_sck_capturer +( +) +const +{ +return +allow_sck_capturer_ +; +} +void +set_allow_sck_capturer +( +bool +allow +) +{ +allow_sck_capturer_ += +allow +; +} ++ ++ +/ +/ +If +ScreenCaptureKit +is +used +for +desktop +capture +and +this +flag +is ++ +/ +/ +set +the +ScreenCaptureKit +backend +will +use +SCContentSharingPicker +for ++ +/ +/ +picking +source +. ++ +bool +allow_sck_system_picker +( +) +const +{ +return +allow_sck_system_picker_ +; +} ++ +void +set_allow_sck_system_picker +( +bool +allow +) +{ ++ +allow_sck_system_picker_ += +allow +; ++ +} +# +endif +const +rtc +: +: +scoped_refptr +< +FullScreenWindowDetector +> +& +- +243 +6 ++ +251 +7 +class +RTC_EXPORT +DesktopCaptureOptions +{ +rtc +: +: +scoped_refptr +< +DesktopConfigurationMonitor +> +configuration_monitor_ +; +bool +allow_iosurface_ += +false +; +bool +allow_sck_capturer_ += +false +; ++ +bool +allow_sck_system_picker_ += +false +; +# +endif +rtc +: +: +scoped_refptr +< +FullScreenWindowDetector +> +full_screen_window_detector_ +; +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +desktop_capturer +. +cc +b +/ +modules +/ +desktop_capture +/ +desktop_capturer +. +cc +index +a52a76c262 +. +. +02f11b3867 +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +desktop_capturer +. +cc ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +desktop_capturer +. +cc +- +30 +6 ++ +30 +10 +# +include +" +modules +/ +desktop_capture +/ +linux +/ +wayland +/ +base_capturer_pipewire +. +h +" +# +endif ++ +# +if +defined +( +WEBRTC_MAC +) ++ +# +include +" +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +h +" ++ +# +endif ++ +namespace +webrtc +{ +void +LogDesktopCapturerFullscreenDetectorUsage +( +) +{ +- +117 +11 ++ +121 +13 +std +: +: +unique_ptr +< +DesktopCapturer +> +DesktopCapturer +: +: +CreateGenericCapturer +( +capturer += +std +: +: +make_unique +< +BaseCapturerPipeWire +> +( +options +CaptureType +: +: +kAnyScreenContent +) +; +} ++ +# +elif +defined +( +WEBRTC_MAC +) ++ +capturer += +CreateGenericCapturerSck +( +options +) +; ++ +# +endif +if +( +capturer +& +& +options +. +detect_updated_region +( +) +) +{ +capturer +. +reset +( +new +DesktopCapturerDifferWrapper +( +std +: +: +move +( +capturer +) +) +) +; +} +- +# +endif +/ +/ +defined +( +WEBRTC_USE_PIPEWIRE +) +return +capturer +; +} +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +h +b +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +h +new +file +mode +100644 +index +0000000000 +. +. +c2279733b6 +- +- +- +/ +dev +/ +null ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +h +- +0 +0 ++ +1 +49 ++ +/ +* ++ +* +Copyright +( +c +) +2024 +The +WebRTC +project +authors +. +All +Rights +Reserved +. ++ +* ++ +* +Use +of +this +source +code +is +governed +by +a +BSD +- +style +license ++ +* +that +can +be +found +in +the +LICENSE +file +in +the +root +of +the +source ++ +* +tree +. +An +additional +intellectual +property +rights +grant +can +be +found ++ +* +in +the +file +PATENTS +. +All +contributing +project +authors +may ++ +* +be +found +in +the +AUTHORS +file +in +the +root +of +the +source +tree +. ++ +* +/ ++ ++ +# +ifndef +MODULES_DESKTOP_CAPTURE_MAC_SCK_PICKER_HANDLE_H_ ++ +# +define +MODULES_DESKTOP_CAPTURE_MAC_SCK_PICKER_HANDLE_H_ ++ ++ +# +include +< +os +/ +availability +. +h +> ++ +# +include +< +cstddef +> ++ +# +include +< +memory +> ++ +# +include +" +modules +/ +desktop_capture +/ +desktop_capturer +. +h +" ++ ++ +class +SCContentSharingPicker +; ++ +class +SCStream +; ++ ++ +namespace +webrtc +{ ++ ++ +/ +/ +Helper +class +to +manage +multiple +users +of +SCContentSharingPicker +. ++ +/ +/ ++ +/ +/ +The +active +and +maximumStreamCount +properties +are +automatically +managed +on ++ +/ +/ +SCContentSharingPicker +. +sharedPicker +which +is +what +is +returned +from ++ +/ +/ +GetPicker +( +) +. ++ +/ +/ ++ +/ +/ +When +using +this +class +for +stream +limits +to +work +only +create +one +stream +per ++ +/ +/ +handle +. ++ +/ +/ ++ +/ +/ +Designed +for +single +thread +use +. ++ +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +SckPickerHandleInterface +{ ++ +public +: ++ +virtual +~ +SckPickerHandleInterface +( +) += +default +; ++ +/ +/ +Effectively +identical +to +SCContentSharingPicker +. +sharedPicker +. ++ +virtual +SCContentSharingPicker +* +GetPicker +( +) +const += +0 +; ++ +/ +/ +A +SourceId +unique +to +this +handle +. ++ +virtual +DesktopCapturer +: +: +SourceId +Source +( +) +const += +0 +; ++ +} +; ++ ++ +/ +/ +Returns +a +newly +created +picker +handle +if +the +stream +count +limit +has +not +been ++ +/ +/ +reached +null +otherwise +. ++ +std +: +: +unique_ptr +< +SckPickerHandleInterface +> +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +CreateSckPickerHandle +( +) +; ++ ++ +} +/ +/ +namespace +webrtc ++ ++ +# +endif +/ +/ +MODULES_DESKTOP_CAPTURE_MAC_SCK_PICKER_HANDLE_H_ +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm +b +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm +new +file +mode +100644 +index +0000000000 +. +. +25e98b671f +- +- +- +/ +dev +/ +null ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm +- +0 +0 ++ +1 +68 ++ +/ +* ++ +* +Copyright +( +c +) +2024 +The +WebRTC +project +authors +. +All +Rights +Reserved +. ++ +* ++ +* +Use +of +this +source +code +is +governed +by +a +BSD +- +style +license ++ +* +that +can +be +found +in +the +LICENSE +file +in +the +root +of +the +source ++ +* +tree +. +An +additional +intellectual +property +rights +grant +can +be +found ++ +* +in +the +file +PATENTS +. +All +contributing +project +authors +may ++ +* +be +found +in +the +AUTHORS +file +in +the +root +of +the +source +tree +. ++ +* +/ ++ ++ +# +include +" +sck_picker_handle +. +h +" ++ ++ +# +import +< +ScreenCaptureKit +/ +ScreenCaptureKit +. +h +> ++ ++ +# +include +" +api +/ +sequence_checker +. +h +" ++ ++ +namespace +webrtc +{ ++ ++ +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +SckPickerHandle +: +public +SckPickerHandleInterface +{ ++ +public +: ++ +explicit +SckPickerHandle +( +DesktopCapturer +: +: +SourceId +source +) +: +source_ +( +source +) +{ ++ +RTC_DCHECK_RUN_ON +( +& +checker_ +) +; ++ +RTC_CHECK_LE +( +sHandleCount +maximumStreamCount +) +; ++ +if +( +sHandleCount ++ ++ += += +0 +) +{ ++ +auto +* +picker += +GetPicker +( +) +; ++ +picker +. +maximumStreamCount += +[ +NSNumber +numberWithUnsignedInt +: +maximumStreamCount +] +; ++ +picker +. +active += +YES +; ++ +} ++ +} ++ ++ +~ +SckPickerHandle +( +) +{ ++ +RTC_DCHECK_RUN_ON +( +& +checker_ +) +; ++ +if +( +- +- +sHandleCount +> +0 +) +{ ++ +return +; ++ +} ++ +GetPicker +( +) +. +active += +NO +; ++ +} ++ ++ +SCContentSharingPicker +* +GetPicker +( +) +const +override +{ ++ +return +SCContentSharingPicker +. +sharedPicker +; ++ +} ++ ++ +DesktopCapturer +: +: +SourceId +Source +( +) +const +override +{ ++ +return +source_ +; ++ +} ++ ++ +static +bool +AtCapacity +( +) +{ +return +sHandleCount += += +maximumStreamCount +; +} ++ ++ +private +: ++ +/ +/ +100 +is +an +arbitrary +number +that +seems +high +enough +to +never +get +reached +while +still +providing ++ +/ +/ +a +reasonably +low +upper +bound +. ++ +static +constexpr +size_t +maximumStreamCount += +100 +; ++ +static +size_t +sHandleCount +; ++ +SequenceChecker +checker_ +; ++ +const +DesktopCapturer +: +: +SourceId +source_ +; ++ +} +; ++ ++ +size_t +SckPickerHandle +: +: +sHandleCount += +0 +; ++ ++ +std +: +: +unique_ptr +< +SckPickerHandleInterface +> +CreateSckPickerHandle +( +) +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +{ ++ +if +( +SckPickerHandle +: +: +AtCapacity +( +) +) +{ ++ +return +nullptr +; ++ +} ++ +static +DesktopCapturer +: +: +SourceId +unique_source_id += +0 +; ++ +return +std +: +: +make_unique +< +SckPickerHandle +> +( ++ ++ +unique_source_id +) +; ++ +} ++ ++ +} +/ +/ +namespace +webrtc +\ +No +newline +at +end +of +file +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +h +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +h +index +105cbf0783 +. +. +eb3a370eed +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +h ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +h +- +21 +10 ++ +21 +17 +namespace +webrtc +{ +/ +/ +Returns +true +if +the +ScreenCaptureKit +capturer +is +available +. +bool +ScreenCapturerSckAvailable +( +) +; ++ +/ +/ +Returns +true +if +the +ScreenCaptureKit +capturer +is +available +using +SCContentSharingPicker ++ +/ +/ +for +picking +a +generic +source +. ++ +bool +GenericCapturerSckWithPickerAvailable +( +) +; ++ +/ +/ +A +DesktopCapturer +implementation +that +uses +ScreenCaptureKit +. +std +: +: +unique_ptr +< +DesktopCapturer +> +CreateScreenCapturerSck +( +const +DesktopCaptureOptions +& +options +) +; ++ +std +: +: +unique_ptr +< +DesktopCapturer +> +CreateGenericCapturerSck +( ++ +const +DesktopCaptureOptions +& +options +) +; ++ +} +/ +/ +namespace +webrtc +# +endif +/ +/ +MODULES_DESKTOP_CAPTURE_MAC_SCREEN_CAPTURER_SCK_H_ +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +index +a7fdfb1012 +. +. +51a5275905 +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +- +20 +11 ++ +20 +13 +# +include +" +rtc_base +/ +synchronization +/ +mutex +. +h +" +# +include +" +rtc_base +/ +thread_annotations +. +h +" +# +include +" +rtc_base +/ +time_utils +. +h +" ++ +# +include +" +sck_picker_handle +. +h +" +# +include +" +sdk +/ +objc +/ +helpers +/ +scoped_cftyperef +. +h +" +using +webrtc +: +: +DesktopFrameIOSurface +; +# +define +SCK_AVAILABLE +available +( +macOS +14 +. +0 +* +) ++ +# +define +SCCSPICKER_AVAILABLE +available +( +macOS +15 +. +0 +* +) +namespace +webrtc +{ +class +ScreenCapturerSck +; +- +35 +7 ++ +37 +7 +class +ScreenCapturerSck +; +/ +/ +Also +the +SCContentFilter +fields +contentRect +and +pointPixelScale +were +introduced +in +/ +/ +macOS +14 +. +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +- +interface +SckHelper +: +NSObject +< +SCStreamDelegate +SCStreamOutput +> ++ +interface +SckHelper +: +NSObject +< +SCStreamDelegate +SCStreamOutput +SCContentSharingPickerObserver +> +- +( +instancetype +) +initWithCapturer +: +( +webrtc +: +: +ScreenCapturerSck +* +) +capturer +; +- +58 +10 ++ +60 +18 +bool +ScreenCapturerSckAvailable +( +) +{ +return +sonomaOrHigher +; +} ++ +bool +GenericCapturerSckWithPickerAvailable +( +) +{ ++ +bool +available += +false +; ++ +if +( +SCCSPICKER_AVAILABLE +) +{ ++ +available += +true +; ++ +} ++ +return +available +; ++ +} ++ +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +ScreenCapturerSck +final +: +public +DesktopCapturer +{ +public +: +explicit +ScreenCapturerSck +( +const +DesktopCaptureOptions +& +options +) +; +- ++ +ScreenCapturerSck +( +const +DesktopCaptureOptions +& +options +SCContentSharingPickerMode +modes +) +; +ScreenCapturerSck +( +const +ScreenCapturerSck +& +) += +delete +; +ScreenCapturerSck +& +operator += +( +const +ScreenCapturerSck +& +) += +delete +; +- +71 +12 ++ +81 +27 +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +ScreenCapturerSck +final +: +public +DesktopCapture +void +Start +( +DesktopCapturer +: +: +Callback +* +callback +) +override +; +void +SetMaxFrameRate +( +uint32_t +max_frame_rate +) +override +; +void +CaptureFrame +( +) +override +; ++ +bool +GetSourceList +( +SourceList +* +sources +) +override +; +bool +SelectSource +( +SourceId +id +) +override +; ++ +/ +/ +Prep +for +implementing +DelegatedSourceListController +interface +for +now +used +by +Start +( +) +. ++ +/ +/ +Triggers +SCContentSharingPicker +. +Runs +on +the +caller +' +s +thread +. ++ +void +EnsureVisible +( +) +; ++ +/ +/ +Helper +functions +to +forward +SCContentSharingPickerObserver +notifications +to ++ +/ +/ +source_list_observer_ +. ++ +void +NotifySourceSelection +( +SCContentFilter +* +filter +SCStream +* +stream +) +; ++ +void +NotifySourceCancelled +( +SCStream +* +stream +) +; ++ +void +NotifySourceError +( +) +; ++ ++ +/ +/ +Called +after +a +SCStreamDelegate +stop +notification +. ++ +void +NotifyCaptureStopped +( +SCStream +* +stream +) +; +/ +/ +Called +by +SckHelper +when +shareable +content +is +returned +by +ScreenCaptureKit +. +content +will +be +/ +/ +nil +if +an +error +occurred +. +May +run +on +an +arbitrary +thread +. +void +OnShareableContentCreated +( +SCShareableContent +* +content +) +; ++ +/ +/ +Start +capture +with +the +given +filter +. +Creates +or +updates +stream_ +as +needed +. ++ +void +StartWithFilter +( +SCContentFilter +* +filter +) +RTC_EXCLUSIVE_LOCKS_REQUIRED +( +lock_ +) +; ++ +/ +/ +Called +by +SckHelper +to +notify +of +a +newly +captured +frame +. +May +run +on +an +arbitrary +thread +. +void +OnNewIOSurface +( +IOSurfaceRef +io_surface +CFDictionaryRef +attachment +) +; +- +96 +9 ++ +121 +20 +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +ScreenCapturerSck +final +: +public +DesktopCapture +/ +/ +thread +. +Callback +* +callback_ += +nullptr +; ++ +/ +/ +Helper +class +that +tracks +the +number +of +capturers +needing +SCContentSharingPicker +to +stay +active +. ++ +/ +/ +Only +used +on +the +caller +' +s +thread +. ++ +std +: +: +unique_ptr +< +SckPickerHandleInterface +> +picker_handle_ +; ++ ++ +/ +/ +Flag +to +track +if +we +have +added +ourselves +as +observer +to +picker_handle_ +. ++ +/ +/ +Only +used +on +the +caller +' +s +thread +. ++ +bool +picker_handle_registered_ += +false +; ++ +/ +/ +Options +passed +to +the +constructor +. +May +be +accessed +on +any +thread +but +the +options +are +/ +/ +unchanged +during +the +capturer +' +s +lifetime +. +- +DesktopCaptureOptions +capture_options_ +; ++ +const +DesktopCaptureOptions +capture_options_ +; ++ ++ +/ +/ +Modes +to +use +iff +using +the +system +picker +. +See +docs +on +SCContentSharingPickerMode +. ++ +const +SCContentSharingPickerMode +picker_modes_ +; +/ +/ +Signals +that +a +permanent +error +occurred +. +This +may +be +set +on +any +thread +and +is +read +by +/ +/ +CaptureFrame +( +) +which +runs +on +the +caller +' +s +thread +. +- +110 +6 ++ +146 +9 +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +ScreenCapturerSck +final +: +public +DesktopCapture +/ +/ +Provides +captured +desktop +frames +. +SCStream +* +__strong +stream_ +RTC_GUARDED_BY +( +lock_ +) +; ++ +/ +/ +Current +filter +on +stream_ +. ++ +SCContentFilter +* +__strong +filter_ +RTC_GUARDED_BY +( +lock_ +) +; ++ +/ +/ +Currently +selected +display +or +0 +if +the +full +desktop +is +selected +. +This +capturer +does +not +/ +/ +support +full +- +desktop +capture +and +will +fall +back +to +the +first +display +. +CGDirectDisplayID +current_display_ +RTC_GUARDED_BY +( +lock_ +) += +0 +; +- +118 +7 ++ +157 +7 +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +ScreenCapturerSck +final +: +public +DesktopCapture +/ +/ +caller +' +s +thread +. +MacDesktopConfiguration +desktop_config_ +; +- +Mutex +latest_frame_lock_ +; ++ +Mutex +latest_frame_lock_ +RTC_ACQUIRED_AFTER +( +lock_ +) +; +std +: +: +unique_ptr +< +SharedDesktopFrame +> +latest_frame_ +RTC_GUARDED_BY +( +latest_frame_lock_ +) +; +int32_t +latest_frame_dpi_ +RTC_GUARDED_BY +( +latest_frame_lock_ +) += +kStandardDPI +; +- +133 +18 ++ +172 +50 +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +ScreenCapturerSck +final +: +public +DesktopCapture +} +; +ScreenCapturerSck +: +: +ScreenCapturerSck +( +const +DesktopCaptureOptions +& +options +) +- +: +capture_options_ +( +options +) +{ ++ +: +ScreenCapturerSck +( +options +SCContentSharingPickerModeSingleDisplay +) +{ +} ++ ++ +ScreenCapturerSck +: +: +ScreenCapturerSck +( +const +DesktopCaptureOptions +& +options +SCContentSharingPickerMode +modes +) ++ +: +capture_options_ +( +options +) ++ +picker_modes_ +( +modes +) +{ ++ +picker_handle_ += +CreateSckPickerHandle +( +) +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +created +. +allow_sck_system_picker += +" ++ +< +< +capture_options_ +. +allow_sck_system_picker +( +) +< +< +" +source += +" ++ +< +< +( +picker_handle_ +? +picker_handle_ +- +> +Source +( +) +: +- +1 +) +< +< +" +mode += +" +< +< +( +[ +& +modes +] +{ ++ +std +: +: +stringstream +ss +; ++ +bool +empty += +true +; ++ +auto +maybeAppend += +[ +& +] +( +auto +mode +auto +* +str +) +{ ++ +if +( +modes +& +mode +) +{ ++ +if +( +! +empty +) +{ ++ +ss +< +< +" +| +" +; ++ +} ++ +empty += +false +; ++ +ss +< +< +str +; ++ +} ++ +} +; ++ +maybeAppend +( +SCContentSharingPickerModeSingleWindow +" +SingleWindow +" +) +; ++ +maybeAppend +( +SCContentSharingPickerModeMultipleWindows +" +MultiWindow +" +) +; ++ +maybeAppend +( +SCContentSharingPickerModeSingleApplication +" +SingleApp +" +) +; ++ +maybeAppend +( +SCContentSharingPickerModeMultipleApplications +" +MultiApp +" +) +; ++ +maybeAppend +( +SCContentSharingPickerModeSingleDisplay +" +SingleDisplay +" +) +; ++ +return +ss +. +str +( +) +; ++ +} +) +( +) +; +helper_ += +[ +[ +SckHelper +alloc +] +initWithCapturer +: +this +] +; +} +ScreenCapturerSck +: +: +~ +ScreenCapturerSck +( +) +{ ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +destroyed +. +" +; +[ +stream_ +stopCaptureWithCompletionHandler +: +nil +] +; +[ +helper_ +releaseCapturer +] +; +} +void +ScreenCapturerSck +: +: +Start +( +DesktopCapturer +: +: +Callback +* +callback +) +{ ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +< +< +" +. +" +; +callback_ += +callback +; +desktop_config_ += +capture_options_ +. +configuration_monitor +( +) +- +> +desktop_configuration +( +) +; ++ +if +( +capture_options_ +. +allow_sck_system_picker +( +) +) +{ ++ +EnsureVisible +( +) +; ++ +return +; ++ +} +StartOrReconfigureCapturer +( +) +; +} +- +156 +6 ++ +227 +7 +void +ScreenCapturerSck +: +: +CaptureFrame +( +) +{ +int64_t +capture_start_time_millis += +rtc +: +: +TimeMillis +( +) +; +if +( +permanent_error_ +) +{ ++ +RTC_LOG +( +LS_VERBOSE +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +CaptureFrame +( +) +- +> +ERROR_PERMANENT +" +; +callback_ +- +> +OnCaptureResult +( +Result +: +: +ERROR_PERMANENT +nullptr +) +; +return +; +} +- +181 +14 ++ +253 +120 +void +ScreenCapturerSck +: +: +CaptureFrame +( +) +{ +} +if +( +frame +) +{ ++ +RTC_LOG +( +LS_VERBOSE +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +CaptureFrame +( +) +- +> +SUCCESS +" +; +frame +- +> +set_capture_time_ms +( +rtc +: +: +TimeSince +( +capture_start_time_millis +) +) +; +callback_ +- +> +OnCaptureResult +( +Result +: +: +SUCCESS +std +: +: +move +( +frame +) +) +; +} +else +{ ++ +RTC_LOG +( +LS_VERBOSE +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +CaptureFrame +( +) +- +> +ERROR_TEMPORARY +" +; +callback_ +- +> +OnCaptureResult +( +Result +: +: +ERROR_TEMPORARY +nullptr +) +; +} +} ++ +void +ScreenCapturerSck +: +: +EnsureVisible +( +) +{ ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +< +< +" +. +" +; ++ +if +( +picker_handle_ +) +{ ++ +if +( +! +picker_handle_registered_ +) +{ ++ +picker_handle_registered_ += +true +; ++ +[ +picker_handle_ +- +> +GetPicker +( +) +addObserver +: +helper_ +] +; ++ +} ++ +} +else +{ ++ +/ +/ +We +reached +the +maximum +number +of +streams +. ++ +RTC_LOG +( +LS_ERROR +) +< +< +" +ScreenCapturerSck +" +< +< +this ++ +< +< +" +EnsureVisible +( +) +reached +the +maximum +number +of +streams +. +" +; ++ +permanent_error_ += +true +; ++ +return +; ++ +} ++ +SCContentSharingPicker +* +picker += +picker_handle_ +- +> +GetPicker +( +) +; ++ +SCStream +* +stream +; ++ +{ ++ +MutexLock +lock +( +& +lock_ +) +; ++ +stream += +stream_ +; ++ +stream_ += +nil +; ++ +filter_ += +nil +; ++ +} ++ +[ +stream +removeStreamOutput +: +helper_ +type +: +SCStreamOutputTypeScreen +error +: +nil +] +; ++ +[ +stream +stopCaptureWithCompletionHandler +: +nil +] +; ++ +SCContentSharingPickerConfiguration +* +config += +picker +. +defaultConfiguration +; ++ +config +. +allowedPickerModes += +picker_modes_ +; ++ +picker +. +defaultConfiguration += +config +; ++ +/ +/ +Pick +a +sensible +style +to +start +out +with +based +on +our +current +mode +. ++ +/ +/ +Default +to +Screen +because +if +using +Window +the +picker +automatically +hides ++ +/ +/ +our +current +window +to +show +others +. ++ +SCShareableContentStyle +style += +SCShareableContentStyleDisplay +; ++ +if +( +picker_modes_ += += +SCContentSharingPickerModeSingleDisplay +) +{ ++ +style += +SCShareableContentStyleDisplay +; ++ +} +else +if +( +picker_modes_ += += +SCContentSharingPickerModeSingleWindow +| +| ++ +picker_modes_ += += +SCContentSharingPickerModeMultipleWindows +) +{ ++ +style += +SCShareableContentStyleWindow +; ++ +} +else +if +( +picker_modes_ += += +SCContentSharingPickerModeSingleApplication +| +| ++ +picker_modes_ += += +SCContentSharingPickerModeMultipleApplications +) +{ ++ +style += +SCShareableContentStyleApplication +; ++ +} ++ +/ +/ +This +dies +silently +if +maximumStreamCount +is +already +running +. +We +need +our ++ +/ +/ +own +stream +count +bookkeeping +because +of +this +and +to +be +able +to +unset +active +. ++ +[ +picker +presentPickerForStream +: +stream +usingContentStyle +: +style +] +; ++ +} ++ ++ +void +ScreenCapturerSck +: +: +NotifySourceSelection +( +SCContentFilter +* +filter +SCStream +* +stream +) +{ ++ +MutexLock +lock +( +& +lock_ +) +; ++ +if +( +stream_ +! += +stream +) +{ ++ +/ +/ +The +picker +selected +a +source +for +another +capturer +. ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +< +< +" +. +stream_ +! += +stream +. +" +; ++ +return +; ++ +} ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +< +< +" +. +Starting +. +" +; ++ +StartWithFilter +( +filter +) +; ++ +} ++ ++ +void +ScreenCapturerSck +: +: +NotifySourceCancelled +( +SCStream +* +stream +) +{ ++ +MutexLock +lock +( +& +lock_ +) +; ++ +if +( +stream_ +! += +stream +) +{ ++ +/ +/ +The +picker +was +cancelled +for +another +capturer +. ++ +return +; ++ +} ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +< +< +" +. +" +; ++ +if +( +! +stream_ +) +{ ++ +/ +/ +The +initial +picker +was +cancelled +. +There +is +no +stream +to +fall +back +to +. ++ +permanent_error_ += +true +; ++ +} ++ +} ++ ++ +void +ScreenCapturerSck +: +: +NotifySourceError +( +) +{ ++ +{ ++ +MutexLock +lock +( +& +lock_ +) +; ++ +if +( +stream_ +) +{ ++ +/ +/ +The +picker +failed +to +start +. +But +fear +not +it +was +not +our +picker ++ +/ +/ +we +already +have +a +stream +! ++ +return +; ++ +} ++ +} ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +< +< +" +. +" +; ++ +permanent_error_ += +true +; ++ +} ++ ++ +void +ScreenCapturerSck +: +: +NotifyCaptureStopped +( +SCStream +* +stream +) +{ ++ +MutexLock +lock +( +& +lock_ +) +; ++ +if +( +stream_ +! += +stream +) +{ ++ +return +; ++ +} ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +< +< +" +. +" +; ++ +permanent_error_ += +true +; ++ +} ++ ++ +bool +ScreenCapturerSck +: +: +GetSourceList +( +SourceList +* +sources +) +{ ++ +sources +- +> +clear +( +) +; ++ +if +( +capture_options_ +. +allow_sck_system_picker +( +) +& +& +picker_handle_ +) +{ ++ +sources +- +> +push_back +( +{ +picker_handle_ +- +> +Source +( +) +} +) +; ++ +} ++ +return +true +; ++ +} ++ +bool +ScreenCapturerSck +: +: +SelectSource +( +SourceId +id +) +{ ++ +if +( +capture_options_ +. +allow_sck_system_picker +( +) +) +{ ++ +return +true +; ++ +} ++ ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +SelectSource +( +id += +" +< +< +id +< +< +" +) +. +" +; +bool +stream_started += +false +; +{ +MutexLock +lock +( +& +lock_ +) +; +- +209 +20 ++ +387 +23 +bool +ScreenCapturerSck +: +: +SelectSource +( +SourceId +id +) +{ +void +ScreenCapturerSck +: +: +OnShareableContentCreated +( +SCShareableContent +* +content +) +{ +if +( +! +content +) +{ +- +RTC_LOG +( +LS_ERROR +) +< +< +" +getShareableContent +failed +. +" +; ++ +RTC_LOG +( +LS_ERROR +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +getShareableContent +failed +. +" +; +permanent_error_ += +true +; +return +; +} +if +( +! +content +. +displays +. +count +) +{ +- +RTC_LOG +( +LS_ERROR +) +< +< +" +getShareableContent +returned +no +displays +. +" +; ++ +RTC_LOG +( +LS_ERROR +) +< +< +" +ScreenCapturerSck +" +< +< +this ++ +< +< +" +getShareableContent +returned +no +displays +. +" +; +permanent_error_ += +true +; +return +; +} ++ +MutexLock +lock +( +& +lock_ +) +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ ++ +< +< +" +. +current_display_ += +" +< +< +current_display_ +; +SCDisplay +* +captured_display +; +{ +- +MutexLock +lock +( +& +lock_ +) +; +for +( +SCDisplay +* +display +in +content +. +displays +) +{ +if +( +current_display_ += += +display +. +displayID +) +{ +captured_display += +display +; +- +232 +9 ++ +413 +10 +void +ScreenCapturerSck +: +: +OnShareableContentCreated +( +SCShareableContent +* +content +) +{ +if +( +! +captured_display +) +{ +if +( +current_display_ += += +static_cast +< +CGDirectDisplayID +> +( +kFullDesktopScreenId +) +) +{ +RTC_LOG +( +LS_WARNING +) +- +< +< +" +Full +screen +capture +is +not +supported +falling +back +to +first +display +. +" +; ++ +< +< +" +ScreenCapturerSck +" +< +< +this ++ +< +< +" +Full +screen +capture +is +not +supported +falling +back +to +first +display +. +" +; +} +else +{ +- +RTC_LOG +( +LS_WARNING +) +< +< +" +Display +" +< +< +current_display_ ++ +RTC_LOG +( +LS_WARNING +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +Display +" +< +< +current_display_ +< +< +" +not +found +falling +back +to +first +display +. +" +; +} +captured_display += +content +. +displays +. +firstObject +; +- +243 +26 ++ +425 +30 +void +ScreenCapturerSck +: +: +OnShareableContentCreated +( +SCShareableContent +* +content +) +{ +SCContentFilter +* +filter += +[ +[ +SCContentFilter +alloc +] +initWithDisplay +: +captured_display +excludingWindows +: +[ +] +] +; ++ +StartWithFilter +( +filter +) +; ++ +} ++ ++ +void +ScreenCapturerSck +: +: +StartWithFilter +( +SCContentFilter +* +__strong +filter +) +{ ++ +lock_ +. +AssertHeld +( +) +; +SCStreamConfiguration +* +config += +[ +[ +SCStreamConfiguration +alloc +] +init +] +; +config +. +pixelFormat += +kCVPixelFormatType_32BGRA +; +config +. +colorSpaceName += +kCGColorSpaceSRGB +; +config +. +showsCursor += +capture_options_ +. +prefer_cursor_embedded +( +) +; +- +config +. +width += +filter +. +contentRect +. +size +. +width +* +filter +. +pointPixelScale +; +- +config +. +height += +filter +. +contentRect +. +size +. +height +* +filter +. +pointPixelScale +; +- +config +. +captureResolution += +SCCaptureResolutionNominal +; ++ +config +. +captureResolution += +SCCaptureResolutionAutomatic +; +{ +MutexLock +lock +( +& +latest_frame_lock_ +) +; +latest_frame_dpi_ += +filter +. +pointPixelScale +* +kStandardDPI +; +} +- +MutexLock +lock +( +& +lock_ +) +; ++ +filter_ += +filter +; +if +( +stream_ +) +{ +- +RTC_LOG +( +LS_INFO +) +< +< +" +Updating +stream +configuration +. +" +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +Updating +stream +configuration +. +" +; +[ +stream_ +updateContentFilter +: +filter +completionHandler +: +nil +] +; +[ +stream_ +updateConfiguration +: +config +completionHandler +: +nil +] +; +} +else +{ ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +Creating +new +stream +. +" +; +stream_ += +[ +[ +SCStream +alloc +] +initWithFilter +: +filter +configuration +: +config +delegate +: +helper_ +] +; +/ +/ +TODO +: +crbug +. +com +/ +327458809 +- +Choose +an +appropriate +sampleHandlerQueue +for +best +performance +. +- +273 +7 ++ +459 +8 +void +ScreenCapturerSck +: +: +OnShareableContentCreated +( +SCShareableContent +* +content +) +{ +error +: +& +add_stream_output_error +] +; +if +( +! +add_stream_output_result +) +{ +stream_ += +nil +; +- +RTC_LOG +( +LS_ERROR +) +< +< +" +addStreamOutput +failed +. +" +; ++ +filter_ += +nil +; ++ +RTC_LOG +( +LS_ERROR +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +addStreamOutput +failed +. +" +; +permanent_error_ += +true +; +return +; +} +- +283 +9 ++ +470 +9 +void +ScreenCapturerSck +: +: +OnShareableContentCreated +( +SCShareableContent +* +content +) +{ +/ +/ +It +should +be +safe +to +access +this +here +because +the +C ++ ++ +destructor +calls +/ +/ +stopCaptureWithCompletionHandler +on +the +stream +which +cancels +this +handler +. +permanent_error_ += +true +; +- +RTC_LOG +( +LS_ERROR +) +< +< +" +startCaptureWithCompletionHandler +failed +. +" +; ++ +RTC_LOG +( +LS_ERROR +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +Starting +failed +. +" +; +} +else +{ +- +RTC_LOG +( +LS_INFO +) +< +< +" +Capture +started +. +" +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +Capture +started +. +" +; +} +} +; +- +294 +6 ++ +481 +9 +void +ScreenCapturerSck +: +: +OnShareableContentCreated +( +SCShareableContent +* +content +) +{ +} +void +ScreenCapturerSck +: +: +OnNewIOSurface +( +IOSurfaceRef +io_surface +CFDictionaryRef +attachment +) +{ ++ +RTC_LOG +( +LS_VERBOSE +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ ++ +< +< +" +width += +" +< +< +IOSurfaceGetWidth +( +io_surface +) ++ +< +< +" +height += +" +< +< +IOSurfaceGetHeight +( +io_surface +) +< +< +" +. +" +; +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +scoped_io_surface +( +io_surface +rtc +: +: +RetainPolicy +: +: +RETAIN +) +; +std +: +: +unique_ptr +< +DesktopFrameIOSurface +> +desktop_frame_io_surface += +DesktopFrameIOSurface +: +: +Wrap +( +scoped_io_surface +) +; +- +352 +6 ++ +542 +15 +void +ScreenCapturerSck +: +: +OnNewIOSurface +( +IOSurfaceRef +io_surface +CFDictionaryRef +} +void +ScreenCapturerSck +: +: +StartOrReconfigureCapturer +( +) +{ ++ +if +( +capture_options_ +. +allow_sck_system_picker +( +) +) +{ ++ +MutexLock +lock +( +& +lock_ +) +; ++ +if +( +filter_ +) +{ ++ +StartWithFilter +( +filter_ +) +; ++ +} ++ +return +; ++ +} ++ ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +< +< +" +. +" +; +/ +/ +The +copy +is +needed +to +avoid +capturing +this +in +the +Objective +- +C +block +. +Accessing +helper_ +/ +/ +inside +the +block +is +equivalent +to +this +- +> +helper_ +and +would +crash +( +UAF +) +if +this +is +/ +/ +deleted +before +the +block +is +executed +. +- +370 +6 ++ +569 +17 +std +: +: +unique_ptr +< +DesktopCapturer +> +CreateScreenCapturerSck +( +const +DesktopCaptureOpt +return +nullptr +; +} ++ +std +: +: +unique_ptr +< +DesktopCapturer +> +CreateGenericCapturerSck +( +const +DesktopCaptureOptions +& +options +) +{ ++ +if +( +SCCSPICKER_AVAILABLE +) +{ ++ +if +( +options +. +allow_sck_system_picker +( +) +) +{ ++ +return +std +: +: +make_unique +< +ScreenCapturerSck +> +( ++ +options ++ +SCContentSharingPickerModeSingleDisplay +| +SCContentSharingPickerModeMultipleWindows +) +; ++ +} ++ +} ++ +return +nullptr +; ++ +} ++ +} +/ +/ +namespace +webrtc +implementation +SckHelper +{ +- +393 +6 ++ +603 +50 +std +: +: +unique_ptr +< +DesktopCapturer +> +CreateScreenCapturerSck +( +const +DesktopCaptureOpt +} +} ++ +- +( +void +) +stream +: +( +SCStream +* +) +stream +didStopWithError +: +( +NSError +* +) +error +{ ++ +webrtc +: +: +MutexLock +lock +( +& +_capturer_lock +) +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +_capturer +< +< +" +" +< +< +__func__ +< +< +" +. +" +; ++ +if +( +_capturer +) +{ ++ +_capturer +- +> +NotifyCaptureStopped +( +stream +) +; ++ +} ++ +} ++ ++ +- +( +void +) +userDidStopStream +: +( +SCStream +* +) +stream +NS_SWIFT_NAME +( +userDidStopStream +( +_ +: +) +) ++ +API_AVAILABLE +( +macos +( +14 +. +4 +) +) +{ ++ +webrtc +: +: +MutexLock +lock +( +& +_capturer_lock +) +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +_capturer +< +< +" +" +< +< +__func__ +< +< +" +. +" +; ++ +if +( +_capturer +) +{ ++ +_capturer +- +> +NotifyCaptureStopped +( +stream +) +; ++ +} ++ +} ++ ++ +- +( +void +) +contentSharingPicker +: +( +SCContentSharingPicker +* +) +picker ++ +didUpdateWithFilter +: +( +SCContentFilter +* +) +filter ++ +forStream +: +( +SCStream +* +) +stream +{ ++ +webrtc +: +: +MutexLock +lock +( +& +_capturer_lock +) +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +_capturer +< +< +" +" +< +< +__func__ +< +< +" +. +" +; ++ +if +( +_capturer +) +{ ++ +_capturer +- +> +NotifySourceSelection +( +filter +stream +) +; ++ +} ++ +} ++ ++ +- +( +void +) +contentSharingPicker +: +( +SCContentSharingPicker +* +) +picker +didCancelForStream +: +( +SCStream +* +) +stream +{ ++ +webrtc +: +: +MutexLock +lock +( +& +_capturer_lock +) +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +_capturer +< +< +" +" +< +< +__func__ +< +< +" +. +" +; ++ +if +( +_capturer +) +{ ++ +_capturer +- +> +NotifySourceCancelled +( +stream +) +; ++ +} ++ +} ++ ++ +- +( +void +) +contentSharingPickerStartDidFailWithError +: +( +NSError +* +) +error +{ ++ +webrtc +: +: +MutexLock +lock +( +& +_capturer_lock +) +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +_capturer +< +< +" +" +< +< +__func__ ++ +< +< +" +. +error +. +code += +" +< +< +error +. +code +; ++ +if +( +_capturer +) +{ ++ +_capturer +- +> +NotifySourceError +( +) +; ++ +} ++ +} ++ +- +( +void +) +stream +: +( +SCStream +* +) +stream +didOutputSampleBuffer +: +( +CMSampleBufferRef +) +sampleBuffer +ofType +: +( +SCStreamOutputType +) +type +{ +- +424 +6 ++ +678 +7 +std +: +: +unique_ptr +< +DesktopCapturer +> +CreateScreenCapturerSck +( +const +DesktopCaptureOpt +- +( +void +) +releaseCapturer +{ +webrtc +: +: +MutexLock +lock +( +& +_capturer_lock +) +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +_capturer +< +< +" +" +< +< +__func__ +< +< +" +. +" +; +_capturer += +nullptr +; +} diff --git a/third_party/libwebrtc/moz-patch-stack/0124.patch b/third_party/libwebrtc/moz-patch-stack/0124.patch new file mode 100644 index 000000000000..222e78365f21 --- /dev/null +++ b/third_party/libwebrtc/moz-patch-stack/0124.patch @@ -0,0 +1,754 @@ +From +: +Andreas +Pehrson +< +apehrson +mozilla +. +com +> +Date +: +Thu +12 +Sep +2024 +22 +: +36 +: +00 ++ +0000 +Subject +: +Bug +1918096 +- +In +ScreenCapturerSck +improve +dictionary +ergonomics +. +r += +webrtc +- +reviewers +ng +Differential +Revision +: +https +: +/ +/ +phabricator +. +services +. +mozilla +. +com +/ +D221940 +Mercurial +Revision +: +https +: +/ +/ +hg +. +mozilla +. +org +/ +mozilla +- +central +/ +rev +/ +aabf0bd94f282ae97a010016058446e45fc781c8 +- +- +- +. +. +. +/ +mac +/ +screen_capturer_sck +. +mm +| +25 ++ ++ ++ ++ ++ ++ ++ ++ +- +- +- +- +- +- +- +- +- +- +- +1 +file +changed +10 +insertions +( ++ +) +15 +deletions +( +- +) +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +index +51a5275905 +. +. +e98b61ccdb +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +- +103 +7 ++ +103 +7 +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +ScreenCapturerSck +final +: +public +DesktopCapture +void +StartWithFilter +( +SCContentFilter +* +filter +) +RTC_EXCLUSIVE_LOCKS_REQUIRED +( +lock_ +) +; +/ +/ +Called +by +SckHelper +to +notify +of +a +newly +captured +frame +. +May +run +on +an +arbitrary +thread +. +- +void +OnNewIOSurface +( +IOSurfaceRef +io_surface +CFDictionaryRef +attachment +) +; ++ +void +OnNewIOSurface +( +IOSurfaceRef +io_surface +NSDictionary +* +attachment +) +; +private +: +/ +/ +Called +when +starting +the +capturer +or +the +configuration +has +changed +( +either +from +a +- +480 +10 ++ +480 +13 +void +ScreenCapturerSck +: +: +StartWithFilter +( +SCContentFilter +* +__strong +filter +) +{ +} +} +- +void +ScreenCapturerSck +: +: +OnNewIOSurface +( +IOSurfaceRef +io_surface +CFDictionaryRef +attachment +) +{ ++ +void +ScreenCapturerSck +: +: +OnNewIOSurface +( +IOSurfaceRef +io_surface +NSDictionary +* +attachment +) +{ +RTC_LOG +( +LS_VERBOSE +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +< +< +" +width += +" +< +< +IOSurfaceGetWidth +( +io_surface +) +< +< +" +height += +" +< +< +IOSurfaceGetHeight +( +io_surface +) +< +< +" +. +" +; ++ ++ +const +auto +* +dirty_rects += +( +NSArray +* +) +attachment +[ +SCStreamFrameInfoDirtyRects +] +; ++ +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +scoped_io_surface +( +io_surface +rtc +: +: +RetainPolicy +: +: +RETAIN +) +; +std +: +: +unique_ptr +< +DesktopFrameIOSurface +> +desktop_frame_io_surface += +DesktopFrameIOSurface +: +: +Wrap +( +scoped_io_surface +) +; +- +505 +28 ++ +508 +20 +void +ScreenCapturerSck +: +: +OnNewIOSurface +( +IOSurfaceRef +io_surface +CFDictionaryRef +} +if +( +! +dirty +) +{ +- +const +void +* +dirty_rects_ptr += +- +CFDictionaryGetValue +( +attachment +( +__bridge +CFStringRef +) +SCStreamFrameInfoDirtyRects +) +; +- +if +( +! +dirty_rects_ptr +) +{ ++ +if +( +! +dirty_rects +) +{ +/ +/ +This +is +never +expected +to +happen +- +SCK +attaches +a +non +- +empty +dirty +- +rects +list +to +every +/ +/ +frame +even +when +nothing +has +changed +. +return +; +} +- +if +( +CFGetTypeID +( +dirty_rects_ptr +) +! += +CFArrayGetTypeID +( +) +) +{ +- +return +; +- +} +- +- +CFArrayRef +dirty_rects_array += +static_cast +< +CFArrayRef +> +( +dirty_rects_ptr +) +; +- +int +size += +CFArrayGetCount +( +dirty_rects_array +) +; +- +for +( +int +i += +0 +; +i +< +size +; +i ++ ++ +) +{ +- +const +void +* +rect_ptr += +CFArrayGetValueAtIndex +( +dirty_rects_array +i +) +; ++ +for +( +NSUInteger +i += +0 +; +i +< +dirty_rects +. +count +; +i ++ ++ +) +{ ++ +const +auto +* +rect_ptr += +( +__bridge +CFDictionaryRef +) +dirty_rects +[ +i +] +; +if +( +CFGetTypeID +( +rect_ptr +) +! += +CFDictionaryGetTypeID +( +) +) +{ +/ +/ +This +is +never +expected +to +happen +- +the +dirty +- +rects +attachment +should +always +be +an +array +/ +/ +of +dictionaries +. +return +; +} +CGRect +rect +{ +} +; +- +CGRectMakeWithDictionaryRepresentation +( +static_cast +< +CFDictionaryRef +> +( +rect_ptr +) +& +rect +) +; ++ +CGRectMakeWithDictionaryRepresentation +( +rect_ptr +& +rect +) +; +if +( +! +CGRectIsEmpty +( +rect +) +) +{ +dirty += +true +; +break +; +- +672 +7 ++ +667 +7 +std +: +: +unique_ptr +< +DesktopCapturer +> +CreateGenericCapturerSck +( +const +DesktopCaptureOp +webrtc +: +: +MutexLock +lock +( +& +_capturer_lock +) +; +if +( +_capturer +) +{ +- +_capturer +- +> +OnNewIOSurface +( +ioSurface +attachment +) +; ++ +_capturer +- +> +OnNewIOSurface +( +ioSurface +( +__bridge +NSDictionary +* +) +attachment +) +; +} +} diff --git a/third_party/libwebrtc/moz-patch-stack/0125.patch b/third_party/libwebrtc/moz-patch-stack/0125.patch new file mode 100644 index 000000000000..b5603cd5e27b --- /dev/null +++ b/third_party/libwebrtc/moz-patch-stack/0125.patch @@ -0,0 +1,2445 @@ +From +: +Andreas +Pehrson +< +apehrson +mozilla +. +com +> +Date +: +Thu +12 +Sep +2024 +22 +: +36 +: +00 ++ +0000 +Subject +: +Bug +1918096 +- +In +ScreenCapturerSck +adapt +to +sources +that +change +resolution +. +r += +webrtc +- +reviewers +ng +If +the +resolution +is +smaller +than +the +allocated +surface +we +crop +. +If +the +resolution +is +larger +than +the +allocated +surface +we +reconfigure +with +a +larger +surface +. +The +allocated +surface +has +the +size +we +told +it +to +have +in +the +SCStreamConfiguration +in +pixels +. +If +the +source +is +a +screen +the +size +is +pretty +static +. +Changing +display +settings +could +affect +it +. +If +the +source +is +a +window +the +size +is +initially +the +size +of +the +window +. +The +user +resizing +the +window +affects +the +size +. +If +the +source +is +multiple +windows +the +size +initially +seems +to +be +that +of +the +display +they +' +re +sitting +on +. +Windows +across +multiple +displays +are +not +captured +into +the +same +surface +as +of +macOS +14 +. +Differential +Revision +: +https +: +/ +/ +phabricator +. +services +. +mozilla +. +com +/ +D221941 +Mercurial +Revision +: +https +: +/ +/ +hg +. +mozilla +. +org +/ +mozilla +- +central +/ +rev +/ +bc6215142feaab1a3f7820006129219504851bc8 +- +- +- +. +. +. +/ +mac +/ +desktop_frame_iosurface +. +h +| +9 ++ +- +. +. +. +/ +mac +/ +desktop_frame_iosurface +. +mm +| +37 ++ ++ ++ ++ ++ ++ +- +- +. +. +. +/ +mac +/ +screen_capturer_sck +. +mm +| +89 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +- +- +3 +files +changed +120 +insertions +( ++ +) +15 +deletions +( +- +) +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +desktop_frame_iosurface +. +h +b +/ +modules +/ +desktop_capture +/ +mac +/ +desktop_frame_iosurface +. +h +index +73da0f693c +. +. +ed90e40993 +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +mac +/ +desktop_frame_iosurface +. +h ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +desktop_frame_iosurface +. +h +- +26 +7 ++ +26 +7 +class +DesktopFrameIOSurface +final +: +public +DesktopFrame +{ +/ +/ +Lock +an +IOSurfaceRef +containing +a +snapshot +of +a +display +. +Return +NULL +if +/ +/ +failed +to +lock +. +static +std +: +: +unique_ptr +< +DesktopFrameIOSurface +> +Wrap +( +- +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +io_surface +) +; ++ +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +io_surface +CGRect +rect += +{ +} +) +; +~ +DesktopFrameIOSurface +( +) +override +; +- +35 +7 ++ +35 +12 +class +DesktopFrameIOSurface +final +: +public +DesktopFrame +{ +private +: +/ +/ +This +constructor +expects +io_surface +to +hold +a +non +- +null +IOSurfaceRef +. +- +explicit +DesktopFrameIOSurface +( +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +io_surface +) +; ++ +DesktopFrameIOSurface +( ++ +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +io_surface ++ +uint8_t +* +data ++ +int32_t +width ++ +int32_t +height ++ +int32_t +stride +) +; +const +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +io_surface_ +; +} +; +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +desktop_frame_iosurface +. +mm +b +/ +modules +/ +desktop_capture +/ +mac +/ +desktop_frame_iosurface +. +mm +index +b59b319db9 +. +. +7a5b595f19 +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +mac +/ +desktop_frame_iosurface +. +mm ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +desktop_frame_iosurface +. +mm +- +17 +7 ++ +17 +7 +namespace +webrtc +{ +/ +/ +static +std +: +: +unique_ptr +< +DesktopFrameIOSurface +> +DesktopFrameIOSurface +: +: +Wrap +( +- +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +io_surface +) +{ ++ +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +io_surface +CGRect +rect +) +{ +if +( +! +io_surface +) +{ +return +nullptr +; +} +- +40 +14 ++ +40 +39 +std +: +: +unique_ptr +< +DesktopFrameIOSurface +> +DesktopFrameIOSurface +: +: +Wrap +( +return +nullptr +; +} +- +return +std +: +: +unique_ptr +< +DesktopFrameIOSurface +> +( +new +DesktopFrameIOSurface +( +io_surface +) +) +; ++ +size_t +surfaceWidth += +IOSurfaceGetWidth +( +io_surface +. +get +( +) +) +; ++ +size_t +surfaceHeight += +IOSurfaceGetHeight +( +io_surface +. +get +( +) +) +; ++ +uint8_t +* +data += +static_cast +< +uint8_t +* +> +( +IOSurfaceGetBaseAddress +( +io_surface +. +get +( +) +) +) +; ++ +size_t +offset += +0 +; ++ +size_t +width += +surfaceWidth +; ++ +size_t +height += +surfaceHeight +; ++ +size_t +offsetColumns += +0 +; ++ +size_t +offsetRows += +0 +; ++ +int32_t +stride += +IOSurfaceGetBytesPerRow +( +io_surface +. +get +( +) +) +; ++ +if +( +rect +. +size +. +width +> +0 +& +& +rect +. +size +. +height +> +0 +) +{ ++ +width += +std +: +: +floor +( +rect +. +size +. +width +) +; ++ +height += +std +: +: +floor +( +rect +. +size +. +height +) +; ++ +offsetColumns += +std +: +: +ceil +( +rect +. +origin +. +x +) +; ++ +offsetRows += +std +: +: +ceil +( +rect +. +origin +. +y +) +; ++ +RTC_CHECK_GE +( +surfaceWidth +offsetColumns ++ +width +) +; ++ +RTC_CHECK_GE +( +surfaceHeight +offsetRows ++ +height +) +; ++ +offset += +stride +* +offsetRows ++ +bytes_per_pixel +* +offsetColumns +; ++ +} ++ ++ +RTC_LOG +( +LS_VERBOSE +) +< +< +" +DesktopFrameIOSurface +wrapping +IOSurface +with +size +" +< +< +surfaceWidth +< +< +" +x +" ++ +< +< +surfaceHeight +< +< +" +. +Cropping +to +( +" +< +< +offsetColumns +< +< +" +" +< +< +offsetRows +< +< +" +; +" ++ +< +< +width +< +< +" +x +" +< +< +height +< +< +" +) +. +Stride += +" +< +< +stride +/ +bytes_per_pixel ++ +< +< +" +buffer +- +offset +- +px += +" +< +< +offset +/ +bytes_per_pixel +< +< +" +buffer +- +offset +- +bytes += +" +< +< +offset +; ++ ++ +return +std +: +: +unique_ptr +< +DesktopFrameIOSurface +> +( +new +DesktopFrameIOSurface +( +io_surface +data ++ +offset +width +height +stride +) +) +; +} +- +DesktopFrameIOSurface +: +: +DesktopFrameIOSurface +( +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +io_surface +) ++ +DesktopFrameIOSurface +: +: +DesktopFrameIOSurface +( ++ +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +io_surface +uint8_t +* +data +int32_t +width +int32_t +height +int32_t +stride +) +: +DesktopFrame +( +- +DesktopSize +( +IOSurfaceGetWidth +( +io_surface +. +get +( +) +) +IOSurfaceGetHeight +( +io_surface +. +get +( +) +) +) +- +IOSurfaceGetBytesPerRow +( +io_surface +. +get +( +) +) +- +static_cast +< +uint8_t +* +> +( +IOSurfaceGetBaseAddress +( +io_surface +. +get +( +) +) +) ++ +DesktopSize +( +width +height +) ++ +stride ++ +data +nullptr +) +io_surface_ +( +io_surface +) +{ +RTC_DCHECK +( +io_surface_ +) +; +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +index +e98b61ccdb +. +. +19c887d435 +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +- +169 +6 ++ +169 +12 +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +ScreenCapturerSck +final +: +public +DesktopCapture +/ +/ +TODO +: +crbug +. +com +/ +327458809 +- +Replace +this +flag +with +ScreenCapturerHelper +to +more +accurately +/ +/ +track +the +dirty +rectangles +from +the +SCStreamFrameInfoDirtyRects +attachment +. +bool +frame_is_dirty_ +RTC_GUARDED_BY +( +latest_frame_lock_ +) += +true +; ++ ++ +/ +/ +Tracks +whether +a +reconfigure +is +needed +. ++ +bool +frame_needs_reconfigure_ +RTC_GUARDED_BY +( +latest_frame_lock_ +) += +false +; ++ +/ +/ +If +a +reconfigure +is +needed +this +will +be +set +to +the +size +in +pixels +required +to +fit +the +entire ++ +/ +/ +source +without +downscaling +. ++ +std +: +: +optional +< +CGSize +> +frame_reconfigure_img_size_ +RTC_GUARDED_BY +( +latest_frame_lock_ +) +; +} +; +ScreenCapturerSck +: +: +ScreenCapturerSck +( +const +DesktopCaptureOptions +& +options +) +- +240 +6 ++ +246 +7 +void +ScreenCapturerSck +: +: +CaptureFrame +( +) +{ +} +std +: +: +unique_ptr +< +DesktopFrame +> +frame +; ++ +bool +needs_reconfigure += +false +; +{ +MutexLock +lock +( +& +latest_frame_lock_ +) +; +if +( +latest_frame_ +) +{ +- +250 +6 ++ +257 +8 +void +ScreenCapturerSck +: +: +CaptureFrame +( +) +{ +frame_is_dirty_ += +false +; +} +} ++ +needs_reconfigure += +frame_needs_reconfigure_ +; ++ +frame_needs_reconfigure_ += +false +; +} +if +( +frame +) +{ +- +260 +6 ++ +269 +10 +void +ScreenCapturerSck +: +: +CaptureFrame +( +) +{ +RTC_LOG +( +LS_VERBOSE +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +CaptureFrame +( +) +- +> +ERROR_TEMPORARY +" +; +callback_ +- +> +OnCaptureResult +( +Result +: +: +ERROR_TEMPORARY +nullptr +) +; +} ++ ++ +if +( +needs_reconfigure +) +{ ++ +StartOrReconfigureCapturer +( +) +; ++ +} +} +void +ScreenCapturerSck +: +: +EnsureVisible +( +) +{ +- +283 +6 ++ +296 +9 +void +ScreenCapturerSck +: +: +EnsureVisible +( +) +{ +stream += +stream_ +; +stream_ += +nil +; +filter_ += +nil +; ++ +MutexLock +lock2 +( +& +latest_frame_lock_ +) +; ++ +frame_needs_reconfigure_ += +false +; ++ +frame_reconfigure_img_size_ += +std +: +: +nullopt +; +} +[ +stream +removeStreamOutput +: +helper_ +type +: +SCStreamOutputTypeScreen +error +: +nil +] +; +[ +stream +stopCaptureWithCompletionHandler +: +nil +] +; +- +439 +12 ++ +455 +21 +void +ScreenCapturerSck +: +: +StartWithFilter +( +SCContentFilter +* +__strong +filter +) +{ +{ +MutexLock +lock +( +& +latest_frame_lock_ +) +; +latest_frame_dpi_ += +filter +. +pointPixelScale +* +kStandardDPI +; ++ +if +( +filter_ +! += +filter +) +{ ++ +frame_reconfigure_img_size_ += +std +: +: +nullopt +; ++ +} ++ +auto +sourceImgRect += +frame_reconfigure_img_size_ +. +value_or +( +CGSizeMake +( ++ +filter +. +contentRect +. +size +. +width +* +filter +. +pointPixelScale ++ +filter +. +contentRect +. +size +. +height +* +filter +. +pointPixelScale +) +) +; ++ +config +. +width += +sourceImgRect +. +width +; ++ +config +. +height += +sourceImgRect +. +height +; +} +filter_ += +filter +; +if +( +stream_ +) +{ +- +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +Updating +stream +configuration +. +" +; ++ +RTC_LOG +( +LS_INFO +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +Updating +stream +configuration +to +size += +" ++ +< +< +config +. +width +< +< +" +x +" +< +< +config +. +height +< +< +" +. +" +; +[ +stream_ +updateContentFilter +: +filter +completionHandler +: +nil +] +; +[ +stream_ +updateConfiguration +: +config +completionHandler +: +nil +] +; +} +else +{ +- +481 +20 ++ +506 +63 +void +ScreenCapturerSck +: +: +StartWithFilter +( +SCContentFilter +* +__strong +filter +) +{ +} +void +ScreenCapturerSck +: +: +OnNewIOSurface +( +IOSurfaceRef +io_surface +NSDictionary +* +attachment +) +{ +- +RTC_LOG +( +LS_VERBOSE +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ +- +< +< +" +width += +" +< +< +IOSurfaceGetWidth +( +io_surface +) +- +< +< +" +height += +" +< +< +IOSurfaceGetHeight +( +io_surface +) +< +< +" +. +" +; +- ++ +double +scaleFactor += +1 +; ++ +double +contentScale += +1 +; ++ +CGRect +contentRect += +{ +} +; ++ +CGRect +boundingRect += +{ +} +; ++ +CGRect +overlayRect += +{ +} +; +const +auto +* +dirty_rects += +( +NSArray +* +) +attachment +[ +SCStreamFrameInfoDirtyRects +] +; ++ +if +( +auto +factor += +( +NSNumber +* +) +attachment +[ +SCStreamFrameInfoScaleFactor +] +) +{ ++ +scaleFactor += +[ +factor +floatValue +] +; ++ +} ++ +if +( +auto +scale += +( +NSNumber +* +) +attachment +[ +SCStreamFrameInfoContentScale +] +) +{ ++ +contentScale += +[ +scale +floatValue +] +; ++ +} ++ +if +( +const +auto +* +rectDict += +( +__bridge +CFDictionaryRef +) +attachment +[ +SCStreamFrameInfoContentRect +] +) +{ ++ +if +( +! +CGRectMakeWithDictionaryRepresentation +( +rectDict +& +contentRect +) +) +{ ++ +contentRect += +CGRect +( +) +; ++ +} ++ +} ++ +if +( +const +auto +* +rectDict += +( +__bridge +CFDictionaryRef +) +attachment +[ +SCStreamFrameInfoBoundingRect +] +) +{ ++ +if +( +! +CGRectMakeWithDictionaryRepresentation +( +rectDict +& +boundingRect +) +) +{ ++ +boundingRect += +CGRect +( +) +; ++ +} ++ +} ++ +if +( +available +( +macOS +14 +. +2 +* +) +) +{ ++ +if +( +const +auto +* +rectDict += +( +__bridge +CFDictionaryRef +) +attachment +[ +SCStreamFrameInfoPresenterOverlayContentRect +] +) +{ ++ +if +( +! +CGRectMakeWithDictionaryRepresentation +( +rectDict +& +overlayRect +) +) +{ ++ +overlayRect += +CGRect +( +) +; ++ +} ++ +} ++ +} ++ ++ ++ +auto +imgBoundingRect += +CGRectMake +( ++ +scaleFactor +* +boundingRect +. +origin +. +x ++ +scaleFactor +* +boundingRect +. +origin +. +y ++ +scaleFactor +* +boundingRect +. +size +. +width ++ +scaleFactor +* +boundingRect +. +size +. +height +) +; +rtc +: +: +ScopedCFTypeRef +< +IOSurfaceRef +> +scoped_io_surface +( +io_surface +rtc +: +: +RetainPolicy +: +: +RETAIN +) +; +std +: +: +unique_ptr +< +DesktopFrameIOSurface +> +desktop_frame_io_surface += +- +DesktopFrameIOSurface +: +: +Wrap +( +scoped_io_surface +) +; ++ +DesktopFrameIOSurface +: +: +Wrap +( +scoped_io_surface +imgBoundingRect +) +; +if +( +! +desktop_frame_io_surface +) +{ +RTC_LOG +( +LS_ERROR +) +< +< +" +Failed +to +lock +IOSurface +. +" +; +return +; +} ++ +const +size_t +width += +IOSurfaceGetWidth +( +io_surface +) +; ++ +const +size_t +height += +IOSurfaceGetHeight +( +io_surface +) +; ++ ++ +RTC_LOG +( +LS_VERBOSE +) +< +< +" +ScreenCapturerSck +" +< +< +this +< +< +" +" +< +< +__func__ ++ +< +< +" +. +New +surface +: +width += +" +< +< +width +< +< +" +height += +" +< +< +height ++ +< +< +" +contentRect += +" +< +< +NSStringFromRect +( +contentRect +) +. +UTF8String ++ +< +< +" +boundingRect += +" +< +< +NSStringFromRect +( +boundingRect +) +. +UTF8String ++ +< +< +" +overlayRect += +( +" +< +< +NSStringFromRect +( +overlayRect +) +. +UTF8String ++ +< +< +" +scaleFactor += +" +< +< +scaleFactor +< +< +" +contentScale += +" +< +< +contentScale ++ +< +< +" +. +Cropping +to +rect +" +< +< +NSStringFromRect +( +imgBoundingRect +) +. +UTF8String ++ +< +< +" +. +" +; ++ +std +: +: +unique_ptr +< +SharedDesktopFrame +> +frame += +SharedDesktopFrame +: +: +Wrap +( +std +: +: +move +( +desktop_frame_io_surface +) +) +; +- +529 +8 ++ +597 +15 +void +ScreenCapturerSck +: +: +OnNewIOSurface +( +IOSurfaceRef +io_surface +NSDictionary +* +at +} +} ++ +MutexLock +lock +( +& +latest_frame_lock_ +) +; ++ +if +( +contentScale +> +0 +& +& +contentScale +< +1 +) +{ ++ +frame_needs_reconfigure_ += +true +; ++ +double +scale += +1 +/ +contentScale +; ++ +frame_reconfigure_img_size_ += +CGSizeMake +( ++ +std +: +: +ceil +( +scale +* +width +) ++ +std +: +: +ceil +( +scale +* +height +) +) +; ++ +} +if +( +dirty +) +{ +- +MutexLock +lock +( +& +latest_frame_lock_ +) +; +frame_is_dirty_ += +true +; +std +: +: +swap +( +latest_frame_ +frame +) +; +} diff --git a/third_party/libwebrtc/moz-patch-stack/0126.patch b/third_party/libwebrtc/moz-patch-stack/0126.patch new file mode 100644 index 000000000000..49c0888a262b --- /dev/null +++ b/third_party/libwebrtc/moz-patch-stack/0126.patch @@ -0,0 +1,385 @@ +From +: +Andreas +Pehrson +< +apehrson +mozilla +. +com +> +Date +: +Thu +12 +Sep +2024 +22 +: +36 +: +00 ++ +0000 +Subject +: +Bug +1918096 +- +In +ScreenCapturerSck +skip +some +processing +when +possible +. +r += +webrtc +- +reviewers +ng +No +need +to +update +the +last +frame +unless +it +has +changed +. +Differential +Revision +: +https +: +/ +/ +phabricator +. +services +. +mozilla +. +com +/ +D221942 +Mercurial +Revision +: +https +: +/ +/ +hg +. +mozilla +. +org +/ +mozilla +- +central +/ +rev +/ +8d52f2fd575479da72508033b3a2151906e2bf19 +- +- +- +. +. +. +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +| +17 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +1 +file +changed +17 +insertions +( ++ +) +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +index +19c887d435 +. +. +482501e2d9 +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +- +511 +6 ++ +511 +7 +void +ScreenCapturerSck +: +: +OnNewIOSurface +( +IOSurfaceRef +io_surface +NSDictionary +* +at +CGRect +contentRect += +{ +} +; +CGRect +boundingRect += +{ +} +; +CGRect +overlayRect += +{ +} +; ++ +SCFrameStatus +status += +SCFrameStatusStopped +; +const +auto +* +dirty_rects += +( +NSArray +* +) +attachment +[ +SCStreamFrameInfoDirtyRects +] +; +if +( +auto +factor += +( +NSNumber +* +) +attachment +[ +SCStreamFrameInfoScaleFactor +] +) +{ +scaleFactor += +[ +factor +floatValue +] +; +- +536 +6 ++ +537 +22 +void +ScreenCapturerSck +: +: +OnNewIOSurface +( +IOSurfaceRef +io_surface +NSDictionary +* +at +} +} ++ +if +( +auto +statusNr += +( +NSNumber +* +) +attachment +[ +SCStreamFrameInfoStatus +] +) +{ ++ +status += +( +SCFrameStatus +) +[ +statusNr +integerValue +] +; ++ +} ++ ++ +switch +( +status +) +{ ++ +case +SCFrameStatusBlank +: ++ +case +SCFrameStatusIdle +: ++ +case +SCFrameStatusSuspended +: ++ +case +SCFrameStatusStopped +: ++ +/ +/ +No +new +frame +. +Ignore +. ++ +return +; ++ +case +SCFrameStatusComplete +: ++ +case +SCFrameStatusStarted +: ++ +/ +/ +New +frame +. +Process +it +. ++ +break +; ++ +} +auto +imgBoundingRect += +CGRectMake +( +scaleFactor +* +boundingRect +. +origin +. +x diff --git a/third_party/libwebrtc/moz-patch-stack/0127.patch b/third_party/libwebrtc/moz-patch-stack/0127.patch new file mode 100644 index 000000000000..4daa3e9ea1d3 --- /dev/null +++ b/third_party/libwebrtc/moz-patch-stack/0127.patch @@ -0,0 +1,1042 @@ +From +: +Andreas +Pehrson +< +apehrson +mozilla +. +com +> +Date +: +Fri +13 +Sep +2024 +09 +: +48 +: +00 ++ +0000 +Subject +: +Bug +1918096 +- +Make +SckPickerHandle +thread +safe +. +r += +padenot +We +cannot +guarantee +that +the +thread +it +is +used +on +is +static +as +both +the +VideoCapture +and +DesktopCapture +threads +can +come +and +go +. +Differential +Revision +: +https +: +/ +/ +phabricator +. +services +. +mozilla +. +com +/ +D222082 +Mercurial +Revision +: +https +: +/ +/ +hg +. +mozilla +. +org +/ +mozilla +- +central +/ +rev +/ +cfcdd5339805363c495841abc4b4f82cd287f712 +- +- +- +. +. +. +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm +| +90 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +- +- +- +- +- +- +1 +file +changed +62 +insertions +( ++ +) +28 +deletions +( +- +) +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm +b +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm +index +25e98b671f +. +. +0f26be79d1 +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +sck_picker_handle +. +mm +- +12 +57 ++ +12 +91 +# +import +< +ScreenCaptureKit +/ +ScreenCaptureKit +. +h +> +- +# +include +" +api +/ +sequence_checker +. +h +" ++ +# +include +" +absl +/ +base +/ +attributes +. +h +" ++ +# +include +" +rtc_base +/ +synchronization +/ +mutex +. +h +" ++ ++ +# +include +< +memory +> ++ +# +include +< +optional +> +namespace +webrtc +{ +- +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +SckPickerHandle +: +public +SckPickerHandleInterface +{ ++ +class +SckPickerProxy +; ++ ++ +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +SckPickerProxy +{ +public +: +- +explicit +SckPickerHandle +( +DesktopCapturer +: +: +SourceId +source +) +: +source_ +( +source +) +{ +- +RTC_DCHECK_RUN_ON +( +& +checker_ +) +; +- +RTC_CHECK_LE +( +sHandleCount +maximumStreamCount +) +; +- +if +( +sHandleCount ++ ++ += += +0 +) +{ ++ +static +SckPickerProxy +* +Get +( +) +{ ++ +static +SckPickerProxy +* +sPicker += +new +SckPickerProxy +( +) +; ++ +return +sPicker +; ++ +} ++ ++ +bool +AtCapacity +( +) +const +{ ++ +MutexLock +lock +( +& +mutex_ +) +; ++ +return +AtCapacityLocked +( +) +; ++ +} ++ ++ +SCContentSharingPicker +* +GetPicker +( +) +const +{ +return +SCContentSharingPicker +. +sharedPicker +; +} ++ ++ +ABSL_MUST_USE_RESULT +std +: +: +optional +< +DesktopCapturer +: +: +SourceId +> +AcquireSourceId +( +) +{ ++ +MutexLock +lock +( +& +mutex_ +) +; ++ +if +( +AtCapacityLocked +( +) +) +{ ++ +return +std +: +: +nullopt +; ++ +} ++ +if +( +handle_count_ ++ ++ += += +0 +) +{ +auto +* +picker += +GetPicker +( +) +; +picker +. +maximumStreamCount += +[ +NSNumber +numberWithUnsignedInt +: +maximumStreamCount +] +; +picker +. +active += +YES +; +} ++ +return ++ ++ +unique_source_id_ +; +} +- +~ +SckPickerHandle +( +) +{ +- +RTC_DCHECK_RUN_ON +( +& +checker_ +) +; +- +if +( +- +- +sHandleCount +> +0 +) +{ ++ +void +RelinquishSourceId +( +DesktopCapturer +: +: +SourceId +source +) +{ ++ +MutexLock +lock +( +& +mutex_ +) +; ++ +if +( +- +- +handle_count_ +> +0 +) +{ +return +; +} +GetPicker +( +) +. +active += +NO +; +} +- +SCContentSharingPicker +* +GetPicker +( +) +const +override +{ +- +return +SCContentSharingPicker +. +sharedPicker +; ++ +private +: ++ +bool +AtCapacityLocked +( +) +const +{ ++ +mutex_ +. +AssertHeld +( +) +; ++ +return +handle_count_ += += +maximumStreamCount +; +} +- +DesktopCapturer +: +: +SourceId +Source +( +) +const +override +{ +- +return +source_ +; ++ +mutable +Mutex +mutex_ +; ++ +/ +/ +100 +is +an +arbitrary +number +that +seems +high +enough +to +never +get +reached +while +still +providing ++ +/ +/ +a +reasonably +low +upper +bound +. ++ +static +constexpr +size_t +maximumStreamCount += +100 +; ++ +size_t +handle_count_ +RTC_GUARDED_BY +( +mutex_ +) += +0 +; ++ +DesktopCapturer +: +: +SourceId +unique_source_id_ +RTC_GUARDED_BY +( +mutex_ +) += +0 +; ++ +} +; ++ ++ +class +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +SckPickerHandle +: +public +SckPickerHandleInterface +{ ++ +public +: ++ +static +std +: +: +unique_ptr +< +SckPickerHandle +> +Create +( +SckPickerProxy +* +proxy +) +{ ++ +std +: +: +optional +< +DesktopCapturer +: +: +SourceId +> +id += +proxy +- +> +AcquireSourceId +( +) +; ++ +if +( +! +id +) +{ ++ +return +nullptr +; ++ +} ++ +return +std +: +: +unique_ptr +< +SckPickerHandle +> +( +new +SckPickerHandle +( +proxy +* +id +) +) +; +} +- +static +bool +AtCapacity +( +) +{ +return +sHandleCount += += +maximumStreamCount +; +} ++ +~ +SckPickerHandle +( +) +{ +proxy_ +- +> +RelinquishSourceId +( +source_ +) +; +} ++ ++ +SCContentSharingPicker +* +GetPicker +( +) +const +override +{ +return +proxy_ +- +> +GetPicker +( +) +; +} ++ ++ +DesktopCapturer +: +: +SourceId +Source +( +) +const +override +{ +return +source_ +; +} +private +: +- +/ +/ +100 +is +an +arbitrary +number +that +seems +high +enough +to +never +get +reached +while +still +providing +- +/ +/ +a +reasonably +low +upper +bound +. +- +static +constexpr +size_t +maximumStreamCount += +100 +; +- +static +size_t +sHandleCount +; +- +SequenceChecker +checker_ +; ++ +SckPickerHandle +( +SckPickerProxy +* +proxy +DesktopCapturer +: +: +SourceId +source +) ++ +: +proxy_ +( +proxy +) +source_ +( +source +) +{ +} ++ ++ +SckPickerProxy +* +const +proxy_ +; +const +DesktopCapturer +: +: +SourceId +source_ +; +} +; +- +size_t +SckPickerHandle +: +: +sHandleCount += +0 +; +- +- +std +: +: +unique_ptr +< +SckPickerHandleInterface +> +CreateSckPickerHandle +( +) +API_AVAILABLE +( +macos +( +14 +. +0 +) +) +{ +- +if +( +SckPickerHandle +: +: +AtCapacity +( +) +) +{ +- +return +nullptr +; +- +} +- +static +DesktopCapturer +: +: +SourceId +unique_source_id += +0 +; +- +return +std +: +: +make_unique +< +SckPickerHandle +> +( ++ ++ +unique_source_id +) +; ++ +std +: +: +unique_ptr +< +SckPickerHandleInterface +> +CreateSckPickerHandle +( +) +{ ++ +return +SckPickerHandle +: +: +Create +( +SckPickerProxy +: +: +Get +( +) +) +; +} +- +} +/ +/ +namespace +webrtc +\ +No +newline +at +end +of +file ++ +} +/ +/ +namespace +webrtc diff --git a/third_party/libwebrtc/moz-patch-stack/0128.patch b/third_party/libwebrtc/moz-patch-stack/0128.patch new file mode 100644 index 000000000000..98cd1610ea39 --- /dev/null +++ b/third_party/libwebrtc/moz-patch-stack/0128.patch @@ -0,0 +1,389 @@ +From +: +Andreas +Pehrson +< +apehrson +mozilla +. +com +> +Date +: +Mon +16 +Sep +2024 +14 +: +51 +: +00 ++ +0000 +Subject +: +Bug +1918996 +- +Use +SCShareableContentStyleNone +on +macOS +15 +. +r += +webrtc +- +reviewers +jib +Differential +Revision +: +https +: +/ +/ +phabricator +. +services +. +mozilla +. +com +/ +D222270 +Mercurial +Revision +: +https +: +/ +/ +hg +. +mozilla +. +org +/ +mozilla +- +central +/ +rev +/ +ade6f6dc0c5a5df1c87e78a45b2878c4ade54358 +- +- +- +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +| +14 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +- +- +- +1 +file +changed +11 +insertions +( ++ +) +3 +deletions +( +- +) +diff +- +- +git +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +index +482501e2d9 +. +. +9e45e94ccd +100644 +- +- +- +a +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm ++ ++ ++ +b +/ +modules +/ +desktop_capture +/ +mac +/ +screen_capturer_sck +. +mm +- +305 +10 ++ +305 +18 +void +ScreenCapturerSck +: +: +EnsureVisible +( +) +{ +SCContentSharingPickerConfiguration +* +config += +picker +. +defaultConfiguration +; +config +. +allowedPickerModes += +picker_modes_ +; +picker +. +defaultConfiguration += +config +; ++ +SCShareableContentStyle +style += +SCShareableContentStyleNone +; +/ +/ +Pick +a +sensible +style +to +start +out +with +based +on +our +current +mode +. +- +/ +/ +Default +to +Screen +because +if +using +Window +the +picker +automatically +hides +- +/ +/ +our +current +window +to +show +others +. +- +SCShareableContentStyle +style += +SCShareableContentStyleDisplay +; ++ +if +( +available +( +macOS +15 +* +) +) +{ ++ +/ +/ +Stick +with +None +because +if +we +use +Display +the +picker +doesn +' +t +let +us ++ +/ +/ +pick +a +window +when +first +opened +. +Behaves +like +Window +in +14 +except +doesn +' +t ++ +/ +/ +change +window +focus +. ++ +} +else +{ ++ +/ +/ +Default +to +Display +because +if +using +Window +the +picker +automatically +hides ++ +/ +/ +our +current +window +to +show +others +. +Saves +a +click +compared +to +None +when ++ +/ +/ +picking +a +display +. ++ +style += +SCShareableContentStyleDisplay +; ++ +} +if +( +picker_modes_ += += +SCContentSharingPickerModeSingleDisplay +) +{ +style += +SCShareableContentStyleDisplay +; +} +else +if +( +picker_modes_ += += +SCContentSharingPickerModeSingleWindow +| +| diff --git a/third_party/libwebrtc/moz-patch-stack/0129.patch b/third_party/libwebrtc/moz-patch-stack/0129.patch new file mode 100644 index 000000000000..bd109f2cdcde --- /dev/null +++ b/third_party/libwebrtc/moz-patch-stack/0129.patch @@ -0,0 +1,507 @@ +From +: +Jan +Grulich +< +jgrulich +redhat +. +com +> +Date +: +Tue +24 +Sep +2024 +11 +: +20 +: +00 ++ +0000 +Subject +: +Bug +1920460 +- +WebRTC +backport +: +PipeWire +camera +: +get +max +FPS +for +each +format +when +specified +as +list +r += +pehrsons +webrtc +- +reviewers +In +many +cases +the +framerate +can +be +specified +as +list +of +possible +values +and +in +that +case +we +would +end +up +with +max +FPS +to +be +set +to +0 +as +this +case +was +not +handled +. +This +is +a +simple +backport +of +an +WebRTC +upstream +change +. +Upstream +commit +: +3aa47cfd30dc965446cf1405bb062b756a62e6d1 +Differential +Revision +: +https +: +/ +/ +phabricator +. +services +. +mozilla +. +com +/ +D223112 +Mercurial +Revision +: +https +: +/ +/ +hg +. +mozilla +. +org +/ +mozilla +- +central +/ +rev +/ +90f241650577182dbd08f8c5b96c645cf48ff397 +- +- +- +modules +/ +video_capture +/ +linux +/ +pipewire_session +. +cc +| +12 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +- +- +1 +file +changed +10 +insertions +( ++ +) +2 +deletions +( +- +) +diff +- +- +git +a +/ +modules +/ +video_capture +/ +linux +/ +pipewire_session +. +cc +b +/ +modules +/ +video_capture +/ +linux +/ +pipewire_session +. +cc +index +d9bc49d521 +. +. +e5db278ff6 +100644 +- +- +- +a +/ +modules +/ +video_capture +/ +linux +/ +pipewire_session +. +cc ++ ++ ++ +b +/ +modules +/ +video_capture +/ +linux +/ +pipewire_session +. +cc +- +17 +6 ++ +17 +8 +# +include +< +spa +/ +param +/ +video +/ +raw +. +h +> +# +include +< +spa +/ +pod +/ +parser +. +h +> ++ +# +include +< +algorithm +> ++ +# +include +" +common_video +/ +libyuv +/ +include +/ +webrtc_libyuv +. +h +" +# +include +" +modules +/ +video_capture +/ +device_info_impl +. +h +" +# +include +" +rtc_base +/ +logging +. +h +" +- +152 +9 ++ +154 +15 +void +PipeWireNode +: +: +OnNodeParam +( +void +* +data +fract += +static_cast +< +spa_fraction +* +> +( +SPA_POD_BODY +( +val +) +) +; +- +if +( +choice += += +SPA_CHOICE_None +) ++ +if +( +choice += += +SPA_CHOICE_None +) +{ +cap +. +maxFPS += +1 +. +0 +* +fract +[ +0 +] +. +num +/ +fract +[ +0 +] +. +denom +; +- +else +if +( +choice += += +SPA_CHOICE_Range +& +& +fract +[ +1 +] +. +num +> +0 +) ++ +} +else +if +( +choice += += +SPA_CHOICE_Enum +) +{ ++ +for +( +uint32_t +i += +1 +; +i +< +n_items +; +i ++ ++ +) +{ ++ +cap +. +maxFPS += +std +: +: +max +( ++ +static_cast +< +int32_t +> +( +1 +. +0 +* +fract +[ +i +] +. +num +/ +fract +[ +i +] +. +denom +) ++ +cap +. +maxFPS +) +; ++ +} ++ +} +else +if +( +choice += += +SPA_CHOICE_Range +& +& +fract +[ +1 +] +. +num +> +0 +) +cap +. +maxFPS += +1 +. +0 +* +fract +[ +1 +] +. +num +/ +fract +[ +1 +] +. +denom +; +} +} diff --git a/third_party/libwebrtc/moz-patch-stack/0130.patch b/third_party/libwebrtc/moz-patch-stack/0130.patch new file mode 100644 index 000000000000..4df6eeaa864d --- /dev/null +++ b/third_party/libwebrtc/moz-patch-stack/0130.patch @@ -0,0 +1,1335 @@ +From +: +Jan +Grulich +< +jgrulich +redhat +. +com +> +Date +: +Wed +25 +Sep +2024 +06 +: +52 +: +00 ++ +0000 +Subject +: +Bug +1920472 +- +WebRTC +backport +: +PipeWire +camera +: +use +exact +stream +parameters +specified +by +capability +r += +pehrsons +webrtc +- +reviewers +We +currently +specify +stream +parameters +to +be +a +range +for +both +framerate +and +resolution +where +preferred +value +is +specified +. +The +preferred +value +doesn +' +t +seem +to +be +taken +into +account +and +we +end +up +accepting +resolution +from +1x1 +to +MAX_INTxMAX_INT +. +In +case +the +other +side +tries +to +first +match +with +lower +resolution +than +requested +we +will +happily +match +it +and +start +streaming +low +quality +video +. +We +should +instead +request +the +exact +stream +parameters +as +specified +by +requested +capability +. +This +capability +always +come +from +what +has +been +originally +reported +as +supported +so +it +shouldn +' +t +happen +we +don +' +t +find +a +matching +stream +. +This +also +applies +to +requested +video +format +. +We +previously +requested +mjpg +for +streams +with +resolution +higher +than +640x480 +but +it +doesn +' +t +necessarily +mean +the +camera +supports +mjpg +for +the +requested +resolution +. +Again +refer +to +requested +capability +in +this +case +as +it +should +indicate +what +is +supported +and +we +know +we +can +request +exactly +the +same +video +format +. +It +can +happen +that +framerate +is +set +to +0 +as +unspecified +. +In +that +case +keep +using +a +range +as +before +but +with +more +sane +values +. +This +is +a +simple +backport +of +an +WebRTC +upstream +change +. +Upstream +commit +: +9703f8474f156e08e4a96dc36253f1cdccd549e1 +Differential +Revision +: +https +: +/ +/ +phabricator +. +services +. +mozilla +. +com +/ +D223119 +Mercurial +Revision +: +https +: +/ +/ +hg +. +mozilla +. +org +/ +mozilla +- +central +/ +rev +/ +75a999c1bd73f3fe323652aa1def8d2daa3ebb2d +- +- +- +. +. +. +/ +linux +/ +video_capture_pipewire +. +cc +| +85 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +- +- +- +- +- +- +- +- +. +. +. +/ +linux +/ +video_capture_pipewire +. +h +| +1 ++ +2 +files +changed +51 +insertions +( ++ +) +35 +deletions +( +- +) +diff +- +- +git +a +/ +modules +/ +video_capture +/ +linux +/ +video_capture_pipewire +. +cc +b +/ +modules +/ +video_capture +/ +linux +/ +video_capture_pipewire +. +cc +index +940db43fd5 +. +. +61b1b54233 +100644 +- +- +- +a +/ +modules +/ +video_capture +/ +linux +/ +video_capture_pipewire +. +cc ++ ++ ++ +b +/ +modules +/ +video_capture +/ +linux +/ +video_capture_pipewire +. +cc +- +52 +10 ++ +52 +20 +VideoType +VideoCaptureModulePipeWire +: +: +PipeWireRawFormatToVideoType +( +if +( +spa_and_pixel_format +. +spa_format += += +spa_format +) +return +spa_and_pixel_format +. +video_type +; +} +- +RTC_LOG +( +LS_INFO +) +< +< +" +Unsupported +pixel +format +: +" +< +< +spa_format +; ++ +RTC_LOG +( +LS_WARNING +) +< +< +" +Unsupported +pixel +format +: +" +< +< +spa_format +; +return +VideoType +: +: +kUnknown +; +} ++ +uint32_t +VideoCaptureModulePipeWire +: +: +VideoTypeToPipeWireRawFormat +( ++ +VideoType +type +) +{ ++ +for +( +const +auto +& +spa_and_pixel_format +: +kSupportedFormats +) +{ ++ +if +( +spa_and_pixel_format +. +video_type += += +type +) ++ +return +spa_and_pixel_format +. +spa_format +; ++ +} ++ +RTC_LOG +( +LS_WARNING +) +< +< +" +Unsupported +video +type +: +" +< +< +static_cast +< +int +> +( +type +) +; ++ +return +SPA_VIDEO_FORMAT_UNKNOWN +; ++ +} ++ +VideoCaptureModulePipeWire +: +: +VideoCaptureModulePipeWire +( +VideoCaptureOptions +* +options +) +: +VideoCaptureImpl +( +) +- +88 +45 ++ +98 +53 +int32_t +VideoCaptureModulePipeWire +: +: +Init +( +const +char +* +deviceUniqueId +) +{ +} +static +spa_pod +* +BuildFormat +( +spa_pod_builder +* +builder +- +uint32_t +format ++ +VideoType +video_type +uint32_t +width +uint32_t +height +float +frame_rate +) +{ +- +spa_pod_frame +frames +[ +2 +] +; ++ +spa_pod_frame +frame +; ++ ++ +const +uint32_t +media_subtype += +video_type += += +VideoType +: +: +kMJPEG ++ +? +SPA_MEDIA_SUBTYPE_mjpg ++ +: +SPA_MEDIA_SUBTYPE_raw +; +- +spa_pod_builder_push_object +( +builder +& +frames +[ +0 +] +SPA_TYPE_OBJECT_Format ++ +spa_pod_builder_push_object +( +builder +& +frame +SPA_TYPE_OBJECT_Format +SPA_PARAM_EnumFormat +) +; +spa_pod_builder_add +( +builder +SPA_FORMAT_mediaType +SPA_POD_Id +( +SPA_MEDIA_TYPE_video +) +SPA_FORMAT_mediaSubtype +- +SPA_POD_Id +( +format +) +0 +) +; +- +- +if +( +format += += +SPA_MEDIA_SUBTYPE_raw +) +{ +- +spa_pod_builder_prop +( +builder +SPA_FORMAT_VIDEO_format +0 +) +; +- +spa_pod_builder_push_choice +( +builder +& +frames +[ +1 +] +SPA_CHOICE_Enum +0 +) +; +- +spa_pod_builder_id +( +builder +kSupportedFormats +[ +0 +] +. +spa_format +) +; +- +for +( +const +auto +& +spa_and_pixel_format +: +kSupportedFormats +) +- +spa_pod_builder_id +( +builder +spa_and_pixel_format +. +spa_format +) +; +- +spa_pod_builder_pop +( +builder +& +frames +[ +1 +] +) +; +- +} ++ +SPA_POD_Id +( +media_subtype +) +0 +) +; +- +spa_rectangle +preferred_size += +spa_rectangle +{ +width +height +} +; +- +spa_rectangle +min_size += +spa_rectangle +{ +1 +1 +} +; +- +spa_rectangle +max_size += +spa_rectangle +{ +4096 +4096 +} +; +- +spa_pod_builder_add +( +- +builder +SPA_FORMAT_VIDEO_size +- +SPA_POD_CHOICE_RANGE_Rectangle +( +& +preferred_size +& +min_size +& +max_size +) +0 +) +; ++ +if +( +media_subtype += += +SPA_MEDIA_SUBTYPE_raw +) +{ ++ +const +uint32_t +format += ++ +VideoCaptureModulePipeWire +: +: +VideoTypeToPipeWireRawFormat +( +video_type +) +; ++ +RTC_CHECK +( +format +! += +SPA_VIDEO_FORMAT_UNKNOWN +) +; ++ +spa_pod_builder_add +( +builder +SPA_FORMAT_VIDEO_format +SPA_POD_Id +( +format +) ++ +0 +) +; ++ +} +- +spa_fraction +preferred_frame_rate += +- +spa_fraction +{ +static_cast +< +uint32_t +> +( +frame_rate +) +1 +} +; +- +spa_fraction +min_frame_rate += +spa_fraction +{ +0 +1 +} +; +- +spa_fraction +max_frame_rate += +spa_fraction +{ +INT32_MAX +1 +} +; +- +spa_pod_builder_add +( +- +builder +SPA_FORMAT_VIDEO_framerate +- +SPA_POD_CHOICE_RANGE_Fraction +( +& +preferred_frame_rate +& +min_frame_rate +- +& +max_frame_rate +) +- +0 +) +; ++ +spa_rectangle +resolution += +spa_rectangle +{ +width +height +} +; ++ +spa_pod_builder_add +( +builder +SPA_FORMAT_VIDEO_size ++ +SPA_POD_Rectangle +( +& +resolution +) +0 +) +; ++ ++ +/ +/ +Framerate +can +be +also +set +to +0 +to +be +unspecified ++ +if +( +frame_rate +) +{ ++ +spa_fraction +framerate += +spa_fraction +{ +static_cast +< +uint32_t +> +( +frame_rate +) +1 +} +; ++ +spa_pod_builder_add +( +builder +SPA_FORMAT_VIDEO_framerate ++ +SPA_POD_Fraction +( +& +framerate +) +0 +) +; ++ +} +else +{ ++ +/ +/ +Default +to +some +reasonable +values ++ +spa_fraction +preferred_frame_rate += ++ +spa_fraction +{ +static_cast +< +uint32_t +> +( +30 +) +1 +} +; ++ +spa_fraction +min_frame_rate += +spa_fraction +{ +1 +1 +} +; ++ +spa_fraction +max_frame_rate += +spa_fraction +{ +30 +1 +} +; ++ +spa_pod_builder_add +( ++ +builder +SPA_FORMAT_VIDEO_framerate ++ +SPA_POD_CHOICE_RANGE_Fraction +( +& +preferred_frame_rate +& +min_frame_rate ++ +& +max_frame_rate +) ++ +0 +) +; ++ +} +- +return +static_cast +< +spa_pod +* +> +( +spa_pod_builder_pop +( +builder +& +frames +[ +0 +] +) +) +; ++ +return +static_cast +< +spa_pod +* +> +( +spa_pod_builder_pop +( +builder +& +frame +) +) +; +} +RTC_NO_SANITIZE +( +" +cfi +- +icall +" +) +- +178 +13 ++ +196 +10 +int32_t +VideoCaptureModulePipeWire +: +: +StartCapture +( +uint32_t +width += +capability +. +width +; +uint32_t +height += +capability +. +height +; +uint32_t +frame_rate += +capability +. +maxFPS +; +- +bool +prefer_jpeg += +( +width +> +640 +) +| +| +( +height +> +480 +) +; ++ +VideoType +video_type += +capability +. +videoType +; +params +. +push_back +( +- +BuildFormat +( +& +builder +SPA_MEDIA_SUBTYPE_raw +width +height +frame_rate +) +) +; +- +params +. +insert +( +- +prefer_jpeg +? +params +. +begin +( +) +: +params +. +end +( +) +- +BuildFormat +( +& +builder +SPA_MEDIA_SUBTYPE_mjpg +width +height +frame_rate +) +) +; ++ +BuildFormat +( +& +builder +video_type +width +height +frame_rate +) +) +; +int +res += +pw_stream_connect +( +stream_ +PW_DIRECTION_INPUT +node_id_ +diff +- +- +git +a +/ +modules +/ +video_capture +/ +linux +/ +video_capture_pipewire +. +h +b +/ +modules +/ +video_capture +/ +linux +/ +video_capture_pipewire +. +h +index +eeb3b9497c +. +. +789f2034d3 +100644 +- +- +- +a +/ +modules +/ +video_capture +/ +linux +/ +video_capture_pipewire +. +h ++ ++ ++ +b +/ +modules +/ +video_capture +/ +linux +/ +video_capture_pipewire +. +h +- +28 +6 ++ +28 +7 +class +VideoCaptureModulePipeWire +: +public +VideoCaptureImpl +{ +int32_t +CaptureSettings +( +VideoCaptureCapability +& +settings +) +override +; +static +VideoType +PipeWireRawFormatToVideoType +( +uint32_t +format +) +; ++ +static +uint32_t +VideoTypeToPipeWireRawFormat +( +VideoType +type +) +; +private +: +static +void +OnStreamParamChanged +( +void +* +data