[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() : NvFBC::NvFBC() :
m_options(NULL), m_options(NULL),
m_optCrop(false), m_optNoCrop(false),
m_optNoWait(false), m_optNoWait(false),
m_initialized(false), m_initialized(false),
m_hDLL(NULL), m_hDLL(NULL),
@ -51,11 +51,11 @@ bool NvFBC::Initialize(CaptureOptions * options)
DeInitialize(); DeInitialize();
m_options = options; m_options = options;
m_optCrop = false; m_optNoCrop = false;
for (CaptureOptions::const_iterator it = options->cbegin(); it != options->cend(); ++it) 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; } if (_strcmpi(*it, "nowait") == 0) { m_optNoWait = true ; continue; }
} }
std::string nvfbc = Util::GetSystemRoot() + "\\" + NVFBC_LIBRARY_NAME; std::string nvfbc = Util::GetSystemRoot() + "\\" + NVFBC_LIBRARY_NAME;
@ -217,15 +217,9 @@ enum GrabStatus NvFBC::GrabFrame(struct FrameInfo & frame)
if (!m_initialized) if (!m_initialized)
return GRAB_STATUS_ERROR; 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) for(int i = 0; i < 2; ++i)
{ {
NVFBCRESULT status = m_nvFBC->NvFBCToSysGrabFrame(&m_grabFrameParams); NVFBCRESULT status = m_nvFBC->NvFBCToSysGrabFrame(&m_grabFrameParams);
if (status == NVFBC_SUCCESS) if (status == NVFBC_SUCCESS)
{ {
@ -249,25 +243,46 @@ enum GrabStatus NvFBC::GrabFrame(struct FrameInfo & frame)
unsigned int dataWidth; unsigned int dataWidth;
unsigned int dataOffset; unsigned int dataOffset;
if (m_optCrop) if (m_optNoCrop)
{ {
const unsigned int realHeight = min(m_grabInfo.dwHeight, screenHeight); dataWidth = m_grabInfo.dwWidth * 4;
const unsigned int realWidth = min(m_grabInfo.dwWidth, screenWidth); dataOffset = 0;
dataWidth = realWidth * 4; frame.width = m_grabInfo.dwWidth;
dataOffset = frame.height = m_grabInfo.dwHeight;
(((m_grabInfo.dwHeight - realHeight) >> 1) * m_grabInfo.dwBufferWidth +
((m_grabInfo.dwWidth - realWidth) >> 1)) * 4;
frame.width = realWidth;
frame.height = realHeight;
} }
else else
{ {
dataWidth = m_grabInfo.dwWidth * 4; // get the actual resolution
dataOffset = 0; HMONITOR monitor = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTOPRIMARY);
MONITORINFO monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFO);
frame.width = m_grabInfo.dwWidth; unsigned int screenWidth, screenHeight;
frame.height = m_grabInfo.dwHeight; 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;
} }
frame.stride = frame.width; frame.stride = frame.width;

View File

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