clang-format
This commit is contained in:
parent
e10261543f
commit
5f9f547db8
4 changed files with 259 additions and 273 deletions
44
.clang-format
Executable file
44
.clang-format
Executable file
|
@ -0,0 +1,44 @@
|
|||
BasedOnStyle: Google
|
||||
|
||||
# force T* or T&
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
|
||||
TabWidth: 4
|
||||
IndentWidth: 4
|
||||
UseTab: Always
|
||||
IndentPPDirectives: BeforeHash
|
||||
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: InlineOnly
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakStringLiterals: false
|
||||
|
||||
ColumnLimit: 150
|
||||
CompactNamespaces: false
|
||||
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ContinuationIndentWidth: 0
|
||||
|
||||
# turning this on causes major issues with initalizer lists
|
||||
Cpp11BracedListStyle: false
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
|
||||
FixNamespaceComments: true
|
||||
|
||||
NamespaceIndentation: All
|
||||
ReflowComments: true
|
||||
|
||||
SortIncludes: CaseInsensitive
|
||||
SortUsingDeclarations: true
|
||||
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeParens: Never
|
||||
SpacesBeforeTrailingComments: 1
|
|
@ -1,3 +1,4 @@
|
|||
// clang-format off
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#include <WinSock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
@ -11,11 +12,12 @@
|
|||
|
||||
#include "NvFBCLibrary.h"
|
||||
#include <NvFBC/nvFBCToSys.h>
|
||||
// clang-format on
|
||||
|
||||
#pragma pack(push, 1)
|
||||
enum class MessageType : u32 {
|
||||
Resize, // tResizeMessage
|
||||
Data, // tDataMessage
|
||||
Data, // tDataMessage
|
||||
};
|
||||
|
||||
struct tMessageHeader {
|
||||
|
@ -45,19 +47,19 @@ struct tDataMessage {
|
|||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
struct tileRect {
|
||||
u32 x, y, width, height;
|
||||
};
|
||||
|
||||
// client for streamserver
|
||||
class cStreamClient {
|
||||
SOCKET tcpSocket{ -1 };
|
||||
public:
|
||||
SOCKET tcpSocket { -1 };
|
||||
|
||||
public:
|
||||
cStreamClient() = default;
|
||||
|
||||
~cStreamClient() {
|
||||
if (tcpSocket != -1) {
|
||||
if(tcpSocket != -1) {
|
||||
closesocket(tcpSocket);
|
||||
tcpSocket = -1;
|
||||
}
|
||||
|
@ -65,17 +67,17 @@ public:
|
|||
|
||||
bool Connect(const char* address, int port) {
|
||||
tcpSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (tcpSocket == -1) {
|
||||
if(tcpSocket == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sockaddr_in clientSvc{};
|
||||
sockaddr_in clientSvc {};
|
||||
clientSvc.sin_family = AF_INET;
|
||||
inet_pton(AF_INET, address, &clientSvc.sin_addr.s_addr);
|
||||
// clientSvc.sin_addr.s_addr = inet_addr(address);
|
||||
// clientSvc.sin_addr.s_addr = inet_addr(address);
|
||||
clientSvc.sin_port = htons(port);
|
||||
|
||||
if (connect(tcpSocket, (SOCKADDR*)&clientSvc, sizeof(clientSvc)) == SOCKET_ERROR) {
|
||||
if(connect(tcpSocket, (SOCKADDR*)&clientSvc, sizeof(clientSvc)) == SOCKET_ERROR) {
|
||||
printf("No connection socket. Fuck you\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -98,21 +100,18 @@ public:
|
|||
void SendData(const unique_buffer<u32>& data, u32 width, u32 height, const std::vector<tileRect>& tiles) {
|
||||
tMessageHeader header;
|
||||
header.type = MessageType::Data;
|
||||
//header.datalen = data.get_size() * sizeof(UINT32);
|
||||
// header.datalen = data.get_size() * sizeof(UINT32);
|
||||
header.datalen = sizeof(tDataMessage);
|
||||
|
||||
|
||||
|
||||
auto* pData = data.data();
|
||||
|
||||
// send tile header
|
||||
bool sendFull = false;
|
||||
tDataMessage dm;
|
||||
if (tiles.empty()) {
|
||||
if(tiles.empty()) {
|
||||
dm.tileCount = 1;
|
||||
sendFull = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dm.tileCount = (u32)tiles.size();
|
||||
}
|
||||
|
||||
|
@ -121,22 +120,15 @@ public:
|
|||
send(tcpSocket, (const char*)&header, sizeof(header), 0);
|
||||
send(tcpSocket, (const char*)&dm, sizeof(dm), 0);
|
||||
|
||||
|
||||
// send each tile
|
||||
if (!sendFull) {
|
||||
for (auto& tile : tiles) {
|
||||
tTile tile_wire{
|
||||
tile.x,
|
||||
tile.y,
|
||||
tile.width,
|
||||
tile.height
|
||||
};
|
||||
|
||||
if(!sendFull) {
|
||||
for(auto& tile : tiles) {
|
||||
tTile tile_wire { tile.x, tile.y, tile.width, tile.height };
|
||||
|
||||
std::vector<u32> data;
|
||||
data.resize(tile.width * tile.height * 4);
|
||||
|
||||
for (u32 y = 0; y < tile.height; ++y) {
|
||||
for(u32 y = 0; y < tile.height; ++y) {
|
||||
auto* pTileLineStart = &pData[(tile.y + y) * width + tile.x];
|
||||
memcpy(&data[y * tile.width], pTileLineStart, tile.width * sizeof(u32));
|
||||
}
|
||||
|
@ -152,32 +144,25 @@ public:
|
|||
}*/
|
||||
}
|
||||
} else {
|
||||
tTile tDummyTile{
|
||||
0,
|
||||
0,
|
||||
width,
|
||||
height
|
||||
};
|
||||
tTile tDummyTile { 0, 0, width, height };
|
||||
|
||||
send(tcpSocket, (const char*)&tDummyTile, sizeof(tDummyTile), 0);
|
||||
send(tcpSocket, (const char*)&data.data()[0], (i32)(data.get_size() * sizeof(u32)), 0);
|
||||
}
|
||||
|
||||
|
||||
//send(tcpSocket, (const char*)&data.data()[0], data.get_size() * sizeof(UINT32), 0);
|
||||
// send(tcpSocket, (const char*)&data.data()[0], data.get_size() * sizeof(UINT32), 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// FIXME: make this a class, I've clearly got the ability to pull it into one
|
||||
|
||||
// stuff
|
||||
NvFBCLibrary* nvfbcLibrary = nullptr;
|
||||
NvFBCToSys *nvfbcToSys = nullptr;
|
||||
NvFBCToSys* nvfbcToSys = nullptr;
|
||||
|
||||
// filled in by NVFBC
|
||||
unsigned char *frameBuffer = nullptr;
|
||||
unsigned char *diffMap = nullptr;
|
||||
unsigned char* frameBuffer = nullptr;
|
||||
unsigned char* diffMap = nullptr;
|
||||
|
||||
bool nvfbcSetup() {
|
||||
//! Setup the frame grab
|
||||
|
@ -185,7 +170,7 @@ bool nvfbcSetup() {
|
|||
fbcSysSetupParams.dwVersion = NVFBC_TOSYS_SETUP_PARAMS_VER;
|
||||
fbcSysSetupParams.eMode = NVFBC_TOSYS_ARGB;
|
||||
fbcSysSetupParams.bWithHWCursor = true;
|
||||
fbcSysSetupParams.ppBuffer = (void **)&frameBuffer;
|
||||
fbcSysSetupParams.ppBuffer = (void**)&frameBuffer;
|
||||
|
||||
// enable a 32x32 difference map
|
||||
fbcSysSetupParams.bDiffMap = TRUE;
|
||||
|
@ -197,7 +182,7 @@ bool nvfbcSetup() {
|
|||
}
|
||||
|
||||
void nvfbcDestroy() {
|
||||
if (nvfbcToSys) {
|
||||
if(nvfbcToSys) {
|
||||
nvfbcToSys->NvFBCToSysRelease();
|
||||
diffMap = nullptr;
|
||||
frameBuffer = nullptr;
|
||||
|
@ -205,16 +190,15 @@ void nvfbcDestroy() {
|
|||
}
|
||||
|
||||
bool nvfbcCreate() {
|
||||
if (nvfbcToSys) {
|
||||
if(nvfbcToSys) {
|
||||
nvfbcDestroy();
|
||||
}
|
||||
|
||||
DWORD maxDisplayWidth = -1, maxDisplayHeight = -1;
|
||||
|
||||
//! Create an instance of NvFBCToSys
|
||||
nvfbcToSys = (NvFBCToSys *)nvfbcLibrary->create(NVFBC_TO_SYS, &maxDisplayWidth, &maxDisplayHeight);
|
||||
if (!nvfbcToSys)
|
||||
{
|
||||
nvfbcToSys = (NvFBCToSys*)nvfbcLibrary->create(NVFBC_TO_SYS, &maxDisplayWidth, &maxDisplayHeight);
|
||||
if(!nvfbcToSys) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -223,13 +207,13 @@ bool nvfbcCreate() {
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
WSADATA data;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &data) != NO_ERROR) {
|
||||
if(WSAStartup(MAKEWORD(2, 2), &data) != NO_ERROR) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
cStreamClient* client = new cStreamClient();
|
||||
|
||||
if (!client->Connect("192.168.1.149", 9438)) {
|
||||
if(!client->Connect("192.168.1.149", 9438)) {
|
||||
printf("conn failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -237,12 +221,12 @@ int main(int argc, char** argv) {
|
|||
nvfbcLibrary = new NvFBCLibrary();
|
||||
|
||||
//! Load NvFBC
|
||||
if (!nvfbcLibrary->load()) {
|
||||
if(!nvfbcLibrary->load()) {
|
||||
fprintf(stderr, "Unable to load the NvFBC library\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!nvfbcCreate()) {
|
||||
if(!nvfbcCreate()) {
|
||||
fprintf(stderr, "Unable to create an instance of NvFBC\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -257,14 +241,13 @@ int main(int argc, char** argv) {
|
|||
NvFBCFrameGrabInfo grabInfo;
|
||||
unique_buffer<u32> buffer;
|
||||
|
||||
if (nvfbcSetup())
|
||||
{
|
||||
if(nvfbcSetup()) {
|
||||
// Sleep so that ToSysSetUp forces a framebuffer update
|
||||
Sleep(100);
|
||||
|
||||
NVFBC_TOSYS_GRAB_FRAME_PARAMS fbcSysGrabParams = { 0 };
|
||||
|
||||
std::vector<tileRect> tiles{};
|
||||
std::vector<tileRect> tiles {};
|
||||
|
||||
// set up grab parameters
|
||||
fbcSysGrabParams.dwVersion = NVFBC_TOSYS_GRAB_FRAME_PARAMS_VER;
|
||||
|
@ -277,45 +260,45 @@ int main(int argc, char** argv) {
|
|||
fbcSysGrabParams.pNvFBCFrameGrabInfo = &grabInfo;
|
||||
fbcSysGrabParams.dwWaitTime = 16;
|
||||
|
||||
while (true) {
|
||||
while(true) {
|
||||
// Grab the frame
|
||||
status = nvfbcToSys->NvFBCToSysGrabFrame(&fbcSysGrabParams);
|
||||
if (status == NVFBC_SUCCESS) {
|
||||
if(status == NVFBC_SUCCESS) {
|
||||
bRecoveryDone = FALSE;
|
||||
|
||||
// handle resizing the buffer
|
||||
if (width != grabInfo.dwWidth || height != grabInfo.dwHeight) {
|
||||
if(width != grabInfo.dwWidth || height != grabInfo.dwHeight) {
|
||||
width = grabInfo.dwWidth;
|
||||
height = grabInfo.dwHeight;
|
||||
|
||||
buffer.resize(grabInfo.dwWidth * grabInfo.dwHeight);
|
||||
|
||||
firstFrame = true;
|
||||
client->SendResize(tResizeMessage{ width, height });
|
||||
client->SendResize(tResizeMessage { width, height });
|
||||
}
|
||||
|
||||
// splat the data into an unpadded buffer
|
||||
// REMOVE THIS
|
||||
for (u32 y = 0; y < grabInfo.dwHeight; ++y) {
|
||||
for(u32 y = 0; y < grabInfo.dwHeight; ++y) {
|
||||
memcpy(&buffer.data()[y * grabInfo.dwWidth], &frameBuffer[(y * grabInfo.dwBufferWidth) * 4], grabInfo.dwWidth * 4);
|
||||
}
|
||||
|
||||
tiles.clear();
|
||||
|
||||
// diffmap
|
||||
if (firstFrame == false) {
|
||||
if(firstFrame == false) {
|
||||
u32 dwDiffMapWidth = (u32)ceil((f32)width / 32);
|
||||
u32 dwDiffMapHeight = (u32)ceil((f32)height / 32);
|
||||
|
||||
for (u32 y = 0; y < dwDiffMapHeight; ++y) {
|
||||
for (u32 x = 0; x < dwDiffMapWidth; ++x) {
|
||||
for(u32 y = 0; y < dwDiffMapHeight; ++y) {
|
||||
for(u32 x = 0; x < dwDiffMapWidth; ++x) {
|
||||
auto& bl = diffMap[y * dwDiffMapWidth + x];
|
||||
if (bl != 0) {
|
||||
tiles.push_back(tileRect{
|
||||
x * (width / dwDiffMapWidth), // x
|
||||
y * (height / dwDiffMapHeight), // y
|
||||
width / dwDiffMapWidth, // width
|
||||
height / dwDiffMapHeight // height
|
||||
if(bl != 0) {
|
||||
tiles.push_back(tileRect {
|
||||
x * (width / dwDiffMapWidth), // x
|
||||
y * (height / dwDiffMapHeight), // y
|
||||
width / dwDiffMapWidth, // width
|
||||
height / dwDiffMapHeight // height
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -325,43 +308,40 @@ int main(int argc, char** argv) {
|
|||
// send that to the server
|
||||
client->SendData(buffer, width, height, tiles);
|
||||
|
||||
if (firstFrame)
|
||||
if(firstFrame)
|
||||
firstFrame = false;
|
||||
} else {
|
||||
if (bRecoveryDone == TRUE) {
|
||||
if(bRecoveryDone == TRUE) {
|
||||
fprintf(stderr, "Unable to recover from NvFBC Frame grab failure.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (status == NVFBC_ERROR_DYNAMIC_DISABLE) {
|
||||
if(status == NVFBC_ERROR_DYNAMIC_DISABLE) {
|
||||
fprintf(stderr, "NvFBC disabled. Quitting\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// Try to recover the session
|
||||
if (status == NVFBC_ERROR_INVALIDATED_SESSION) {
|
||||
if(status == NVFBC_ERROR_INVALIDATED_SESSION) {
|
||||
fprintf(stderr, "Session Invalidated. Attempting recovery\n");
|
||||
|
||||
if (!nvfbcCreate()) {
|
||||
if(!nvfbcCreate()) {
|
||||
fprintf(stderr, "Unable to re-create NvFBC\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (nvfbcSetup()) {
|
||||
if(nvfbcSetup()) {
|
||||
bRecoveryDone = TRUE;
|
||||
} else {
|
||||
fprintf(stderr, "Unable to recover from NvFBC Frame grab failure.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (status != NVFBC_SUCCESS)
|
||||
{
|
||||
if(status != NVFBC_SUCCESS) {
|
||||
fprintf(stderr, "Unable to setup frame grab.\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -3,236 +3,199 @@
|
|||
#define WINDOWS_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include "NvFBC/nvFBC.h"
|
||||
#include <string>
|
||||
|
||||
#include "NvFBC/nvFBC.h"
|
||||
|
||||
|
||||
#define NVFBC64_LIBRARY_NAME "NvFBC64.dll"
|
||||
#define NVFBC_LIBRARY_NAME "NvFBC.dll"
|
||||
|
||||
// Wraps loading and using NvFBC
|
||||
class NvFBCLibrary
|
||||
{
|
||||
NvFBCLibrary(const NvFBCLibrary &);
|
||||
NvFBCLibrary &operator=(const NvFBCLibrary &);
|
||||
class NvFBCLibrary {
|
||||
NvFBCLibrary(const NvFBCLibrary&);
|
||||
NvFBCLibrary& operator=(const NvFBCLibrary&);
|
||||
|
||||
public:
|
||||
NvFBCLibrary()
|
||||
: m_handle(NULL)
|
||||
, pfn_get_status(NULL)
|
||||
, pfn_create(NULL)
|
||||
, pfn_enable(NULL)
|
||||
{}
|
||||
public:
|
||||
NvFBCLibrary() : m_handle(NULL), pfn_get_status(NULL), pfn_create(NULL), pfn_enable(NULL) {}
|
||||
|
||||
~NvFBCLibrary()
|
||||
{
|
||||
if(NULL != m_handle)
|
||||
close();
|
||||
}
|
||||
~NvFBCLibrary() {
|
||||
if(NULL != m_handle)
|
||||
close();
|
||||
}
|
||||
|
||||
// Attempts to load NvFBC from system directory.
|
||||
// on 32-bit OS: looks for NvFBC.dll in system32
|
||||
// for 32-bit app on 64-bit OS: looks for NvFBC.dll in syswow64
|
||||
// for 64-bit app on 64-bit OS: looks for NvFBC64.dll in system32
|
||||
bool load(std::string fileName = std::string())
|
||||
{
|
||||
if(NULL != m_handle)
|
||||
return true;
|
||||
// Attempts to load NvFBC from system directory.
|
||||
// on 32-bit OS: looks for NvFBC.dll in system32
|
||||
// for 32-bit app on 64-bit OS: looks for NvFBC.dll in syswow64
|
||||
// for 64-bit app on 64-bit OS: looks for NvFBC64.dll in system32
|
||||
bool load(std::string fileName = std::string()) {
|
||||
if(NULL != m_handle)
|
||||
return true;
|
||||
|
||||
if(!fileName.empty())
|
||||
m_handle = ::LoadLibraryA(fileName.c_str());
|
||||
if(!fileName.empty())
|
||||
m_handle = ::LoadLibraryA(fileName.c_str());
|
||||
|
||||
if(NULL == m_handle)
|
||||
{
|
||||
m_handle = ::LoadLibraryA(getDefaultPath().c_str());
|
||||
}
|
||||
if(NULL == m_handle) {
|
||||
m_handle = ::LoadLibraryA(getDefaultPath().c_str());
|
||||
}
|
||||
|
||||
if(NULL == m_handle)
|
||||
{
|
||||
fprintf(stderr, "Unable to load NvFBC.\n");
|
||||
return false;
|
||||
}
|
||||
if(NULL == m_handle) {
|
||||
fprintf(stderr, "Unable to load NvFBC.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load the three functions exported by NvFBC
|
||||
pfn_create = (NvFBC_CreateFunctionExType)::GetProcAddress(m_handle, "NvFBC_CreateEx");
|
||||
pfn_set_global_flags = (NvFBC_SetGlobalFlagsType)::GetProcAddress(m_handle, "NvFBC_SetGlobalFlags");
|
||||
pfn_get_status = (NvFBC_GetStatusExFunctionType)::GetProcAddress(m_handle, "NvFBC_GetStatusEx");
|
||||
pfn_enable = (NvFBC_EnableFunctionType)::GetProcAddress(m_handle,"NvFBC_Enable");
|
||||
// Load the three functions exported by NvFBC
|
||||
pfn_create = (NvFBC_CreateFunctionExType)::GetProcAddress(m_handle, "NvFBC_CreateEx");
|
||||
pfn_set_global_flags = (NvFBC_SetGlobalFlagsType)::GetProcAddress(m_handle, "NvFBC_SetGlobalFlags");
|
||||
pfn_get_status = (NvFBC_GetStatusExFunctionType)::GetProcAddress(m_handle, "NvFBC_GetStatusEx");
|
||||
pfn_enable = (NvFBC_EnableFunctionType)::GetProcAddress(m_handle, "NvFBC_Enable");
|
||||
|
||||
if((NULL == pfn_create) || (NULL == pfn_set_global_flags) || (NULL == pfn_get_status) || (NULL == pfn_enable))
|
||||
{
|
||||
fprintf(stderr, "Unable to load the NvFBC function pointers.\n");
|
||||
close();
|
||||
if((NULL == pfn_create) || (NULL == pfn_set_global_flags) || (NULL == pfn_get_status) || (NULL == pfn_enable)) {
|
||||
fprintf(stderr, "Unable to load the NvFBC function pointers.\n");
|
||||
close();
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Close the NvFBC dll
|
||||
void close()
|
||||
{
|
||||
if(NULL != m_handle)
|
||||
FreeLibrary(m_handle);
|
||||
// Close the NvFBC dll
|
||||
void close() {
|
||||
if(NULL != m_handle)
|
||||
FreeLibrary(m_handle);
|
||||
|
||||
m_handle = NULL;
|
||||
pfn_create = NULL;
|
||||
pfn_get_status = NULL;
|
||||
pfn_enable = NULL;
|
||||
}
|
||||
m_handle = NULL;
|
||||
pfn_create = NULL;
|
||||
pfn_get_status = NULL;
|
||||
pfn_enable = NULL;
|
||||
}
|
||||
|
||||
// Get the status for the provided adapter, if no adapter is
|
||||
// provided the default adapter is used.
|
||||
NVFBCRESULT getStatus(NvFBCStatusEx *status)
|
||||
{
|
||||
return pfn_get_status((void*)status);
|
||||
}
|
||||
// Get the status for the provided adapter, if no adapter is
|
||||
// provided the default adapter is used.
|
||||
NVFBCRESULT getStatus(NvFBCStatusEx* status) { return pfn_get_status((void*)status); }
|
||||
|
||||
// Sets the global flags for the provided adapter, if
|
||||
// no adapter is provided the default adapter is used
|
||||
void setGlobalFlags(DWORD flags, int adapter = 0)
|
||||
{
|
||||
setTargetAdapter(adapter);
|
||||
pfn_set_global_flags(flags);
|
||||
}
|
||||
// Sets the global flags for the provided adapter, if
|
||||
// no adapter is provided the default adapter is used
|
||||
void setGlobalFlags(DWORD flags, int adapter = 0) {
|
||||
setTargetAdapter(adapter);
|
||||
pfn_set_global_flags(flags);
|
||||
}
|
||||
|
||||
// Creates an instance of the provided NvFBC type if possible
|
||||
NVFBCRESULT createEx(NvFBCCreateParams *pParams)
|
||||
{
|
||||
return pfn_create((void *)pParams);
|
||||
}
|
||||
// Creates an instance of the provided NvFBC type if possible.
|
||||
void *create(DWORD type, DWORD *maxWidth, DWORD *maxHeight, int adapter = 0, void *devicePtr = NULL)
|
||||
{
|
||||
if(NULL == m_handle)
|
||||
return NULL;
|
||||
// Creates an instance of the provided NvFBC type if possible
|
||||
NVFBCRESULT createEx(NvFBCCreateParams* pParams) { return pfn_create((void*)pParams); }
|
||||
// Creates an instance of the provided NvFBC type if possible.
|
||||
void* create(DWORD type, DWORD* maxWidth, DWORD* maxHeight, int adapter = 0, void* devicePtr = NULL) {
|
||||
if(NULL == m_handle)
|
||||
return NULL;
|
||||
|
||||
NVFBCRESULT res = NVFBC_SUCCESS;
|
||||
NvFBCStatusEx status = {0};
|
||||
status.dwVersion = NVFBC_STATUS_VER;
|
||||
status.dwAdapterIdx = adapter;
|
||||
res = getStatus(&status);
|
||||
NVFBCRESULT res = NVFBC_SUCCESS;
|
||||
NvFBCStatusEx status = { 0 };
|
||||
status.dwVersion = NVFBC_STATUS_VER;
|
||||
status.dwAdapterIdx = adapter;
|
||||
res = getStatus(&status);
|
||||
|
||||
if (res != NVFBC_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "NvFBC not supported on this device + driver.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
if(res != NVFBC_SUCCESS) {
|
||||
fprintf(stderr, "NvFBC not supported on this device + driver.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check to see if the device and driver are supported
|
||||
if(!status.bIsCapturePossible)
|
||||
{
|
||||
fprintf(stderr, "Unsupported device or driver.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
// Check to see if the device and driver are supported
|
||||
if(!status.bIsCapturePossible) {
|
||||
fprintf(stderr, "Unsupported device or driver.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check to see if an instance can be created
|
||||
if(!status.bCanCreateNow)
|
||||
{
|
||||
fprintf(stderr, "Unable to create an instance of NvFBC.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
// Check to see if an instance can be created
|
||||
if(!status.bCanCreateNow) {
|
||||
fprintf(stderr, "Unable to create an instance of NvFBC.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NvFBCCreateParams createParams;
|
||||
memset(&createParams, 0, sizeof(createParams));
|
||||
createParams.dwVersion = NVFBC_CREATE_PARAMS_VER;
|
||||
createParams.dwInterfaceType = type;
|
||||
createParams.pDevice = devicePtr;
|
||||
createParams.dwAdapterIdx = adapter;
|
||||
NvFBCCreateParams createParams;
|
||||
memset(&createParams, 0, sizeof(createParams));
|
||||
createParams.dwVersion = NVFBC_CREATE_PARAMS_VER;
|
||||
createParams.dwInterfaceType = type;
|
||||
createParams.pDevice = devicePtr;
|
||||
createParams.dwAdapterIdx = adapter;
|
||||
|
||||
res = pfn_create(&createParams);
|
||||
|
||||
*maxWidth = createParams.dwMaxDisplayWidth;
|
||||
*maxHeight = createParams.dwMaxDisplayHeight;
|
||||
|
||||
return createParams.pNvFBC;
|
||||
}
|
||||
res = pfn_create(&createParams);
|
||||
|
||||
// enable/disable NVFBC
|
||||
void enable(NVFBC_STATE nvFBCState)
|
||||
{
|
||||
NVFBCRESULT res = NVFBC_SUCCESS;
|
||||
res = pfn_enable(nvFBCState);
|
||||
*maxWidth = createParams.dwMaxDisplayWidth;
|
||||
*maxHeight = createParams.dwMaxDisplayHeight;
|
||||
|
||||
if (res != NVFBC_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "Failed to %s. Insufficient privilege\n", nvFBCState == 0?"disable":"enable");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stdout, "NvFBC is %s\n", nvFBCState == 0 ? "disabled" : "enabled");
|
||||
return;
|
||||
}
|
||||
}
|
||||
return createParams.pNvFBC;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Get the default NvFBC library path
|
||||
typedef BOOL (WINAPI *pfnIsWow64Process) (HANDLE, PBOOL);
|
||||
pfnIsWow64Process fnIsWow64Process;
|
||||
// enable/disable NVFBC
|
||||
void enable(NVFBC_STATE nvFBCState) {
|
||||
NVFBCRESULT res = NVFBC_SUCCESS;
|
||||
res = pfn_enable(nvFBCState);
|
||||
|
||||
BOOL IsWow64()
|
||||
{
|
||||
BOOL bIsWow64 = FALSE;
|
||||
if(res != NVFBC_SUCCESS) {
|
||||
fprintf(stderr, "Failed to %s. Insufficient privilege\n", nvFBCState == 0 ? "disable" : "enable");
|
||||
return;
|
||||
} else {
|
||||
fprintf(stdout, "NvFBC is %s\n", nvFBCState == 0 ? "disabled" : "enabled");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fnIsWow64Process = (pfnIsWow64Process) GetProcAddress(
|
||||
GetModuleHandle(TEXT("kernel32.dll")),"IsWow64Process");
|
||||
|
||||
if (NULL != fnIsWow64Process)
|
||||
{
|
||||
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
|
||||
{
|
||||
bIsWow64 = false;
|
||||
}
|
||||
}
|
||||
return bIsWow64;
|
||||
}
|
||||
protected:
|
||||
// Get the default NvFBC library path
|
||||
typedef BOOL(WINAPI* pfnIsWow64Process)(HANDLE, PBOOL);
|
||||
pfnIsWow64Process fnIsWow64Process;
|
||||
|
||||
std::string getDefaultPath()
|
||||
{
|
||||
std::string defaultPath;
|
||||
BOOL IsWow64() {
|
||||
BOOL bIsWow64 = FALSE;
|
||||
|
||||
size_t pathSize;
|
||||
char *libPath;
|
||||
fnIsWow64Process = (pfnIsWow64Process)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "IsWow64Process");
|
||||
|
||||
if(0 != _dupenv_s(&libPath, &pathSize, "SystemRoot"))
|
||||
{
|
||||
fprintf(stderr, "Unable to get the SystemRoot environment variable\n");
|
||||
return defaultPath;
|
||||
}
|
||||
if(NULL != fnIsWow64Process) {
|
||||
if(!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) {
|
||||
bIsWow64 = false;
|
||||
}
|
||||
}
|
||||
return bIsWow64;
|
||||
}
|
||||
|
||||
if(0 == pathSize)
|
||||
{
|
||||
fprintf(stderr, "The SystemRoot environment variable is not set\n");
|
||||
return defaultPath;
|
||||
}
|
||||
std::string getDefaultPath() {
|
||||
std::string defaultPath;
|
||||
|
||||
size_t pathSize;
|
||||
char* libPath;
|
||||
|
||||
if(0 != _dupenv_s(&libPath, &pathSize, "SystemRoot")) {
|
||||
fprintf(stderr, "Unable to get the SystemRoot environment variable\n");
|
||||
return defaultPath;
|
||||
}
|
||||
|
||||
if(0 == pathSize) {
|
||||
fprintf(stderr, "The SystemRoot environment variable is not set\n");
|
||||
return defaultPath;
|
||||
}
|
||||
#ifdef _WIN64
|
||||
defaultPath = std::string(libPath) + "\\System32\\" + NVFBC64_LIBRARY_NAME;
|
||||
defaultPath = std::string(libPath) + "\\System32\\" + NVFBC64_LIBRARY_NAME;
|
||||
#else
|
||||
if (IsWow64())
|
||||
{
|
||||
defaultPath = std::string(libPath) + "\\Syswow64\\" + NVFBC_LIBRARY_NAME;
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultPath = std::string(libPath) + "\\System32\\" + NVFBC_LIBRARY_NAME;
|
||||
}
|
||||
if(IsWow64()) {
|
||||
defaultPath = std::string(libPath) + "\\Syswow64\\" + NVFBC_LIBRARY_NAME;
|
||||
} else {
|
||||
defaultPath = std::string(libPath) + "\\System32\\" + NVFBC_LIBRARY_NAME;
|
||||
}
|
||||
#endif
|
||||
return defaultPath;
|
||||
}
|
||||
return defaultPath;
|
||||
}
|
||||
|
||||
void setTargetAdapter(int adapter = 0)
|
||||
{
|
||||
char targetAdapter[10] = {0};
|
||||
_snprintf_s(targetAdapter, 10, 9, "%d", adapter);
|
||||
SetEnvironmentVariableA("NVFBC_TARGET_ADAPTER", targetAdapter);
|
||||
}
|
||||
void setTargetAdapter(int adapter = 0) {
|
||||
char targetAdapter[10] = { 0 };
|
||||
_snprintf_s(targetAdapter, 10, 9, "%d", adapter);
|
||||
SetEnvironmentVariableA("NVFBC_TARGET_ADAPTER", targetAdapter);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
HMODULE m_handle;
|
||||
NvFBC_GetStatusExFunctionType pfn_get_status;
|
||||
NvFBC_SetGlobalFlagsType pfn_set_global_flags;
|
||||
NvFBC_CreateFunctionExType pfn_create;
|
||||
NvFBC_EnableFunctionType pfn_enable;
|
||||
protected:
|
||||
HMODULE m_handle;
|
||||
NvFBC_GetStatusExFunctionType pfn_get_status;
|
||||
NvFBC_SetGlobalFlagsType pfn_set_global_flags;
|
||||
NvFBC_CreateFunctionExType pfn_create;
|
||||
NvFBC_EnableFunctionType pfn_enable;
|
||||
};
|
||||
|
|
|
@ -16,11 +16,12 @@ using f32 = float;
|
|||
using f64 = double;
|
||||
|
||||
/// like vector<T> but doesn't grow on its own
|
||||
template<class T>
|
||||
template <class T>
|
||||
struct unique_buffer {
|
||||
T* m_buffer;
|
||||
size_t size;
|
||||
public:
|
||||
|
||||
public:
|
||||
unique_buffer() {
|
||||
m_buffer = nullptr;
|
||||
size = 0;
|
||||
|
@ -30,20 +31,18 @@ public:
|
|||
unique_buffer(const unique_buffer&) = delete;
|
||||
unique_buffer(unique_buffer&&) = delete;
|
||||
|
||||
~unique_buffer() {
|
||||
resize(0);
|
||||
}
|
||||
~unique_buffer() { resize(0); }
|
||||
|
||||
size_t get_size() const { return this->size; }
|
||||
|
||||
void resize(size_t new_size) {
|
||||
if (m_buffer) {
|
||||
if(m_buffer) {
|
||||
delete[] m_buffer;
|
||||
m_buffer = nullptr;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
if (new_size) {
|
||||
if(new_size) {
|
||||
m_buffer = new T[new_size];
|
||||
size = new_size;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue