From aaf02d5e9c8e3d5d90ac3a1bae16df9669385011 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Sun, 8 Feb 2015 06:10:26 +0100
Subject: [PATCH] nvencodeapi: First implementation.

---
 configure.ac                          |   2 +
 dlls/nvencodeapi/Makefile.in          |   4 +
 dlls/nvencodeapi/nvencodeapi.c        | 370 ++++++++++++++++++++++++++
 dlls/nvencodeapi/nvencodeapi.spec     |   1 +
 dlls/nvencodeapi64/Makefile.in        |   5 +
 dlls/nvencodeapi64/nvencodeapi64.spec |   1 +
 include/Makefile.in                   |   1 +
 include/nvencodeapi.h                 | 281 +++++++++++++++++++
 8 files changed, 665 insertions(+)
 create mode 100644 dlls/nvencodeapi/Makefile.in
 create mode 100644 dlls/nvencodeapi/nvencodeapi.c
 create mode 100644 dlls/nvencodeapi/nvencodeapi.spec
 create mode 100644 dlls/nvencodeapi64/Makefile.in
 create mode 100644 dlls/nvencodeapi64/nvencodeapi64.spec
 create mode 100644 include/nvencodeapi.h

diff --git a/configure.ac b/configure.ac
index 326d03975..a2f06d7ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3555,6 +3555,8 @@ WINE_CONFIG_MAKEFILE(dlls/nvapi64,enable_win64)
 WINE_CONFIG_MAKEFILE(dlls/nvcuda)
 WINE_CONFIG_MAKEFILE(dlls/nvcuda/tests)
 WINE_CONFIG_MAKEFILE(dlls/nvcuvid)
+WINE_CONFIG_MAKEFILE(dlls/nvencodeapi,enable_win32)
+WINE_CONFIG_MAKEFILE(dlls/nvencodeapi64,enable_win64)
 WINE_CONFIG_MAKEFILE(dlls/objsel)
 WINE_CONFIG_MAKEFILE(dlls/odbc32)
 WINE_CONFIG_MAKEFILE(dlls/odbcbcp)
diff --git a/dlls/nvencodeapi/Makefile.in b/dlls/nvencodeapi/Makefile.in
new file mode 100644
index 000000000..a2e58acaf
--- /dev/null
+++ b/dlls/nvencodeapi/Makefile.in
@@ -0,0 +1,4 @@
+MODULE    = nvencodeapi.dll
+
+C_SRCS = \
+	nvencodeapi.c
diff --git a/dlls/nvencodeapi/nvencodeapi.c b/dlls/nvencodeapi/nvencodeapi.c
new file mode 100644
index 000000000..91a33fd58
--- /dev/null
+++ b/dlls/nvencodeapi/nvencodeapi.c
@@ -0,0 +1,370 @@
+/*
+ * Copyright (C) 2015 Michael Müller
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wine/debug.h"
+#include "wine/library.h"
+
+#include "nvencodeapi.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(nvencodeapi);
+
+static void *libnvidia_encode_handle = NULL;
+static LINUX_NV_ENCODE_API_FUNCTION_LIST origFunctions;
+
+static NVENCSTATUS (*pNvEncodeAPICreateInstance)(LINUX_NV_ENCODE_API_FUNCTION_LIST *functionList);
+
+static NVENCSTATUS WINAPI NvEncOpenEncodeSession(void *device, uint32_t deviceType, void **encoder)
+{
+    TRACE("(%p, %u, %p)\n", device, deviceType, encoder);
+    return origFunctions.nvEncOpenEncodeSession(device, deviceType, encoder);
+}
+
+static NVENCSTATUS WINAPI NvEncGetEncodeGUIDCount(void *encoder, uint32_t *encodeGUIDCount)
+{
+    TRACE("(%p, %p)\n", encoder, encodeGUIDCount);
+    return origFunctions.nvEncGetEncodeGUIDCount(encoder, encodeGUIDCount);
+}
+
+static NVENCSTATUS WINAPI NvEncGetEncodeGUIDs(void *encoder, GUID *GUIDs, uint32_t guidArraySize, uint32_t *GUIDCount)
+{
+    TRACE("(%p, %p, %u, %p)\n", encoder, GUIDs, guidArraySize, GUIDCount);
+    return origFunctions.nvEncGetEncodeGUIDs(encoder, GUIDs, guidArraySize, GUIDCount);
+}
+
+static NVENCSTATUS WINAPI NvEncGetEncodeProfileGUIDCount(void *encoder, GUID encodeGUID, uint32_t *encodeProfileGUIDCount)
+{
+    TRACE("(%p, %s, %p)\n", encoder, debugstr_guid(&encodeGUID), encodeProfileGUIDCount);
+    return origFunctions.nvEncGetEncodeProfileGUIDCount(encoder, encodeGUID, encodeProfileGUIDCount);
+}
+
+static NVENCSTATUS WINAPI NvEncGetEncodeProfileGUIDs(void *encoder, GUID encodeGUID, GUID *profileGUIDs,
+                                                     uint32_t guidArraySize, uint32_t *GUIDCount)
+{
+    TRACE("(%p, %s, %p, %u, %p)\n", encoder, debugstr_guid(&encodeGUID), profileGUIDs, guidArraySize, GUIDCount);
+    return origFunctions.nvEncGetEncodeProfileGUIDs(encoder, encodeGUID, profileGUIDs, guidArraySize, GUIDCount);
+}
+
+static NVENCSTATUS WINAPI NvEncGetInputFormatCount(void *encoder, GUID encodeGUID, uint32_t *inputFmtCount)
+{
+    TRACE("(%p, %s, %p)\n", encoder, debugstr_guid(&encodeGUID), inputFmtCount);
+    return origFunctions.nvEncGetInputFormatCount(encoder, encodeGUID, inputFmtCount);
+}
+
+static NVENCSTATUS WINAPI NvEncGetInputFormats(void *encoder, GUID encodeGUID, NV_ENC_BUFFER_FORMAT *inputFmts,
+                                               uint32_t inputFmtArraySize, uint32_t *inputFmtCount)
+{
+    TRACE("(%p, %s, %p)\n", encoder, debugstr_guid(&encodeGUID), inputFmtCount);
+    return origFunctions.nvEncGetInputFormatCount(encoder, encodeGUID, inputFmtCount);
+}
+
+static NVENCSTATUS WINAPI NvEncGetEncodeCaps(void *encoder, GUID encodeGUID, NV_ENC_CAPS_PARAM *capsParam, int *capsVal)
+{
+    TRACE("(%p, %s, %p, %p)\n", encoder, debugstr_guid(&encodeGUID), capsParam, capsVal);
+    return origFunctions.nvEncGetEncodeCaps(encoder, encodeGUID, capsParam, capsVal);
+}
+
+static NVENCSTATUS WINAPI NvEncGetEncodePresetCount(void *encoder, GUID encodeGUID, uint32_t *encodePresetGUIDCount)
+{
+    TRACE("(%p, %s, %p)\n", encoder, debugstr_guid(&encodeGUID), encodePresetGUIDCount);
+    return origFunctions.nvEncGetEncodePresetCount(encoder, encodeGUID, encodePresetGUIDCount);
+}
+
+static NVENCSTATUS WINAPI NvEncGetEncodePresetGUIDs(void *encoder, GUID encodeGUID, GUID *presetGUIDs, uint32_t guidArraySize,
+                                                    uint32_t *encodePresetGUIDCount)
+{
+    TRACE("(%p, %s, %p, %u, %p)\n", encoder, debugstr_guid(&encodeGUID), presetGUIDs, guidArraySize, encodePresetGUIDCount);
+    return origFunctions.nvEncGetEncodePresetGUIDs(encoder, encodeGUID, presetGUIDs, guidArraySize, encodePresetGUIDCount);
+}
+
+static NVENCSTATUS WINAPI NvEncGetEncodePresetConfig(void *encoder, GUID encodeGUID, GUID presetGUID, NV_ENC_PRESET_CONFIG *presetConfig)
+{
+    TRACE("(%p, %s, %s, %p)\n", encoder, debugstr_guid(&encodeGUID), debugstr_guid(&presetGUID), presetConfig);
+    return origFunctions.nvEncGetEncodePresetConfig(encoder, encodeGUID, presetGUID, presetConfig);
+}
+
+static NVENCSTATUS WINAPI NvEncInitializeEncoder(void *encoder, NV_ENC_INITIALIZE_PARAMS *createEncodeParams)
+{
+    NV_ENC_INITIALIZE_PARAMS linux_encode_params;
+
+    TRACE("(%p, %p)\n", encoder, createEncodeParams);
+
+    if (!createEncodeParams)
+        return NV_ENC_ERR_INVALID_PTR;
+
+    if (createEncodeParams->enableEncodeAsync)
+    {
+        FIXME("Async encoding is not supported by the linux NVIDIA driver.\n");
+        FIXME("Trying to emulate async mode, but this might not work for all applications.\n");
+
+        /* Forward modified information to the linux library. */
+        linux_encode_params = *createEncodeParams;
+        createEncodeParams = &linux_encode_params;
+        linux_encode_params.enableEncodeAsync = 0;
+    }
+
+    return origFunctions.nvEncInitializeEncoder(encoder, createEncodeParams);
+}
+
+static NVENCSTATUS WINAPI NvEncCreateInputBuffer(void *encoder, NV_ENC_CREATE_INPUT_BUFFER *createInputBufferParams)
+{
+    TRACE("(%p, %p)\n", encoder, createInputBufferParams);
+    return origFunctions.nvEncCreateInputBuffer(encoder, createInputBufferParams);
+}
+
+static NVENCSTATUS WINAPI NvEncDestroyInputBuffer(void *encoder, NV_ENC_INPUT_PTR inputBuffer)
+{
+    TRACE("(%p, %p)\n", encoder, inputBuffer);
+    return origFunctions.nvEncDestroyInputBuffer(encoder, inputBuffer);
+}
+
+static NVENCSTATUS WINAPI NvEncCreateBitstreamBuffer(void *encoder, NV_ENC_CREATE_BITSTREAM_BUFFER *createBitstreamBufferParams)
+{
+    TRACE("(%p, %p)\n", encoder, createBitstreamBufferParams);
+    return origFunctions.nvEncCreateBitstreamBuffer(encoder, createBitstreamBufferParams);
+}
+
+static NVENCSTATUS WINAPI NvEncDestroyBitstreamBuffer(void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer)
+{
+    TRACE("(%p, %p)\n", encoder, bitstreamBuffer);
+    return origFunctions.nvEncDestroyBitstreamBuffer(encoder, bitstreamBuffer);
+}
+
+static NVENCSTATUS WINAPI NvEncEncodePicture(void *encoder, NV_ENC_PIC_PARAMS *encodePicParams)
+{
+    NVENCSTATUS result;
+    TRACE("(%p, %p)\n", encoder, encodePicParams);
+
+    result = origFunctions.nvEncEncodePicture(encoder, encodePicParams);
+
+    if (encodePicParams->completionEvent)
+        SetEvent(encodePicParams->completionEvent);
+
+    return result;
+}
+
+static NVENCSTATUS WINAPI NvEncLockBitstream(void *encoder, NV_ENC_LOCK_BITSTREAM *lockBitstreamBufferParams)
+{
+    TRACE("(%p, %p)\n", encoder, lockBitstreamBufferParams);
+    return origFunctions.nvEncLockBitstream(encoder, lockBitstreamBufferParams);
+}
+
+static NVENCSTATUS WINAPI NvEncUnlockBitstream(void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer)
+{
+    TRACE("(%p, %p)\n", encoder, bitstreamBuffer);
+    return origFunctions.nvEncUnlockBitstream(encoder, bitstreamBuffer);
+}
+
+static NVENCSTATUS WINAPI NvEncLockInputBuffer(void *encoder, NV_ENC_LOCK_INPUT_BUFFER *lockInputBufferParams)
+{
+    TRACE("(%p, %p)\n", encoder, lockInputBufferParams);
+    return origFunctions.nvEncLockInputBuffer(encoder, lockInputBufferParams);
+}
+
+static NVENCSTATUS WINAPI NvEncUnlockInputBuffer(void *encoder, NV_ENC_INPUT_PTR inputBuffer)
+{
+    TRACE("(%p, %p)\n", encoder, inputBuffer);
+    return origFunctions.nvEncUnlockInputBuffer(encoder, inputBuffer);
+}
+
+static NVENCSTATUS WINAPI NvEncGetEncodeStats(void *encoder, NV_ENC_STAT *encodeStats)
+{
+    TRACE("(%p, %p)\n", encoder, encodeStats);
+    return origFunctions.nvEncGetEncodeStats(encoder, encodeStats);
+}
+
+static NVENCSTATUS WINAPI NvEncGetSequenceParams(void *encoder, NV_ENC_SEQUENCE_PARAM_PAYLOAD *sequenceParamPayload)
+{
+    TRACE("(%p, %p)\n", encoder, sequenceParamPayload);
+    return origFunctions.nvEncGetSequenceParams(encoder, sequenceParamPayload);
+}
+
+static NVENCSTATUS WINAPI NvEncRegisterAsyncEvent(void *encoder, NV_ENC_EVENT_PARAMS *eventParams)
+{
+    TRACE("(%p, %p)\n", encoder, eventParams);
+    /* This function will always fail as the linux NVIDIA driver doesn't support async mode */
+    /* return origFunctions.nvEncRegisterAsyncEvent(encoder, eventParams); */
+    return NV_ENC_SUCCESS;
+}
+
+static NVENCSTATUS WINAPI NvEncUnregisterAsyncEvent(void *encoder, NV_ENC_EVENT_PARAMS *eventParams)
+{
+    TRACE("(%p, %p)\n", encoder, eventParams);
+    /* This function will always fail as the linux NVIDIA driver doesn't support async mode */
+    /* return origFunctions.nvEncUnregisterAsyncEvent(encoder, eventParams); */
+    return NV_ENC_SUCCESS;
+}
+
+static NVENCSTATUS WINAPI NvEncMapInputResource(void *encoder, NV_ENC_MAP_INPUT_RESOURCE *mapInputResParams)
+{
+    TRACE("(%p, %p)\n", encoder, mapInputResParams);
+    return origFunctions.nvEncMapInputResource(encoder, mapInputResParams);
+}
+
+static NVENCSTATUS WINAPI NvEncUnmapInputResource(void *encoder, NV_ENC_INPUT_PTR mappedInputBuffer)
+{
+    TRACE("(%p, %p)\n", encoder, mappedInputBuffer);
+    return origFunctions.nvEncUnmapInputResource(encoder, mappedInputBuffer);
+}
+
+static NVENCSTATUS WINAPI NvEncDestroyEncoder(void *encoder)
+{
+    TRACE("(%p)\n", encoder);
+    return origFunctions.nvEncDestroyEncoder(encoder);
+}
+
+static NVENCSTATUS WINAPI NvEncInvalidateRefFrames(void *encoder, uint64_t invalidRefFrameTimeStamp)
+{
+    TRACE("(%p, %s)\n", encoder, wine_dbgstr_longlong(invalidRefFrameTimeStamp));
+    return origFunctions.nvEncInvalidateRefFrames(encoder, invalidRefFrameTimeStamp);
+}
+
+static NVENCSTATUS WINAPI NvEncOpenEncodeSessionEx(NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS *openSessionExParams, void **encoder)
+{
+    TRACE("(%p, %p)\n", openSessionExParams, encoder);
+    return origFunctions.nvEncOpenEncodeSessionEx(openSessionExParams, encoder);
+}
+
+static NVENCSTATUS WINAPI NvEncRegisterResource(void *encoder, NV_ENC_REGISTER_RESOURCE *registerResParams)
+{
+    TRACE("(%p, %p)\n", encoder, registerResParams);
+    return origFunctions.nvEncRegisterResource(encoder, registerResParams);
+}
+
+static NVENCSTATUS WINAPI NvEncUnregisterResource(void *encoder, NV_ENC_REGISTERED_PTR registeredResource)
+{
+    TRACE("(%p, %p)\n", encoder, registeredResource);
+    return origFunctions.nvEncUnregisterResource(encoder, registeredResource);
+}
+
+static NVENCSTATUS WINAPI NvEncReconfigureEncoder(void *encoder, NV_ENC_RECONFIGURE_PARAMS *reInitEncodeParams)
+{
+    TRACE("(%p, %p)\n", encoder, reInitEncodeParams);
+    return origFunctions.nvEncReconfigureEncoder(encoder, reInitEncodeParams);
+}
+
+
+NVENCSTATUS WINAPI NvEncodeAPICreateInstance(NV_ENCODE_API_FUNCTION_LIST *functionList)
+{
+    TRACE("(%p)\n", functionList);
+
+    if (!functionList)
+        return NV_ENC_ERR_INVALID_PTR;
+
+    /* FIXME: Provide forward/backwards compatibility */
+    if (functionList->version != NV_ENCODE_API_FUNCTION_LIST_VER)
+        FIXME("Application expects nvencodeapi version %x, but wrapper only supports version %x\n",
+              functionList->version, NV_ENCODE_API_FUNCTION_LIST_VER);
+
+    /* set all function points and reserved values to zero */
+    memset(functionList, 0, sizeof(*functionList));
+    functionList->version = origFunctions.version;
+
+    #define SET_FUNCPTR(f) if (origFunctions.nv##f) functionList->nv##f = &Nv##f
+
+    SET_FUNCPTR(EncOpenEncodeSession);
+    SET_FUNCPTR(EncGetEncodeGUIDCount);
+    SET_FUNCPTR(EncGetEncodeProfileGUIDCount);
+    SET_FUNCPTR(EncGetEncodeProfileGUIDs);
+    SET_FUNCPTR(EncGetEncodeGUIDs);
+    SET_FUNCPTR(EncGetInputFormatCount);
+    SET_FUNCPTR(EncGetInputFormats);
+    SET_FUNCPTR(EncGetEncodeCaps);
+    SET_FUNCPTR(EncGetEncodePresetCount);
+    SET_FUNCPTR(EncGetEncodePresetGUIDs);
+    SET_FUNCPTR(EncGetEncodePresetConfig);
+    SET_FUNCPTR(EncInitializeEncoder);
+    SET_FUNCPTR(EncCreateInputBuffer);
+    SET_FUNCPTR(EncDestroyInputBuffer);
+    SET_FUNCPTR(EncCreateBitstreamBuffer);
+    SET_FUNCPTR(EncDestroyBitstreamBuffer);
+    SET_FUNCPTR(EncEncodePicture);
+    SET_FUNCPTR(EncLockBitstream);
+    SET_FUNCPTR(EncUnlockBitstream);
+    SET_FUNCPTR(EncLockInputBuffer);
+    SET_FUNCPTR(EncUnlockInputBuffer);
+    SET_FUNCPTR(EncGetEncodeStats);
+    SET_FUNCPTR(EncGetSequenceParams);
+    SET_FUNCPTR(EncRegisterAsyncEvent);
+    SET_FUNCPTR(EncUnregisterAsyncEvent);
+    SET_FUNCPTR(EncMapInputResource);
+    SET_FUNCPTR(EncUnmapInputResource);
+    SET_FUNCPTR(EncDestroyEncoder);
+    SET_FUNCPTR(EncInvalidateRefFrames);
+    SET_FUNCPTR(EncOpenEncodeSessionEx);
+    SET_FUNCPTR(EncRegisterResource);
+    SET_FUNCPTR(EncUnregisterResource);
+    SET_FUNCPTR(EncReconfigureEncoder);
+
+    #undef SET_FUNCPTR
+
+    return NV_ENC_SUCCESS;
+}
+
+static BOOL load_nvencode(void)
+{
+    libnvidia_encode_handle = dlopen("libnvidia-encode.so", RTLD_NOW);
+    if (!libnvidia_encode_handle)
+    {
+        FIXME("Wine cannot find the libnvidia-encode.so library, NVIDIA video encoding support disabled.\n");
+        return FALSE;
+    }
+
+    pNvEncodeAPICreateInstance = dlsym(libnvidia_encode_handle, "NvEncodeAPICreateInstance");
+    if (!pNvEncodeAPICreateInstance)
+    {
+        FIXME("Can't find symbol NvEncodeAPICreateInstance.\n");
+        return FALSE;
+    }
+
+    memset(&origFunctions, 0, sizeof(origFunctions));
+    origFunctions.version = NV_ENCODE_API_FUNCTION_LIST_VER;
+    if (pNvEncodeAPICreateInstance(&origFunctions))
+    {
+        FIXME("Failed to get function pointers.\n");
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
+{
+    TRACE("(%p, %u, %p)\n", instance, reason, reserved);
+
+    switch (reason)
+    {
+        case DLL_PROCESS_ATTACH:
+            DisableThreadLibraryCalls(instance);
+            if (!load_nvencode()) return FALSE;
+            break;
+        case DLL_PROCESS_DETACH:
+            if (reserved) break;
+            if (libnvidia_encode_handle)
+                dlclose(libnvidia_encode_handle);
+            break;
+    }
+
+    return TRUE;
+}
diff --git a/dlls/nvencodeapi/nvencodeapi.spec b/dlls/nvencodeapi/nvencodeapi.spec
new file mode 100644
index 000000000..11d74e82d
--- /dev/null
+++ b/dlls/nvencodeapi/nvencodeapi.spec
@@ -0,0 +1 @@
+@ stdcall NvEncodeAPICreateInstance(ptr)
diff --git a/dlls/nvencodeapi64/Makefile.in b/dlls/nvencodeapi64/Makefile.in
new file mode 100644
index 000000000..8297ec352
--- /dev/null
+++ b/dlls/nvencodeapi64/Makefile.in
@@ -0,0 +1,5 @@
+MODULE    = nvencodeapi64.dll
+PARENTSRC = ../nvencodeapi
+
+C_SRCS = \
+	nvencodeapi.c
diff --git a/dlls/nvencodeapi64/nvencodeapi64.spec b/dlls/nvencodeapi64/nvencodeapi64.spec
new file mode 100644
index 000000000..11d74e82d
--- /dev/null
+++ b/dlls/nvencodeapi64/nvencodeapi64.spec
@@ -0,0 +1 @@
+@ stdcall NvEncodeAPICreateInstance(ptr)
diff --git a/include/Makefile.in b/include/Makefile.in
index c38dd2ad1..5b21ec0df 100644
--- a/include/Makefile.in
+++ b/include/Makefile.in
@@ -500,6 +500,7 @@ SOURCES = \
 	ntstatus.h \
 	nvapi.h \
 	nvcuvid.h \
+	nvencodeapi.h \
 	oaidl.idl \
 	objbase.h \
 	objectarray.idl \
diff --git a/include/nvencodeapi.h b/include/nvencodeapi.h
new file mode 100644
index 000000000..45e9fb97f
--- /dev/null
+++ b/include/nvencodeapi.h
@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2015 Michael Müller
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <guiddef.h>
+#include <stdint.h>
+
+#ifndef __WINE_NVENCODEAPI_H
+#define __WINE_NVENCODEAPI_H
+
+#define NVENCAPI_MAJOR_VERSION 5
+#define NVENCAPI_MINOR_VERSION 0
+#define NVENCAPI_VERSION ((NVENCAPI_MAJOR_VERSION << 4) | (NVENCAPI_MINOR_VERSION))
+#define NVENCAPI_STRUCT_VERSION(type, version) (uint32_t)(sizeof(type) | ((version)<<16) | (NVENCAPI_VERSION << 24))
+
+#define NVENCSTATUS int
+#define NV_ENC_SUCCESS 0
+#define NV_ENC_ERR_INVALID_PTR 6
+#define NV_ENC_ERR_UNSUPPORTED_PARAM 12
+#define NV_ENC_ERR_INVALID_VERSION 15
+
+typedef void *NV_ENC_INPUT_PTR;
+typedef void *NV_ENC_OUTPUT_PTR;
+typedef void *NV_ENC_REGISTERED_PTR;
+
+typedef struct _NV_ENC_CAPS_PARAM NV_ENC_CAPS_PARAM;
+typedef struct _NV_ENC_CREATE_INPUT_BUFFER NV_ENC_CREATE_INPUT_BUFFER;
+typedef struct _NV_ENC_CREATE_BITSTREAM_BUFFER NV_ENC_CREATE_BITSTREAM_BUFFER;
+typedef struct _NV_ENC_QP NV_ENC_QP;
+typedef struct _NV_ENC_RC_PARAMS NV_ENC_RC_PARAMS;
+typedef struct _NV_ENC_CONFIG_H264_VUI_PARAMETERS NV_ENC_CONFIG_H264_VUI_PARAMETERS;
+typedef struct _NV_ENC_CONFIG_H264 NV_ENC_CONFIG_H264;
+typedef struct _NV_ENC_CONFIG_HEVC NV_ENC_CONFIG_HEVC;
+typedef struct _NV_ENC_CONFIG NV_ENC_CONFIG;
+typedef struct _NV_ENC_RECONFIGURE_PARAMS NV_ENC_RECONFIGURE_PARAMS;
+typedef struct _NV_ENC_PRESET_CONFIG NV_ENC_PRESET_CONFIG;
+typedef struct _NV_ENC_H264_SEI_PAYLOAD NV_ENC_H264_SEI_PAYLOAD;
+typedef struct _NV_ENC_LOCK_BITSTREAM NV_ENC_LOCK_BITSTREAM;
+typedef struct _NV_ENC_LOCK_INPUT_BUFFER NV_ENC_LOCK_INPUT_BUFFER;
+typedef struct _NV_ENC_MAP_INPUT_RESOURCE NV_ENC_MAP_INPUT_RESOURCE;
+typedef struct _NV_ENC_REGISTER_RESOURCE NV_ENC_REGISTER_RESOURCE;
+typedef struct _NV_ENC_STAT NV_ENC_STAT;
+typedef struct _NV_ENC_SEQUENCE_PARAM_PAYLOAD NV_ENC_SEQUENCE_PARAM_PAYLOAD;
+typedef struct _NV_ENC_EVENT_PARAMS NV_ENC_EVENT_PARAMS;
+typedef struct _NV_ENC_OPEN_ENCODE_SESSIONEX_PARAMS NV_ENC_OPEN_ENCODE_SESSIONEX_PARAMS;
+typedef struct _NV_ENC_BUFFER_FORMAT NV_ENC_BUFFER_FORMAT;
+typedef struct _NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS;
+
+typedef struct _NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE
+{
+    uint32_t numCandsPerBlk16x16 : 4;
+    uint32_t numCandsPerBlk16x8  : 4;
+    uint32_t numCandsPerBlk8x16  : 4;
+    uint32_t numCandsPerBlk8x8   : 4;
+    uint32_t reserved            : 16;
+    uint32_t reserved1[3];
+} NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE;
+
+typedef struct _NV_ENC_INITIALIZE_PARAMS
+{
+    uint32_t version;
+    GUID encodeGUID;
+    GUID presetGUID;
+    uint32_t encodeWidth;
+    uint32_t encodeHeight;
+    uint32_t darWidth;
+    uint32_t darHeight;
+    uint32_t frameRateNum;
+    uint32_t frameRateDen;
+    uint32_t enableEncodeAsync;
+    uint32_t enablePTD;
+    uint32_t reportSliceOffsets    : 1;
+    uint32_t enableSubFrameWrite   : 1;
+    uint32_t enableExternalMEHints : 1;
+    uint32_t reservedBitFields     : 29;
+    uint32_t privDataSize;
+    void *privData;
+    void *encodeConfig;
+    uint32_t maxEncodeWidth;
+    uint32_t maxEncodeHeight;
+    NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE maxMEHintCountsPerBlock[2];
+    uint32_t reserved[289];
+    void *reserved2[64];
+} NV_ENC_INITIALIZE_PARAMS;
+
+typedef struct _NV_ENC_PIC_PARAMS_H264
+{
+    uint32_t displayPOCSyntax;
+    uint32_t reserved3;
+    uint32_t refPicFlag;
+    uint32_t colourPlaneId;
+    uint32_t forceIntraRefreshWithFrameCnt;
+    uint32_t constrainedFrame    : 1;
+    uint32_t sliceModeDataUpdate : 1;
+    uint32_t ltrMarkFrame        : 1;
+    uint32_t ltrUseFrames        : 1;
+    uint32_t reservedBitFields   : 28;
+    uint8_t *sliceTypeData;
+    uint32_t sliceTypeArrayCnt;
+    uint32_t seiPayloadArrayCnt;
+    NV_ENC_H264_SEI_PAYLOAD *seiPayloadArray;
+    uint32_t sliceMode;
+    uint32_t sliceModeData;
+    uint32_t ltrMarkFrameIdx;
+    uint32_t ltrUseFrameBitmap;
+    uint32_t ltrUsageMode;
+    uint32_t reserved[243];
+    void *reserved2[62];
+} NV_ENC_PIC_PARAMS_H264;
+
+typedef struct _NV_ENC_PIC_PARAMS_HEVC
+{
+    uint32_t displayPOCSyntax;
+    uint32_t refPicFlag;
+    uint32_t temporalId;
+    uint32_t forceIntraRefreshWithFrameCnt;
+    uint32_t constrainedFrame    : 1;
+    uint32_t sliceModeDataUpdate : 1;
+    uint32_t ltrMarkFrame        : 1;
+    uint32_t ltrUseFrames        : 1;
+    uint32_t reservedBitFields   : 28;
+    uint8_t *sliceTypeData;
+    uint32_t sliceTypeArrayCnt;
+    uint32_t sliceMode;
+    uint32_t sliceModeData;
+    uint32_t ltrMarkFrameIdx;
+    uint32_t ltrUseFrameBitmap;
+    uint32_t ltrUsageMode;
+    uint32_t reserved[246];
+    void *reserved2[62];
+} NV_ENC_PIC_PARAMS_HEVC;
+
+typedef union _NV_ENC_CODEC_PIC_PARAMS
+{
+    NV_ENC_PIC_PARAMS_H264 h264PicParams;
+    NV_ENC_PIC_PARAMS_HEVC hevcPicParams;
+    uint32_t reserved[256];
+} NV_ENC_CODEC_PIC_PARAMS;
+
+struct _NVENC_EXTERNAL_ME_HINT
+{
+    int32_t mvx        : 12;
+    int32_t mvy        : 10;
+    int32_t refidx     : 5;
+    int32_t dir        : 1;
+    int32_t partType   : 2;
+    int32_t lastofPart : 1;
+    int32_t lastOfMB   : 1;
+};
+
+typedef struct _NV_ENC_PIC_PARAMS
+{
+    uint32_t version;
+    uint32_t inputWidth;
+    uint32_t inputHeight;
+    uint32_t inputPitch;
+    uint32_t encodePicFlags;
+    uint32_t frameIdx;
+    uint64_t inputTimeStamp;
+    uint64_t inputDuration;
+    void *inputBuffer;
+    void *outputBitstream;
+    void *completionEvent;
+    int bufferFmt;
+    int pictureStruct;
+    int pictureType;
+    NV_ENC_CODEC_PIC_PARAMS codecPicParams;
+    struct _NVENC_EXTERNAL_ME_HINT_COUNTS_PER_BLOCKTYPE meHintCountsPerBlock[2];
+    struct _NVENC_EXTERNAL_ME_HINT *meExternalHints;
+    uint32_t reserved1[6];
+    void *reserved2[2];
+    int8_t *qpDeltaMap;
+    uint32_t qpDeltaMapSize;
+    uint32_t reservedBitFields;
+    uint32_t reserved3[287];
+    void *reserved4[60];
+} NV_ENC_PIC_PARAMS;
+
+typedef struct __NV_ENCODE_API_FUNCTION_LIST
+{
+    uint32_t version;
+    uint32_t reserved;
+    NVENCSTATUS (WINAPI *nvEncOpenEncodeSession)(void *device, uint32_t deviceType, void **encoder);
+    NVENCSTATUS (WINAPI *nvEncGetEncodeGUIDCount)(void *encoder, uint32_t *encodeGUIDCount);
+    NVENCSTATUS (WINAPI *nvEncGetEncodeProfileGUIDCount)(void *encoder, GUID encodeGUID, uint32_t *encodePresetGUIDCount);
+    NVENCSTATUS (WINAPI *nvEncGetEncodeProfileGUIDs)(void *encoder, GUID encodeGUID, GUID *presetGUIDs, uint32_t guidArraySize,
+                                                     uint32_t *encodePresetGUIDCount);
+    NVENCSTATUS (WINAPI *nvEncGetEncodeGUIDs)(void *encoder, GUID *GUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);
+    NVENCSTATUS (WINAPI *nvEncGetInputFormatCount)(void *encoder, GUID encodeGUID, uint32_t *inputFmtCount);
+    NVENCSTATUS (WINAPI *nvEncGetInputFormats)(void *encoder, GUID encodeGUID, NV_ENC_BUFFER_FORMAT *inputFmts,
+                                               uint32_t inputFmtArraySize, uint32_t *inputFmtCount);
+    NVENCSTATUS (WINAPI *nvEncGetEncodeCaps)(void *encoder, GUID encodeGUID, NV_ENC_CAPS_PARAM *capsParam, int *capsVal);
+    NVENCSTATUS (WINAPI *nvEncGetEncodePresetCount)(void *encoder, GUID encodeGUID, uint32_t *encodePresetGUIDCount);
+    NVENCSTATUS (WINAPI *nvEncGetEncodePresetGUIDs)(void *encoder, GUID encodeGUID, GUID *presetGUIDs, uint32_t guidArraySize,
+                                                    uint32_t *encodePresetGUIDCount);
+    NVENCSTATUS (WINAPI *nvEncGetEncodePresetConfig)(void *encoder, GUID encodeGUID, GUID presetGUID, NV_ENC_PRESET_CONFIG *presetConfig);
+    NVENCSTATUS (WINAPI *nvEncInitializeEncoder)(void *encoder, NV_ENC_INITIALIZE_PARAMS *createEncodeParams);
+    NVENCSTATUS (WINAPI *nvEncCreateInputBuffer)(void *encoder, NV_ENC_CREATE_INPUT_BUFFER *createInputBufferParams);
+    NVENCSTATUS (WINAPI *nvEncDestroyInputBuffer)(void *encoder, NV_ENC_INPUT_PTR inputBuffer);
+    NVENCSTATUS (WINAPI *nvEncCreateBitstreamBuffer)(void *encoder, NV_ENC_CREATE_BITSTREAM_BUFFER *createBitstreamBufferParams);
+    NVENCSTATUS (WINAPI *nvEncDestroyBitstreamBuffer)(void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);
+    NVENCSTATUS (WINAPI *nvEncEncodePicture)(void *encoder, NV_ENC_PIC_PARAMS *encodePicParams);
+    NVENCSTATUS (WINAPI *nvEncLockBitstream)(void *encoder, NV_ENC_LOCK_BITSTREAM *lockBitstreamBufferParams);
+    NVENCSTATUS (WINAPI *nvEncUnlockBitstream)(void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);
+    NVENCSTATUS (WINAPI *nvEncLockInputBuffer)(void *encoder, NV_ENC_LOCK_INPUT_BUFFER *lockInputBufferParams);
+    NVENCSTATUS (WINAPI *nvEncUnlockInputBuffer)(void *encoder, NV_ENC_INPUT_PTR inputBuffer);
+    NVENCSTATUS (WINAPI *nvEncGetEncodeStats)(void *encoder, NV_ENC_STAT *encodeStats);
+    NVENCSTATUS (WINAPI *nvEncGetSequenceParams)(void *encoder, NV_ENC_SEQUENCE_PARAM_PAYLOAD *hsequenceParamPayload);
+    NVENCSTATUS (WINAPI *nvEncRegisterAsyncEvent)(void *encoder, NV_ENC_EVENT_PARAMS *eventParams);
+    NVENCSTATUS (WINAPI *nvEncUnregisterAsyncEvent)(void *encoder, NV_ENC_EVENT_PARAMS *eventParams);
+    NVENCSTATUS (WINAPI *nvEncMapInputResource)(void *encoder, NV_ENC_MAP_INPUT_RESOURCE *mapInputResParams);
+    NVENCSTATUS (WINAPI *nvEncUnmapInputResource)(void *encoder, NV_ENC_INPUT_PTR mappedInputBuffer);
+    NVENCSTATUS (WINAPI *nvEncDestroyEncoder)(void *encoder);
+    NVENCSTATUS (WINAPI *nvEncInvalidateRefFrames)(void *encoder, uint64_t invalidRefFrameTimeStamp);
+    NVENCSTATUS (WINAPI *nvEncOpenEncodeSessionEx)(NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS *openSessionExParams, void **encoder);
+    NVENCSTATUS (WINAPI *nvEncRegisterResource)(void *encoder, NV_ENC_REGISTER_RESOURCE *registerResParams);
+    NVENCSTATUS (WINAPI *nvEncUnregisterResource)(void *encoder, NV_ENC_REGISTERED_PTR registeredRes);
+    NVENCSTATUS (WINAPI *nvEncReconfigureEncoder)(void *encoder, NV_ENC_RECONFIGURE_PARAMS *reInitEncodeParams);
+    void *reserved2[285];
+} NV_ENCODE_API_FUNCTION_LIST;
+
+#define NV_ENCODE_API_FUNCTION_LIST_VER NVENCAPI_STRUCT_VERSION(NV_ENCODE_API_FUNCTION_LIST, 2)
+
+typedef struct __LINUX_NV_ENCODE_API_FUNCTION_LIST
+{
+    uint32_t version;
+    uint32_t reserved;
+    NVENCSTATUS (*nvEncOpenEncodeSession)(void *device, uint32_t deviceType, void **encoder);
+    NVENCSTATUS (*nvEncGetEncodeGUIDCount)(void *encoder, uint32_t *encodeGUIDCount);
+    NVENCSTATUS (*nvEncGetEncodeProfileGUIDCount)(void *encoder, GUID encodeGUID, uint32_t *encodePresetGUIDCount);
+    NVENCSTATUS (*nvEncGetEncodeProfileGUIDs)(void *encoder, GUID encodeGUID, GUID *presetGUIDs, uint32_t guidArraySize,
+                                              uint32_t *encodePresetGUIDCount);
+    NVENCSTATUS (*nvEncGetEncodeGUIDs)(void *encoder, GUID *GUIDs, uint32_t guidArraySize, uint32_t *GUIDCount);
+    NVENCSTATUS (*nvEncGetInputFormatCount)(void *encoder, GUID encodeGUID, uint32_t *inputFmtCount);
+    NVENCSTATUS (*nvEncGetInputFormats)(void *encoder, GUID encodeGUID, NV_ENC_BUFFER_FORMAT *inputFmts,
+                                        uint32_t inputFmtArraySize, uint32_t *inputFmtCount);
+    NVENCSTATUS (*nvEncGetEncodeCaps)(void *encoder, GUID encodeGUID, NV_ENC_CAPS_PARAM *capsParam, int *capsVal);
+    NVENCSTATUS (*nvEncGetEncodePresetCount)(void *encoder, GUID encodeGUID, uint32_t *encodePresetGUIDCount);
+    NVENCSTATUS (*nvEncGetEncodePresetGUIDs)(void *encoder, GUID encodeGUID, GUID *presetGUIDs, uint32_t guidArraySize,
+                                             uint32_t *encodePresetGUIDCount);
+    NVENCSTATUS (*nvEncGetEncodePresetConfig)(void *encoder, GUID encodeGUID, GUID presetGUID, NV_ENC_PRESET_CONFIG *presetConfig);
+    NVENCSTATUS (*nvEncInitializeEncoder)(void *encoder, NV_ENC_INITIALIZE_PARAMS *createEncodeParams);
+    NVENCSTATUS (*nvEncCreateInputBuffer)(void *encoder, NV_ENC_CREATE_INPUT_BUFFER *createInputBufferParams);
+    NVENCSTATUS (*nvEncDestroyInputBuffer)(void *encoder, NV_ENC_INPUT_PTR inputBuffer);
+    NVENCSTATUS (*nvEncCreateBitstreamBuffer)(void *encoder, NV_ENC_CREATE_BITSTREAM_BUFFER *createBitstreamBufferParams);
+    NVENCSTATUS (*nvEncDestroyBitstreamBuffer)(void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);
+    NVENCSTATUS (*nvEncEncodePicture)(void *encoder, NV_ENC_PIC_PARAMS *encodePicParams);
+    NVENCSTATUS (*nvEncLockBitstream)(void *encoder, NV_ENC_LOCK_BITSTREAM *lockBitstreamBufferParams);
+    NVENCSTATUS (*nvEncUnlockBitstream)(void *encoder, NV_ENC_OUTPUT_PTR bitstreamBuffer);
+    NVENCSTATUS (*nvEncLockInputBuffer)(void *encoder, NV_ENC_LOCK_INPUT_BUFFER *lockInputBufferParams);
+    NVENCSTATUS (*nvEncUnlockInputBuffer)(void *encoder, NV_ENC_INPUT_PTR inputBuffer);
+    NVENCSTATUS (*nvEncGetEncodeStats)(void *encoder, NV_ENC_STAT *encodeStats);
+    NVENCSTATUS (*nvEncGetSequenceParams)(void *encoder, NV_ENC_SEQUENCE_PARAM_PAYLOAD *hsequenceParamPayload);
+    NVENCSTATUS (*nvEncRegisterAsyncEvent)(void *encoder, NV_ENC_EVENT_PARAMS *eventParams);
+    NVENCSTATUS (*nvEncUnregisterAsyncEvent)(void *encoder, NV_ENC_EVENT_PARAMS *eventParams);
+    NVENCSTATUS (*nvEncMapInputResource)(void *encoder, NV_ENC_MAP_INPUT_RESOURCE *mapInputResParams);
+    NVENCSTATUS (*nvEncUnmapInputResource)(void *encoder, NV_ENC_INPUT_PTR mappedInputBuffer);
+    NVENCSTATUS (*nvEncDestroyEncoder)(void *encoder);
+    NVENCSTATUS (*nvEncInvalidateRefFrames)(void *encoder, uint64_t invalidRefFrameTimeStamp);
+    NVENCSTATUS (*nvEncOpenEncodeSessionEx)(NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS *openSessionExParams, void **encoder);
+    NVENCSTATUS (*nvEncRegisterResource)(void *encoder, NV_ENC_REGISTER_RESOURCE *registerResParams);
+    NVENCSTATUS (*nvEncUnregisterResource)(void *encoder, NV_ENC_REGISTERED_PTR registeredRes);
+    NVENCSTATUS (*nvEncReconfigureEncoder)(void *encoder, NV_ENC_RECONFIGURE_PARAMS *reInitEncodeParams);
+    void *reserved2[285];
+} LINUX_NV_ENCODE_API_FUNCTION_LIST;
+
+#endif /* __WINE_NVENCODEAPI_H */
-- 
2.24.0

