summaryrefslogtreecommitdiffstats
path: root/libavcodec/nvenc.h
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/nvenc.h')
-rw-r--r--libavcodec/nvenc.h147
1 files changed, 75 insertions, 72 deletions
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index b42b930..c7506d6 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -1,97 +1,79 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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 Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_NVENC_H
#define AVCODEC_NVENC_H
-#include <nvEncodeAPI.h>
-
#include "config.h"
+#if CONFIG_D3D11VA
+#define COBJMACROS
+#include "libavutil/hwcontext_d3d11va.h"
+#else
+typedef void ID3D11Device;
+#endif
+
+#include <ffnvcodec/nvEncodeAPI.h>
+
+#include "compat/cuda/dynlink_loader.h"
#include "libavutil/fifo.h"
#include "libavutil/opt.h"
#include "avcodec.h"
-#if CONFIG_CUDA
-#include <cuda.h>
-#else
+#define MAX_REGISTERED_FRAMES 64
+#define RC_MODE_DEPRECATED 0x800000
+#define RCD(rc_mode) ((rc_mode) | RC_MODE_DEPRECATED)
-#if defined(_WIN32)
-#define CUDAAPI __stdcall
-#else
-#define CUDAAPI
-#endif
+#define NVENCAPI_CHECK_VERSION(major, minor) \
+ ((major) < NVENCAPI_MAJOR_VERSION || ((major) == NVENCAPI_MAJOR_VERSION && (minor) <= NVENCAPI_MINOR_VERSION))
-typedef enum cudaError_enum {
- CUDA_SUCCESS = 0
-} CUresult;
-typedef int CUdevice;
-typedef void* CUcontext;
-typedef void* CUdeviceptr;
+// SDK 8.1 compile time feature checks
+#if NVENCAPI_CHECK_VERSION(8, 1)
+#define NVENC_HAVE_BFRAME_REF_MODE
+#define NVENC_HAVE_QP_MAP_MODE
#endif
-#define MAX_REGISTERED_FRAMES 64
-
-typedef struct NVENCFrame {
- NV_ENC_INPUT_PTR in;
- AVFrame *in_ref;
- NV_ENC_MAP_INPUT_RESOURCE in_map;
+typedef struct NvencSurface
+{
+ NV_ENC_INPUT_PTR input_surface;
+ AVFrame *in_ref;
int reg_idx;
+ int width;
+ int height;
+ int pitch;
- NV_ENC_OUTPUT_PTR out;
+ NV_ENC_OUTPUT_PTR output_surface;
NV_ENC_BUFFER_FORMAT format;
-} NVENCFrame;
-
-typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags);
-typedef CUresult(CUDAAPI *PCUDEVICEGETCOUNT)(int *count);
-typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal);
-typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev);
-typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev);
-typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev);
-typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx);
-typedef CUresult(CUDAAPI *PCUCTXPUSHCURRENT)(CUcontext ctx);
-typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx);
+ int size;
+} NvencSurface;
-typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
-
-typedef struct NVENCLibraryContext
+typedef struct NvencDynLoadFunctions
{
-#if !CONFIG_CUDA
- void *cuda;
-#endif
- void *nvenc;
-
- PCUINIT cu_init;
- PCUDEVICEGETCOUNT cu_device_get_count;
- PCUDEVICEGET cu_device_get;
- PCUDEVICEGETNAME cu_device_get_name;
- PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability;
- PCUCTXCREATE cu_ctx_create;
- PCUCTXPOPCURRENT cu_ctx_pop_current;
- PCUCTXPUSHCURRENT cu_ctx_push_current;
- PCUCTXDESTROY cu_ctx_destroy;
+ CudaFunctions *cuda_dl;
+ NvencFunctions *nvenc_dl;
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
-} NVENCLibraryContext;
+ int nvenc_device_count;
+} NvencDynLoadFunctions;
enum {
- PRESET_DEFAULT,
+ PRESET_DEFAULT = 0,
PRESET_SLOW,
PRESET_MEDIUM,
PRESET_FAST,
@@ -101,7 +83,7 @@ enum {
PRESET_LOW_LATENCY_DEFAULT ,
PRESET_LOW_LATENCY_HQ ,
PRESET_LOW_LATENCY_HP,
- PRESET_LOSSLESS_DEFAULT,
+ PRESET_LOSSLESS_DEFAULT, // lossless presets must be the last ones
PRESET_LOSSLESS_HP,
};
@@ -109,8 +91,7 @@ enum {
NV_ENC_H264_PROFILE_BASELINE,
NV_ENC_H264_PROFILE_MAIN,
NV_ENC_H264_PROFILE_HIGH,
- NV_ENC_H264_PROFILE_HIGH_444,
- NV_ENC_H264_PROFILE_CONSTRAINED_HIGH,
+ NV_ENC_H264_PROFILE_HIGH_444P,
};
enum {
@@ -131,25 +112,34 @@ enum {
ANY_DEVICE,
};
-typedef struct NVENCContext {
- AVClass *class;
- NVENCLibraryContext nvel;
+typedef struct NvencContext
+{
+ AVClass *avclass;
- NV_ENC_INITIALIZE_PARAMS params;
- NV_ENC_CONFIG config;
+ NvencDynLoadFunctions nvenc_dload_funcs;
+ NV_ENC_INITIALIZE_PARAMS init_encode_params;
+ NV_ENC_CONFIG encode_config;
CUcontext cu_context;
CUcontext cu_context_internal;
+ ID3D11Device *d3d11_device;
int nb_surfaces;
- NVENCFrame *frames;
- AVFifoBuffer *timestamps;
- AVFifoBuffer *pending, *ready, *unused_surface_queue;
+ NvencSurface *surfaces;
+
+ AVFifoBuffer *unused_surface_queue;
+ AVFifoBuffer *output_surface_queue;
+ AVFifoBuffer *output_surface_ready_queue;
+ AVFifoBuffer *timestamp_list;
+
+ int encoder_flushing;
struct {
- CUdeviceptr ptr;
+ void *ptr;
+ int ptr_index;
NV_ENC_REGISTERED_PTR regptr;
int mapped;
+ NV_ENC_MAP_INPUT_RESOURCE in_map;
} registered_frames[MAX_REGISTERED_FRAMES];
int nb_registered_frames;
@@ -162,35 +152,48 @@ typedef struct NVENCContext {
int64_t initial_pts[2];
int first_packet_output;
- void *nvenc_ctx;
+ void *nvencoder;
int preset;
int profile;
int level;
int tier;
int rc;
+ int cbr;
+ int twopass;
int device;
int flags;
int async_depth;
int rc_lookahead;
int aq;
int no_scenecut;
+ int forced_idr;
int b_adapt;
int temporal_aq;
int zerolatency;
int nonref_p;
int strict_gop;
int aq_strength;
- int quality;
+ float quality;
+ int aud;
+ int bluray_compat;
int init_qp_p;
int init_qp_b;
int init_qp_i;
-} NVENCContext;
+ int cqp;
+ int weighted_pred;
+ int coder;
+ int b_ref_mode;
+} NvencContext;
int ff_nvenc_encode_init(AVCodecContext *avctx);
int ff_nvenc_encode_close(AVCodecContext *avctx);
+int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame);
+
+int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
+
int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet);
OpenPOWER on IntegriCloud