mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Merge remote-tracking branch 'origin/grabberDiscovery' into mediafoundation
This commit is contained in:
@@ -22,7 +22,7 @@ void check_error(xcb_generic_error_t * error)
|
||||
// Requests with void response type
|
||||
template<class Request, class ...Args>
|
||||
typename std::enable_if<std::is_same<typename Request::ResponseType, xcb_void_cookie_t>::value, void>::type
|
||||
query(xcb_connection_t * connection, Args&& ...args)
|
||||
static query(xcb_connection_t * connection, Args&& ...args)
|
||||
{
|
||||
auto cookie = Request::RequestFunction(connection, std::forward<Args>(args)...);
|
||||
|
||||
@@ -33,9 +33,8 @@ template<class Request, class ...Args>
|
||||
|
||||
// Requests with non-void response type
|
||||
template<class Request, class ...Args>
|
||||
typename std::enable_if<!std::is_same<typename Request::ResponseType, xcb_void_cookie_t>::value,
|
||||
std::unique_ptr<typename Request::ResponseType, decltype(&free)>>::type
|
||||
query(xcb_connection_t * connection, Args&& ...args)
|
||||
typename std::enable_if<!std::is_same<typename Request::ResponseType, xcb_void_cookie_t>::value, std::unique_ptr<typename Request::ResponseType, decltype(&free)>>::type
|
||||
static query(xcb_connection_t * connection, Args&& ...args)
|
||||
{
|
||||
auto cookie = Request::RequestFunction(connection, std::forward<Args>(args)...);
|
||||
|
||||
|
@@ -21,6 +21,14 @@ struct GetGeometry
|
||||
static constexpr auto ReplyFunction = xcb_get_geometry_reply;
|
||||
};
|
||||
|
||||
struct GetProperty
|
||||
{
|
||||
typedef xcb_get_property_reply_t ResponseType;
|
||||
|
||||
static constexpr auto RequestFunction = xcb_get_property;
|
||||
static constexpr auto ReplyFunction = xcb_get_property_reply;
|
||||
};
|
||||
|
||||
struct ShmQueryVersion
|
||||
{
|
||||
typedef xcb_shm_query_version_reply_t ResponseType;
|
||||
|
@@ -14,6 +14,11 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
// Constants
|
||||
namespace {
|
||||
const bool verbose = false;
|
||||
} //End of constants
|
||||
|
||||
#define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
|
||||
|
||||
XcbGrabber::XcbGrabber(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation)
|
||||
@@ -36,6 +41,7 @@ XcbGrabber::XcbGrabber(int cropLeft, int cropRight, int cropTop, int cropBottom,
|
||||
, _XcbRandRAvailable{}
|
||||
, _XcbShmAvailable{}
|
||||
, _XcbShmPixmapAvailable{}
|
||||
, _isWayland (false)
|
||||
, _logger{}
|
||||
, _shmData{}
|
||||
, _XcbRandREventBase{-1}
|
||||
@@ -181,48 +187,77 @@ void XcbGrabber::setupShm()
|
||||
}
|
||||
}
|
||||
|
||||
bool XcbGrabber::Setup()
|
||||
bool XcbGrabber::open()
|
||||
{
|
||||
int screen_num;
|
||||
_connection = xcb_connect(nullptr, &screen_num);
|
||||
bool rc = false;
|
||||
|
||||
int ret = xcb_connection_has_error(_connection);
|
||||
if (ret != 0)
|
||||
if (getenv("WAYLAND_DISPLAY") != nullptr)
|
||||
{
|
||||
Error(_logger, "Cannot open display, error %d", ret);
|
||||
return false;
|
||||
_isWayland = true;
|
||||
}
|
||||
|
||||
const xcb_setup_t * setup = xcb_get_setup(_connection);
|
||||
_screen = getScreen(setup, screen_num);
|
||||
|
||||
if (!_screen)
|
||||
else
|
||||
{
|
||||
Error(_log, "Unable to open display, screen %d does not exist", screen_num);
|
||||
_connection = xcb_connect(nullptr, &_screen_num);
|
||||
|
||||
if (getenv("DISPLAY"))
|
||||
Error(_log, "%s", getenv("DISPLAY"));
|
||||
int ret = xcb_connection_has_error(_connection);
|
||||
if (ret != 0)
|
||||
{
|
||||
Debug(_logger, "Cannot open display, error %d", ret);
|
||||
}
|
||||
else
|
||||
Error(_log, "DISPLAY environment variable not set");
|
||||
|
||||
freeResources();
|
||||
return false;
|
||||
{
|
||||
const xcb_setup_t * setup = xcb_get_setup(_connection);
|
||||
_screen = getScreen(setup, _screen_num);
|
||||
if ( _screen != nullptr)
|
||||
{
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setupRandr();
|
||||
setupRender();
|
||||
setupShm();
|
||||
return rc;
|
||||
}
|
||||
|
||||
Info(_log, QString("XcbRandR=[%1] XcbRender=[%2] XcbShm=[%3] XcbPixmap=[%4]")
|
||||
.arg(_XcbRandRAvailable ? "available" : "unavailable")
|
||||
.arg(_XcbRenderAvailable ? "available" : "unavailable")
|
||||
.arg(_XcbShmAvailable ? "available" : "unavailable")
|
||||
.arg(_XcbShmPixmapAvailable ? "available" : "unavailable")
|
||||
.toStdString().c_str());
|
||||
bool XcbGrabber::setupDisplay()
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
bool result = (updateScreenDimensions(true) >= 0);
|
||||
ErrorIf(!result, _log, "XCB Grabber start failed");
|
||||
setEnabled(result);
|
||||
if ( ! open() )
|
||||
{
|
||||
if ( _isWayland )
|
||||
{
|
||||
Error(_log, "Grabber does not work under Wayland!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getenv("DISPLAY") != nullptr)
|
||||
{
|
||||
Error(_log, "Unable to open display [%s], screen %d does not exist", getenv("DISPLAY"), _screen_num);
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "DISPLAY environment variable not set");
|
||||
}
|
||||
freeResources();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setupRandr();
|
||||
setupRender();
|
||||
setupShm();
|
||||
|
||||
Info(_log, QString("XcbRandR=[%1] XcbRender=[%2] XcbShm=[%3] XcbPixmap=[%4]")
|
||||
.arg(_XcbRandRAvailable ? "available" : "unavailable")
|
||||
.arg(_XcbRenderAvailable ? "available" : "unavailable")
|
||||
.arg(_XcbShmAvailable ? "available" : "unavailable")
|
||||
.arg(_XcbShmPixmapAvailable ? "available" : "unavailable")
|
||||
.toStdString().c_str());
|
||||
|
||||
result = (updateScreenDimensions(true) >= 0);
|
||||
ErrorIf(!result, _log, "XCB Grabber start failed");
|
||||
setEnabled(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -394,13 +429,15 @@ void XcbGrabber::setVideoMode(VideoMode mode)
|
||||
updateScreenDimensions(true);
|
||||
}
|
||||
|
||||
void XcbGrabber::setPixelDecimation(int pixelDecimation)
|
||||
bool XcbGrabber::setPixelDecimation(int pixelDecimation)
|
||||
{
|
||||
if(_pixelDecimation != pixelDecimation)
|
||||
if(Grabber::setPixelDecimation(pixelDecimation))
|
||||
{
|
||||
_pixelDecimation = pixelDecimation;
|
||||
updateScreenDimensions(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void XcbGrabber::setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom)
|
||||
@@ -459,3 +496,89 @@ xcb_render_pictformat_t XcbGrabber::findFormatForVisual(xcb_visualid_t visual) c
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
QJsonObject XcbGrabber::discover(const QJsonObject& params)
|
||||
{
|
||||
DebugIf(verbose, _log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
|
||||
QJsonObject inputsDiscovered;
|
||||
if ( open() )
|
||||
{
|
||||
inputsDiscovered["device"] = "xcb";
|
||||
inputsDiscovered["device_name"] = "XCB";
|
||||
inputsDiscovered["type"] = "screen";
|
||||
|
||||
QJsonArray video_inputs;
|
||||
|
||||
if (_connection != nullptr && _screen != nullptr )
|
||||
{
|
||||
QJsonArray fps = { 1, 5, 10, 15, 20, 25, 30, 40, 50, 60 };
|
||||
|
||||
const xcb_setup_t * setup = xcb_get_setup(_connection);
|
||||
|
||||
xcb_screen_iterator_t it = xcb_setup_roots_iterator(setup);
|
||||
xcb_screen_t * screen = nullptr;
|
||||
|
||||
int i = 0;
|
||||
// Iterate through all X screens
|
||||
for (; it.rem > 0; xcb_screen_next(&it))
|
||||
{
|
||||
screen = it.data;
|
||||
|
||||
auto geometry = query<GetGeometry>(_connection, screen->root);
|
||||
if (geometry == nullptr)
|
||||
{
|
||||
Debug(_log, "Failed to obtain screen geometry for screen [%d]", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
QJsonObject in;
|
||||
|
||||
QString displayName;
|
||||
auto property = query<GetProperty>(_connection, 0, screen->root, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 0, 0);
|
||||
if ( property != nullptr )
|
||||
{
|
||||
if ( xcb_get_property_value_length(property.get()) > 0 )
|
||||
{
|
||||
displayName = (char *) xcb_get_property_value(property.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (displayName.isEmpty())
|
||||
{
|
||||
displayName = QString("Display:%1").arg(i);
|
||||
}
|
||||
|
||||
in["name"] = displayName;
|
||||
in["inputIdx"] = i;
|
||||
|
||||
QJsonArray formats;
|
||||
QJsonArray resolutionArray;
|
||||
QJsonObject format;
|
||||
QJsonObject resolution;
|
||||
|
||||
resolution["width"] = geometry->width;
|
||||
resolution["height"] = geometry->height;
|
||||
resolution["fps"] = fps;
|
||||
|
||||
resolutionArray.append(resolution);
|
||||
|
||||
format["resolutions"] = resolutionArray;
|
||||
formats.append(format);
|
||||
|
||||
in["formats"] = formats;
|
||||
video_inputs.append(in);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
if ( !video_inputs.isEmpty() )
|
||||
{
|
||||
inputsDiscovered["video_inputs"] = video_inputs;
|
||||
}
|
||||
}
|
||||
}
|
||||
DebugIf(verbose, _log, "device: [%s]", QString(QJsonDocument(inputsDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
|
||||
return inputsDiscovered;
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ void XcbWrapper::action()
|
||||
if (! _init )
|
||||
{
|
||||
_init = true;
|
||||
if ( ! _grabber.Setup() )
|
||||
if ( ! _grabber.setupDisplay() )
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
Reference in New Issue
Block a user