nvenc: factor out the pixel format list
[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
25#include "libavutil/fifo.h"
26#include "libavutil/opt.h"
27
28#include "avcodec.h"
29
30typedef struct NVENCInputSurface {
31 NV_ENC_INPUT_PTR in;
32 NV_ENC_BUFFER_FORMAT format;
33 int locked;
34} NVENCInputSurface;
35
36typedef struct NVENCOutputSurface {
37 NV_ENC_OUTPUT_PTR out;
38 NVENCInputSurface *in;
39 int busy;
40} NVENCOutputSurface;
41
42typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags);
43typedef CUresult(CUDAAPI *PCUDEVICEGETCOUNT)(int *count);
44typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal);
45typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev);
46typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev);
47typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev);
48typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx);
49typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx);
50
51typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
52
53typedef struct NVENCLibraryContext
54{
55 void *cuda;
56 void *nvenc;
57
58 PCUINIT cu_init;
59 PCUDEVICEGETCOUNT cu_device_get_count;
60 PCUDEVICEGET cu_device_get;
61 PCUDEVICEGETNAME cu_device_get_name;
62 PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability;
63 PCUCTXCREATE cu_ctx_create;
64 PCUCTXPOPCURRENT cu_ctx_pop_current;
65 PCUCTXDESTROY cu_ctx_destroy;
66
67 NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
68} NVENCLibraryContext;
69
70enum {
71 PRESET_DEFAULT,
72 PRESET_HP,
73 PRESET_HQ,
74 PRESET_BD ,
75 PRESET_LOW_LATENCY_DEFAULT ,
76 PRESET_LOW_LATENCY_HQ ,
77 PRESET_LOW_LATENCY_HP,
78 PRESET_LOSSLESS_DEFAULT,
79 PRESET_LOSSLESS_HP,
80};
81
82enum {
83 NV_ENC_H264_PROFILE_BASELINE,
84 NV_ENC_H264_PROFILE_MAIN,
85 NV_ENC_H264_PROFILE_HIGH,
86 NV_ENC_H264_PROFILE_HIGH_444,
87 NV_ENC_H264_PROFILE_CONSTRAINED_HIGH,
88};
89
90enum {
91 NVENC_LOWLATENCY = 1,
92 NVENC_LOSSLESS,
93};
94
95enum {
96 LIST_DEVICES = -2,
97 ANY_DEVICE,
98};
99
100typedef struct NVENCContext {
101 AVClass *class;
102 NVENCLibraryContext nvel;
103
104 NV_ENC_INITIALIZE_PARAMS params;
105 NV_ENC_CONFIG config;
106
107 CUcontext cu_context;
108
109 int nb_surfaces;
110 NVENCInputSurface *in;
111 NVENCOutputSurface *out;
112 AVFifoBuffer *timestamps;
113 AVFifoBuffer *pending, *ready;
114
c59fec78
AK
115 /* timestamps of the first two frames, for computing the first dts
116 * when b-frames are present */
117 int64_t initial_pts[2];
118 int first_packet_output;
b08caa87
LB
119
120 void *nvenc_ctx;
121
122 int preset;
123 int profile;
124 int level;
125 int tier;
126 int rc;
127 int device;
128 int flags;
129} NVENCContext;
130
131int ff_nvenc_encode_init(AVCodecContext *avctx);
132
133int ff_nvenc_encode_close(AVCodecContext *avctx);
134
135int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
136 const AVFrame *frame, int *got_packet);
137
28259c13
AK
138extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
139
b08caa87 140#endif /* AVCODEC_NVENC_H */