mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1652552 - Remove remaining application capture code; r=jib
Differential Revision: https://phabricator.services.mozilla.com/D83491
This commit is contained in:
parent
4a7c519a9b
commit
459301b96c
@ -123,92 +123,6 @@ int32_t ScreenDeviceInfoImpl::GetOrientation(const char* deviceUniqueIdUTF8,
|
||||
return 0;
|
||||
}
|
||||
|
||||
AppDeviceInfoImpl::AppDeviceInfoImpl(const int32_t id) {}
|
||||
|
||||
AppDeviceInfoImpl::~AppDeviceInfoImpl(void) {}
|
||||
|
||||
int32_t AppDeviceInfoImpl::Init() {
|
||||
desktop_device_info_ =
|
||||
std::unique_ptr<DesktopDeviceInfo>(DesktopDeviceInfoImpl::Create());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AppDeviceInfoImpl::Refresh() {
|
||||
desktop_device_info_->Refresh();
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t AppDeviceInfoImpl::NumberOfDevices() {
|
||||
return desktop_device_info_->getApplicationCount();
|
||||
}
|
||||
|
||||
int32_t AppDeviceInfoImpl::GetDeviceName(
|
||||
uint32_t deviceNumber, char* deviceNameUTF8, uint32_t deviceNameUTF8Size,
|
||||
char* deviceUniqueIdUTF8, uint32_t deviceUniqueIdUTF8Size,
|
||||
char* productUniqueIdUTF8, uint32_t productUniqueIdUTF8Size, pid_t* pid) {
|
||||
DesktopApplication desktopApplication;
|
||||
|
||||
// always initialize output
|
||||
if (deviceNameUTF8Size && deviceNameUTF8Size > 0) {
|
||||
memset(deviceNameUTF8, 0, deviceNameUTF8Size);
|
||||
}
|
||||
if (deviceUniqueIdUTF8 && deviceUniqueIdUTF8Size > 0) {
|
||||
memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Size);
|
||||
}
|
||||
if (productUniqueIdUTF8 && productUniqueIdUTF8Size > 0) {
|
||||
memset(productUniqueIdUTF8, 0, productUniqueIdUTF8Size);
|
||||
}
|
||||
|
||||
if (desktop_device_info_->getApplicationInfo(deviceNumber,
|
||||
desktopApplication) == 0) {
|
||||
size_t len;
|
||||
|
||||
const char* deviceName = desktopApplication.getProcessAppName();
|
||||
len = deviceName ? strlen(deviceName) : 0;
|
||||
if (len && len < deviceNameUTF8Size) {
|
||||
memcpy(deviceNameUTF8, deviceName, len);
|
||||
}
|
||||
|
||||
const char* deviceUniqueId = desktopApplication.getUniqueIdName();
|
||||
len = deviceUniqueId ? strlen(deviceUniqueId) : 0;
|
||||
if (len && deviceUniqueIdUTF8 && len < deviceUniqueIdUTF8Size) {
|
||||
memcpy(deviceUniqueIdUTF8, deviceUniqueId, len);
|
||||
}
|
||||
if (pid) {
|
||||
*pid = desktopApplication.getProcessId();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AppDeviceInfoImpl::DisplayCaptureSettingsDialogBox(
|
||||
const char* deviceUniqueIdUTF8, const char* dialogTitleUTF8,
|
||||
void* parentWindow, uint32_t positionX, uint32_t positionY) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AppDeviceInfoImpl::NumberOfCapabilities(
|
||||
const char* deviceUniqueIdUTF8) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AppDeviceInfoImpl::GetCapability(const char* deviceUniqueIdUTF8,
|
||||
const uint32_t deviceCapabilityNumber,
|
||||
VideoCaptureCapability& capability) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AppDeviceInfoImpl::GetBestMatchedCapability(
|
||||
const char* deviceUniqueIdUTF8, const VideoCaptureCapability& requested,
|
||||
VideoCaptureCapability& resulting) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AppDeviceInfoImpl::GetOrientation(const char* deviceUniqueIdUTF8,
|
||||
VideoRotation& orientation) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
VideoCaptureModule* DesktopCaptureImpl::Create(const int32_t id,
|
||||
const char* uniqueId,
|
||||
const CaptureDeviceType type) {
|
||||
|
@ -79,41 +79,6 @@ class ScreenDeviceInfoImpl : public VideoCaptureModule::DeviceInfo {
|
||||
std::unique_ptr<DesktopDeviceInfo> desktop_device_info_;
|
||||
};
|
||||
|
||||
class AppDeviceInfoImpl : public VideoCaptureModule::DeviceInfo {
|
||||
public:
|
||||
AppDeviceInfoImpl(const int32_t id);
|
||||
virtual ~AppDeviceInfoImpl(void);
|
||||
|
||||
int32_t Init();
|
||||
int32_t Refresh();
|
||||
|
||||
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, 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,
|
||||
const uint32_t deviceCapabilityNumber,
|
||||
VideoCaptureCapability& capability);
|
||||
|
||||
virtual int32_t GetBestMatchedCapability(
|
||||
const char* deviceUniqueIdUTF8, const VideoCaptureCapability& requested,
|
||||
VideoCaptureCapability& resulting);
|
||||
virtual int32_t GetOrientation(const char* deviceUniqueIdUTF8,
|
||||
VideoRotation& orientation);
|
||||
|
||||
protected:
|
||||
int32_t _id;
|
||||
std::unique_ptr<DesktopDeviceInfo> desktop_device_info_;
|
||||
};
|
||||
|
||||
class WindowDeviceInfoImpl : public VideoCaptureModule::DeviceInfo {
|
||||
public:
|
||||
WindowDeviceInfoImpl(const int32_t id) : _id(id){};
|
||||
|
@ -94,82 +94,6 @@ DesktopDisplayDevice& DesktopDisplayDevice::operator= (DesktopDisplayDevice& oth
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DesktopApplication::DesktopApplication() {
|
||||
processId_ = 0;
|
||||
processPathNameUTF8_= NULL;
|
||||
applicationNameUTF8_= NULL;
|
||||
processUniqueIdUTF8_= NULL;
|
||||
windowCount_ = 0;
|
||||
}
|
||||
|
||||
DesktopApplication::~DesktopApplication() {
|
||||
if (processPathNameUTF8_) {
|
||||
delete [] processPathNameUTF8_;
|
||||
}
|
||||
|
||||
if (applicationNameUTF8_) {
|
||||
delete [] applicationNameUTF8_;
|
||||
}
|
||||
|
||||
if (processUniqueIdUTF8_) {
|
||||
delete [] processUniqueIdUTF8_;
|
||||
}
|
||||
|
||||
processPathNameUTF8_= NULL;
|
||||
applicationNameUTF8_= NULL;
|
||||
processUniqueIdUTF8_= NULL;
|
||||
}
|
||||
|
||||
void DesktopApplication::setProcessId(const ProcessId processId) {
|
||||
processId_ = processId;
|
||||
}
|
||||
|
||||
void DesktopApplication::setProcessPathName(const char *appPathNameUTF8) {
|
||||
SetStringMember(&processPathNameUTF8_, appPathNameUTF8);
|
||||
}
|
||||
|
||||
void DesktopApplication::setUniqueIdName(const char *appUniqueIdUTF8) {
|
||||
SetStringMember(&processUniqueIdUTF8_, appUniqueIdUTF8);
|
||||
}
|
||||
|
||||
void DesktopApplication::setProcessAppName(const char *appNameUTF8) {
|
||||
SetStringMember(&applicationNameUTF8_, appNameUTF8);
|
||||
}
|
||||
|
||||
void DesktopApplication::setWindowCount(const uint32_t count) {
|
||||
windowCount_ = count;
|
||||
}
|
||||
|
||||
ProcessId DesktopApplication::getProcessId() {
|
||||
return processId_;
|
||||
}
|
||||
|
||||
const char *DesktopApplication::getProcessPathName() {
|
||||
return processPathNameUTF8_;
|
||||
}
|
||||
|
||||
const char *DesktopApplication::getUniqueIdName() {
|
||||
return processUniqueIdUTF8_;
|
||||
}
|
||||
|
||||
const char *DesktopApplication::getProcessAppName() {
|
||||
return applicationNameUTF8_;
|
||||
}
|
||||
|
||||
uint32_t DesktopApplication::getWindowCount() {
|
||||
return windowCount_;
|
||||
}
|
||||
|
||||
DesktopApplication& DesktopApplication::operator= (DesktopApplication& other) {
|
||||
processId_ = other.getProcessId();
|
||||
setProcessPathName(other.getProcessPathName());
|
||||
setUniqueIdName(other.getUniqueIdName());
|
||||
setProcessAppName(other.getProcessAppName());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
DesktopTab::DesktopTab() {
|
||||
tabBrowserId_ = 0;
|
||||
tabNameUTF8_= NULL;
|
||||
@ -277,26 +201,6 @@ int32_t DesktopDeviceInfoImpl::getWindowInfo(int32_t nIndex,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t DesktopDeviceInfoImpl::getApplicationCount() {
|
||||
return desktop_application_list_.size();
|
||||
}
|
||||
|
||||
int32_t DesktopDeviceInfoImpl::getApplicationInfo(int32_t nIndex,
|
||||
DesktopApplication & desktopApplication) {
|
||||
if(nIndex < 0 || (size_t) nIndex >= desktop_application_list_.size()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::map<intptr_t,DesktopApplication*>::iterator iter = desktop_application_list_.begin();
|
||||
std::advance (iter, nIndex);
|
||||
DesktopApplication * pDesktopApplication = iter->second;
|
||||
if (pDesktopApplication) {
|
||||
desktopApplication = (*pDesktopApplication);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t DesktopDeviceInfoImpl::getTabCount() {
|
||||
return desktop_tab_list_.size();
|
||||
}
|
||||
@ -320,13 +224,11 @@ int32_t DesktopDeviceInfoImpl::getTabInfo(int32_t nIndex,
|
||||
void DesktopDeviceInfoImpl::CleanUp() {
|
||||
CleanUpScreenList();
|
||||
CleanUpWindowList();
|
||||
CleanUpApplicationList();
|
||||
CleanUpTabList();
|
||||
}
|
||||
int32_t DesktopDeviceInfoImpl::Init() {
|
||||
InitializeScreenList();
|
||||
InitializeWindowList();
|
||||
InitializeApplicationList();
|
||||
InitializeTabList();
|
||||
|
||||
return 0;
|
||||
@ -334,7 +236,6 @@ int32_t DesktopDeviceInfoImpl::Init() {
|
||||
int32_t DesktopDeviceInfoImpl::Refresh() {
|
||||
RefreshScreenList();
|
||||
RefreshWindowList();
|
||||
RefreshApplicationList();
|
||||
RefreshTabList();
|
||||
|
||||
return 0;
|
||||
@ -380,20 +281,6 @@ void DesktopDeviceInfoImpl::RefreshWindowList() {
|
||||
InitializeWindowList();
|
||||
}
|
||||
|
||||
void DesktopDeviceInfoImpl::CleanUpApplicationList() {
|
||||
std::map<intptr_t,DesktopApplication*>::iterator iterApp;
|
||||
for (iterApp = desktop_application_list_.begin(); iterApp != desktop_application_list_.end(); iterApp++){
|
||||
DesktopApplication *pDesktopApplication = iterApp->second;
|
||||
delete pDesktopApplication;
|
||||
iterApp->second = NULL;
|
||||
}
|
||||
desktop_application_list_.clear();
|
||||
}
|
||||
void DesktopDeviceInfoImpl::RefreshApplicationList() {
|
||||
CleanUpApplicationList();
|
||||
InitializeApplicationList();
|
||||
}
|
||||
|
||||
void DesktopDeviceInfoImpl::CleanUpTabList() {
|
||||
for (auto &iterTab : desktop_tab_list_) {
|
||||
DesktopTab *pDesktopTab = iterTab.second;
|
||||
|
@ -36,35 +36,6 @@ protected:
|
||||
|
||||
typedef std::map<intptr_t,DesktopDisplayDevice*> DesktopDisplayDeviceList;
|
||||
|
||||
class DesktopApplication {
|
||||
public:
|
||||
DesktopApplication();
|
||||
~DesktopApplication();
|
||||
|
||||
void setProcessId(const ProcessId processId);
|
||||
void setProcessPathName(const char *appPathNameUTF8);
|
||||
void setUniqueIdName(const char *appUniqueIdUTF8);
|
||||
void setProcessAppName(const char *appNameUTF8);
|
||||
void setWindowCount(const uint32_t count);
|
||||
|
||||
ProcessId getProcessId();
|
||||
const char *getProcessPathName();
|
||||
const char *getUniqueIdName();
|
||||
const char *getProcessAppName();
|
||||
uint32_t getWindowCount();
|
||||
|
||||
DesktopApplication& operator= (DesktopApplication& other);
|
||||
|
||||
protected:
|
||||
ProcessId processId_;
|
||||
char* processPathNameUTF8_;
|
||||
char* applicationNameUTF8_;
|
||||
char* processUniqueIdUTF8_;
|
||||
uint32_t windowCount_;
|
||||
};
|
||||
|
||||
typedef std::map<intptr_t, DesktopApplication*> DesktopApplicationList;
|
||||
|
||||
class DesktopTab {
|
||||
public:
|
||||
DesktopTab();
|
||||
@ -103,9 +74,6 @@ public:
|
||||
virtual int32_t getWindowCount() = 0;
|
||||
virtual int32_t getWindowInfo(int32_t nindex,
|
||||
DesktopDisplayDevice &windowDevice) = 0;
|
||||
virtual int32_t getApplicationCount() = 0;
|
||||
virtual int32_t getApplicationInfo(int32_t nIndex,
|
||||
DesktopApplication & desktopApplication) = 0;
|
||||
virtual int32_t getTabCount() = 0;
|
||||
virtual int32_t getTabInfo(int32_t nIndex,
|
||||
DesktopTab & desktopTab) = 0;
|
||||
@ -124,9 +92,6 @@ public:
|
||||
int32_t getWindowCount() override;
|
||||
int32_t getWindowInfo(int32_t nindex,
|
||||
DesktopDisplayDevice &windowDevice) override;
|
||||
int32_t getApplicationCount() override;
|
||||
int32_t getApplicationInfo(int32_t nIndex,
|
||||
DesktopApplication & desktopApplication) override;
|
||||
int32_t getTabCount() override;
|
||||
int32_t getTabInfo(int32_t nIndex,
|
||||
DesktopTab & desktopTab) override;
|
||||
@ -134,22 +99,18 @@ public:
|
||||
protected:
|
||||
DesktopDisplayDeviceList desktop_display_list_;
|
||||
DesktopDisplayDeviceList desktop_window_list_;
|
||||
DesktopApplicationList desktop_application_list_;
|
||||
DesktopTabList desktop_tab_list_;
|
||||
|
||||
void CleanUp();
|
||||
void CleanUpWindowList();
|
||||
void CleanUpApplicationList();
|
||||
void CleanUpTabList();
|
||||
void CleanUpScreenList();
|
||||
|
||||
void InitializeWindowList();
|
||||
virtual void InitializeApplicationList() = 0;
|
||||
virtual void InitializeTabList();
|
||||
virtual void InitializeScreenList() = 0;
|
||||
|
||||
void RefreshWindowList();
|
||||
void RefreshApplicationList();
|
||||
void RefreshTabList();
|
||||
void RefreshScreenList();
|
||||
|
||||
|
@ -46,91 +46,4 @@ void DesktopDeviceInfoX11::InitializeScreenList() {
|
||||
MultiMonitorScreenshare();
|
||||
}
|
||||
|
||||
void DesktopDeviceInfoX11::InitializeApplicationList() {
|
||||
//List all running applications exclude background process.
|
||||
rtc::scoped_refptr<SharedXDisplay> SharedDisplay = SharedXDisplay::CreateDefault();
|
||||
XErrorTrap error_trap(SharedDisplay->display());
|
||||
|
||||
WindowUtilX11 window_util_x11(SharedDisplay);
|
||||
int num_screens = XScreenCount(SharedDisplay->display());
|
||||
for (int screen = 0; screen < num_screens; ++screen) {
|
||||
::Window root_window = XRootWindow(SharedDisplay->display(), screen);
|
||||
::Window parent;
|
||||
::Window *children;
|
||||
unsigned int num_children;
|
||||
int status = XQueryTree(SharedDisplay->display(), root_window, &root_window, &parent,
|
||||
&children, &num_children);
|
||||
if (status == 0) {
|
||||
RTC_LOG(LS_ERROR) << "Failed to query for child windows for screen " << screen;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < num_children; ++i) {
|
||||
::Window app_window = window_util_x11.GetApplicationWindow(children[num_children - 1 - i]);
|
||||
|
||||
if (!app_window
|
||||
|| window_util_x11.IsDesktopElement(app_window)
|
||||
|| window_util_x11.GetWindowStatus(app_window) == WithdrawnState) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned int processId = window_util_x11.GetWindowProcessID(app_window);
|
||||
// filter out non-process
|
||||
if (processId == 0) {
|
||||
continue;
|
||||
}
|
||||
// filter out current process
|
||||
if (processId == getpid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// filter out existing applications, after incrementing its window count
|
||||
DesktopApplicationList::iterator itr = desktop_application_list_.find(processId);
|
||||
if (itr != desktop_application_list_.end()) {
|
||||
itr->second->setWindowCount(itr->second->getWindowCount() + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add one application
|
||||
DesktopApplication *pDesktopApplication = new DesktopApplication;
|
||||
if (!pDesktopApplication) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// process id
|
||||
pDesktopApplication->setProcessId(processId);
|
||||
// initialize count to 1
|
||||
pDesktopApplication->setWindowCount(1);
|
||||
|
||||
// process path name
|
||||
pDesktopApplication->setProcessPathName("");
|
||||
|
||||
// application name
|
||||
std::string strAppName;
|
||||
window_util_x11.GetWindowTitle(app_window, &strAppName);
|
||||
pDesktopApplication->setProcessAppName(strAppName.c_str());
|
||||
|
||||
// unique id name
|
||||
char idStr[64];
|
||||
snprintf(idStr, sizeof(idStr), "%ld", pDesktopApplication->getProcessId());
|
||||
pDesktopApplication->setUniqueIdName(idStr);
|
||||
desktop_application_list_[processId] = pDesktopApplication;
|
||||
}
|
||||
|
||||
// re-walk the application list, prepending the window count to the application name
|
||||
DesktopApplicationList::iterator itr;
|
||||
for (itr = desktop_application_list_.begin(); itr != desktop_application_list_.end(); itr++) {
|
||||
DesktopApplication *pApp = itr->second;
|
||||
// localized name can be *VERY* large
|
||||
char nameStr[BUFSIZ];
|
||||
snprintf(nameStr, sizeof(nameStr), "%d\x1e%s",
|
||||
pApp->getWindowCount(), pApp->getProcessAppName());
|
||||
pApp->setProcessAppName(nameStr);
|
||||
}
|
||||
|
||||
if (children) {
|
||||
XFree(children);
|
||||
}
|
||||
}
|
||||
}
|
||||
} //namespace webrtc
|
||||
|
@ -21,7 +21,6 @@ public:
|
||||
|
||||
protected:
|
||||
//DesktopDeviceInfo Interfaces
|
||||
virtual void InitializeApplicationList() override;
|
||||
virtual void InitializeScreenList() override;
|
||||
|
||||
private:
|
||||
|
@ -17,7 +17,6 @@ public:
|
||||
|
||||
protected:
|
||||
//DesktopDeviceInfo Interfaces
|
||||
virtual void InitializeApplicationList() override;
|
||||
virtual void InitializeScreenList() override;
|
||||
|
||||
private:
|
||||
|
@ -75,69 +75,4 @@ void DesktopDeviceInfoMac::InitializeScreenList() {
|
||||
MultiMonitorScreenshare();
|
||||
}
|
||||
|
||||
void DesktopDeviceInfoMac::InitializeApplicationList() {
|
||||
//List all running applications (excluding background processes).
|
||||
|
||||
// Get a list of all windows, to match to applications
|
||||
AppWindowCountMap appWins;
|
||||
CFArrayRef windowInfos = CGWindowListCopyWindowInfo(
|
||||
kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements,
|
||||
kCGNullWindowID);
|
||||
CFIndex windowInfosCount = CFArrayGetCount(windowInfos);
|
||||
for (CFIndex idx = 0; idx < windowInfosCount; idx++) {
|
||||
CFDictionaryRef info = reinterpret_cast<CFDictionaryRef>(
|
||||
CFArrayGetValueAtIndex(windowInfos, idx));
|
||||
CFNumberRef winOwner = reinterpret_cast<CFNumberRef>(
|
||||
CFDictionaryGetValue(info, kCGWindowOwnerPID));
|
||||
|
||||
pid_t owner;
|
||||
CFNumberGetValue(winOwner, kCFNumberIntType, &owner);
|
||||
AppWindowCountMap::iterator itr = appWins.find(owner);
|
||||
if (itr == appWins.end()) {
|
||||
appWins[owner] = 1;
|
||||
} else {
|
||||
appWins[owner]++;
|
||||
}
|
||||
}
|
||||
|
||||
NSArray *running = [[NSWorkspace sharedWorkspace] runningApplications];
|
||||
for (NSRunningApplication *ra in running) {
|
||||
if (ra.activationPolicy != NSApplicationActivationPolicyRegular)
|
||||
continue;
|
||||
|
||||
ProcessId pid = ra.processIdentifier;
|
||||
if (pid == 0) {
|
||||
continue;
|
||||
}
|
||||
if (pid == getpid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DesktopApplication *pDesktopApplication = new DesktopApplication;
|
||||
if (!pDesktopApplication) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pDesktopApplication->setProcessId(pid);
|
||||
pDesktopApplication->setWindowCount(appWins[pid]);
|
||||
|
||||
NSString *str;
|
||||
str = [ra.executableURL absoluteString];
|
||||
pDesktopApplication->setProcessPathName([str UTF8String]);
|
||||
|
||||
// Record <window count> then <localized name>
|
||||
// NOTE: localized names can get *VERY* long
|
||||
str = ra.localizedName;
|
||||
char nameStr[BUFSIZ];
|
||||
snprintf(nameStr, sizeof(nameStr), "%d\x1e%s", pDesktopApplication->getWindowCount(), [str UTF8String]);
|
||||
pDesktopApplication->setProcessAppName(nameStr);
|
||||
|
||||
char idStr[64];
|
||||
snprintf(idStr, sizeof(idStr), "%ld", pDesktopApplication->getProcessId());
|
||||
pDesktopApplication->setUniqueIdName(idStr);
|
||||
|
||||
desktop_application_list_[pDesktopApplication->getProcessId()] = pDesktopApplication;
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace webrtc
|
||||
|
@ -78,110 +78,4 @@ void DesktopDeviceInfoWin::InitializeScreenList() {
|
||||
MultiMonitorScreenshare();
|
||||
}
|
||||
|
||||
void DesktopDeviceInfoWin::InitializeApplicationList() {
|
||||
// List all running applications exclude background process.
|
||||
HWND hWnd;
|
||||
for (hWnd = GetWindow(GetDesktopWindow(), GW_CHILD); hWnd; hWnd = GetWindow(hWnd, GW_HWNDNEXT)) {
|
||||
if (!IsWindowVisible(hWnd)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DWORD dwProcessId = 0;
|
||||
GetWindowThreadProcessId(hWnd, &dwProcessId);
|
||||
|
||||
// filter out non-process, current process
|
||||
if (dwProcessId == 0 || dwProcessId == GetCurrentProcessId()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Win8 introduced "Modern Apps" whose associated window is
|
||||
// non-shareable. We want to filter them out.
|
||||
const int classLength = 256;
|
||||
WCHAR class_name[classLength] = {0};
|
||||
GetClassName(hWnd, class_name, classLength);
|
||||
if (IsWindows8OrGreater() &&
|
||||
(wcscmp(class_name, L"ApplicationFrameWindow") == 0 ||
|
||||
wcscmp(class_name, L"Windows.UI.Core.CoreWindow") == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// filter out already-seen processes, after updating the window count
|
||||
DesktopApplicationList::iterator itr = desktop_application_list_.find(dwProcessId);
|
||||
if (itr != desktop_application_list_.end()) {
|
||||
itr->second->setWindowCount(itr->second->getWindowCount() + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add one application
|
||||
DesktopApplication *pDesktopApplication = new DesktopApplication;
|
||||
if (!pDesktopApplication) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// process id
|
||||
pDesktopApplication->setProcessId(dwProcessId);
|
||||
// initialize window count to 1 (updated on subsequent finds)
|
||||
pDesktopApplication->setWindowCount(1);
|
||||
|
||||
// process path name
|
||||
WCHAR szFilePathName[MAX_PATH]={0};
|
||||
decltype(QueryFullProcessImageName) *lpfnQueryFullProcessImageNameProc =
|
||||
reinterpret_cast<decltype(QueryFullProcessImageName) *>(GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "QueryFullProcessImageNameW"));
|
||||
if (lpfnQueryFullProcessImageNameProc) {
|
||||
// After Vista
|
||||
DWORD dwMaxSize = _MAX_PATH;
|
||||
HANDLE hWndPro = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, dwProcessId);
|
||||
if(hWndPro) {
|
||||
lpfnQueryFullProcessImageNameProc(hWndPro, 0, szFilePathName, &dwMaxSize);
|
||||
CloseHandle(hWndPro);
|
||||
}
|
||||
} else {
|
||||
HMODULE hModPSAPI = LoadLibrary(TEXT("PSAPI.dll"));
|
||||
if (hModPSAPI) {
|
||||
decltype(GetProcessImageFileName) *pfnGetProcessImageFileName =
|
||||
reinterpret_cast<decltype(GetProcessImageFileName) *>(GetProcAddress(hModPSAPI, "GetProcessImageFileNameW"));
|
||||
|
||||
if (pfnGetProcessImageFileName) {
|
||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, dwProcessId);
|
||||
if (hProcess) {
|
||||
DWORD dwMaxSize = _MAX_PATH;
|
||||
pfnGetProcessImageFileName(hProcess, szFilePathName, dwMaxSize);
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
}
|
||||
FreeLibrary(hModPSAPI);
|
||||
}
|
||||
}
|
||||
pDesktopApplication->setProcessPathName(Utf16ToUtf8(szFilePathName).c_str());
|
||||
|
||||
// application name
|
||||
WCHAR szWndTitle[_MAX_PATH]={0};
|
||||
GetWindowText(hWnd, szWndTitle, MAX_PATH);
|
||||
if (lstrlen(szWndTitle) <= 0) {
|
||||
pDesktopApplication->setProcessAppName(Utf16ToUtf8(szFilePathName).c_str());
|
||||
} else {
|
||||
pDesktopApplication->setProcessAppName(Utf16ToUtf8(szWndTitle).c_str());
|
||||
}
|
||||
|
||||
// unique id name
|
||||
char idStr[64];
|
||||
_snprintf_s(idStr, sizeof(idStr), sizeof(idStr) - 1, "%ld", pDesktopApplication->getProcessId());
|
||||
pDesktopApplication->setUniqueIdName(idStr);
|
||||
|
||||
desktop_application_list_[pDesktopApplication->getProcessId()] = pDesktopApplication;
|
||||
}
|
||||
|
||||
// re-walk the application list, prepending the window count to the application name
|
||||
DesktopApplicationList::iterator itr;
|
||||
for (itr = desktop_application_list_.begin(); itr != desktop_application_list_.end(); itr++) {
|
||||
DesktopApplication *pApp = itr->second;
|
||||
|
||||
// localized application names can be *VERY* large
|
||||
char nameStr[BUFSIZ];
|
||||
_snprintf_s(nameStr, sizeof(nameStr), sizeof(nameStr) - 1, "%d\x1e%s",
|
||||
pApp->getWindowCount(), pApp->getProcessAppName());
|
||||
pApp->setProcessAppName(nameStr);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -17,7 +17,6 @@ public:
|
||||
|
||||
protected:
|
||||
//DesktopDeviceInfo Interfaces
|
||||
virtual void InitializeApplicationList() override;
|
||||
virtual void InitializeScreenList() override;
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user