mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-05 18:24:08 +00:00
[host] initial NvFBC implementation
This commit is contained in:
135
host/Capture/NvFBC.cpp
Normal file
135
host/Capture/NvFBC.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
#include "NvFBC.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "common\debug.h"
|
||||
#include "Util.h"
|
||||
|
||||
#ifdef _WIN64
|
||||
#define NVFBC_LIBRARY_NAME "NvFBC64.dll"
|
||||
#else
|
||||
#define NVFBC_LIBRARY_NAME "NvFBC.dll"
|
||||
#endif
|
||||
|
||||
namespace Capture
|
||||
{
|
||||
|
||||
NvFBC::NvFBC() :
|
||||
m_hDLL(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
NvFBC::~NvFBC()
|
||||
{
|
||||
}
|
||||
|
||||
bool NvFBC::Initialize()
|
||||
{
|
||||
if (m_initialized)
|
||||
DeInitialize();
|
||||
|
||||
std::string nvfbc = Util::GetSystemRoot() + "\\" + NVFBC_LIBRARY_NAME;
|
||||
m_hDLL = LoadLibraryA(nvfbc.c_str());
|
||||
if (!m_hDLL)
|
||||
{
|
||||
DEBUG_ERROR("Failed to load the NvFBC library: %d - %s", GetLastError(), nvfbc.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_fnCreateEx = (NvFBC_CreateFunctionExType )GetProcAddress(m_hDLL, "NvFBC_CreateEx" );
|
||||
m_fnSetGlobalFlags = (NvFBC_SetGlobalFlagsType )GetProcAddress(m_hDLL, "NvFBC_SetGlobalFlags");
|
||||
m_fnGetStatusEx = (NvFBC_GetStatusExFunctionType)GetProcAddress(m_hDLL, "NvFBC_GetStatusEx" );
|
||||
m_fnEnable = (NvFBC_EnableFunctionType )GetProcAddress(m_hDLL, "NvFBC_Enable" );
|
||||
|
||||
if (!m_fnCreateEx || !m_fnSetGlobalFlags || !m_fnGetStatusEx || !m_fnEnable)
|
||||
{
|
||||
DEBUG_ERROR("Unable to locate required entry points in %s", nvfbc.c_str());
|
||||
DeInitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
NvFBCStatusEx status;
|
||||
ZeroMemory(&status, sizeof(NvFBCStatusEx));
|
||||
status.dwVersion = NVFBC_STATUS_VER;
|
||||
status.dwAdapterIdx = 0;
|
||||
|
||||
if (m_fnGetStatusEx(&status) != NVFBC_SUCCESS)
|
||||
{
|
||||
DEBUG_ERROR("Failed to get NvFBC status");
|
||||
DeInitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!status.bIsCapturePossible)
|
||||
{
|
||||
DEBUG_ERROR("Capture is not possible, unsupported device or driver");
|
||||
DeInitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!status.bCanCreateNow)
|
||||
{
|
||||
DEBUG_ERROR("Can not create an instance of NvFBC at this time");
|
||||
DeInitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
NvFBCCreateParams params;
|
||||
ZeroMemory(¶ms, sizeof(NvFBCCreateParams));
|
||||
params.dwVersion = NVFBC_CREATE_PARAMS_VER;
|
||||
params.dwInterfaceType = NVFBC_TO_SYS;
|
||||
params.pDevice = NULL;
|
||||
params.dwAdapterIdx = 0;
|
||||
|
||||
// do not remove this
|
||||
#include "NvFBCSpecial.h"
|
||||
|
||||
if (m_fnCreateEx(¶ms) != NVFBC_SUCCESS)
|
||||
{
|
||||
DEBUG_ERROR("Failed to create an instance of NvFBC");
|
||||
DeInitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_maxCaptureWidth = params.dwMaxDisplayWidth;
|
||||
m_maxCaptureHeight = params.dwMaxDisplayHeight;
|
||||
|
||||
|
||||
m_initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void NvFBC::DeInitialize()
|
||||
{
|
||||
m_fnCreateEx = NULL;
|
||||
m_fnSetGlobalFlags = NULL;
|
||||
m_fnGetStatusEx = NULL;
|
||||
m_fnEnable = NULL;
|
||||
|
||||
FreeLibrary(m_hDLL);
|
||||
m_hDLL = NULL;
|
||||
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
FrameType NvFBC::GetFrameType()
|
||||
{
|
||||
return FRAME_TYPE_RGB;
|
||||
}
|
||||
|
||||
FrameComp NvFBC::GetFrameCompression()
|
||||
{
|
||||
return FRAME_COMP_NONE;
|
||||
}
|
||||
|
||||
size_t NvFBC::GetMaxFrameSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool NvFBC::GrabFrame(void * buffer, size_t bufferSize, size_t * outLen)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
36
host/Capture/NvFBC.h
Normal file
36
host/Capture/NvFBC.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "ICapture.h"
|
||||
|
||||
#define W32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
#include <NvFBC\nvFBC.h>
|
||||
#include <NvFBC\nvFBCToSys.h>
|
||||
|
||||
namespace Capture
|
||||
{
|
||||
class NvFBC : public ICapture
|
||||
{
|
||||
public:
|
||||
NvFBC();
|
||||
~NvFBC();
|
||||
|
||||
bool Initialize();
|
||||
void DeInitialize();
|
||||
enum FrameType GetFrameType();
|
||||
enum FrameComp GetFrameCompression();
|
||||
size_t GetMaxFrameSize();
|
||||
bool GrabFrame(void * buffer, size_t bufferSize, size_t * outLen);
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
HMODULE m_hDLL;
|
||||
|
||||
NvFBC_CreateFunctionExType m_fnCreateEx;
|
||||
NvFBC_SetGlobalFlagsType m_fnSetGlobalFlags;
|
||||
NvFBC_GetStatusExFunctionType m_fnGetStatusEx;
|
||||
NvFBC_EnableFunctionType m_fnEnable;
|
||||
|
||||
DWORD m_maxCaptureWidth, m_maxCaptureHeight;
|
||||
};
|
||||
};
|
0
host/Capture/NvFBCSpecial.h
Normal file
0
host/Capture/NvFBCSpecial.h
Normal file
Reference in New Issue
Block a user