mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-23 14:03:40 +00:00
[host] initial NvFBC implementation
This commit is contained in:
parent
b03254b7c2
commit
85f39b7070
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
@ -4,12 +4,13 @@
|
||||
#include <Windows.h>
|
||||
|
||||
#include "ICapture.h"
|
||||
#include "Capture\NvFBC.h"
|
||||
|
||||
static class CaptureFactory
|
||||
{
|
||||
public:
|
||||
static ICapture * GetCaptureDevice()
|
||||
{
|
||||
return NULL;
|
||||
return new Capture::NvFBC();
|
||||
}
|
||||
};
|
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <common/KVMGFXHeader.h>
|
||||
#include "common/KVMGFXHeader.h"
|
||||
|
||||
__interface ICapture
|
||||
{
|
||||
public:
|
||||
bool Initialize();
|
||||
bool DeInitialize();
|
||||
void DeInitialize();
|
||||
enum FrameType GetFrameType();
|
||||
enum FrameComp GetFrameCompression();
|
||||
size_t GetMaxFrameSize();
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#include <Windows.h>
|
||||
#include <SetupAPI.h>
|
||||
#include <vendor\kvm-guest-drivers-windows\ivshmem\Public.h>
|
||||
#include <common\debug.h>
|
||||
#include "vendor\kvm-guest-drivers-windows\ivshmem\Public.h"
|
||||
#include "common\debug.h"
|
||||
|
||||
IVSHMEM * IVSHMEM::m_instance = NULL;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "Service.h"
|
||||
#include "IVSHMEM.h"
|
||||
|
||||
#include <common\debug.h>
|
||||
#include <common\KVMGFXHeader.h>
|
||||
#include "common\debug.h"
|
||||
#include "common\KVMGFXHeader.h"
|
||||
|
||||
#include "CaptureFactory.h"
|
||||
|
||||
@ -26,6 +26,14 @@ bool Service::Initialize()
|
||||
if (m_initialized)
|
||||
DeInitialize();
|
||||
|
||||
m_capture = CaptureFactory::GetCaptureDevice();
|
||||
if (!m_capture || !m_capture->Initialize())
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize capture interface");
|
||||
DeInitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_ivshmem->Initialize())
|
||||
{
|
||||
DEBUG_ERROR("IVSHMEM failed to initalize");
|
||||
@ -56,14 +64,6 @@ bool Service::Initialize()
|
||||
return false;
|
||||
}
|
||||
|
||||
m_capture = CaptureFactory::GetCaptureDevice();
|
||||
if (!m_capture || !m_capture->Initialize())
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize capture interface");
|
||||
DeInitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
KVMGFXHeader * header = static_cast<KVMGFXHeader*>(m_memory);
|
||||
ZeroMemory(header, sizeof(KVMGFXHeader));
|
||||
memcpy(header->magic, KVMGFX_HEADER_MAGIC, sizeof(KVMGFX_HEADER_MAGIC));
|
||||
@ -77,17 +77,18 @@ bool Service::Initialize()
|
||||
|
||||
void Service::DeInitialize()
|
||||
{
|
||||
if (m_readyEvent != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(m_readyEvent);
|
||||
|
||||
m_memory = NULL;
|
||||
m_ivshmem->DeInitialize();
|
||||
|
||||
if (m_capture)
|
||||
{
|
||||
m_capture->DeInitialize();
|
||||
m_capture = NULL;
|
||||
}
|
||||
|
||||
if (m_readyEvent != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(m_readyEvent);
|
||||
|
||||
m_memory = NULL;
|
||||
m_ivshmem->DeInitialize();
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
|
41
host/Util.h
Normal file
41
host/Util.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#include "common\debug.h"
|
||||
|
||||
static class Util
|
||||
{
|
||||
public:
|
||||
static std::string GetSystemRoot()
|
||||
{
|
||||
std::string defaultPath;
|
||||
|
||||
size_t pathSize;
|
||||
char *libPath;
|
||||
|
||||
if (_dupenv_s(&libPath, &pathSize, "SystemRoot") != 0)
|
||||
{
|
||||
DEBUG_ERROR("Unable to get the SystemRoot environment variable");
|
||||
return defaultPath;
|
||||
}
|
||||
|
||||
if (!pathSize)
|
||||
{
|
||||
DEBUG_ERROR("The SystemRoot environment variable is not set");
|
||||
return defaultPath;
|
||||
}
|
||||
#ifdef _WIN64
|
||||
defaultPath = std::string(libPath) + "\\System32";
|
||||
#else
|
||||
if (IsWow64())
|
||||
{
|
||||
defaultPath = std::string(libPath) + "\\Syswow64";
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultPath = std::string(libPath) + "\\System32";
|
||||
}
|
||||
#endif
|
||||
return defaultPath;
|
||||
}
|
||||
};
|
@ -69,19 +69,19 @@
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);..\</IncludePath>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);;C:\Program Files %28x86%29\NVIDIA Corporation\NVIDIA Capture SDK\inc</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);..\</IncludePath>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);;C:\Program Files %28x86%29\NVIDIA Corporation\NVIDIA Capture SDK\inc</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);..\</IncludePath>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);;C:\Program Files %28x86%29\NVIDIA Corporation\NVIDIA Capture SDK\inc</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);..\</IncludePath>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);;C:\Program Files %28x86%29\NVIDIA Corporation\NVIDIA Capture SDK\inc</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
@ -91,11 +91,13 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions);DEBUG</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>C:\Program Files %28x86%29\NVIDIA Corporation\NVIDIA Capture SDK\lib\NvAPI\$(PlatformTarget);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@ -106,11 +108,13 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions);DEBUG</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>C:\Program Files %28x86%29\NVIDIA Corporation\NVIDIA Capture SDK\lib\NvAPI\$(PlatformTarget);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@ -123,6 +127,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@ -130,6 +135,7 @@
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>C:\Program Files %28x86%29\NVIDIA Corporation\NVIDIA Capture SDK\lib\NvAPI\$(PlatformTarget);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@ -142,6 +148,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>..\;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@ -149,18 +156,22 @@
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>C:\Program Files %28x86%29\NVIDIA Corporation\NVIDIA Capture SDK\lib\NvAPI\$(PlatformTarget);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Capture\NvFBC.cpp" />
|
||||
<ClCompile Include="ivshmem.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Service.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CaptureFactory.h" />
|
||||
<ClInclude Include="Capture\NvFBC.h" />
|
||||
<ClInclude Include="ICapture.h" />
|
||||
<ClInclude Include="ivshmem.h" />
|
||||
<ClInclude Include="Service.h" />
|
||||
<ClInclude Include="Util.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -13,6 +13,12 @@
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Capture">
|
||||
<UniqueIdentifier>{3a65593b-37a9-448d-acf0-6339dea46ed1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Capture">
|
||||
<UniqueIdentifier>{0a865d22-907e-44ea-a230-ad7ede7edeb0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ivshmem.cpp">
|
||||
@ -24,6 +30,9 @@
|
||||
<ClCompile Include="Service.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Capture\NvFBC.cpp">
|
||||
<Filter>Source Files\Capture</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ivshmem.h">
|
||||
@ -38,5 +47,11 @@
|
||||
<ClInclude Include="CaptureFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Capture\NvFBC.h">
|
||||
<Filter>Header Files\Capture</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Util.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,6 +1,6 @@
|
||||
#include <Windows.h>
|
||||
#include <tchar.h>
|
||||
#include <common\debug.h>
|
||||
#include "common\debug.h"
|
||||
|
||||
#include "Service.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user