Bug 1311048 - Pick out Firefox windows as scary by pid (only OSX atm). r=jesup
authorJan-Ivar Bruaroey <jib@mozilla.com>
Fri, 30 Sep 2016 13:23:42 -0400
changeset 351354 5b9dacd187bb70d51e24d148d03b410d334094f9
parent 351249 572249b2ffb6ccd84e7fb5ffdf529aceb557ce51
child 351355 533d7494d9cad184fc90d3dcf10b74e9925ccefe
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1311048
milestone52.0a1
Bug 1311048 - Pick out Firefox windows as scary by pid (only OSX atm). r=jesup MozReview-Commit-ID: DwUodsRWswm
dom/media/systemservices/CamerasChild.cpp
dom/media/systemservices/CamerasChild.h
dom/media/systemservices/CamerasParent.cpp
dom/media/systemservices/PCameras.ipdl
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
dom/media/webrtc/MediaEngineWebRTC.cpp
media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_device_info.cc
media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_device_info.h
media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer.h
media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_mac.mm
media/webrtc/trunk/webrtc/modules/video_capture/include/video_capture.h
media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.h
media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.mm
media/webrtc/trunk/webrtc/video_engine/browser_capture_impl.h
media/webrtc/trunk/webrtc/video_engine/desktop_capture_impl.cc
media/webrtc/trunk/webrtc/video_engine/desktop_capture_impl.h
media/webrtc/trunk/webrtc/video_engine/include/vie_capture.h
media/webrtc/trunk/webrtc/video_engine/vie_capture_impl.cc
media/webrtc/trunk/webrtc/video_engine/vie_capture_impl.h
media/webrtc/trunk/webrtc/video_engine/vie_input_manager.cc
media/webrtc/trunk/webrtc/video_engine/vie_input_manager.h
--- a/dom/media/systemservices/CamerasChild.cpp
+++ b/dom/media/systemservices/CamerasChild.cpp
@@ -381,45 +381,51 @@ CamerasChild::RecvReplyGetCaptureCapabil
   return true;
 }
 
 int
 CamerasChild::GetCaptureDevice(CaptureEngine aCapEngine,
                                unsigned int list_number, char* device_nameUTF8,
                                const unsigned int device_nameUTF8Length,
                                char* unique_idUTF8,
-                               const unsigned int unique_idUTF8Length)
+                               const unsigned int unique_idUTF8Length,
+                               bool* scary)
 {
   LOG((__PRETTY_FUNCTION__));
   nsCOMPtr<nsIRunnable> runnable =
     media::NewRunnableFrom([this, aCapEngine, list_number]() -> nsresult {
       if (this->SendGetCaptureDevice(aCapEngine, list_number)) {
         return NS_OK;
       }
       return NS_ERROR_FAILURE;
     });
   LockAndDispatch<> dispatcher(this, __func__, runnable);
   if (dispatcher.Success()) {
     base::strlcpy(device_nameUTF8, mReplyDeviceName.get(), device_nameUTF8Length);
     base::strlcpy(unique_idUTF8, mReplyDeviceID.get(), unique_idUTF8Length);
+    if (scary) {
+      *scary = mReplyScary;
+    }
     LOG(("Got %s name %s id", device_nameUTF8, unique_idUTF8));
   }
   return dispatcher.ReturnValue();
 }
 
 bool
 CamerasChild::RecvReplyGetCaptureDevice(const nsCString& device_name,
-                                        const nsCString& device_id)
+                                        const nsCString& device_id,
+                                        const bool& scary)
 {
   LOG((__PRETTY_FUNCTION__));
   MonitorAutoLock monitor(mReplyMonitor);
   mReceivedReply = true;
   mReplySuccess = true;
   mReplyDeviceName = device_name;
   mReplyDeviceID = device_id;
+  mReplyScary = scary;
   monitor.Notify();
   return true;
 }
 
 int
 CamerasChild::AllocateCaptureDevice(CaptureEngine aCapEngine,
                                     const char* unique_idUTF8,
                                     const unsigned int unique_idUTF8Length,
--- a/dom/media/systemservices/CamerasChild.h
+++ b/dom/media/systemservices/CamerasChild.h
@@ -160,17 +160,18 @@ public:
   int SetFakeDeviceChangeEvents();
 
   // these are response messages to our outgoing requests
   virtual bool RecvReplyNumberOfCaptureDevices(const int&) override;
   virtual bool RecvReplyNumberOfCapabilities(const int&) override;
   virtual bool RecvReplyAllocateCaptureDevice(const int&) override;
   virtual bool RecvReplyGetCaptureCapability(const CaptureCapability& capability) override;
   virtual bool RecvReplyGetCaptureDevice(const nsCString& device_name,
-                                         const nsCString& device_id) override;
+                                         const nsCString& device_id,
+                                         const bool& scary) override;
   virtual bool RecvReplyFailure(void) override;
   virtual bool RecvReplySuccess(void) override;
   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
 
   // the webrtc.org ViECapture calls are mirrored here, but with access
   // to a specific PCameras instance to communicate over. These also
   // run on the MediaManager thread
   int NumberOfCaptureDevices(CaptureEngine aCapEngine);
@@ -190,17 +191,18 @@ public:
   int GetCaptureCapability(CaptureEngine aCapEngine,
                            const char* unique_idUTF8,
                            const unsigned int capability_number,
                            webrtc::CaptureCapability& capability);
   int GetCaptureDevice(CaptureEngine aCapEngine,
                        unsigned int list_number, char* device_nameUTF8,
                        const unsigned int device_nameUTF8Length,
                        char* unique_idUTF8,
-                       const unsigned int unique_idUTF8Length);
+                       const unsigned int unique_idUTF8Length,
+                       bool* scary = nullptr);
   void ShutdownAll();
   int EnsureInitialized(CaptureEngine aCapEngine);
 
   webrtc::ExternalRenderer* Callback(CaptureEngine aCapEngine, int capture_id);
 
 private:
   CamerasChild();
   ~CamerasChild();
@@ -234,14 +236,15 @@ private:
   // Async response valid?
   bool mReceivedReply;
   // Async responses data contents;
   bool mReplySuccess;
   int mReplyInteger;
   webrtc::CaptureCapability mReplyCapability;
   nsCString mReplyDeviceName;
   nsCString mReplyDeviceID;
+  bool mReplyScary;
 };
 
 } // namespace camera
 } // namespace mozilla
 
 #endif  // mozilla_CamerasChild_h
--- a/dom/media/systemservices/CamerasParent.cpp
+++ b/dom/media/systemservices/CamerasParent.cpp
@@ -675,41 +675,45 @@ CamerasParent::RecvGetCaptureDevice(cons
 
   RefPtr<CamerasParent> self(this);
   RefPtr<Runnable> webrtc_runnable =
     media::NewRunnableFrom([self, aCapEngine, aListNumber]() -> nsresult {
       char deviceName[MediaEngineSource::kMaxDeviceNameLength];
       char deviceUniqueId[MediaEngineSource::kMaxUniqueIdLength];
       nsCString name;
       nsCString uniqueId;
+      int devicePid = 0;
       int error = -1;
       if (self->EnsureInitialized(aCapEngine)) {
           error = self->mEngines[aCapEngine].mPtrViECapture->GetCaptureDevice(aListNumber,
                                                                               deviceName,
                                                                               sizeof(deviceName),
                                                                               deviceUniqueId,
-                                                                              sizeof(deviceUniqueId));
+                                                                              sizeof(deviceUniqueId),
+                                                                              &devicePid);
       }
       if (!error) {
         name.Assign(deviceName);
         uniqueId.Assign(deviceUniqueId);
       }
       RefPtr<nsIRunnable> ipc_runnable =
-        media::NewRunnableFrom([self, error, name, uniqueId]() -> nsresult {
+        media::NewRunnableFrom([self, error, name, uniqueId, devicePid]() {
           if (self->IsShuttingDown()) {
             return NS_ERROR_FAILURE;
           }
           if (error) {
             LOG(("GetCaptureDevice failed: %d", error));
             Unused << self->SendReplyFailure();
             return NS_ERROR_FAILURE;
           }
+          bool scary = (devicePid == getpid());
 
-          LOG(("Returning %s name %s id", name.get(), uniqueId.get()));
-          Unused << self->SendReplyGetCaptureDevice(name, uniqueId);
+          LOG(("Returning %s name %s id (pid = %d)%s", name.get(),
+               uniqueId.get(), devicePid, (scary? " (scary)" : "")));
+          Unused << self->SendReplyGetCaptureDevice(name, uniqueId, scary);
           return NS_OK;
         });
       self->mPBackgroundThread->Dispatch(ipc_runnable, NS_DISPATCH_NORMAL);
       return NS_OK;
     });
   DispatchToVideoCaptureThread(webrtc_runnable);
   return true;
 }
--- a/dom/media/systemservices/PCameras.ipdl
+++ b/dom/media/systemservices/PCameras.ipdl
@@ -31,17 +31,17 @@ child:
   async DeliverFrame(CaptureEngine capEngine, int cap_id,
                      Shmem buffer, size_t size, uint32_t time_stamp,
                      int64_t ntp_time, int64_t render_time);
   async DeviceChange();
   async ReplyNumberOfCaptureDevices(int numdev);
   async ReplyNumberOfCapabilities(int numdev);
   async ReplyAllocateCaptureDevice(int numdev);
   async ReplyGetCaptureCapability(CaptureCapability cap);
-  async ReplyGetCaptureDevice(nsCString device_name, nsCString device_id);
+  async ReplyGetCaptureDevice(nsCString device_name, nsCString device_id, bool scary);
   async ReplyFailure();
   async ReplySuccess();
   async __delete__();
 
 parent:
   async NumberOfCaptureDevices(CaptureEngine engine);
   async NumberOfCapabilities(CaptureEngine engine, nsCString deviceUniqueIdUTF8);
 
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -47,17 +47,17 @@ MediaEngineRemoteVideoSource::Init()
 {
   LOG((__PRETTY_FUNCTION__));
   char deviceName[kMaxDeviceNameLength];
   char uniqueId[kMaxUniqueIdLength];
   if (mozilla::camera::GetChildAndCall(
     &mozilla::camera::CamerasChild::GetCaptureDevice,
     mCapEngine, mCaptureIndex,
     deviceName, kMaxDeviceNameLength,
-    uniqueId, kMaxUniqueIdLength)) {
+    uniqueId, kMaxUniqueIdLength, nullptr)) {
     LOG(("Error initializing RemoteVideoSource (GetCaptureDevice)"));
     return;
   }
 
   SetName(NS_ConvertUTF8toUTF16(deviceName));
   SetUUID(uniqueId);
 
   mInitDone = true;
@@ -491,17 +491,17 @@ void MediaEngineRemoteVideoSource::Refre
   // Caller looked up this source by uniqueId, so it shouldn't change
   char deviceName[kMaxDeviceNameLength];
   char uniqueId[kMaxUniqueIdLength];
 
   if (mozilla::camera::GetChildAndCall(
     &mozilla::camera::CamerasChild::GetCaptureDevice,
     mCapEngine, aIndex,
     deviceName, sizeof(deviceName),
-    uniqueId, sizeof(uniqueId))) {
+    uniqueId, sizeof(uniqueId), nullptr)) {
     return;
   }
 
   SetName(NS_ConvertUTF8toUTF16(deviceName));
 #ifdef DEBUG
   MOZ_ASSERT(GetUUID().Equals(uniqueId));
 #endif
 }
--- a/dom/media/webrtc/MediaEngineWebRTC.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTC.cpp
@@ -194,46 +194,37 @@ MediaEngineWebRTC::EnumerateVideoDevices
   int num;
   num = mozilla::camera::GetChildAndCall(
     &mozilla::camera::CamerasChild::NumberOfCaptureDevices,
     capEngine);
 
   for (int i = 0; i < num; i++) {
     char deviceName[MediaEngineSource::kMaxDeviceNameLength];
     char uniqueId[MediaEngineSource::kMaxUniqueIdLength];
-    bool scaryWindow = false;
+    bool scarySource = false;
 
     // paranoia
     deviceName[0] = '\0';
     uniqueId[0] = '\0';
     int error;
 
     error =  mozilla::camera::GetChildAndCall(
       &mozilla::camera::CamerasChild::GetCaptureDevice,
       capEngine,
       i, deviceName,
       sizeof(deviceName), uniqueId,
-      sizeof(uniqueId));
+      sizeof(uniqueId),
+      &scarySource);
     if (error) {
       LOG(("camera:GetCaptureDevice: Failed %d", error ));
       continue;
     }
 #ifdef DEBUG
     LOG(("  Capture Device Index %d, Name %s", i, deviceName));
 
-    if (aMediaSource == dom::MediaSourceEnum::Window) {
-      // TODO: Detect firefox windows
-      //scaryWindow = true;
-    }
-
-    if (aMediaSource == dom::MediaSourceEnum::Application) {
-      // TODO: Detect firefox application windows
-      //scaryWindow = true;
-    }
-
     webrtc::CaptureCapability cap;
     int numCaps = mozilla::camera::GetChildAndCall(
       &mozilla::camera::CamerasChild::NumberOfCapabilities,
       capEngine,
       uniqueId);
     LOG(("Number of Capabilities %d", numCaps));
     for (int j = 0; j < numCaps; j++) {
       if (mozilla::camera::GetChildAndCall(
@@ -257,17 +248,17 @@ MediaEngineWebRTC::EnumerateVideoDevices
     RefPtr<MediaEngineVideoSource> vSource;
     NS_ConvertUTF8toUTF16 uuid(uniqueId);
     if (mVideoSources.Get(uuid, getter_AddRefs(vSource))) {
       // We've already seen this device, just refresh and append.
       static_cast<MediaEngineRemoteVideoSource*>(vSource.get())->Refresh(i);
       aVSources->AppendElement(vSource.get());
     } else {
       vSource = new MediaEngineRemoteVideoSource(i, capEngine, aMediaSource,
-                                                 scaryKind || scaryWindow);
+                                                 scaryKind || scarySource);
       mVideoSources.Put(uuid, vSource); // Hashtable takes ownership.
       aVSources->AppendElement(vSource);
     }
   }
 
   if (mHasTabVideoSource || dom::MediaSourceEnum::Browser == aMediaSource) {
     aVSources->AppendElement(new MediaEngineTabVideoSource());
   }
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_device_info.cc
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_device_info.cc
@@ -29,16 +29,17 @@ static inline void SetStringMember(char 
   buffer[nBufLen - 1] = '\0';
   *member = buffer;
 }
 
 DesktopDisplayDevice::DesktopDisplayDevice() {
   screenId_ = kInvalidScreenId;
   deviceUniqueIdUTF8_ = NULL;
   deviceNameUTF8_ = NULL;
+  pid_ = 0;
 }
 
 DesktopDisplayDevice::~DesktopDisplayDevice() {
   screenId_ = kInvalidScreenId;
 
   if (deviceUniqueIdUTF8_){
     delete [] deviceUniqueIdUTF8_;
   }
@@ -58,35 +59,44 @@ void DesktopDisplayDevice::setScreenId(c
 void DesktopDisplayDevice::setDeviceName(const char *deviceNameUTF8) {
   SetStringMember(&deviceNameUTF8_, deviceNameUTF8);
 }
 
 void DesktopDisplayDevice::setUniqueIdName(const char *deviceUniqueIdUTF8) {
   SetStringMember(&deviceUniqueIdUTF8_, deviceUniqueIdUTF8);
 }
 
+void DesktopDisplayDevice::setPid(const int pid) {
+  pid_ = pid;
+}
+
 ScreenId DesktopDisplayDevice::getScreenId() {
   return screenId_;
 }
 
 const char *DesktopDisplayDevice::getDeviceName() {
   return deviceNameUTF8_;
 }
 
 const char *DesktopDisplayDevice::getUniqueIdName() {
   return deviceUniqueIdUTF8_;
 }
 
+pid_t DesktopDisplayDevice::getPid() {
+  return pid_;
+}
+
 DesktopDisplayDevice& DesktopDisplayDevice::operator= (DesktopDisplayDevice& other) {
   if (&other == this) {
     return *this;
   }
   screenId_ = other.getScreenId();
   setUniqueIdName(other.getUniqueIdName());
   setDeviceName(other.getDeviceName());
+  pid_ = other.getPid();
 
   return *this;
 }
 
 
 DesktopApplication::DesktopApplication() {
   processId_ = 0;
   processPathNameUTF8_= NULL;
@@ -266,16 +276,17 @@ void DesktopDeviceInfoImpl::InitializeWi
     for (itr = list.begin(); itr != list.end(); itr++) {
       DesktopDisplayDevice *pWinDevice = new DesktopDisplayDevice;
       if (!pWinDevice) {
         continue;
       }
 
       pWinDevice->setScreenId(itr->id);
       pWinDevice->setDeviceName(itr->title.c_str());
+      pWinDevice->setPid(itr->pid);
 
       char idStr[BUFSIZ];
 #if WEBRTC_WIN
       _snprintf_s(idStr, sizeof(idStr), sizeof(idStr) - 1, "%ld", pWinDevice->getScreenId());
 #else
       snprintf(idStr, sizeof(idStr), "%ld", pWinDevice->getScreenId());
 #endif
       pWinDevice->setUniqueIdName(idStr);
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_device_info.h
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_device_info.h
@@ -13,27 +13,30 @@ namespace webrtc {
 class DesktopDisplayDevice {
 public:
   DesktopDisplayDevice();
   ~DesktopDisplayDevice();
 
   void setScreenId(const ScreenId screenId);
   void setDeviceName(const char *deviceNameUTF8);
   void setUniqueIdName(const char *deviceUniqueIdUTF8);
+  void setPid(pid_t pid);
 
   ScreenId getScreenId();
   const char *getDeviceName();
   const char *getUniqueIdName();
+  pid_t getPid();
 
   DesktopDisplayDevice& operator= (DesktopDisplayDevice& other);
 
 protected:
   ScreenId screenId_;
   char* deviceNameUTF8_;
   char* deviceUniqueIdUTF8_;
+  pid_t pid_;
 };
 
 typedef std::map<intptr_t,DesktopDisplayDevice*> DesktopDisplayDeviceList;
 
 class DesktopApplication {
 public:
   DesktopApplication();
   ~DesktopApplication();
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer.h
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer.h
@@ -24,16 +24,17 @@ namespace webrtc {
 class DesktopCaptureOptions;
 
 class WindowCapturer : public DesktopCapturer {
  public:
   typedef webrtc::WindowId WindowId;
 
   struct Window {
     WindowId id;
+    pid_t pid;
 
     // Title of the window in UTF-8 encoding.
     std::string title;
   };
 
   typedef std::vector<Window> WindowList;
 
   static WindowCapturer* Create(const DesktopCaptureOptions& options);
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_mac.mm
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_mac.mm
@@ -95,16 +95,18 @@ bool WindowCapturerMac::GetWindowList(Wi
   CFIndex count = CFArrayGetCount(window_array);
   for (CFIndex i = 0; i < count; ++i) {
     CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>(
         CFArrayGetValueAtIndex(window_array, i));
     CFStringRef window_title = reinterpret_cast<CFStringRef>(
         CFDictionaryGetValue(window, kCGWindowName));
     CFNumberRef window_id = reinterpret_cast<CFNumberRef>(
         CFDictionaryGetValue(window, kCGWindowNumber));
+    CFNumberRef window_pid = reinterpret_cast<CFNumberRef>(
+        CFDictionaryGetValue(window, kCGWindowOwnerPID));
     CFNumberRef window_layer = reinterpret_cast<CFNumberRef>(
         CFDictionaryGetValue(window, kCGWindowLayer));
     if (window_title && window_id && window_layer) {
       //Skip windows of zero area
       CFDictionaryRef bounds_ref = reinterpret_cast<CFDictionaryRef>(
            CFDictionaryGetValue(window,kCGWindowBounds));
       CGRect bounds_rect;
       if(!(bounds_ref) ||
@@ -118,18 +120,21 @@ bool WindowCapturerMac::GetWindowList(Wi
       // Skip windows with layer=0 (menu, dock).
       int layer;
       CFNumberGetValue(window_layer, kCFNumberIntType, &layer);
       if (layer != 0)
         continue;
 
       int id;
       CFNumberGetValue(window_id, kCFNumberIntType, &id);
+      pid_t pid = 0;
+      CFNumberGetValue(window_pid, kCFNumberIntType, &pid);
       WindowCapturer::Window window;
       window.id = id;
+      window.pid = pid;
       if (!rtc::ToUtf8(window_title, &(window.title)) ||
           window.title.empty()) {
         continue;
       }
       windows->push_back(window);
     }
   }
 
--- a/media/webrtc/trunk/webrtc/modules/video_capture/include/video_capture.h
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/include/video_capture.h
@@ -53,24 +53,26 @@ class VideoCaptureModule: public RefCoun
 
     // Returns the available capture devices.
     // deviceNumber   - Index of capture device.
     // deviceNameUTF8 - Friendly name of the capture device.
     // deviceUniqueIdUTF8 - Unique name of the capture device if it exist.
     //                      Otherwise same as deviceNameUTF8.
     // productUniqueIdUTF8 - Unique product id if it exist.
     //                       Null terminated otherwise.
+    // pid                 - Owning process id (pid).
     virtual int32_t GetDeviceName(
         uint32_t deviceNumber,
         char* deviceNameUTF8,
         uint32_t deviceNameLength,
         char* deviceUniqueIdUTF8,
         uint32_t deviceUniqueIdUTF8Length,
         char* productUniqueIdUTF8 = 0,
-        uint32_t productUniqueIdUTF8Length = 0) = 0;
+        uint32_t productUniqueIdUTF8Length = 0,
+        int32_t* pid = 0) = 0;
 
 
     // Returns the number of capabilities this device.
     virtual int32_t NumberOfCapabilities(
         const char* deviceUniqueIdUTF8) = 0;
 
     // Gets the capabilities of the named device.
     virtual int32_t GetCapability(
--- a/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.h
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.h
@@ -43,17 +43,18 @@ public:
      * productUniqueIdUTF8 - unique product id if it exist. Null terminated
      *      otherwise.
      */
     virtual int32_t GetDeviceName(
         uint32_t deviceNumber, char* deviceNameUTF8,
         uint32_t deviceNameLength, char* deviceUniqueIdUTF8,
         uint32_t deviceUniqueIdUTF8Length,
         char* productUniqueIdUTF8 = 0,
-        uint32_t productUniqueIdUTF8Length = 0);
+        uint32_t productUniqueIdUTF8Length = 0,
+        pid_t* pid = 0);
 
     /*
      *   Returns the number of capabilities for this device
      */
     virtual int32_t NumberOfCapabilities(
         const char* deviceUniqueIdUTF8);
 
     /*
--- a/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.mm
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.mm
@@ -49,17 +49,18 @@ uint32_t VideoCaptureMacAVFoundationInfo
     return captureDeviceCount;
 
 }
 
 int32_t VideoCaptureMacAVFoundationInfo::GetDeviceName(
     uint32_t deviceNumber, char* deviceNameUTF8,
     uint32_t deviceNameLength, char* deviceUniqueIdUTF8,
     uint32_t deviceUniqueIdUTF8Length, char* productUniqueIdUTF8,
-    uint32_t productUniqueIdUTF8Length)
+    uint32_t productUniqueIdUTF8Length,
+    pid_t* pid)
 {
     nsAutoreleasePool localPool;
     int errNum = [[_captureInfo getDeviceNamesFromIndex:deviceNumber
                    DefaultName:deviceNameUTF8 WithLength:deviceNameLength
                    AndUniqueID:deviceUniqueIdUTF8
                    WithLength:deviceUniqueIdUTF8Length
                    AndProductID:productUniqueIdUTF8
                    WithLength:productUniqueIdUTF8Length]intValue];
--- a/media/webrtc/trunk/webrtc/video_engine/browser_capture_impl.h
+++ b/media/webrtc/trunk/webrtc/video_engine/browser_capture_impl.h
@@ -14,17 +14,18 @@ namespace webrtc {
     virtual int32_t Refresh() { return 0; }
 
     virtual int32_t GetDeviceName(uint32_t deviceNumber,
                                   char* deviceNameUTF8,
                                   uint32_t deviceNameLength,
                                   char* deviceUniqueIdUTF8,
                                   uint32_t deviceUniqueIdUTF8Length,
                                   char* productUniqueIdUTF8 = NULL,
-                                  uint32_t productUniqueIdUTF8Length = 0) {
+                                  uint32_t productUniqueIdUTF8Length = 0,
+                                  pid_t* pid = 0) {
       deviceNameUTF8 = const_cast<char*>(kDeviceName);
       deviceUniqueIdUTF8 = const_cast<char*>(kUniqueDeviceName);
       productUniqueIdUTF8 =  const_cast<char*>(kProductUniqueId);
       return 1;
     };
 
 
     virtual int32_t NumberOfCapabilities(const char* deviceUniqueIdUTF8) {
--- a/media/webrtc/trunk/webrtc/video_engine/desktop_capture_impl.cc
+++ b/media/webrtc/trunk/webrtc/video_engine/desktop_capture_impl.cc
@@ -53,17 +53,18 @@ uint32_t ScreenDeviceInfoImpl::NumberOfD
 }
 
 int32_t ScreenDeviceInfoImpl::GetDeviceName(uint32_t deviceNumber,
                                             char* deviceNameUTF8,
                                             uint32_t deviceNameUTF8Length,
                                             char* deviceUniqueIdUTF8,
                                             uint32_t deviceUniqueIdUTF8Length,
                                             char* productUniqueIdUTF8,
-                                            uint32_t productUniqueIdUTF8Length) {
+                                            uint32_t productUniqueIdUTF8Length,
+                                            pid_t* pid) {
 
   DesktopDisplayDevice desktopDisplayDevice;
 
   // always initialize output
   if (deviceNameUTF8 && deviceNameUTF8Length > 0) {
     memset(deviceNameUTF8, 0, deviceNameUTF8Length);
   }
 
@@ -149,17 +150,18 @@ uint32_t AppDeviceInfoImpl::NumberOfDevi
 }
 
 int32_t AppDeviceInfoImpl::GetDeviceName(uint32_t deviceNumber,
                                          char* deviceNameUTF8,
                                          uint32_t deviceNameUTF8Length,
                                          char* deviceUniqueIdUTF8,
                                          uint32_t deviceUniqueIdUTF8Length,
                                          char* productUniqueIdUTF8,
-                                         uint32_t productUniqueIdUTF8Length) {
+                                         uint32_t productUniqueIdUTF8Length,
+                                         pid_t* pid) {
 
   DesktopApplication desktopApplication;
 
   // always initialize output
   if (deviceNameUTF8Length && deviceNameUTF8Length > 0) {
     memset(deviceNameUTF8, 0, deviceNameUTF8Length);
   }
   if (deviceUniqueIdUTF8 && deviceUniqueIdUTF8Length > 0) {
@@ -249,17 +251,18 @@ uint32_t WindowDeviceInfoImpl::NumberOfD
 }
 
 int32_t WindowDeviceInfoImpl::GetDeviceName(uint32_t deviceNumber,
                                             char* deviceNameUTF8,
                                             uint32_t deviceNameUTF8Length,
                                             char* deviceUniqueIdUTF8,
                                             uint32_t deviceUniqueIdUTF8Length,
                                             char* productUniqueIdUTF8,
-                                            uint32_t productUniqueIdUTF8Length) {
+                                            uint32_t productUniqueIdUTF8Length,
+                                            pid_t* pid) {
 
   DesktopDisplayDevice desktopDisplayDevice;
 
   // always initialize output
   if (deviceNameUTF8 && deviceNameUTF8Length > 0) {
     memset(deviceNameUTF8, 0, deviceNameUTF8Length);
   }
   if (deviceUniqueIdUTF8 && deviceUniqueIdUTF8Length > 0) {
@@ -284,16 +287,19 @@ int32_t WindowDeviceInfoImpl::GetDeviceN
 
     const char *deviceUniqueId = desktopDisplayDevice.getUniqueIdName();
     len = deviceUniqueId ? strlen(deviceUniqueId) : 0;
     if (len && deviceUniqueIdUTF8 && len <= deviceUniqueIdUTF8Length) {
       memcpy(deviceUniqueIdUTF8,
              deviceUniqueId,
              len);
     }
+    if (pid) {
+      *pid = desktopDisplayDevice.getPid();
+    }
   }
 
   return 0;
 }
 
 int32_t WindowDeviceInfoImpl::DisplayCaptureSettingsDialogBox(const char* deviceUniqueIdUTF8,
                                                               const char* dialogTitleUTF8,
                                                               void* parentWindow,
--- a/media/webrtc/trunk/webrtc/video_engine/desktop_capture_impl.h
+++ b/media/webrtc/trunk/webrtc/video_engine/desktop_capture_impl.h
@@ -50,17 +50,18 @@ public:
 
   virtual uint32_t NumberOfDevices();
   virtual int32_t GetDeviceName(uint32_t deviceNumber,
                                 char* deviceNameUTF8,
                                 uint32_t deviceNameLength,
                                 char* deviceUniqueIdUTF8,
                                 uint32_t deviceUniqueIdUTF8Length,
                                 char* productUniqueIdUTF8,
-                                uint32_t productUniqueIdUTF8Length);
+                                uint32_t productUniqueIdUTF8Length,
+                                pid_t* pid);
 
   virtual int32_t DisplayCaptureSettingsDialogBox(const char* deviceUniqueIdUTF8,
                                                   const char* dialogTitleUTF8,
                                                   void* parentWindow,
                                                   uint32_t positionX,
                                                   uint32_t positionY);
   virtual int32_t NumberOfCapabilities(const char* deviceUniqueIdUTF8);
   virtual int32_t GetCapability(const char* deviceUniqueIdUTF8,
@@ -88,17 +89,18 @@ public:
 
   virtual uint32_t NumberOfDevices();
   virtual int32_t GetDeviceName(uint32_t deviceNumber,
                                 char* deviceNameUTF8,
                                 uint32_t deviceNameLength,
                                 char* deviceUniqueIdUTF8,
                                 uint32_t deviceUniqueIdUTF8Length,
                                 char* productUniqueIdUTF8,
-                                uint32_t productUniqueIdUTF8Length);
+                                uint32_t productUniqueIdUTF8Length,
+                                pid_t* pid);
 
   virtual int32_t DisplayCaptureSettingsDialogBox(const char* deviceUniqueIdUTF8,
                                                   const char* dialogTitleUTF8,
                                                   void* parentWindow,
                                                   uint32_t positionX,
                                                   uint32_t positionY);
   virtual int32_t NumberOfCapabilities(const char* deviceUniqueIdUTF8);
   virtual int32_t GetCapability(const char* deviceUniqueIdUTF8,
@@ -125,17 +127,18 @@ public:
 
   virtual uint32_t NumberOfDevices();
   virtual int32_t GetDeviceName(uint32_t deviceNumber,
                                 char* deviceNameUTF8,
                                 uint32_t deviceNameLength,
                                 char* deviceUniqueIdUTF8,
                                 uint32_t deviceUniqueIdUTF8Length,
                                 char* productUniqueIdUTF8,
-                                uint32_t productUniqueIdUTF8Length);
+                                uint32_t productUniqueIdUTF8Length,
+                                pid_t* pid);
 
   virtual int32_t DisplayCaptureSettingsDialogBox(const char* deviceUniqueIdUTF8,
                                                   const char* dialogTitleUTF8,
                                                   void* parentWindow,
                                                   uint32_t positionX,
                                                   uint32_t positionY);
   virtual int32_t NumberOfCapabilities(const char* deviceUniqueIdUTF8);
   virtual int32_t GetCapability(const char* deviceUniqueIdUTF8,
--- a/media/webrtc/trunk/webrtc/video_engine/include/vie_capture.h
+++ b/media/webrtc/trunk/webrtc/video_engine/include/vie_capture.h
@@ -17,16 +17,20 @@
 
 #ifndef WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CAPTURE_H_
 #define WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CAPTURE_H_
 
 #include "webrtc/common_types.h"
 #include "webrtc/common_video/interface/i420_video_frame.h"
 #include "webrtc/common_video/rotation.h"
 
+#ifdef XP_WIN
+typedef int pid_t;
+#endif
+
 namespace webrtc {
 
 class VideoEngine;
 class VideoCaptureModule;
 
 // The observer is registered using RegisterInputObserver() and
 // deregistered using DeregisterInputObserver().
 class WEBRTC_DLLEXPORT ViEInputObserver {
@@ -141,17 +145,18 @@ class WEBRTC_DLLEXPORT ViECapture {
   // Gets the number of available capture devices.
   virtual int NumberOfCaptureDevices() = 0;
 
   // Gets the name and unique id of a capture device.
   virtual int GetCaptureDevice(unsigned int list_number,
                                char* device_nameUTF8,
                                const unsigned int device_nameUTF8Length,
                                char* unique_idUTF8,
-                               const unsigned int unique_idUTF8Length) = 0;
+                               const unsigned int unique_idUTF8Length,
+                               pid_t* pid = nullptr) = 0;
 
   // Allocates a capture device to be used in VideoEngine.
   virtual int AllocateCaptureDevice(const char* unique_idUTF8,
                                     const unsigned int unique_idUTF8Length,
                                     int& capture_id) = 0;
 
   // Registers an external capture device to be used in VideoEngine
   virtual int AllocateExternalCaptureDevice(
--- a/media/webrtc/trunk/webrtc/video_engine/vie_capture_impl.cc
+++ b/media/webrtc/trunk/webrtc/video_engine/vie_capture_impl.cc
@@ -64,21 +64,22 @@ int ViECaptureImpl::NumberOfCaptureDevic
   return  shared_data_->input_manager()->NumberOfCaptureDevices();
 }
 
 
 int ViECaptureImpl::GetCaptureDevice(unsigned int list_number,
                                      char* device_nameUTF8,
                                      unsigned int device_nameUTF8Length,
                                      char* unique_idUTF8,
-                                     unsigned int unique_idUTF8Length) {
+                                     unsigned int unique_idUTF8Length,
+                                     pid_t* pid) {
   return shared_data_->input_manager()->GetDeviceName(
       list_number,
       device_nameUTF8, device_nameUTF8Length,
-      unique_idUTF8, unique_idUTF8Length);
+      unique_idUTF8, unique_idUTF8Length, pid);
 }
 
 int ViECaptureImpl::AllocateCaptureDevice(
   const char* unique_idUTF8,
   const unsigned int unique_idUTF8Length,
   int& capture_id) {
   LOG(LS_INFO) << "AllocateCaptureDevice " << unique_idUTF8;
   const int32_t result =
--- a/media/webrtc/trunk/webrtc/video_engine/vie_capture_impl.h
+++ b/media/webrtc/trunk/webrtc/video_engine/vie_capture_impl.h
@@ -25,17 +25,19 @@ class ViECaptureImpl
       public ViERefCount {
  public:
   // Implements ViECapture.
   virtual int Release();
   virtual int NumberOfCaptureDevices();
   virtual int GetCaptureDevice(unsigned int list_number, char* device_nameUTF8,
                                const unsigned int device_nameUTF8Length,
                                char* unique_idUTF8,
-                               const unsigned int unique_idUTF8Length);
+                               const unsigned int unique_idUTF8Length,
+                               pid_t* pid = nullptr);
+
   virtual int AllocateCaptureDevice(const char* unique_idUTF8,
                                     const unsigned int unique_idUTF8Length,
                                     int& capture_id);
   virtual int AllocateCaptureDevice(
       VideoCaptureModule& capture_module, int& capture_id);  // NOLINT
   virtual int AllocateExternalCaptureDevice(
       int& capture_id, ViEExternalCapture *&external_capture);
   virtual int ReleaseCaptureDevice(const int capture_id);
--- a/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.cc
+++ b/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.cc
@@ -65,24 +65,26 @@ int ViEInputManager::NumberOfCaptureDevi
   capture_device_info_->Refresh();
   return capture_device_info_->NumberOfDevices();
 }
 
 int ViEInputManager::GetDeviceName(uint32_t device_number,
                                    char* device_nameUTF8,
                                    uint32_t device_name_length,
                                    char* device_unique_idUTF8,
-                                   uint32_t device_unique_idUTF8Length) {
+                                   uint32_t device_unique_idUTF8Length,
+                                   pid_t* pid) {
   CriticalSectionScoped cs(device_info_cs_.get());
   GetDeviceInfo();
   assert(capture_device_info_);
   return capture_device_info_->GetDeviceName(device_number, device_nameUTF8,
                                              device_name_length,
                                              device_unique_idUTF8,
-                                             device_unique_idUTF8Length);
+                                             device_unique_idUTF8Length,
+                                             NULL, 0, pid);
 }
 
 int ViEInputManager::NumberOfCaptureCapabilities(
   const char* device_unique_idUTF8) {
   CriticalSectionScoped cs(device_info_cs_.get());
   if (!GetDeviceInfo())
     return 0;
   assert(capture_device_info_);
--- a/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.h
+++ b/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.h
@@ -44,17 +44,18 @@ class ViEInputManager : private ViEManag
   // Returns number of capture devices.
   int NumberOfCaptureDevices();
 
   // Gets name and id for a capture device.
   int GetDeviceName(uint32_t device_number,
                     char* device_nameUTF8,
                     uint32_t device_name_length,
                     char* device_unique_idUTF8,
-                    uint32_t device_unique_idUTF8Length);
+                    uint32_t device_unique_idUTF8Length,
+                    pid_t* pid);
 
   // Returns the number of capture capabilities for a specified device.
   int NumberOfCaptureCapabilities(const char* device_unique_idUTF8);
 
   // Gets a specific capability for a capture device.
   int GetCaptureCapability(const char* device_unique_idUTF8,
                            const uint32_t device_capability_number,
                            CaptureCapability& capability);