2014-04-28 17:59:53 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#define blog(level, msg, ...) blog(level, "xcompcap: " msg, ##__VA_ARGS__)
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
class PLock {
|
2014-04-28 17:59:53 -07:00
|
|
|
pthread_mutex_t *m;
|
|
|
|
bool islock;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
public:
|
|
|
|
PLock(const PLock &) = delete;
|
|
|
|
PLock &operator=(const PLock &) = delete;
|
2014-04-28 17:59:53 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
PLock(pthread_mutex_t *mtx, bool trylock = false);
|
2014-04-28 17:59:53 -07:00
|
|
|
|
|
|
|
~PLock();
|
|
|
|
|
|
|
|
bool isLocked();
|
|
|
|
|
|
|
|
void unlock();
|
|
|
|
void lock();
|
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
class XErrorLock {
|
2014-04-28 17:59:53 -07:00
|
|
|
bool islock;
|
|
|
|
bool goterr;
|
|
|
|
XErrorHandler prevhandler;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
public:
|
|
|
|
XErrorLock(const XErrorLock &) = delete;
|
|
|
|
XErrorLock &operator=(const XErrorLock &) = delete;
|
2014-04-28 17:59:53 -07:00
|
|
|
|
|
|
|
XErrorLock();
|
|
|
|
~XErrorLock();
|
|
|
|
|
|
|
|
bool isLocked();
|
|
|
|
|
|
|
|
void unlock();
|
|
|
|
void lock();
|
|
|
|
|
|
|
|
bool gotError();
|
|
|
|
std::string getErrorText();
|
|
|
|
void resetError();
|
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
class XDisplayLock {
|
linux-capture: Fix window capture crashes
The xcomposite window capture crashes were due to a few factors:
-------------------------------
1.) The source's X error handler was possibly being overwritten by
another part of the program despite us locking the display, presumably
something in Qt which isn't locking the display when pushing/popping its
own error handler (though this is not yet certain). The source's calls
to X functions happen in the graphics thread, which is separate from the
UI thread, and it was noticed that somehow the error handler would be
overwritten almost seemingly at random, indicating that something else
in the program outside of OBS code was not locking the display while
pushing/popping the error handler.
To replicate this, make it so that the source cannot find the target
window and so it continually searches for it each video_tick call, then
resize the main OBS window continually (which causes Qt to push/pop its
own error handlers). A crash will almost always occur due to BadWindow
despite our error handling.
2.) Calling X functions with a window ID that no longer exists,
particularly XGetWindowAttributes, in conjunction the unknown error
handler set in case #1 would cause the program to outright crash because
that error handler is programmed to crash on BadWindow for whatever
reason. The source would call X functions without even checking if
'win' was 0.
3.) The source stored window IDs (in JSON, even if they've long since
become invalid/pointless, such as system restarts). This is a bad
practice and will result in more cases of BadWindow.
Fixing the problem (reducing the possibility of getting BadWindow):
-------------------------------
Step 1.) Deprecate and ignore window IDs in stored settings. Instead of
using window IDs to find the window, we now must always search the
windows and find the target window via the window name exclusively.
This helps ensure that we actually consistently have a working window
ID.
Step 2.) Do not call any X functions if the window ID is 0.
Step 3.) Reset the window ID to 0 any time the window has updated, and
make the source find the window again to ensure it still exists before
attempting to use any X functions on the window ID again.
2016-06-04 14:20:41 -07:00
|
|
|
bool islock;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
public:
|
|
|
|
XDisplayLock(const XDisplayLock &) = delete;
|
|
|
|
XDisplayLock &operator=(const XDisplayLock &) = delete;
|
linux-capture: Fix window capture crashes
The xcomposite window capture crashes were due to a few factors:
-------------------------------
1.) The source's X error handler was possibly being overwritten by
another part of the program despite us locking the display, presumably
something in Qt which isn't locking the display when pushing/popping its
own error handler (though this is not yet certain). The source's calls
to X functions happen in the graphics thread, which is separate from the
UI thread, and it was noticed that somehow the error handler would be
overwritten almost seemingly at random, indicating that something else
in the program outside of OBS code was not locking the display while
pushing/popping the error handler.
To replicate this, make it so that the source cannot find the target
window and so it continually searches for it each video_tick call, then
resize the main OBS window continually (which causes Qt to push/pop its
own error handlers). A crash will almost always occur due to BadWindow
despite our error handling.
2.) Calling X functions with a window ID that no longer exists,
particularly XGetWindowAttributes, in conjunction the unknown error
handler set in case #1 would cause the program to outright crash because
that error handler is programmed to crash on BadWindow for whatever
reason. The source would call X functions without even checking if
'win' was 0.
3.) The source stored window IDs (in JSON, even if they've long since
become invalid/pointless, such as system restarts). This is a bad
practice and will result in more cases of BadWindow.
Fixing the problem (reducing the possibility of getting BadWindow):
-------------------------------
Step 1.) Deprecate and ignore window IDs in stored settings. Instead of
using window IDs to find the window, we now must always search the
windows and find the target window via the window name exclusively.
This helps ensure that we actually consistently have a working window
ID.
Step 2.) Do not call any X functions if the window ID is 0.
Step 3.) Reset the window ID to 0 any time the window has updated, and
make the source find the window again to ensure it still exists before
attempting to use any X functions on the window ID again.
2016-06-04 14:20:41 -07:00
|
|
|
|
|
|
|
XDisplayLock();
|
|
|
|
~XDisplayLock();
|
|
|
|
|
|
|
|
bool isLocked();
|
|
|
|
|
|
|
|
void unlock();
|
|
|
|
void lock();
|
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
class ObsGsContextHolder {
|
|
|
|
public:
|
|
|
|
ObsGsContextHolder(const ObsGsContextHolder &) = delete;
|
|
|
|
ObsGsContextHolder &operator=(const ObsGsContextHolder &) = delete;
|
2014-04-28 17:59:53 -07:00
|
|
|
|
|
|
|
ObsGsContextHolder();
|
|
|
|
~ObsGsContextHolder();
|
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
namespace XCompcap {
|
|
|
|
Display *disp();
|
|
|
|
void cleanupDisplay();
|
|
|
|
|
|
|
|
std::string getWindowCommand(Window win);
|
|
|
|
int getRootWindowScreen(Window root);
|
|
|
|
std::string getWindowAtom(Window win, const char *atom);
|
|
|
|
int getWindowPid(Window win);
|
|
|
|
bool ewmhIsSupported();
|
|
|
|
std::list<Window> getTopLevelWindows();
|
|
|
|
std::list<Window> getAllWindows();
|
|
|
|
|
|
|
|
inline std::string getWindowName(Window win)
|
|
|
|
{
|
|
|
|
return getWindowAtom(win, "_NET_WM_NAME");
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string getWindowClass(Window win)
|
2014-04-28 17:59:53 -07:00
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
return getWindowAtom(win, "WM_CLASS");
|
|
|
|
}
|
|
|
|
|
|
|
|
void processEvents();
|
|
|
|
bool windowWasReconfigured(Window win);
|
2014-04-28 17:59:53 -07:00
|
|
|
}
|