2015-07-30 06:42:38 +00:00
|
|
|
/* GStreamer NVENC plugin
|
|
|
|
* Copyright (C) 2015 Centricular Ltd
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstnvenc.h"
|
|
|
|
#include "gstnvh264enc.h"
|
2018-04-06 14:22:26 +00:00
|
|
|
#include "gstnvh265enc.h"
|
2021-12-08 11:48:08 +00:00
|
|
|
#include <gst/cuda/gstcudautils.h>
|
|
|
|
#include <gst/cuda/gstcudabufferpool.h>
|
2022-12-19 10:53:28 +00:00
|
|
|
#include <string.h>
|
2019-08-30 04:57:15 +00:00
|
|
|
|
2018-11-22 03:14:44 +00:00
|
|
|
#include <gmodule.h>
|
|
|
|
|
2023-02-17 15:36:29 +00:00
|
|
|
#ifdef HAVE_CUDA_GST_GL
|
2019-07-09 04:31:27 +00:00
|
|
|
#include <gst/gl/gl.h>
|
|
|
|
#endif
|
|
|
|
|
2018-11-22 03:14:44 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef _WIN64
|
|
|
|
#define NVENC_LIBRARY_NAME "nvEncodeAPI64.dll"
|
|
|
|
#else
|
|
|
|
#define NVENC_LIBRARY_NAME "nvEncodeAPI.dll"
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define NVENC_LIBRARY_NAME "libnvidia-encode.so.1"
|
|
|
|
#endif
|
|
|
|
|
2019-11-28 12:30:18 +00:00
|
|
|
/* For backward compatibility */
|
|
|
|
#define GST_NVENC_MIN_API_MAJOR_VERSION 8
|
|
|
|
#define GST_NVENC_MIN_API_MINOR_VERSION 1
|
|
|
|
|
|
|
|
#define GST_NVENCAPI_VERSION(major,minor) ((major) | ((minor) << 24))
|
|
|
|
#define GST_NVENCAPI_STRUCT_VERSION(ver,api_ver) ((uint32_t)(api_ver) | ((ver)<<16) | (0x7 << 28))
|
|
|
|
|
|
|
|
static guint32 gst_nvenc_api_version = NVENCAPI_VERSION;
|
2022-12-19 10:53:28 +00:00
|
|
|
static gboolean gst_nvenc_supports_cuda_stream = FALSE;
|
2019-11-28 12:30:18 +00:00
|
|
|
|
2018-11-22 03:14:44 +00:00
|
|
|
typedef NVENCSTATUS NVENCAPI
|
|
|
|
tNvEncodeAPICreateInstance (NV_ENCODE_API_FUNCTION_LIST * functionList);
|
|
|
|
tNvEncodeAPICreateInstance *nvEncodeAPICreateInstance;
|
2015-07-30 06:42:38 +00:00
|
|
|
|
2020-01-29 09:55:55 +00:00
|
|
|
typedef NVENCSTATUS NVENCAPI
|
|
|
|
tNvEncodeAPIGetMaxSupportedVersion (uint32_t * version);
|
|
|
|
tNvEncodeAPIGetMaxSupportedVersion *nvEncodeAPIGetMaxSupportedVersion;
|
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (gst_nvenc_debug);
|
2018-04-06 14:49:12 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_nvenc_debug
|
2015-07-30 06:42:38 +00:00
|
|
|
|
|
|
|
static NV_ENCODE_API_FUNCTION_LIST nvenc_api;
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncOpenEncodeSessionEx (NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS * params,
|
|
|
|
void **encoder)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncOpenEncodeSessionEx != NULL);
|
|
|
|
return nvenc_api.nvEncOpenEncodeSessionEx (params, encoder);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncDestroyEncoder (void *encoder)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncDestroyEncoder != NULL);
|
|
|
|
return nvenc_api.nvEncDestroyEncoder (encoder);
|
|
|
|
}
|
|
|
|
|
2021-12-03 13:12:42 +00:00
|
|
|
const char *NVENCAPI
|
|
|
|
NvEncGetLastErrorString (void *encoder)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetLastErrorString != NULL);
|
|
|
|
return nvenc_api.nvEncGetLastErrorString (encoder);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncGetEncodeGUIDs (void *encoder, GUID * array, uint32_t array_size,
|
|
|
|
uint32_t * count)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetEncodeGUIDs != NULL);
|
|
|
|
return nvenc_api.nvEncGetEncodeGUIDs (encoder, array, array_size, count);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncGetEncodeProfileGUIDCount (void *encoder, GUID encodeGUID,
|
|
|
|
uint32_t * encodeProfileGUIDCount)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetEncodeProfileGUIDCount != NULL);
|
|
|
|
return nvenc_api.nvEncGetEncodeProfileGUIDCount (encoder, encodeGUID,
|
|
|
|
encodeProfileGUIDCount);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncGetEncodeProfileGUIDs (void *encoder, GUID encodeGUID,
|
|
|
|
GUID * profileGUIDs, uint32_t guidArraySize, uint32_t * GUIDCount)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetEncodeProfileGUIDs != NULL);
|
|
|
|
return nvenc_api.nvEncGetEncodeProfileGUIDs (encoder, encodeGUID,
|
|
|
|
profileGUIDs, guidArraySize, GUIDCount);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncGetInputFormats (void *encoder, GUID enc_guid,
|
|
|
|
NV_ENC_BUFFER_FORMAT * array, uint32_t size, uint32_t * num)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetInputFormats != NULL);
|
|
|
|
return nvenc_api.nvEncGetInputFormats (encoder, enc_guid, array, size, num);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2016-04-07 12:46:08 +00:00
|
|
|
NvEncGetEncodePresetCount (void *encoder, GUID encodeGUID,
|
|
|
|
uint32_t * encodePresetGUIDCount)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetEncodeProfileGUIDCount != NULL);
|
|
|
|
return nvenc_api.nvEncGetEncodePresetCount (encoder, encodeGUID,
|
|
|
|
encodePresetGUIDCount);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2016-04-07 12:46:08 +00:00
|
|
|
NvEncGetEncodePresetGUIDs (void *encoder, GUID encodeGUID,
|
|
|
|
GUID * presetGUIDs, uint32_t guidArraySize, uint32_t * GUIDCount)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetEncodeProfileGUIDs != NULL);
|
|
|
|
return nvenc_api.nvEncGetEncodePresetGUIDs (encoder, encodeGUID,
|
|
|
|
presetGUIDs, guidArraySize, GUIDCount);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncGetEncodePresetConfig (void *encoder, GUID encodeGUID,
|
|
|
|
GUID presetGUID, NV_ENC_PRESET_CONFIG * presetConfig)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetEncodePresetConfig != NULL);
|
|
|
|
return nvenc_api.nvEncGetEncodePresetConfig (encoder, encodeGUID, presetGUID,
|
|
|
|
presetConfig);
|
|
|
|
}
|
|
|
|
|
2023-10-02 12:57:19 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
|
|
|
NvEncGetEncodePresetConfigEx (void *encoder, GUID encodeGUID,
|
|
|
|
GUID presetGUID, NV_ENC_TUNING_INFO tuningInfo,
|
|
|
|
NV_ENC_PRESET_CONFIG * presetConfig)
|
|
|
|
{
|
|
|
|
if (!nvenc_api.nvEncGetEncodePresetConfigEx)
|
|
|
|
return NV_ENC_ERR_UNIMPLEMENTED;
|
|
|
|
|
|
|
|
return nvenc_api.nvEncGetEncodePresetConfigEx (encoder, encodeGUID,
|
|
|
|
presetGUID, tuningInfo, presetConfig);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncGetEncodeCaps (void *encoder, GUID encodeGUID,
|
|
|
|
NV_ENC_CAPS_PARAM * capsParam, int *capsVal)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetEncodeCaps != NULL);
|
|
|
|
return nvenc_api.nvEncGetEncodeCaps (encoder, encodeGUID, capsParam, capsVal);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncGetSequenceParams (void *encoder,
|
|
|
|
NV_ENC_SEQUENCE_PARAM_PAYLOAD * sequenceParamPayload)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncGetSequenceParams != NULL);
|
|
|
|
return nvenc_api.nvEncGetSequenceParams (encoder, sequenceParamPayload);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncInitializeEncoder (void *encoder, NV_ENC_INITIALIZE_PARAMS * params)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncInitializeEncoder != NULL);
|
|
|
|
return nvenc_api.nvEncInitializeEncoder (encoder, params);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncReconfigureEncoder (void *encoder, NV_ENC_RECONFIGURE_PARAMS * params)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncReconfigureEncoder != NULL);
|
|
|
|
return nvenc_api.nvEncReconfigureEncoder (encoder, params);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncRegisterResource (void *encoder, NV_ENC_REGISTER_RESOURCE * params)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncRegisterResource != NULL);
|
|
|
|
return nvenc_api.nvEncRegisterResource (encoder, params);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncUnregisterResource (void *encoder, NV_ENC_REGISTERED_PTR resource)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncUnregisterResource != NULL);
|
|
|
|
return nvenc_api.nvEncUnregisterResource (encoder, resource);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncMapInputResource (void *encoder, NV_ENC_MAP_INPUT_RESOURCE * params)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncMapInputResource != NULL);
|
|
|
|
return nvenc_api.nvEncMapInputResource (encoder, params);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncUnmapInputResource (void *encoder, NV_ENC_INPUT_PTR input_buffer)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncUnmapInputResource != NULL);
|
|
|
|
return nvenc_api.nvEncUnmapInputResource (encoder, input_buffer);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncCreateInputBuffer (void *encoder, NV_ENC_CREATE_INPUT_BUFFER * input_buf)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncCreateInputBuffer != NULL);
|
|
|
|
return nvenc_api.nvEncCreateInputBuffer (encoder, input_buf);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncLockInputBuffer (void *encoder, NV_ENC_LOCK_INPUT_BUFFER * input_buf)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncLockInputBuffer != NULL);
|
|
|
|
return nvenc_api.nvEncLockInputBuffer (encoder, input_buf);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncUnlockInputBuffer (void *encoder, NV_ENC_INPUT_PTR input_buf)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncUnlockInputBuffer != NULL);
|
|
|
|
return nvenc_api.nvEncUnlockInputBuffer (encoder, input_buf);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncDestroyInputBuffer (void *encoder, NV_ENC_INPUT_PTR input_buf)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncDestroyInputBuffer != NULL);
|
|
|
|
return nvenc_api.nvEncDestroyInputBuffer (encoder, input_buf);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncCreateBitstreamBuffer (void *encoder, NV_ENC_CREATE_BITSTREAM_BUFFER * bb)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncCreateBitstreamBuffer != NULL);
|
|
|
|
return nvenc_api.nvEncCreateBitstreamBuffer (encoder, bb);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncLockBitstream (void *encoder, NV_ENC_LOCK_BITSTREAM * lock_bs)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncLockBitstream != NULL);
|
|
|
|
return nvenc_api.nvEncLockBitstream (encoder, lock_bs);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncUnlockBitstream (void *encoder, NV_ENC_OUTPUT_PTR bb)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncUnlockBitstream != NULL);
|
|
|
|
return nvenc_api.nvEncUnlockBitstream (encoder, bb);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncDestroyBitstreamBuffer (void *encoder, NV_ENC_OUTPUT_PTR bit_buf)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncDestroyBitstreamBuffer != NULL);
|
|
|
|
return nvenc_api.nvEncDestroyBitstreamBuffer (encoder, bit_buf);
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:07:42 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
2015-07-30 06:42:38 +00:00
|
|
|
NvEncEncodePicture (void *encoder, NV_ENC_PIC_PARAMS * pic_params)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncEncodePicture != NULL);
|
|
|
|
return nvenc_api.nvEncEncodePicture (encoder, pic_params);
|
|
|
|
}
|
|
|
|
|
2022-03-15 19:58:16 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
|
|
|
NvEncRegisterAsyncEvent (void *encoder, NV_ENC_EVENT_PARAMS * event_params)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncRegisterAsyncEvent != NULL);
|
|
|
|
return nvenc_api.nvEncRegisterAsyncEvent (encoder, event_params);
|
|
|
|
}
|
|
|
|
|
|
|
|
NVENCSTATUS NVENCAPI
|
|
|
|
NvEncUnregisterAsyncEvent (void *encoder, NV_ENC_EVENT_PARAMS * event_params)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncUnregisterAsyncEvent != NULL);
|
|
|
|
return nvenc_api.nvEncUnregisterAsyncEvent (encoder, event_params);
|
|
|
|
}
|
|
|
|
|
2022-12-19 10:53:28 +00:00
|
|
|
NVENCSTATUS NVENCAPI
|
|
|
|
NvEncSetIOCudaStreams (void *encoder, NV_ENC_CUSTREAM_PTR input_stream,
|
|
|
|
NV_ENC_CUSTREAM_PTR output_stream)
|
|
|
|
{
|
|
|
|
g_assert (nvenc_api.nvEncSetIOCudaStreams != NULL);
|
|
|
|
return nvenc_api.nvEncSetIOCudaStreams (encoder, input_stream, output_stream);
|
|
|
|
}
|
|
|
|
|
2015-07-30 06:42:38 +00:00
|
|
|
gboolean
|
|
|
|
gst_nvenc_cmp_guid (GUID g1, GUID g2)
|
|
|
|
{
|
|
|
|
return (g1.Data1 == g2.Data1 && g1.Data2 == g2.Data2 && g1.Data3 == g2.Data3
|
|
|
|
&& g1.Data4[0] == g2.Data4[0] && g1.Data4[1] == g2.Data4[1]
|
|
|
|
&& g1.Data4[2] == g2.Data4[2] && g1.Data4[3] == g2.Data4[3]
|
|
|
|
&& g1.Data4[4] == g2.Data4[4] && g1.Data4[5] == g2.Data4[5]
|
|
|
|
&& g1.Data4[6] == g2.Data4[6] && g1.Data4[7] == g2.Data4[7]);
|
|
|
|
}
|
|
|
|
|
|
|
|
NV_ENC_BUFFER_FORMAT
|
|
|
|
gst_nvenc_get_nv_buffer_format (GstVideoFormat fmt)
|
|
|
|
{
|
|
|
|
switch (fmt) {
|
|
|
|
case GST_VIDEO_FORMAT_NV12:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_NV12_PL;
|
|
|
|
case GST_VIDEO_FORMAT_YV12:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_YV12_PL;
|
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_IYUV_PL;
|
|
|
|
case GST_VIDEO_FORMAT_Y444:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_YUV444_PL;
|
2019-07-09 04:31:27 +00:00
|
|
|
case GST_VIDEO_FORMAT_P010_10LE:
|
|
|
|
case GST_VIDEO_FORMAT_P010_10BE:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_YUV420_10BIT;
|
2019-07-30 04:15:32 +00:00
|
|
|
case GST_VIDEO_FORMAT_BGRA:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_ARGB;
|
|
|
|
case GST_VIDEO_FORMAT_RGBA:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_ABGR;
|
|
|
|
case GST_VIDEO_FORMAT_BGR10A2_LE:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_ARGB10;
|
|
|
|
case GST_VIDEO_FORMAT_RGB10A2_LE:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_ABGR10;
|
2019-08-06 12:54:49 +00:00
|
|
|
case GST_VIDEO_FORMAT_Y444_16LE:
|
|
|
|
case GST_VIDEO_FORMAT_Y444_16BE:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_YUV444_10BIT;
|
2019-08-20 13:07:30 +00:00
|
|
|
case GST_VIDEO_FORMAT_VUYA:
|
|
|
|
return NV_ENC_BUFFER_FORMAT_AYUV;
|
2015-07-30 06:42:38 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NV_ENC_BUFFER_FORMAT_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:31:27 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstVideoFormat gst_format;
|
|
|
|
NV_ENC_BUFFER_FORMAT nv_format;
|
|
|
|
gboolean is_10bit;
|
|
|
|
|
|
|
|
gboolean supported;
|
|
|
|
} GstNvEncFormat;
|
|
|
|
|
|
|
|
gboolean
|
2019-08-08 05:00:08 +00:00
|
|
|
gst_nvenc_get_supported_input_formats (gpointer encoder, GUID codec_id,
|
2019-07-09 04:31:27 +00:00
|
|
|
GValue ** formats)
|
|
|
|
{
|
|
|
|
guint32 i, count = 0;
|
|
|
|
NV_ENC_BUFFER_FORMAT format_list[64];
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
GValue *ret = NULL;
|
|
|
|
NV_ENC_CAPS_PARAM param = { 0, };
|
|
|
|
gint support_yuv444 = 0;
|
|
|
|
gint support_10bit = 0;
|
|
|
|
guint num_format = 0;
|
|
|
|
GstNvEncFormat format_map[] = {
|
|
|
|
{GST_VIDEO_FORMAT_NV12, NV_ENC_BUFFER_FORMAT_NV12, FALSE, FALSE},
|
|
|
|
{GST_VIDEO_FORMAT_YV12, NV_ENC_BUFFER_FORMAT_YV12, FALSE, FALSE},
|
|
|
|
{GST_VIDEO_FORMAT_I420, NV_ENC_BUFFER_FORMAT_IYUV, FALSE, FALSE},
|
2019-07-30 04:15:32 +00:00
|
|
|
{GST_VIDEO_FORMAT_BGRA, NV_ENC_BUFFER_FORMAT_ARGB, FALSE, FALSE},
|
|
|
|
{GST_VIDEO_FORMAT_RGBA, NV_ENC_BUFFER_FORMAT_ABGR, FALSE, FALSE},
|
2019-07-09 04:31:27 +00:00
|
|
|
{GST_VIDEO_FORMAT_Y444, NV_ENC_BUFFER_FORMAT_YUV444, FALSE, FALSE},
|
2019-08-20 13:07:30 +00:00
|
|
|
{GST_VIDEO_FORMAT_VUYA, NV_ENC_BUFFER_FORMAT_AYUV, FALSE, FALSE},
|
2019-07-09 04:31:27 +00:00
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
{GST_VIDEO_FORMAT_P010_10LE, NV_ENC_BUFFER_FORMAT_YUV420_10BIT, TRUE,
|
|
|
|
FALSE},
|
2019-07-30 04:15:32 +00:00
|
|
|
{GST_VIDEO_FORMAT_BGR10A2_LE, NV_ENC_BUFFER_FORMAT_ARGB10, TRUE,
|
|
|
|
FALSE},
|
|
|
|
{GST_VIDEO_FORMAT_RGB10A2_LE, NV_ENC_BUFFER_FORMAT_ABGR10, TRUE,
|
|
|
|
FALSE},
|
2019-08-06 12:54:49 +00:00
|
|
|
{GST_VIDEO_FORMAT_Y444_16LE, NV_ENC_BUFFER_FORMAT_YUV444_10BIT, TRUE,
|
|
|
|
FALSE},
|
2019-07-09 04:31:27 +00:00
|
|
|
#else
|
|
|
|
{GST_VIDEO_FORMAT_P010_10BE, NV_ENC_BUFFER_FORMAT_YUV420_10BIT, TRUE,
|
|
|
|
FALSE},
|
2019-08-06 12:54:49 +00:00
|
|
|
{GST_VIDEO_FORMAT_Y444_16BE, NV_ENC_BUFFER_FORMAT_YUV444_10BIT, TRUE,
|
|
|
|
FALSE},
|
2019-07-30 04:15:32 +00:00
|
|
|
/* FIXME: No 10bits big-endian ARGB10 format is defined */
|
2019-07-09 04:31:27 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2019-08-08 05:16:07 +00:00
|
|
|
param.version = gst_nvenc_get_caps_param_version ();
|
2019-07-09 04:31:27 +00:00
|
|
|
param.capsToQuery = NV_ENC_CAPS_SUPPORT_YUV444_ENCODE;
|
|
|
|
if (NvEncGetEncodeCaps (encoder,
|
|
|
|
codec_id, ¶m, &support_yuv444) != NV_ENC_SUCCESS) {
|
|
|
|
support_yuv444 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
param.capsToQuery = NV_ENC_CAPS_SUPPORT_10BIT_ENCODE;
|
|
|
|
if (NvEncGetEncodeCaps (encoder,
|
|
|
|
codec_id, ¶m, &support_10bit) != NV_ENC_SUCCESS) {
|
|
|
|
support_10bit = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NvEncGetInputFormats (encoder,
|
|
|
|
codec_id, format_list, G_N_ELEMENTS (format_list),
|
|
|
|
&count) != NV_ENC_SUCCESS || count == 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
GST_INFO ("input format: 0x%08x", format_list[i]);
|
|
|
|
switch (format_list[i]) {
|
|
|
|
case NV_ENC_BUFFER_FORMAT_NV12:
|
|
|
|
case NV_ENC_BUFFER_FORMAT_YV12:
|
|
|
|
case NV_ENC_BUFFER_FORMAT_IYUV:
|
2019-07-30 04:15:32 +00:00
|
|
|
case NV_ENC_BUFFER_FORMAT_ARGB:
|
|
|
|
case NV_ENC_BUFFER_FORMAT_ABGR:
|
|
|
|
if (!format_map[i].supported) {
|
|
|
|
format_map[i].supported = TRUE;
|
2019-07-09 04:31:27 +00:00
|
|
|
num_format++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NV_ENC_BUFFER_FORMAT_YUV444:
|
2019-08-20 13:07:30 +00:00
|
|
|
case NV_ENC_BUFFER_FORMAT_AYUV:
|
2019-07-30 04:15:32 +00:00
|
|
|
if (support_yuv444 && !format_map[i].supported) {
|
|
|
|
format_map[i].supported = TRUE;
|
2019-07-09 04:31:27 +00:00
|
|
|
num_format++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NV_ENC_BUFFER_FORMAT_YUV420_10BIT:
|
2019-08-06 12:55:36 +00:00
|
|
|
if (support_10bit && !format_map[i].supported) {
|
2019-07-30 04:15:32 +00:00
|
|
|
format_map[i].supported = TRUE;
|
|
|
|
num_format++;
|
|
|
|
}
|
|
|
|
break;
|
2019-08-06 12:54:49 +00:00
|
|
|
case NV_ENC_BUFFER_FORMAT_YUV444_10BIT:
|
|
|
|
if (support_yuv444 && support_10bit && !format_map[i].supported) {
|
|
|
|
format_map[i].supported = TRUE;
|
|
|
|
num_format++;
|
|
|
|
}
|
|
|
|
break;
|
2019-07-30 04:15:32 +00:00
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
case NV_ENC_BUFFER_FORMAT_ARGB10:
|
|
|
|
case NV_ENC_BUFFER_FORMAT_ABGR10:
|
|
|
|
if (support_10bit && !format_map[i].supported) {
|
|
|
|
format_map[i].supported = TRUE;
|
2019-07-09 04:31:27 +00:00
|
|
|
num_format++;
|
|
|
|
}
|
|
|
|
break;
|
2019-07-30 04:15:32 +00:00
|
|
|
#endif
|
2019-07-09 04:31:27 +00:00
|
|
|
default:
|
|
|
|
GST_FIXME ("unmapped input format: 0x%08x", format_list[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_format == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* process a second time so we can add formats in the order we want */
|
|
|
|
g_value_init (&val, G_TYPE_STRING);
|
|
|
|
ret = g_new0 (GValue, 1);
|
|
|
|
g_value_init (ret, GST_TYPE_LIST);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (format_map); i++) {
|
|
|
|
if (!format_map[i].supported)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_value_set_static_string (&val,
|
|
|
|
gst_video_format_to_string (format_map[i].gst_format));
|
|
|
|
|
|
|
|
gst_value_list_append_value (ret, &val);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
*formats = ret;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GValue *
|
2019-08-08 05:00:08 +00:00
|
|
|
gst_nvenc_get_interlace_modes (gpointer enc, GUID codec_id)
|
2019-07-09 04:31:27 +00:00
|
|
|
{
|
|
|
|
NV_ENC_CAPS_PARAM caps_param = { 0, };
|
|
|
|
GValue *list;
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
gint interlace_modes = 0;
|
|
|
|
|
2019-08-08 05:16:07 +00:00
|
|
|
caps_param.version = gst_nvenc_get_caps_param_version ();
|
2019-07-09 04:31:27 +00:00
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_SUPPORT_FIELD_ENCODING;
|
|
|
|
|
|
|
|
if (NvEncGetEncodeCaps (enc, codec_id, &caps_param,
|
|
|
|
&interlace_modes) != NV_ENC_SUCCESS)
|
|
|
|
interlace_modes = 0;
|
|
|
|
|
|
|
|
list = g_new0 (GValue, 1);
|
|
|
|
|
|
|
|
g_value_init (list, GST_TYPE_LIST);
|
|
|
|
g_value_init (&val, G_TYPE_STRING);
|
|
|
|
|
|
|
|
g_value_set_static_string (&val, "progressive");
|
|
|
|
gst_value_list_append_value (list, &val);
|
|
|
|
|
|
|
|
if (interlace_modes == 0)
|
|
|
|
return list;
|
|
|
|
|
|
|
|
if (interlace_modes >= 1) {
|
|
|
|
g_value_set_static_string (&val, "interleaved");
|
|
|
|
gst_value_list_append_value (list, &val);
|
|
|
|
g_value_set_static_string (&val, "mixed");
|
|
|
|
gst_value_list_append_value (list, &val);
|
|
|
|
g_value_unset (&val);
|
|
|
|
}
|
|
|
|
/* TODO: figure out what nvenc frame based interlacing means in gst terms */
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const gchar *gst_profile;
|
|
|
|
const GUID nv_profile;
|
|
|
|
const GUID codec_id;
|
|
|
|
const gboolean need_yuv444;
|
|
|
|
const gboolean need_10bit;
|
|
|
|
|
|
|
|
gboolean supported;
|
|
|
|
} GstNvEncCodecProfile;
|
|
|
|
|
|
|
|
GValue *
|
2019-08-08 05:00:08 +00:00
|
|
|
gst_nvenc_get_supported_codec_profiles (gpointer enc, GUID codec_id)
|
2019-07-09 04:31:27 +00:00
|
|
|
{
|
|
|
|
NVENCSTATUS nv_ret;
|
|
|
|
GUID profile_guids[64];
|
|
|
|
GValue *ret;
|
|
|
|
GValue val = G_VALUE_INIT;
|
|
|
|
guint i, j, n, n_profiles;
|
|
|
|
NV_ENC_CAPS_PARAM param = { 0, };
|
|
|
|
gint support_yuv444 = 0;
|
|
|
|
gint support_10bit = 0;
|
|
|
|
GstNvEncCodecProfile profiles[] = {
|
|
|
|
/* avc profiles */
|
|
|
|
{"main", NV_ENC_H264_PROFILE_MAIN_GUID, NV_ENC_CODEC_H264_GUID, FALSE,
|
|
|
|
FALSE, FALSE},
|
|
|
|
{"high", NV_ENC_H264_PROFILE_HIGH_GUID, NV_ENC_CODEC_H264_GUID, FALSE,
|
|
|
|
FALSE, FALSE},
|
|
|
|
{"high-4:4:4", NV_ENC_H264_PROFILE_HIGH_444_GUID, NV_ENC_CODEC_H264_GUID,
|
|
|
|
TRUE, FALSE, FALSE},
|
2019-09-03 12:22:08 +00:00
|
|
|
/* put baseline to last since it does not support bframe */
|
|
|
|
{"baseline", NV_ENC_H264_PROFILE_BASELINE_GUID, NV_ENC_CODEC_H264_GUID,
|
|
|
|
FALSE, FALSE, FALSE},
|
2021-10-20 12:34:42 +00:00
|
|
|
{"constrained-baseline", NV_ENC_H264_PROFILE_BASELINE_GUID,
|
|
|
|
NV_ENC_CODEC_H264_GUID,
|
|
|
|
FALSE, FALSE, FALSE},
|
2019-07-09 04:31:27 +00:00
|
|
|
/* hevc profiles */
|
|
|
|
{"main", NV_ENC_HEVC_PROFILE_MAIN_GUID, NV_ENC_CODEC_HEVC_GUID, FALSE,
|
|
|
|
FALSE, FALSE},
|
|
|
|
{"main-10", NV_ENC_HEVC_PROFILE_MAIN10_GUID, NV_ENC_CODEC_HEVC_GUID, FALSE,
|
|
|
|
TRUE, FALSE},
|
|
|
|
{"main-444", NV_ENC_HEVC_PROFILE_FREXT_GUID, NV_ENC_CODEC_HEVC_GUID, TRUE,
|
|
|
|
FALSE, FALSE},
|
|
|
|
#if 0
|
|
|
|
/* FIXME: seems to unsupported format */
|
|
|
|
{"main-444-10", NV_ENC_HEVC_PROFILE_FREXT_GUID, FALSE}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2019-08-08 05:16:07 +00:00
|
|
|
param.version = gst_nvenc_get_caps_param_version ();
|
2019-07-09 04:31:27 +00:00
|
|
|
param.capsToQuery = NV_ENC_CAPS_SUPPORT_YUV444_ENCODE;
|
|
|
|
if (NvEncGetEncodeCaps (enc,
|
|
|
|
codec_id, ¶m, &support_yuv444) != NV_ENC_SUCCESS) {
|
|
|
|
support_yuv444 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
param.capsToQuery = NV_ENC_CAPS_SUPPORT_10BIT_ENCODE;
|
|
|
|
if (NvEncGetEncodeCaps (enc,
|
|
|
|
codec_id, ¶m, &support_10bit) != NV_ENC_SUCCESS) {
|
|
|
|
support_10bit = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nv_ret = NvEncGetEncodeProfileGUIDCount (enc, codec_id, &n);
|
|
|
|
|
|
|
|
if (nv_ret != NV_ENC_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
nv_ret = NvEncGetEncodeProfileGUIDs (enc,
|
|
|
|
codec_id, profile_guids, G_N_ELEMENTS (profile_guids), &n);
|
|
|
|
|
|
|
|
if (nv_ret != NV_ENC_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
n_profiles = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
for (j = 0; j < G_N_ELEMENTS (profiles); j++) {
|
|
|
|
if (profiles[j].supported == FALSE &&
|
|
|
|
gst_nvenc_cmp_guid (profile_guids[i], profiles[j].nv_profile) &&
|
|
|
|
gst_nvenc_cmp_guid (codec_id, profiles[j].codec_id)) {
|
|
|
|
if (profiles[j].need_yuv444 && !support_yuv444)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (profiles[j].need_10bit && !support_10bit)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
profiles[j].supported = TRUE;
|
|
|
|
n_profiles++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_profiles == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = g_new0 (GValue, 1);
|
|
|
|
|
|
|
|
g_value_init (ret, GST_TYPE_LIST);
|
|
|
|
g_value_init (&val, G_TYPE_STRING);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (profiles); i++) {
|
|
|
|
if (!profiles[i].supported)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_value_set_static_string (&val, profiles[i].gst_profile);
|
|
|
|
gst_value_list_append_value (ret, &val);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-03 12:28:44 +00:00
|
|
|
#define DEBUG_DEVICE_CAPS(d,c,caps,s) \
|
|
|
|
GST_DEBUG ("[device-%d %s] %s: %s", \
|
|
|
|
d, c, caps, s ? "supported" : "not supported");
|
|
|
|
|
2020-01-20 10:57:30 +00:00
|
|
|
#define ERROR_DETAILS "codec %s, device %i, error code %i"
|
|
|
|
|
2019-07-25 07:45:21 +00:00
|
|
|
static void
|
2019-09-03 09:46:30 +00:00
|
|
|
gst_nv_enc_register (GstPlugin * plugin, GUID codec_id, const gchar * codec,
|
2019-11-28 09:54:31 +00:00
|
|
|
guint rank, gint device_index, CUcontext cuda_ctx)
|
2019-07-09 04:31:27 +00:00
|
|
|
{
|
2019-11-28 09:54:31 +00:00
|
|
|
{
|
2019-07-09 04:31:27 +00:00
|
|
|
GValue *formats = NULL;
|
|
|
|
GValue *profiles;
|
|
|
|
GValue *interlace_modes;
|
|
|
|
gpointer enc;
|
|
|
|
NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS params = { 0, };
|
|
|
|
NV_ENC_CAPS_PARAM caps_param = { 0, };
|
|
|
|
GUID guids[16];
|
|
|
|
guint32 count;
|
|
|
|
gint max_width = 0;
|
|
|
|
gint max_height = 0;
|
2019-11-28 12:30:18 +00:00
|
|
|
gint min_width = 16;
|
|
|
|
gint min_height = 16;
|
2019-07-09 04:31:27 +00:00
|
|
|
GstCaps *sink_templ = NULL;
|
|
|
|
GstCaps *src_templ = NULL;
|
|
|
|
gchar *name;
|
|
|
|
gint j;
|
2019-09-03 12:28:44 +00:00
|
|
|
GstNvEncDeviceCaps device_caps = { 0, };
|
2020-01-20 10:57:30 +00:00
|
|
|
NVENCSTATUS status;
|
|
|
|
CUresult cu_res;
|
2019-07-09 04:31:27 +00:00
|
|
|
|
2019-08-08 05:16:07 +00:00
|
|
|
params.version = gst_nvenc_get_open_encode_session_ex_params_version ();
|
|
|
|
params.apiVersion = gst_nvenc_get_api_version ();
|
2019-07-09 04:31:27 +00:00
|
|
|
params.device = cuda_ctx;
|
|
|
|
params.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
|
|
|
|
|
2020-01-20 10:57:30 +00:00
|
|
|
if ((cu_res = CuCtxPushCurrent (cuda_ctx)) != CUDA_SUCCESS) {
|
|
|
|
GST_ERROR ("CuCtxPushCurrent failed: " ERROR_DETAILS, codec,
|
|
|
|
device_index, cu_res);
|
2019-11-28 09:54:31 +00:00
|
|
|
goto done;
|
2020-01-20 10:57:30 +00:00
|
|
|
}
|
2019-11-28 09:54:31 +00:00
|
|
|
|
2020-01-20 10:57:30 +00:00
|
|
|
if ((status = NvEncOpenEncodeSessionEx (¶ms, &enc)) != NV_ENC_SUCCESS) {
|
2019-11-28 09:54:31 +00:00
|
|
|
CuCtxPopCurrent (NULL);
|
2020-01-20 10:57:30 +00:00
|
|
|
GST_ERROR ("NvEncOpenEncodeSessionEx failed: " ERROR_DETAILS, codec,
|
|
|
|
device_index, status);
|
2019-11-28 09:54:31 +00:00
|
|
|
goto done;
|
2019-07-09 04:31:27 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 10:57:30 +00:00
|
|
|
if ((status = NvEncGetEncodeGUIDs (enc, guids, G_N_ELEMENTS (guids),
|
|
|
|
&count)) != NV_ENC_SUCCESS) {
|
|
|
|
GST_ERROR ("NvEncGetEncodeGUIDs failed: " ERROR_DETAILS, codec,
|
|
|
|
device_index, status);
|
2019-07-09 04:31:27 +00:00
|
|
|
goto enc_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < count; j++) {
|
|
|
|
if (gst_nvenc_cmp_guid (guids[j], codec_id))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == count)
|
|
|
|
goto enc_free;
|
|
|
|
|
2019-08-08 05:00:08 +00:00
|
|
|
if (!gst_nvenc_get_supported_input_formats (enc, codec_id, &formats))
|
2019-07-09 04:31:27 +00:00
|
|
|
goto enc_free;
|
|
|
|
|
2019-08-08 05:00:08 +00:00
|
|
|
profiles = gst_nvenc_get_supported_codec_profiles (enc, codec_id);
|
2019-07-09 04:31:27 +00:00
|
|
|
if (!profiles)
|
|
|
|
goto free_format;
|
|
|
|
|
2019-08-08 05:16:07 +00:00
|
|
|
caps_param.version = gst_nvenc_get_caps_param_version ();
|
2019-07-09 04:31:27 +00:00
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_WIDTH_MAX;
|
2020-01-20 10:57:30 +00:00
|
|
|
if ((status = NvEncGetEncodeCaps (enc,
|
|
|
|
codec_id, &caps_param, &max_width)) != NV_ENC_SUCCESS) {
|
2019-07-09 04:31:27 +00:00
|
|
|
max_width = 4096;
|
2020-01-20 10:57:30 +00:00
|
|
|
GST_WARNING ("could not query max width, setting as %i: "
|
|
|
|
ERROR_DETAILS, max_width, codec, device_index, status);
|
2019-07-09 04:31:27 +00:00
|
|
|
} else if (max_width < 4096) {
|
|
|
|
GST_WARNING ("max width %d is less than expected value", max_width);
|
|
|
|
max_width = 4096;
|
|
|
|
}
|
|
|
|
|
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_HEIGHT_MAX;
|
2020-01-20 10:57:30 +00:00
|
|
|
if ((status = NvEncGetEncodeCaps (enc,
|
|
|
|
codec_id, &caps_param, &max_height)) != NV_ENC_SUCCESS) {
|
|
|
|
GST_WARNING ("could not query max height, setting as %i: "
|
|
|
|
ERROR_DETAILS, max_height, codec, device_index, status);
|
2019-07-09 04:31:27 +00:00
|
|
|
max_height = 4096;
|
|
|
|
} else if (max_height < 4096) {
|
|
|
|
GST_WARNING ("max height %d is less than expected value", max_height);
|
|
|
|
max_height = 4096;
|
|
|
|
}
|
|
|
|
|
2019-11-28 12:30:18 +00:00
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_WIDTH_MIN;
|
2020-01-20 10:57:30 +00:00
|
|
|
if ((status = NvEncGetEncodeCaps (enc,
|
|
|
|
codec_id, &caps_param, &min_width)) != NV_ENC_SUCCESS) {
|
|
|
|
GST_WARNING ("could not query min width, setting as %i: "
|
|
|
|
ERROR_DETAILS, min_width, codec, device_index, status);
|
2019-11-28 12:30:18 +00:00
|
|
|
min_width = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_HEIGHT_MIN;
|
2020-01-20 10:57:30 +00:00
|
|
|
if ((status = NvEncGetEncodeCaps (enc,
|
|
|
|
codec_id, &caps_param, &min_height)) != NV_ENC_SUCCESS) {
|
|
|
|
GST_WARNING ("could not query min height, setting as %i: "
|
|
|
|
ERROR_DETAILS, min_height, codec, device_index, status);
|
2019-11-28 12:30:18 +00:00
|
|
|
min_height = 16;
|
|
|
|
}
|
|
|
|
|
2019-09-03 12:33:15 +00:00
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_SUPPORTED_RATECONTROL_MODES;
|
|
|
|
if (NvEncGetEncodeCaps (enc, codec_id, &caps_param,
|
|
|
|
&device_caps.rc_modes) != NV_ENC_SUCCESS) {
|
|
|
|
device_caps.rc_modes = 0;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("[device-%d %s] rate control modes: 0x%x",
|
2019-11-28 09:54:31 +00:00
|
|
|
device_index, codec, device_caps.rc_modes);
|
2019-09-03 12:33:15 +00:00
|
|
|
#define IS_SUPPORTED_RC(rc_modes,mode) \
|
|
|
|
((((rc_modes) & (mode)) == mode) ? "supported" : "not supported")
|
|
|
|
|
|
|
|
GST_DEBUG ("\tconst-qp: %s",
|
|
|
|
IS_SUPPORTED_RC (device_caps.rc_modes, NV_ENC_PARAMS_RC_CONSTQP));
|
|
|
|
GST_DEBUG ("\tvbr: %s",
|
|
|
|
IS_SUPPORTED_RC (device_caps.rc_modes, NV_ENC_PARAMS_RC_VBR));
|
|
|
|
GST_DEBUG ("\tcbr: %s",
|
|
|
|
IS_SUPPORTED_RC (device_caps.rc_modes, NV_ENC_PARAMS_RC_CBR));
|
|
|
|
GST_DEBUG ("\tcbr-lowdelay-hq: %s",
|
|
|
|
IS_SUPPORTED_RC (device_caps.rc_modes,
|
|
|
|
NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ));
|
|
|
|
GST_DEBUG ("\tcbr-hq: %s",
|
|
|
|
IS_SUPPORTED_RC (device_caps.rc_modes, NV_ENC_PARAMS_RC_CBR_HQ));
|
|
|
|
GST_DEBUG ("\tvbr-hq: %s",
|
|
|
|
IS_SUPPORTED_RC (device_caps.rc_modes, NV_ENC_PARAMS_RC_VBR_HQ));
|
|
|
|
GST_DEBUG ("\tvbr-minqp: %s (deprecated)",
|
|
|
|
IS_SUPPORTED_RC (device_caps.rc_modes, NV_ENC_PARAMS_RC_VBR_MINQP));
|
|
|
|
#undef IS_SUPPORTED_RC
|
|
|
|
}
|
|
|
|
|
2019-09-03 12:28:44 +00:00
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_SUPPORT_WEIGHTED_PREDICTION;
|
|
|
|
if (NvEncGetEncodeCaps (enc, codec_id, &caps_param,
|
|
|
|
&device_caps.weighted_prediction) != NV_ENC_SUCCESS) {
|
|
|
|
device_caps.weighted_prediction = FALSE;
|
|
|
|
}
|
|
|
|
|
2019-09-03 12:33:15 +00:00
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_SUPPORT_CUSTOM_VBV_BUF_SIZE;
|
|
|
|
if (NvEncGetEncodeCaps (enc, codec_id, &caps_param,
|
|
|
|
&device_caps.custom_vbv_bufsize) != NV_ENC_SUCCESS) {
|
|
|
|
device_caps.custom_vbv_bufsize = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_SUPPORT_LOOKAHEAD;
|
|
|
|
if (NvEncGetEncodeCaps (enc,
|
|
|
|
codec_id, &caps_param, &device_caps.lookahead) != NV_ENC_SUCCESS) {
|
|
|
|
device_caps.lookahead = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_SUPPORT_TEMPORAL_AQ;
|
|
|
|
if (NvEncGetEncodeCaps (enc, codec_id, &caps_param,
|
|
|
|
&device_caps.temporal_aq) != NV_ENC_SUCCESS) {
|
|
|
|
device_caps.temporal_aq = FALSE;
|
|
|
|
}
|
|
|
|
|
2019-09-03 12:22:08 +00:00
|
|
|
caps_param.capsToQuery = NV_ENC_CAPS_NUM_MAX_BFRAMES;
|
|
|
|
if (NvEncGetEncodeCaps (enc, codec_id, &caps_param,
|
|
|
|
&device_caps.bframes) != NV_ENC_SUCCESS) {
|
|
|
|
device_caps.bframes = 0;
|
|
|
|
}
|
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
DEBUG_DEVICE_CAPS (device_index,
|
2019-09-03 12:28:44 +00:00
|
|
|
codec, "weighted prediction", device_caps.weighted_prediction);
|
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
DEBUG_DEVICE_CAPS (device_index, codec, "custom vbv-buffer-size",
|
2019-09-03 12:33:15 +00:00
|
|
|
device_caps.custom_vbv_bufsize);
|
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
DEBUG_DEVICE_CAPS (device_index, codec, "rc-loockahead",
|
|
|
|
device_caps.lookahead);
|
2019-09-03 12:33:15 +00:00
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
DEBUG_DEVICE_CAPS (device_index, codec, "temporal adaptive quantization",
|
2019-09-03 12:33:15 +00:00
|
|
|
device_caps.temporal_aq);
|
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
GST_DEBUG ("[device-%d %s] max bframes: %d", device_index, codec,
|
|
|
|
device_caps.bframes);
|
2019-09-03 12:22:08 +00:00
|
|
|
|
2019-08-08 05:00:08 +00:00
|
|
|
interlace_modes = gst_nvenc_get_interlace_modes (enc, codec_id);
|
2019-07-09 04:31:27 +00:00
|
|
|
|
|
|
|
sink_templ = gst_caps_new_empty_simple ("video/x-raw");
|
|
|
|
gst_caps_set_value (sink_templ, "format", formats);
|
|
|
|
|
|
|
|
gst_caps_set_simple (sink_templ,
|
2019-11-28 12:30:18 +00:00
|
|
|
"width", GST_TYPE_INT_RANGE, min_width, max_width,
|
|
|
|
"height", GST_TYPE_INT_RANGE, min_height, max_height,
|
2019-07-09 04:31:27 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
|
|
|
|
|
|
|
if (interlace_modes) {
|
|
|
|
gst_caps_set_value (sink_templ, "interlace-mode", interlace_modes);
|
|
|
|
g_value_unset (interlace_modes);
|
|
|
|
g_free (interlace_modes);
|
|
|
|
}
|
2019-08-30 04:57:15 +00:00
|
|
|
|
2019-07-09 04:31:27 +00:00
|
|
|
{
|
2019-08-30 04:57:15 +00:00
|
|
|
GstCaps *cuda_caps = gst_caps_copy (sink_templ);
|
2023-02-17 15:36:29 +00:00
|
|
|
#ifdef HAVE_CUDA_GST_GL
|
2019-07-09 04:31:27 +00:00
|
|
|
GstCaps *gl_caps = gst_caps_copy (sink_templ);
|
|
|
|
gst_caps_set_features_simple (gl_caps,
|
|
|
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
|
|
|
|
gst_caps_append (sink_templ, gl_caps);
|
|
|
|
#endif
|
|
|
|
|
2019-08-30 04:57:15 +00:00
|
|
|
gst_caps_set_features_simple (cuda_caps,
|
|
|
|
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY));
|
|
|
|
gst_caps_append (sink_templ, cuda_caps);
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:31:27 +00:00
|
|
|
name = g_strdup_printf ("video/x-%s", codec);
|
|
|
|
src_templ = gst_caps_new_simple (name,
|
2019-11-28 12:30:18 +00:00
|
|
|
"width", GST_TYPE_INT_RANGE, min_width, max_width,
|
|
|
|
"height", GST_TYPE_INT_RANGE, min_height, max_height,
|
2019-07-09 04:31:27 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1,
|
|
|
|
"stream-format", G_TYPE_STRING, "byte-stream",
|
|
|
|
"alignment", G_TYPE_STRING, "au", NULL);
|
|
|
|
gst_caps_set_value (src_templ, "profile", profiles);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
GST_DEBUG ("sink template caps %" GST_PTR_FORMAT, sink_templ);
|
|
|
|
GST_DEBUG ("src template caps %" GST_PTR_FORMAT, src_templ);
|
|
|
|
|
|
|
|
g_value_unset (profiles);
|
|
|
|
g_free (profiles);
|
|
|
|
|
|
|
|
free_format:
|
|
|
|
if (formats) {
|
|
|
|
g_value_unset (formats);
|
|
|
|
g_free (formats);
|
|
|
|
}
|
|
|
|
/* fall-through */
|
|
|
|
|
|
|
|
enc_free:
|
|
|
|
NvEncDestroyEncoder (enc);
|
2019-11-28 09:54:31 +00:00
|
|
|
CuCtxPopCurrent (NULL);
|
2019-07-09 04:31:27 +00:00
|
|
|
/* fall-through */
|
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
done:
|
2019-09-03 09:46:30 +00:00
|
|
|
if (sink_templ && src_templ) {
|
|
|
|
if (gst_nvenc_cmp_guid (codec_id, NV_ENC_CODEC_H264_GUID)) {
|
2019-11-28 09:54:31 +00:00
|
|
|
gst_nv_h264_enc_register (plugin, device_index, rank, sink_templ,
|
|
|
|
src_templ, &device_caps);
|
2019-09-03 09:46:30 +00:00
|
|
|
} else if (gst_nvenc_cmp_guid (codec_id, NV_ENC_CODEC_HEVC_GUID)) {
|
2019-11-28 09:54:31 +00:00
|
|
|
gst_nv_h265_enc_register (plugin, device_index, rank, sink_templ,
|
|
|
|
src_templ, &device_caps);
|
2019-09-03 09:46:30 +00:00
|
|
|
} else {
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
2019-07-09 04:31:27 +00:00
|
|
|
|
|
|
|
gst_clear_caps (&sink_templ);
|
|
|
|
gst_clear_caps (&src_templ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 12:30:18 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gint major;
|
|
|
|
gint minor;
|
|
|
|
} GstNvEncVersion;
|
2019-07-09 04:31:27 +00:00
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
gboolean
|
2020-04-09 07:12:58 +00:00
|
|
|
gst_nvenc_load_library (guint * api_major_ver, guint * api_minor_ver)
|
2015-07-30 06:42:38 +00:00
|
|
|
{
|
2019-11-28 09:54:31 +00:00
|
|
|
GModule *module;
|
2019-11-28 12:30:18 +00:00
|
|
|
NVENCSTATUS ret = NV_ENC_SUCCESS;
|
2020-01-29 09:55:55 +00:00
|
|
|
uint32_t max_supported_version;
|
|
|
|
gint major_ver, minor_ver;
|
2019-11-28 12:30:18 +00:00
|
|
|
gint i;
|
|
|
|
static const GstNvEncVersion version_list[] = {
|
|
|
|
{NVENCAPI_MAJOR_VERSION, NVENCAPI_MINOR_VERSION},
|
2022-12-19 10:53:28 +00:00
|
|
|
{9, 1},
|
2019-11-28 12:30:18 +00:00
|
|
|
{9, 0},
|
|
|
|
{GST_NVENC_MIN_API_MAJOR_VERSION, GST_NVENC_MIN_API_MINOR_VERSION}
|
|
|
|
};
|
2019-08-08 05:16:07 +00:00
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
module = g_module_open (NVENC_LIBRARY_NAME, G_MODULE_BIND_LAZY);
|
|
|
|
if (module == NULL) {
|
|
|
|
GST_WARNING ("Could not open library %s, %s",
|
|
|
|
NVENC_LIBRARY_NAME, g_module_error ());
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-07-30 06:42:38 +00:00
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
if (!g_module_symbol (module, "NvEncodeAPICreateInstance",
|
|
|
|
(gpointer *) & nvEncodeAPICreateInstance)) {
|
|
|
|
GST_ERROR ("%s", g_module_error ());
|
|
|
|
return FALSE;
|
2019-07-09 04:31:27 +00:00
|
|
|
}
|
2018-11-22 03:14:44 +00:00
|
|
|
|
2020-01-29 09:55:55 +00:00
|
|
|
if (!g_module_symbol (module, "NvEncodeAPIGetMaxSupportedVersion",
|
|
|
|
(gpointer *) & nvEncodeAPIGetMaxSupportedVersion)) {
|
|
|
|
GST_ERROR ("NvEncodeAPIGetMaxSupportedVersion unavailable");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-08-08 05:16:07 +00:00
|
|
|
|
|
|
|
/* WARNING: Any developers who want to bump SDK version must ensure that
|
|
|
|
* following macro values were not changed and also need to check ABI compatibility.
|
|
|
|
* Otherwise, gst_nvenc_get_ helpers also should be updated.
|
|
|
|
* Currently SDK 8.1 and 9.0 compatible
|
|
|
|
*
|
|
|
|
* NVENCAPI_VERSION (NVENCAPI_MAJOR_VERSION | (NVENCAPI_MINOR_VERSION << 24))
|
|
|
|
*
|
|
|
|
* NVENCAPI_STRUCT_VERSION(ver) ((uint32_t)NVENCAPI_VERSION | ((ver)<<16) | (0x7 << 28))
|
|
|
|
*
|
|
|
|
* NV_ENC_CAPS_PARAM_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_ENCODE_OUT_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_CREATE_INPUT_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_CREATE_BITSTREAM_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_CREATE_MV_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_RC_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_CONFIG_VER (NVENCAPI_STRUCT_VERSION(7) | ( 1<<31 ))
|
|
|
|
* NV_ENC_INITIALIZE_PARAMS_VER (NVENCAPI_STRUCT_VERSION(5) | ( 1<<31 ))
|
|
|
|
* NV_ENC_RECONFIGURE_PARAMS_VER (NVENCAPI_STRUCT_VERSION(1) | ( 1<<31 ))
|
|
|
|
* NV_ENC_PRESET_CONFIG_VER (NVENCAPI_STRUCT_VERSION(4) | ( 1<<31 ))
|
|
|
|
* NV_ENC_PIC_PARAMS_VER (NVENCAPI_STRUCT_VERSION(4) | ( 1<<31 ))
|
|
|
|
* NV_ENC_MEONLY_PARAMS_VER NVENCAPI_STRUCT_VERSION(3)
|
|
|
|
* NV_ENC_LOCK_BITSTREAM_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_LOCK_INPUT_BUFFER_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_MAP_INPUT_RESOURCE_VER NVENCAPI_STRUCT_VERSION(4)
|
|
|
|
* NV_ENC_REGISTER_RESOURCE_VER NVENCAPI_STRUCT_VERSION(3)
|
|
|
|
* NV_ENC_STAT_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_EVENT_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER NVENCAPI_STRUCT_VERSION(1)
|
|
|
|
* NV_ENCODE_API_FUNCTION_LIST_VER NVENCAPI_STRUCT_VERSION(2)
|
|
|
|
*/
|
2019-11-28 12:30:18 +00:00
|
|
|
|
2020-01-29 09:55:55 +00:00
|
|
|
ret = nvEncodeAPIGetMaxSupportedVersion (&max_supported_version);
|
|
|
|
|
|
|
|
if (ret != NV_ENC_SUCCESS) {
|
|
|
|
GST_ERROR ("Could not query max supported api version, ret %d", ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 4 LSB: minor version
|
|
|
|
* the rest: major version */
|
|
|
|
major_ver = max_supported_version >> 4;
|
|
|
|
minor_ver = max_supported_version & 0xf;
|
|
|
|
|
|
|
|
GST_INFO ("Maximum supported API version by driver: %d.%d",
|
|
|
|
major_ver, minor_ver);
|
|
|
|
|
|
|
|
ret = NV_ENC_ERR_INVALID_VERSION;
|
2019-11-28 12:30:18 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (version_list); i++) {
|
2020-01-29 09:55:55 +00:00
|
|
|
if (version_list[i].major > major_ver ||
|
|
|
|
(version_list[i].major == major_ver
|
|
|
|
&& version_list[i].minor > minor_ver)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-12-19 10:53:28 +00:00
|
|
|
GST_INFO ("Checking version %d.%d", version_list[i].major,
|
|
|
|
version_list[i].minor);
|
|
|
|
|
2019-11-28 12:30:18 +00:00
|
|
|
gst_nvenc_api_version =
|
|
|
|
GST_NVENCAPI_VERSION (version_list[i].major, version_list[i].minor);
|
|
|
|
|
2022-12-19 10:53:28 +00:00
|
|
|
memset (&nvenc_api, 0, sizeof (NV_ENCODE_API_FUNCTION_LIST));
|
2019-08-08 05:16:07 +00:00
|
|
|
nvenc_api.version = GST_NVENCAPI_STRUCT_VERSION (2, gst_nvenc_api_version);
|
|
|
|
ret = nvEncodeAPICreateInstance (&nvenc_api);
|
2019-11-28 12:30:18 +00:00
|
|
|
|
|
|
|
if (ret == NV_ENC_SUCCESS) {
|
2020-01-29 09:55:55 +00:00
|
|
|
GST_INFO ("API version %d.%d load done",
|
2019-11-28 12:30:18 +00:00
|
|
|
version_list[i].major, version_list[i].minor);
|
2020-04-09 07:12:58 +00:00
|
|
|
|
|
|
|
*api_major_ver = version_list[i].major;
|
|
|
|
*api_minor_ver = version_list[i].minor;
|
2022-12-19 10:53:28 +00:00
|
|
|
|
|
|
|
if ((version_list[i].major > 9 ||
|
|
|
|
(version_list[i].major == 9 && version_list[i].minor > 0)) &&
|
|
|
|
nvenc_api.nvEncSetIOCudaStreams) {
|
|
|
|
GST_INFO ("nvEncSetIOCudaStreams is supported");
|
|
|
|
gst_nvenc_supports_cuda_stream = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-28 12:30:18 +00:00
|
|
|
break;
|
2022-12-19 10:53:28 +00:00
|
|
|
} else {
|
|
|
|
GST_INFO ("Version %d.%d is not supported", version_list[i].major,
|
|
|
|
version_list[i].minor);
|
2019-11-28 12:30:18 +00:00
|
|
|
}
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
return ret == NV_ENC_SUCCESS;
|
|
|
|
}
|
2019-07-09 04:31:27 +00:00
|
|
|
|
2019-11-28 09:54:31 +00:00
|
|
|
void
|
|
|
|
gst_nvenc_plugin_init (GstPlugin * plugin, guint device_index,
|
|
|
|
CUcontext cuda_ctx)
|
|
|
|
{
|
|
|
|
gst_nv_enc_register (plugin, NV_ENC_CODEC_H264_GUID,
|
|
|
|
"h264", GST_RANK_PRIMARY * 2, device_index, cuda_ctx);
|
|
|
|
gst_nv_enc_register (plugin, NV_ENC_CODEC_HEVC_GUID,
|
|
|
|
"h265", GST_RANK_PRIMARY * 2, device_index, cuda_ctx);
|
2015-07-30 06:42:38 +00:00
|
|
|
}
|
2019-08-08 05:16:07 +00:00
|
|
|
|
2024-04-23 16:47:51 +00:00
|
|
|
/* To verify things when updating SDK */
|
|
|
|
#define USE_STATIC_SDK_VER 0
|
|
|
|
|
2019-08-08 05:16:07 +00:00
|
|
|
guint32
|
|
|
|
gst_nvenc_get_api_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NVENCAPI_VERSION;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NVENCAPI_VERSION == (NVENCAPI_MAJOR_VERSION | (NVENCAPI_MINOR_VERSION << 24)) */
|
|
|
|
return gst_nvenc_api_version;
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_caps_param_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_CAPS_PARAM_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_CAPS_PARAM_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_encode_out_params_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_ENCODE_OUT_PARAMS_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_ENCODE_OUT_PARAMS_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_create_input_buffer_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_CREATE_INPUT_BUFFER_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_CREATE_INPUT_BUFFER_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_create_bitstream_buffer_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_CREATE_BITSTREAM_BUFFER_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_CREATE_BITSTREAM_BUFFER_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_create_mv_buffer_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_CREATE_MV_BUFFER_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_CREATE_MV_BUFFER_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_rc_params_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_RC_PARAMS_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_RC_PARAMS_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_config_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_CONFIG_VER;
|
|
|
|
#else
|
|
|
|
/* Version updated since SDK 12.0 */
|
|
|
|
if ((gst_nvenc_api_version & 12) == 12)
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (8, gst_nvenc_api_version) | (1 << 31);
|
|
|
|
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_CONFIG_VER ==
|
|
|
|
* (NVENCAPI_STRUCT_VERSION(7) | ( 1<<31 )) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (7, gst_nvenc_api_version) | (1 << 31);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_initialize_params_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_INITIALIZE_PARAMS_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_INITIALIZE_PARAMS_VER ==
|
|
|
|
* (NVENCAPI_STRUCT_VERSION(5) | ( 1<<31 )) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (5, gst_nvenc_api_version) | (1 << 31);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_reconfigure_params_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_RECONFIGURE_PARAMS_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_RECONFIGURE_PARAMS_VER ==
|
|
|
|
* (NVENCAPI_STRUCT_VERSION(1) | ( 1<<31 )) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version) | (1 << 31);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_preset_config_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_PRESET_CONFIG_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_PRESET_CONFIG_VER ==
|
|
|
|
* (NVENCAPI_STRUCT_VERSION(4) | ( 1<<31 )) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (4, gst_nvenc_api_version) | (1 << 31);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_pic_params_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_PIC_PARAMS_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_PIC_PARAMS_VER ==
|
|
|
|
* (NVENCAPI_STRUCT_VERSION(4) | ( 1<<31 )) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (4, gst_nvenc_api_version) | (1 << 31);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_meonly_params_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_MEONLY_PARAMS_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_MEONLY_PARAMS_VER == NVENCAPI_STRUCT_VERSION(3) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (3, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_lock_bitstream_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_LOCK_BITSTREAM_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_LOCK_BITSTREAM_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_lock_input_buffer_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_LOCK_INPUT_BUFFER_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_LOCK_INPUT_BUFFER_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_map_input_resource_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_MAP_INPUT_RESOURCE_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_MAP_INPUT_RESOURCE_VER == NVENCAPI_STRUCT_VERSION(4) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (4, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
2021-08-20 17:20:11 +00:00
|
|
|
gst_nvenc_get_register_resource_version (void)
|
2019-08-08 05:16:07 +00:00
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_REGISTER_RESOURCE_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_REGISTER_RESOURCE_VER == NVENCAPI_STRUCT_VERSION(3) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (3, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_stat_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_STAT_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_STAT_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_sequence_param_payload_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_event_params_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_EVENT_PARAMS_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_EVENT_PARAMS_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
|
|
|
gst_nvenc_get_open_encode_session_ex_params_version (void)
|
|
|
|
{
|
2024-04-23 16:47:51 +00:00
|
|
|
#if USE_STATIC_SDK_VER
|
|
|
|
return NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
|
|
|
|
#else
|
2019-08-08 05:16:07 +00:00
|
|
|
/* NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER == NVENCAPI_STRUCT_VERSION(1) */
|
|
|
|
return GST_NVENCAPI_STRUCT_VERSION (1, gst_nvenc_api_version);
|
2024-04-23 16:47:51 +00:00
|
|
|
#endif
|
2019-08-08 05:16:07 +00:00
|
|
|
}
|
2022-12-19 10:53:28 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_nvenc_have_set_io_cuda_streams (void)
|
|
|
|
{
|
|
|
|
return gst_nvenc_supports_cuda_stream;
|
|
|
|
}
|