[host] Cropping is still required on NvFBC... :(

This commit is contained in:
Geoffrey McRae 2017-12-08 17:51:47 +11:00
parent 59a894ae04
commit ad6c2ab544
2 changed files with 41 additions and 26 deletions

View File

@ -33,7 +33,7 @@ using namespace Capture;
NvFBC::NvFBC() :
m_options(NULL),
m_optCrop(false),
m_optNoCrop(false),
m_optNoWait(false),
m_initialized(false),
m_hDLL(NULL),
@ -51,10 +51,10 @@ bool NvFBC::Initialize(CaptureOptions * options)
DeInitialize();
m_options = options;
m_optCrop = false;
m_optNoCrop = false;
for (CaptureOptions::const_iterator it = options->cbegin(); it != options->cend(); ++it)
{
if (_strcmpi(*it, "crop" ) == 0) { m_optCrop = true; continue; }
if (_strcmpi(*it, "nocrop") == 0) { m_optNoCrop = false; continue; }
if (_strcmpi(*it, "nowait") == 0) { m_optNoWait = true ; continue; }
}
@ -217,12 +217,6 @@ enum GrabStatus NvFBC::GrabFrame(struct FrameInfo & frame)
if (!m_initialized)
return GRAB_STATUS_ERROR;
const HWND hDesktop = GetDesktopWindow();
const unsigned int screenWidth = GetSystemMetrics(SM_CXSCREEN);
const unsigned int screenHeight = GetSystemMetrics(SM_CYSCREEN);
RECT desktop;
GetWindowRect(hDesktop, &desktop);
for(int i = 0; i < 2; ++i)
{
NVFBCRESULT status = m_nvFBC->NvFBCToSysGrabFrame(&m_grabFrameParams);
@ -249,26 +243,47 @@ enum GrabStatus NvFBC::GrabFrame(struct FrameInfo & frame)
unsigned int dataWidth;
unsigned int dataOffset;
if (m_optCrop)
if (m_optNoCrop)
{
dataWidth = m_grabInfo.dwWidth * 4;
dataOffset = 0;
frame.width = m_grabInfo.dwWidth;
frame.height = m_grabInfo.dwHeight;
}
else
{
// get the actual resolution
HMONITOR monitor = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTOPRIMARY);
MONITORINFO monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFO);
unsigned int screenWidth, screenHeight;
if (!GetMonitorInfo(monitor, &monitorInfo))
{
DEBUG_WARN("Failed to get monitor dimensions, assuming no cropping required");
screenWidth = m_grabInfo.dwWidth;
screenHeight = m_grabInfo.dwHeight;;
}
else
{
screenWidth = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left;
screenHeight = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top;
}
// use the smaller or the two dimensions provided just to be sure we don't overflow the buffer
const unsigned int realHeight = min(m_grabInfo.dwHeight, screenHeight);
const unsigned int realWidth = min(m_grabInfo.dwWidth , screenWidth );
// calculate the new data width and offset to the start of the data
dataWidth = realWidth * 4;
dataOffset =
(((m_grabInfo.dwHeight - realHeight) >> 1) * m_grabInfo.dwBufferWidth +
((m_grabInfo.dwWidth - realWidth ) >> 1)) * 4;
// update the frame size
frame.width = realWidth;
frame.height = realHeight;
}
else
{
dataWidth = m_grabInfo.dwWidth * 4;
dataOffset = 0;
frame.width = m_grabInfo.dwWidth;
frame.height = m_grabInfo.dwHeight;
}
frame.stride = frame.width;
frame.outSize = frame.width * frame.height * 4;

View File

@ -49,7 +49,7 @@ namespace Capture
private:
CaptureOptions * m_options;
bool m_optCrop;
bool m_optNoCrop;
bool m_optNoWait;
bool m_initialized;