[host] adjusted frame and cursor offset calculations

This commit is contained in:
Geoffrey McRae 2017-12-29 06:10:50 +11:00
parent 40bfdcdf8c
commit f6f4c8070a

View File

@ -75,7 +75,17 @@ bool Service::Initialize(ICapture * captureDevice)
} }
if (!InitPointers()) if (!InitPointers())
{
DeInitialize();
return false; return false;
}
if (m_capture->GetMaxFrameSize() > m_frameSize)
{
DEBUG_ERROR("Maximum frame size of %zu bytes excceds maximum space available", m_capture->GetMaxFrameSize());
DeInitialize();
return false;
}
m_timer = CreateWaitableTimer(NULL, TRUE, NULL); m_timer = CreateWaitableTimer(NULL, TRUE, NULL);
if (!m_timer) if (!m_timer)
@ -96,25 +106,29 @@ bool Service::Initialize(ICapture * captureDevice)
return true; return true;
} }
#define ALIGN_DN(x) ((uintptr_t)(x) & ~0x7F)
#define ALIGN_UP(x) ALIGN_DN(x + 0x7F)
bool Service::InitPointers() bool Service::InitPointers()
{ {
m_shmHeader = reinterpret_cast<KVMFRHeader *>(m_memory); m_shmHeader = reinterpret_cast<KVMFRHeader *>(m_memory);
m_cursorData = (uint8_t *)(((uintptr_t)m_memory + sizeof(KVMFRHeader *) + 0x7F) & ~0x7F); m_cursorData = (uint8_t *)ALIGN_UP(m_memory + sizeof(KVMFRHeader));
m_cursorDataSize = (128 * 128 * 4); m_cursorDataSize = 1048576; // 1MB fixed for cursor size, should be more then enough
m_frame[0] = m_cursorData + (128*128*4); m_frame[0] = (uint8_t *)ALIGN_UP(m_cursorData + m_cursorDataSize);
m_frameSize = ((m_ivshmem->GetSize() - (m_frame[0] - m_memory)) & ~0x7F) >> 1; m_frameSize = ALIGN_DN((m_ivshmem->GetSize() - (m_frame[0] - m_memory)) >> 1);
m_frame[1] = m_frame[0] + m_frameSize; m_frame[1] = (uint8_t *)ALIGN_DN(m_frame[0] + m_frameSize);
m_cursorOffset = m_cursorData - m_memory; m_cursorOffset = m_cursorData - m_memory;
m_dataOffset[0] = m_frame[0] - m_memory; m_dataOffset[0] = m_frame[0] - m_memory;
m_dataOffset[1] = m_frame[1] - m_memory; m_dataOffset[1] = m_frame[1] - m_memory;
if (m_capture->GetMaxFrameSize() > m_frameSize) DEBUG_INFO("Total Available : %3I64u MB", m_ivshmem->GetSize() / 1024 / 1024);
{ DEBUG_INFO("Max Cursor Size : %3I64u MB", m_cursorDataSize / 1024 / 1024);
DEBUG_ERROR("Frame can exceed buffer size!"); DEBUG_INFO("Max Frame Size : %3I64u MB", m_frameSize / 1024 / 1024);
DeInitialize(); DEBUG_INFO("Cursor : %p (0x%08I64x)", m_cursorData, m_cursorOffset );
return false; DEBUG_INFO("Frame 1 : %p (0x%08I64x)", m_frame[0] , m_dataOffset[0]);
} DEBUG_INFO("Frame 2 : %p (0x%08I64x)", m_frame[1] , m_dataOffset[1]);
return true; return true;
} }
@ -217,11 +231,17 @@ bool Service::Process()
Sleep(100); Sleep(100);
} }
if (!m_capture->ReInitialize() || !InitPointers()) if (!m_capture->ReInitialize())
{ {
DEBUG_ERROR("ReInitialize Failed"); DEBUG_ERROR("ReInitialize Failed");
return false; return false;
} }
if (m_capture->GetMaxFrameSize() > m_frameSize)
{
DEBUG_ERROR("Maximum frame size of %zd bytes excceds maximum space available", m_capture->GetMaxFrameSize());
return false;
}
continue; continue;
} }