mozilla-pipewire-0-3.patch
branchfirefox85
changeset 1154 71a92b4d0527
parent 1153 fdd746757dda
child 1155 b8c834aafde2
equal deleted inserted replaced
1153:fdd746757dda 1154:71a92b4d0527
     1 diff -up firefox-83.0/browser/actors/WebRTCParent.jsm.pw6 firefox-83.0/browser/actors/WebRTCParent.jsm
       
     2 --- firefox-83.0/browser/actors/WebRTCParent.jsm.pw6	2020-11-12 19:04:30.000000000 +0100
       
     3 +++ firefox-83.0/browser/actors/WebRTCParent.jsm	2020-11-25 10:28:32.492865982 +0100
       
     4 @@ -45,6 +45,9 @@ XPCOMUtils.defineLazyServiceGetter(
       
     5    "nsIOSPermissionRequest"
       
     6  );
       
     7  
       
     8 +const PIPEWIRE_PORTAL_NAME = "####_PIPEWIRE_PORTAL_####";
       
     9 +const PIPEWIRE_ID = 0xaffffff;
       
    10 +
       
    11  class WebRTCParent extends JSWindowActorParent {
       
    12    didDestroy() {
       
    13      webrtcUI.forgetStreamsFromBrowserContext(this.browsingContext);
       
    14 @@ -753,6 +756,8 @@ function prompt(aActor, aBrowser, aReque
       
    15          );
       
    16          menupopup.appendChild(doc.createXULElement("menuseparator"));
       
    17  
       
    18 +        let isPipeWire = false;
       
    19 +
       
    20          // Build the list of 'devices'.
       
    21          let monitorIndex = 1;
       
    22          for (let i = 0; i < devices.length; ++i) {
       
    23 @@ -774,6 +779,29 @@ function prompt(aActor, aBrowser, aReque
       
    24              }
       
    25            } else {
       
    26              name = device.name;
       
    27 +            // When we share content by PipeWire add only one item to the device
       
    28 +            // list. When it's selected PipeWire portal dialog is opened and
       
    29 +            // user confirms actual window/screen sharing there.
       
    30 +            // Don't mark it as scary as there's an extra confirmation step by
       
    31 +            // PipeWire portal dialog.
       
    32 +            if (name == PIPEWIRE_PORTAL_NAME && device.id == PIPEWIRE_ID) {
       
    33 +              isPipeWire = true;
       
    34 +              let name;
       
    35 +              try {
       
    36 +                name = stringBundle.getString("getUserMedia.sharePipeWirePortal.label");
       
    37 +              } catch (err) {
       
    38 +                name = "Use operating system settings"
       
    39 +              }
       
    40 +              let item = addDeviceToList(
       
    41 +                menupopup,
       
    42 +                name,
       
    43 +                i,
       
    44 +                type
       
    45 +              );
       
    46 +              item.deviceId = device.id;
       
    47 +              item.mediaSource = type;
       
    48 +              break;
       
    49 +            }
       
    50              if (type == "application") {
       
    51                // The application names returned by the platform are of the form:
       
    52                // <window count>\x1e<application name>
       
    53 @@ -888,39 +916,41 @@ function prompt(aActor, aBrowser, aReque
       
    54              perms.EXPIRE_SESSION
       
    55            );
       
    56  
       
    57 -          video.deviceId = deviceId;
       
    58 -          let constraints = {
       
    59 -            video: { mediaSource: type, deviceId: { exact: deviceId } },
       
    60 -          };
       
    61 -          chromeWin.navigator.mediaDevices.getUserMedia(constraints).then(
       
    62 -            stream => {
       
    63 -              if (video.deviceId != deviceId) {
       
    64 -                // The user has selected a different device or closed the panel
       
    65 -                // before getUserMedia finished.
       
    66 -                stream.getTracks().forEach(t => t.stop());
       
    67 -                return;
       
    68 -              }
       
    69 -              video.srcObject = stream;
       
    70 -              video.stream = stream;
       
    71 -              doc.getElementById("webRTC-preview").hidden = false;
       
    72 -              video.onloadedmetadata = function(e) {
       
    73 -                video.play();
       
    74 -              };
       
    75 -            },
       
    76 -            err => {
       
    77 -              if (
       
    78 -                err.name == "OverconstrainedError" &&
       
    79 -                err.constraint == "deviceId"
       
    80 -              ) {
       
    81 -                // Window has disappeared since enumeration, which can happen.
       
    82 -                // No preview for you.
       
    83 -                return;
       
    84 +          if (!isPipeWire) {
       
    85 +            video.deviceId = deviceId;
       
    86 +            let constraints = {
       
    87 +              video: { mediaSource: type, deviceId: { exact: deviceId } },
       
    88 +            };
       
    89 +            chromeWin.navigator.mediaDevices.getUserMedia(constraints).then(
       
    90 +              stream => {
       
    91 +                if (video.deviceId != deviceId) {
       
    92 +                  // The user has selected a different device or closed the panel
       
    93 +                  // before getUserMedia finished.
       
    94 +                  stream.getTracks().forEach(t => t.stop());
       
    95 +                  return;
       
    96 +                }
       
    97 +                video.srcObject = stream;
       
    98 +                video.stream = stream;
       
    99 +                doc.getElementById("webRTC-preview").hidden = false;
       
   100 +                video.onloadedmetadata = function(e) {
       
   101 +                  video.play();
       
   102 +                };
       
   103 +              },
       
   104 +              err => {
       
   105 +                if (
       
   106 +                  err.name == "OverconstrainedError" &&
       
   107 +                  err.constraint == "deviceId"
       
   108 +                ) {
       
   109 +                  // Window has disappeared since enumeration, which can happen.
       
   110 +                  // No preview for you.
       
   111 +                  return;
       
   112 +                }
       
   113 +                Cu.reportError(
       
   114 +                  `error in preview: ${err.message} ${err.constraint}`
       
   115 +                );
       
   116                }
       
   117 -              Cu.reportError(
       
   118 -                `error in preview: ${err.message} ${err.constraint}`
       
   119 -              );
       
   120 -            }
       
   121 -          );
       
   122 +            );
       
   123 +          }
       
   124          };
       
   125          menupopup.addEventListener("command", menupopup._commandEventListener);
       
   126        }
       
   127 diff -up firefox-83.0/browser/locales/en-US/chrome/browser/browser.properties.pw6 firefox-83.0/browser/locales/en-US/chrome/browser/browser.properties
       
   128 --- firefox-83.0/browser/locales/en-US/chrome/browser/browser.properties.pw6	2020-11-12 19:04:30.000000000 +0100
       
   129 +++ firefox-83.0/browser/locales/en-US/chrome/browser/browser.properties	2020-11-25 09:24:26.378857626 +0100
       
   130 @@ -764,6 +764,7 @@ getUserMedia.selectWindowOrScreen.label=
       
   131  getUserMedia.selectWindowOrScreen.accesskey=W
       
   132  getUserMedia.pickWindowOrScreen.label = Select Window or Screen
       
   133  getUserMedia.shareEntireScreen.label = Entire screen
       
   134 +getUserMedia.sharePipeWirePortal.label = Use operating system settings
       
   135  # LOCALIZATION NOTE (getUserMedia.shareMonitor.label):
       
   136  # %S is screen number (digits 1, 2, etc)
       
   137  # Example: Screen 1, Screen 2,..
       
   138 diff -up firefox-83.0/third_party/libwebrtc/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc.pw6 firefox-83.0/third_party/libwebrtc/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
       
   139 --- firefox-83.0/third_party/libwebrtc/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc.pw6	2020-11-25 09:24:26.358857788 +0100
       
   140 +++ firefox-83.0/third_party/libwebrtc/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc	2020-11-25 09:24:26.378857626 +0100
       
   141 @@ -879,17 +879,17 @@ void BaseCapturerPipeWire::CaptureFrame(
       
   142    callback_->OnCaptureResult(Result::SUCCESS, std::move(result));
       
   143  }
       
   144  
       
   145 +#define PIPEWIRE_ID   0xaffffff
       
   146 +#define PIPEWIRE_NAME "####_PIPEWIRE_PORTAL_####"
       
   147 +
       
   148  bool BaseCapturerPipeWire::GetSourceList(SourceList* sources) {
       
   149 -  RTC_DCHECK(sources->size() == 0);
       
   150 -  // List of available screens is already presented by the xdg-desktop-portal.
       
   151 -  // But we have to add an empty source as the code expects it.
       
   152 -  sources->push_back({0});
       
   153 +  sources->push_back({PIPEWIRE_ID, 0, PIPEWIRE_NAME});
       
   154    return true;
       
   155  }
       
   156  
       
   157  bool BaseCapturerPipeWire::SelectSource(SourceId id) {
       
   158    // Screen selection is handled by the xdg-desktop-portal.
       
   159 -  return true;
       
   160 +  return id == PIPEWIRE_ID;
       
   161  }
       
   162  
       
   163  // static