Allow linking to CUDA dynamically instead of dlopen()ing it at runtime
[libav.git] / libavcodec / nvenc.h
CommitLineData
b08caa87
LB
1/*
2 * This file is part of Libav.
3 *
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVCODEC_NVENC_H
20#define AVCODEC_NVENC_H
21
22#include <cuda.h>
23#include <nvEncodeAPI.h>
24
c51b2c79
AK
25#include "config.h"
26
b08caa87
LB
27#include "libavutil/fifo.h"
28#include "libavutil/opt.h"
29
30#include "avcodec.h"
31
118beda3
AK
32typedef struct NVENCFrame {
33 NV_ENC_INPUT_PTR in;
34 NV_ENC_OUTPUT_PTR out;
b08caa87
LB
35 NV_ENC_BUFFER_FORMAT format;
36 int locked;
118beda3 37} NVENCFrame;
b08caa87
LB
38
39typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags);
40typedef CUresult(CUDAAPI *PCUDEVICEGETCOUNT)(int *count);
41typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal);
42typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev);
43typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev);
44typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev);
45typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx);
46typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx);
47
48typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
49
50typedef struct NVENCLibraryContext
51{
c51b2c79 52#if !CONFIG_CUDA
b08caa87 53 void *cuda;
c51b2c79 54#endif
b08caa87
LB
55 void *nvenc;
56
57 PCUINIT cu_init;
58 PCUDEVICEGETCOUNT cu_device_get_count;
59 PCUDEVICEGET cu_device_get;
60 PCUDEVICEGETNAME cu_device_get_name;
61 PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability;
62 PCUCTXCREATE cu_ctx_create;
63 PCUCTXPOPCURRENT cu_ctx_pop_current;
64 PCUCTXDESTROY cu_ctx_destroy;
65
66 NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
67} NVENCLibraryContext;
68
69enum {
70 PRESET_DEFAULT,
71 PRESET_HP,
72 PRESET_HQ,
73 PRESET_BD ,
74 PRESET_LOW_LATENCY_DEFAULT ,
75 PRESET_LOW_LATENCY_HQ ,
76 PRESET_LOW_LATENCY_HP,
77 PRESET_LOSSLESS_DEFAULT,
78 PRESET_LOSSLESS_HP,
79};
80
81enum {
82 NV_ENC_H264_PROFILE_BASELINE,
83 NV_ENC_H264_PROFILE_MAIN,
84 NV_ENC_H264_PROFILE_HIGH,
85 NV_ENC_H264_PROFILE_HIGH_444,
86 NV_ENC_H264_PROFILE_CONSTRAINED_HIGH,
87};
88
89enum {
90 NVENC_LOWLATENCY = 1,
91 NVENC_LOSSLESS,
92};
93
94enum {
95 LIST_DEVICES = -2,
96 ANY_DEVICE,
97};
98
99typedef struct NVENCContext {
100 AVClass *class;
101 NVENCLibraryContext nvel;
102
103 NV_ENC_INITIALIZE_PARAMS params;
104 NV_ENC_CONFIG config;
105
106 CUcontext cu_context;
107
108 int nb_surfaces;
118beda3 109 NVENCFrame *frames;
b08caa87
LB
110 AVFifoBuffer *timestamps;
111 AVFifoBuffer *pending, *ready;
112
c59fec78
AK
113 /* timestamps of the first two frames, for computing the first dts
114 * when b-frames are present */
115 int64_t initial_pts[2];
116 int first_packet_output;
b08caa87
LB
117
118 void *nvenc_ctx;
119
120 int preset;
121 int profile;
122 int level;
123 int tier;
124 int rc;
125 int device;
126 int flags;
127} NVENCContext;
128
129int ff_nvenc_encode_init(AVCodecContext *avctx);
130
131int ff_nvenc_encode_close(AVCodecContext *avctx);
132
133int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
134 const AVFrame *frame, int *got_packet);
135
28259c13
AK
136extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
137
b08caa87 138#endif /* AVCODEC_NVENC_H */