FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
nvenc.c File Reference
#include <dlfcn.h>
#include <nvEncodeAPI.h>
#include "libavutil/internal.h"
#include "libavutil/imgutils.h"
#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include "libavutil/mem.h"
#include "avcodec.h"
#include "internal.h"
#include "thread.h"

Go to the source code of this file.

Data Structures

struct  NvencInputSurface
 
struct  NvencOutputSurface
 
struct  NvencData
 
struct  NvencDataList
 
struct  NvencDynLoadFunctions
 
struct  NvencContext
 

Macros

#define CUDAAPI
 
#define LOAD_FUNC(l, s)   dlsym(l, s)
 
#define DL_CLOSE_FUNC(l)   dlclose(l)
 
#define CHECK_LOAD_FUNC(t, f, s)
 
#define check_cuda_errors(f)   if (!check_cuda_errors(avctx, f, #f)) goto error
 
#define OFFSET(x)   offsetof(NvencContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Typedefs

typedef int CUdevice
 
typedef voidCUcontext
 
typedef CUresult(CUDAAPIPCUINIT )(unsigned int Flags)
 
typedef CUresult(CUDAAPIPCUDEVICEGETCOUNT )(int *count)
 
typedef CUresult(CUDAAPIPCUDEVICEGET )(CUdevice *device, int ordinal)
 
typedef CUresult(CUDAAPIPCUDEVICEGETNAME )(char *name, int len, CUdevice dev)
 
typedef CUresult(CUDAAPIPCUDEVICECOMPUTECAPABILITY )(int *major, int *minor, CUdevice dev)
 
typedef CUresult(CUDAAPIPCUCTXCREATE )(CUcontext *pctx, unsigned int flags, CUdevice dev)
 
typedef CUresult(CUDAAPIPCUCTXPOPCURRENT )(CUcontext *pctx)
 
typedef CUresult(CUDAAPIPCUCTXDESTROY )(CUcontext ctx)
 
typedef NVENCSTATUS(NVENCAPI * PNVENCODEAPICREATEINSTANCE )(NV_ENCODE_API_FUNCTION_LIST *functionList)
 

Enumerations

enum  CUresult { CUDA_SUCCESS = 0 }
 

Functions

static NvencDatadata_queue_dequeue (NvencDataList *queue)
 
static int data_queue_enqueue (NvencDataList *queue, NvencData *data)
 
static int out_surf_queue_enqueue (NvencDataList *queue, NvencOutputSurface *surface)
 
static NvencOutputSurfaceout_surf_queue_dequeue (NvencDataList *queue)
 
static int timestamp_queue_enqueue (NvencDataList *queue, int64_t timestamp)
 
static int64_t timestamp_queue_dequeue (NvencDataList *queue)
 
static av_cold int nvenc_dyload_cuda (AVCodecContext *avctx)
 
static av_cold int check_cuda_errors (AVCodecContext *avctx, CUresult err, const char *func)
 
static av_cold int nvenc_check_cuda (AVCodecContext *avctx)
 
static av_cold int nvenc_dyload_nvenc (AVCodecContext *avctx)
 
static av_cold void nvenc_unload_nvenc (AVCodecContext *avctx)
 
static av_cold int nvenc_encode_init (AVCodecContext *avctx)
 
static av_cold int nvenc_encode_close (AVCodecContext *avctx)
 
static int process_output_surface (AVCodecContext *avctx, AVPacket *pkt, AVFrame *coded_frame, NvencOutputSurface *tmpoutsurf)
 
static int nvenc_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 

Variables

static const GUID dummy_license = { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
 
static enum AVPixelFormat pix_fmts_nvenc []
 
static const AVOption options []
 
static const AVClass nvenc_class
 
static const AVCodecDefault nvenc_defaults []
 
AVCodec ff_nvenc_encoder
 

Macro Definition Documentation

#define CUDAAPI

Definition at line 42 of file nvenc.c.

#define LOAD_FUNC (   l,
  s 
)    dlsym(l, s)

Definition at line 49 of file nvenc.c.

Referenced by nvenc_dyload_nvenc().

#define DL_CLOSE_FUNC (   l)    dlclose(l)

Definition at line 50 of file nvenc.c.

Referenced by nvenc_dyload_cuda(), nvenc_dyload_nvenc(), and nvenc_unload_nvenc().

#define CHECK_LOAD_FUNC (   t,
  f,
  s 
)
Value:
do { \
(f) = (t)LOAD_FUNC(dl_fn->cuda_lib, s); \
if (!(f)) { \
av_log(avctx, AV_LOG_FATAL, "Failed loading %s from CUDA library\n", s); \
goto error; \
} \
} while (0)

Definition at line 264 of file nvenc.c.

Referenced by nvenc_dyload_cuda().

#define check_cuda_errors (   f)    if (!check_cuda_errors(avctx, f, #f)) goto error

Definition at line 321 of file nvenc.c.

Referenced by nvenc_check_cuda().

#define OFFSET (   x)    offsetof(NvencContext, x)

Definition at line 1183 of file nvenc.c.

Definition at line 1184 of file nvenc.c.

Typedef Documentation

typedef int CUdevice

Definition at line 56 of file nvenc.c.

typedef void* CUcontext

Definition at line 57 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUINIT)(unsigned int Flags)

Definition at line 59 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUDEVICEGETCOUNT)(int *count)

Definition at line 60 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUDEVICEGET)(CUdevice *device, int ordinal)

Definition at line 61 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUDEVICEGETNAME)(char *name, int len, CUdevice dev)

Definition at line 62 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev)

Definition at line 63 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev)

Definition at line 64 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUCTXPOPCURRENT)(CUcontext *pctx)

Definition at line 65 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUCTXDESTROY)(CUcontext ctx)

Definition at line 66 of file nvenc.c.

typedef NVENCSTATUS(NVENCAPI* PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList)

Definition at line 68 of file nvenc.c.

Enumeration Type Documentation

enum CUresult
Enumerator:
CUDA_SUCCESS 

Definition at line 53 of file nvenc.c.

Function Documentation

static NvencData* data_queue_dequeue ( NvencDataList queue)
static

Definition at line 163 of file nvenc.c.

Referenced by data_queue_enqueue(), out_surf_queue_dequeue(), and timestamp_queue_dequeue().

static int data_queue_enqueue ( NvencDataList queue,
NvencData data 
)
static

Definition at line 183 of file nvenc.c.

Referenced by out_surf_queue_enqueue(), and timestamp_queue_enqueue().

static int out_surf_queue_enqueue ( NvencDataList queue,
NvencOutputSurface surface 
)
static

Definition at line 228 of file nvenc.c.

Referenced by nvenc_encode_frame().

static NvencOutputSurface* out_surf_queue_dequeue ( NvencDataList queue)
static

Definition at line 236 of file nvenc.c.

Referenced by nvenc_encode_frame().

static int timestamp_queue_enqueue ( NvencDataList queue,
int64_t  timestamp 
)
static

Definition at line 246 of file nvenc.c.

Referenced by nvenc_encode_frame().

static int64_t timestamp_queue_dequeue ( NvencDataList queue)
static

Definition at line 254 of file nvenc.c.

Referenced by process_output_surface().

static av_cold int nvenc_dyload_cuda ( AVCodecContext avctx)
static

Definition at line 273 of file nvenc.c.

Referenced by nvenc_check_cuda().

static av_cold int check_cuda_errors ( AVCodecContext avctx,
CUresult  err,
const char *  func 
)
static

Definition at line 313 of file nvenc.c.

static av_cold int nvenc_check_cuda ( AVCodecContext avctx)
static

Definition at line 323 of file nvenc.c.

Referenced by nvenc_dyload_nvenc().

static av_cold int nvenc_dyload_nvenc ( AVCodecContext avctx)
static

Definition at line 380 of file nvenc.c.

Referenced by nvenc_encode_init().

static av_cold void nvenc_unload_nvenc ( AVCodecContext avctx)
static

Definition at line 438 of file nvenc.c.

Referenced by nvenc_encode_close(), and nvenc_encode_init().

static av_cold int nvenc_encode_init ( AVCodecContext avctx)
static

Definition at line 463 of file nvenc.c.

static av_cold int nvenc_encode_close ( AVCodecContext avctx)
static

Definition at line 862 of file nvenc.c.

static int process_output_surface ( AVCodecContext avctx,
AVPacket pkt,
AVFrame coded_frame,
NvencOutputSurface tmpoutsurf 
)
static

Definition at line 892 of file nvenc.c.

Referenced by nvenc_encode_frame().

static int nvenc_encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame frame,
int *  got_packet 
)
static

Definition at line 979 of file nvenc.c.

Variable Documentation

const GUID dummy_license = { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
static

Definition at line 71 of file nvenc.c.

Referenced by nvenc_encode_init().

enum AVPixelFormat pix_fmts_nvenc[]
static
Initial value:

Definition at line 1178 of file nvenc.c.

const AVOption options[]
static
Initial value:
= {
{ "preset", "Set the encoding preset (one of hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE },
{ "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "2pass", "Use 2pass cbr encoding mode (low latency mode only)", OFFSET(twopass), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
{ "gpu", "Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on.", OFFSET(gpu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ NULL }
}

Definition at line 1185 of file nvenc.c.

const AVClass nvenc_class
static
Initial value:
= {
.class_name = "nvenc",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1193 of file nvenc.c.

const AVCodecDefault nvenc_defaults[]
static
Initial value:
= {
{ "b", "0" },
{ "qmin", "-1" },
{ "qmax", "-1" },
{ "qdiff", "-1" },
{ "qblur", "-1" },
{ "qcomp", "-1" },
{ NULL },
}

Definition at line 1200 of file nvenc.c.

AVCodec ff_nvenc_encoder
Initial value:
= {
.name = "nvenc",
.long_name = NULL_IF_CONFIG_SMALL("Nvidia NVENC h264 encoder"),
.priv_data_size = sizeof(NvencContext),
.encode2 = nvenc_encode_frame,
.capabilities = CODEC_CAP_DELAY,
.priv_class = &nvenc_class,
.pix_fmts = pix_fmts_nvenc,
}

Definition at line 1210 of file nvenc.c.