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,6 +12,7 @@
|
|||
|
||||
#include "NvFBCLibrary.h"
|
||||
#include <NvFBC/nvFBCToSys.h>
|
||||
// clang-format on
|
||||
|
||||
#pragma pack(push, 1)
|
||||
enum class MessageType : u32 {
|
||||
|
@ -45,7 +47,6 @@ struct tDataMessage {
|
|||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
struct tileRect {
|
||||
u32 x, y, width, height;
|
||||
};
|
||||
|
@ -53,6 +54,7 @@ struct tileRect {
|
|||
// client for streamserver
|
||||
class cStreamClient {
|
||||
SOCKET tcpSocket { -1 };
|
||||
|
||||
public:
|
||||
cStreamClient() = default;
|
||||
|
||||
|
@ -101,8 +103,6 @@ public:
|
|||
// header.datalen = data.get_size() * sizeof(UINT32);
|
||||
header.datalen = sizeof(tDataMessage);
|
||||
|
||||
|
||||
|
||||
auto* pData = data.data();
|
||||
|
||||
// send tile header
|
||||
|
@ -111,8 +111,7 @@ public:
|
|||
if(tiles.empty()) {
|
||||
dm.tileCount = 1;
|
||||
sendFull = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dm.tileCount = (u32)tiles.size();
|
||||
}
|
||||
|
||||
|
@ -121,17 +120,10 @@ 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
|
||||
};
|
||||
|
||||
tTile tile_wire { tile.x, tile.y, tile.width, tile.height };
|
||||
|
||||
std::vector<u32> data;
|
||||
data.resize(tile.width * tile.height * 4);
|
||||
|
@ -152,21 +144,14 @@ 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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// FIXME: make this a class, I've clearly got the ability to pull it into one
|
||||
|
@ -213,8 +198,7 @@ bool nvfbcCreate() {
|
|||
|
||||
//! Create an instance of NvFBCToSys
|
||||
nvfbcToSys = (NvFBCToSys*)nvfbcLibrary->create(NVFBC_TO_SYS, &maxDisplayWidth, &maxDisplayHeight);
|
||||
if (!nvfbcToSys)
|
||||
{
|
||||
if(!nvfbcToSys) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -257,8 +241,7 @@ 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);
|
||||
|
||||
|
@ -353,15 +336,12 @@ int main(int argc, char** argv) {
|
|||
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,28 +3,23 @@
|
|||
#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
|
||||
{
|
||||
class NvFBCLibrary {
|
||||
NvFBCLibrary(const NvFBCLibrary&);
|
||||
NvFBCLibrary& operator=(const NvFBCLibrary&);
|
||||
|
||||
public:
|
||||
NvFBCLibrary()
|
||||
: m_handle(NULL)
|
||||
, pfn_get_status(NULL)
|
||||
, pfn_create(NULL)
|
||||
, pfn_enable(NULL)
|
||||
{}
|
||||
NvFBCLibrary() : m_handle(NULL), pfn_get_status(NULL), pfn_create(NULL), pfn_enable(NULL) {}
|
||||
|
||||
~NvFBCLibrary()
|
||||
{
|
||||
~NvFBCLibrary() {
|
||||
if(NULL != m_handle)
|
||||
close();
|
||||
}
|
||||
|
@ -33,21 +28,18 @@ public:
|
|||
// 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())
|
||||
{
|
||||
bool load(std::string fileName = std::string()) {
|
||||
if(NULL != m_handle)
|
||||
return true;
|
||||
|
||||
if(!fileName.empty())
|
||||
m_handle = ::LoadLibraryA(fileName.c_str());
|
||||
|
||||
if(NULL == m_handle)
|
||||
{
|
||||
if(NULL == m_handle) {
|
||||
m_handle = ::LoadLibraryA(getDefaultPath().c_str());
|
||||
}
|
||||
|
||||
if(NULL == m_handle)
|
||||
{
|
||||
if(NULL == m_handle) {
|
||||
fprintf(stderr, "Unable to load NvFBC.\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -58,8 +50,7 @@ public:
|
|||
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))
|
||||
{
|
||||
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();
|
||||
|
||||
|
@ -70,8 +61,7 @@ public:
|
|||
}
|
||||
|
||||
// Close the NvFBC dll
|
||||
void close()
|
||||
{
|
||||
void close() {
|
||||
if(NULL != m_handle)
|
||||
FreeLibrary(m_handle);
|
||||
|
||||
|
@ -83,27 +73,19 @@ public:
|
|||
|
||||
// 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);
|
||||
}
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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)
|
||||
{
|
||||
void* create(DWORD type, DWORD* maxWidth, DWORD* maxHeight, int adapter = 0, void* devicePtr = NULL) {
|
||||
if(NULL == m_handle)
|
||||
return NULL;
|
||||
|
||||
|
@ -113,22 +95,19 @@ public:
|
|||
status.dwAdapterIdx = adapter;
|
||||
res = getStatus(&status);
|
||||
|
||||
if (res != NVFBC_SUCCESS)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if(!status.bCanCreateNow) {
|
||||
fprintf(stderr, "Unable to create an instance of NvFBC.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -149,18 +128,14 @@ public:
|
|||
}
|
||||
|
||||
// enable/disable NVFBC
|
||||
void enable(NVFBC_STATE nvFBCState)
|
||||
{
|
||||
void enable(NVFBC_STATE nvFBCState) {
|
||||
NVFBCRESULT res = NVFBC_SUCCESS;
|
||||
res = pfn_enable(nvFBCState);
|
||||
|
||||
if (res != NVFBC_SUCCESS)
|
||||
{
|
||||
if(res != NVFBC_SUCCESS) {
|
||||
fprintf(stderr, "Failed to %s. Insufficient privilege\n", nvFBCState == 0 ? "disable" : "enable");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fprintf(stdout, "NvFBC is %s\n", nvFBCState == 0 ? "disabled" : "enabled");
|
||||
return;
|
||||
}
|
||||
|
@ -171,64 +146,52 @@ protected:
|
|||
typedef BOOL(WINAPI* pfnIsWow64Process)(HANDLE, PBOOL);
|
||||
pfnIsWow64Process fnIsWow64Process;
|
||||
|
||||
BOOL IsWow64()
|
||||
{
|
||||
BOOL IsWow64() {
|
||||
BOOL bIsWow64 = FALSE;
|
||||
|
||||
fnIsWow64Process = (pfnIsWow64Process) GetProcAddress(
|
||||
GetModuleHandle(TEXT("kernel32.dll")),"IsWow64Process");
|
||||
fnIsWow64Process = (pfnIsWow64Process)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "IsWow64Process");
|
||||
|
||||
if (NULL != fnIsWow64Process)
|
||||
{
|
||||
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
|
||||
{
|
||||
if(NULL != fnIsWow64Process) {
|
||||
if(!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) {
|
||||
bIsWow64 = false;
|
||||
}
|
||||
}
|
||||
return bIsWow64;
|
||||
}
|
||||
|
||||
std::string getDefaultPath()
|
||||
{
|
||||
std::string getDefaultPath() {
|
||||
std::string defaultPath;
|
||||
|
||||
size_t pathSize;
|
||||
char* libPath;
|
||||
|
||||
if(0 != _dupenv_s(&libPath, &pathSize, "SystemRoot"))
|
||||
{
|
||||
if(0 != _dupenv_s(&libPath, &pathSize, "SystemRoot")) {
|
||||
fprintf(stderr, "Unable to get the SystemRoot environment variable\n");
|
||||
return defaultPath;
|
||||
}
|
||||
|
||||
if(0 == pathSize)
|
||||
{
|
||||
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;
|
||||
#else
|
||||
if (IsWow64())
|
||||
{
|
||||
if(IsWow64()) {
|
||||
defaultPath = std::string(libPath) + "\\Syswow64\\" + NVFBC_LIBRARY_NAME;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
defaultPath = std::string(libPath) + "\\System32\\" + NVFBC_LIBRARY_NAME;
|
||||
}
|
||||
#endif
|
||||
return defaultPath;
|
||||
}
|
||||
|
||||
void setTargetAdapter(int adapter = 0)
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -20,6 +20,7 @@ template<class T>
|
|||
struct unique_buffer {
|
||||
T* m_buffer;
|
||||
size_t size;
|
||||
|
||||
public:
|
||||
unique_buffer() {
|
||||
m_buffer = nullptr;
|
||||
|
@ -30,9 +31,7 @@ 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; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue