Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmake/compile_definitions/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ set(PLATFORM_TARGET_FILES
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_ram.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_wgc.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_amd.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/capture_plugin/capture_plugin_api.h"
"${CMAKE_SOURCE_DIR}/src/platform/windows/capture_plugin/capture_plugin_loader.h"
"${CMAKE_SOURCE_DIR}/src/platform/windows/capture_plugin/capture_plugin_loader.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/capture_plugin/display_plugin.h"
"${CMAKE_SOURCE_DIR}/src/platform/windows/capture_plugin/display_plugin.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/audio.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/mic_write.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/device_hdr_states.cpp"
Expand Down
27 changes: 27 additions & 0 deletions examples/capture_plugin_nvfbc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.20)
project(sunshine_nvfbc_plugin LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Path to Sunshine source root (for plugin API header)
set(SUNSHINE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." CACHE PATH
"Path to Sunshine source root")

add_library(sunshine_nvfbc SHARED
sunshine_nvfbc_plugin.cpp
)

target_include_directories(sunshine_nvfbc PRIVATE
"${SUNSHINE_SOURCE_DIR}"
)

# NvFBC does not have a public import library on Windows.
# The plugin loads NvFBC64.dll at runtime via LoadLibrary.

# Output to plugins/ directory for easy deployment
set_target_properties(sunshine_nvfbc PROPERTIES
OUTPUT_NAME "sunshine_nvfbc"
PREFIX ""
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
)
51 changes: 51 additions & 0 deletions examples/capture_plugin_nvfbc/NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# NvFBC Capture Plugin — Legal Notice

## Disclaimer

This plugin interfaces with NVIDIA Frame Buffer Capture (NvFBC), a
proprietary NVIDIA technology. By using this plugin, you acknowledge
and agree to the following:

1. **Authorization Required**: NvFBC access may be restricted to specific
GPU product lines (e.g., NVIDIA Quadro, Tesla, Grid). Using NvFBC on
unsupported hardware may violate NVIDIA's End User License Agreement
(EULA) for GeForce drivers.

2. **No Bypass Mechanisms Included**: This plugin does NOT include any
authentication keys, private data, or technical measures to circumvent
NvFBC access restrictions. Users must independently obtain appropriate
NvFBC authorization.

3. **External Private Data**: If your NvFBC configuration requires private
authentication data, it must be supplied externally via:
- A file at `plugins/nvfbc_auth.bin` (next to the plugin DLL)
- The `NVFBC_PRIVDATA_FILE` environment variable pointing to the file

This plugin does not generate, distribute, or embed such data.

4. **User Responsibility**: Users are solely responsible for ensuring their
use of NvFBC complies with all applicable laws, regulations, and license
agreements, including but not limited to the NVIDIA EULA, DMCA (US),
EU Copyright Directive, and local intellectual property laws.

5. **No Warranty**: This plugin is provided "AS IS" without warranty of any
kind. The authors disclaim all liability for any damages arising from
its use.

## Third-Party Attributions

- **NvFBCCreateParams structure**: Based on definitions from
[keylase/nvidia-patch](https://github.com/keylase/nvidia-patch)
(MIT License)
- **NVFBCRESULT error codes**: Based on publicly documented NVIDIA
NvFBC error codes
- **Sunshine Capture Plugin API**: Part of the Sunshine project
(GPL-3.0 License)

## NVIDIA Capture SDK

For official NvFBC API headers and documentation, obtain the NVIDIA
Capture SDK from: https://developer.nvidia.com/capture-sdk

The Capture SDK provides the complete INvFBCToSys interface definition
needed to fully implement the capture functionality in this plugin.
134 changes: 134 additions & 0 deletions examples/capture_plugin_nvfbc/nvfbc_win_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* @file nvfbc_win_defs.h
* @brief Windows NvFBC API type definitions.
*
* Based on publicly available information:
* - keylase/nvidia-patch nvfbcdefs.h (MIT license) for NvFBCCreateParams
* - NVIDIA public documentation for error codes and buffer formats
*
* IMPORTANT:
* This file does NOT contain proprietary NVIDIA Capture SDK headers.
* The INvFBCToSys interface is NOT defined here — users must provide
* their own interface definitions from an authorized source (NVIDIA
* Capture SDK, Grid SDK, etc.).
*
* No authentication credentials, private keys, or bypass mechanisms
* are included. Users are responsible for obtaining appropriate access
* to NvFBC functionality through legitimate channels.
*/
#pragma once

#include <cstdint>
#include <Windows.h>

// ============================================================================
// NvFBC version and macros (from keylase/nvidia-patch nvfbcdefs.h, MIT license)
// ============================================================================

typedef unsigned long NvU32;

#define NVFBC_DLL_VERSION 0x70

#define NVFBC_STRUCT_VERSION(typeName, ver) \
(NvU32)(sizeof(typeName) | ((ver) << 16) | (NVFBC_DLL_VERSION << 24))

#define NVFBCAPI __stdcall

// ============================================================================
// Error codes (NVFBCRESULT) — documented in NVIDIA public references
// ============================================================================

typedef enum _NVFBCRESULT {
NVFBC_SUCCESS = 0,
NVFBC_ERROR_GENERIC = -1,
NVFBC_ERROR_INVALID_PARAM = -2,
NVFBC_ERROR_INVALIDATED_SESSION = -3,
NVFBC_ERROR_PROTECTED_CONTENT = -4,
NVFBC_ERROR_DRIVER_FAILURE = -5,
NVFBC_ERROR_CUDA_FAILURE = -6,
NVFBC_ERROR_UNSUPPORTED = -7,
NVFBC_ERROR_HW_ENC_FAILURE = -8,
NVFBC_ERROR_INCOMPATIBLE_DRIVER = -9,
NVFBC_ERROR_UNSUPPORTED_PLATFORM = -10,
NVFBC_ERROR_OUT_OF_MEMORY = -11,
NVFBC_ERROR_INVALID_PTR = -12,
NVFBC_ERROR_INCOMPATIBLE_VERSION = -13,
NVFBC_ERROR_OPT_CAPTURE_FAILURE = -14,
NVFBC_ERROR_INSUFFICIENT_PRIVILEGES = -15,
NVFBC_ERROR_INVALID_CALL = -16,
NVFBC_ERROR_SYSTEM_ERROR = -17,
NVFBC_ERROR_INVALID_TARGET = -18,
NVFBC_ERROR_NVAPI_FAILURE = -19,
NVFBC_ERROR_DYNAMIC_DISABLE = -20,
NVFBC_ERROR_IPC_FAILURE = -21,
NVFBC_ERROR_CURSOR_CAPTURE_FAILURE = -22,
} NVFBCRESULT;

// ============================================================================
// Buffer formats — common across NvFBC platforms
// ============================================================================

typedef enum _NVFBC_BUFFER_FORMAT {
NVFBC_BUFFER_FORMAT_ARGB = 0,
NVFBC_BUFFER_FORMAT_RGB = 1,
NVFBC_BUFFER_FORMAT_NV12 = 2,
NVFBC_BUFFER_FORMAT_YUV444P = 3,
NVFBC_BUFFER_FORMAT_RGBA = 4,
NVFBC_BUFFER_FORMAT_BGRA = 5,
} NVFBC_BUFFER_FORMAT;

// ============================================================================
// Interface type IDs for NvFBC_CreateEx
// ============================================================================

typedef enum _NVFBC_INTERFACE_TYPE {
NVFBC_TO_SYS = 0,
NVFBC_TO_CUDA = 1,
NVFBC_TO_DX9VID = 2,
NVFBC_TO_HW_ENC = 3,
} NVFBC_INTERFACE_TYPE;

// ============================================================================
// NvFBC_CreateEx parameters (from keylase/nvidia-patch, MIT license)
// ============================================================================

typedef struct _NvFBCCreateParams {
NvU32 dwVersion;
NvU32 dwInterfaceType;
NvU32 dwMaxDisplayWidth;
NvU32 dwMaxDisplayHeight;
void *pDevice;
void *pPrivateData;
NvU32 dwPrivateDataSize;
NvU32 dwInterfaceVersion;
void *pNvFBC;
NvU32 dwAdapterIdx;
NvU32 dwNvFBCVersion;
void *cudaCtx;
void *pPrivateData2;
NvU32 dwPrivateData2Size;
NvU32 dwReserved[55];
void *pReserved[27];
} NvFBCCreateParams;

#define NVFBC_CREATE_PARAMS_VER NVFBC_STRUCT_VERSION(NvFBCCreateParams, 2)

// ============================================================================
// Function pointer types for NvFBC64.dll exports
// ============================================================================

typedef NVFBCRESULT(NVFBCAPI *NvFBC_CreateFunctionExType)(void *pCreateParams);
typedef NVFBCRESULT(NVFBCAPI *NvFBC_GetStatusExFunctionType)(void *pStatusParams);

// ============================================================================
// Frame grab info (populated after successful capture)
// ============================================================================

typedef struct _NvFBCFrameGrabInfo {
NvU32 dwWidth;
NvU32 dwHeight;
NvU32 dwBufferWidth;
NvU32 dwReserved;
NvU32 bIsNewFrame;
NvU32 dwReservedFields[27];
} NvFBCFrameGrabInfo;
Loading