-
Notifications
You must be signed in to change notification settings - Fork 5
/
nvdecinfo.c
211 lines (186 loc) · 5.24 KB
/
nvdecinfo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
* nvdecinfo - enumerate nvdec capabilities of nvidia video devices
* Copyright (c) 2018 Philip Langdale <[email protected]>
*
* This library 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.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <ffnvcodec/dynlink_loader.h>
static CudaFunctions *cu;
static CuvidFunctions *cv;
static int check_cu(CUresult err, const char *func)
{
const char *err_name;
const char *err_string;
if (err == CUDA_SUCCESS) {
return 0;
}
cu->cuGetErrorName(err, &err_name);
cu->cuGetErrorString(err, &err_string);
fprintf(stderr, "%s failed", func);
if (err_name && err_string) {
fprintf(stderr, " -> %s: %s", err_name, err_string);
}
fprintf(stderr, "\n");
return -1;
}
#define CHECK_CU(x) { int ret = check_cu((x), #x); if (ret != 0) { return ret; } }
static int get_caps(cudaVideoCodec codec_type,
cudaVideoChromaFormat chroma_format,
unsigned int bit_depth)
{
CUVIDDECODECAPS caps;
caps.eCodecType = codec_type;
caps.eChromaFormat = chroma_format;
caps.nBitDepthMinus8 = bit_depth - 8;
CHECK_CU(cv->cuvidGetDecoderCaps(&caps));
if (!caps.bIsSupported) {
return 0;
}
const char *codec;
switch (codec_type) {
case cudaVideoCodec_MPEG1:
codec = "MPEG1";
break;
case cudaVideoCodec_MPEG2:
codec = "MPEG2";
break;
case cudaVideoCodec_MPEG4:
codec = "MPEG4";
break;
case cudaVideoCodec_VC1:
codec = "VC1";
break;
case cudaVideoCodec_H264:
codec = "H264";
break;
case cudaVideoCodec_JPEG:
codec = "MJPEG";
break;
case cudaVideoCodec_H264_SVC:
codec = "H264 SVC";
break;
case cudaVideoCodec_H264_MVC:
codec = "H264 MVC";
break;
case cudaVideoCodec_HEVC:
codec = "HEVC";
break;
case cudaVideoCodec_VP8:
codec = "VP8";
break;
case cudaVideoCodec_VP9:
codec = "VP9";
break;
#if NVDECAPI_MAJOR_VERSION > 10
case cudaVideoCodec_AV1:
codec = "AV1";
break;
#endif
default:
codec = "Unknown";
break;
}
const char *format;
switch (chroma_format) {
case cudaVideoChromaFormat_Monochrome:
format = "400";
break;
case cudaVideoChromaFormat_420:
format = "420";
break;
case cudaVideoChromaFormat_422:
format = "422";
break;
case cudaVideoChromaFormat_444:
format = "444";
break;
}
const char *surface;
switch (caps.nOutputFormatMask) {
case 1 << cudaVideoSurfaceFormat_NV12:
surface = "NV12";
break;
case 1 << cudaVideoSurfaceFormat_P016:
surface = "P016";
break;
case 1 << cudaVideoSurfaceFormat_YUV444:
surface = "YUV444P";
break;
case 1 << cudaVideoSurfaceFormat_YUV444_16Bit:
surface = "YUV444P16";
break;
case (1 << cudaVideoSurfaceFormat_NV12) + (1 << cudaVideoSurfaceFormat_P016):
surface = "P016, NV12";
break;
default:
surface = "Unknown";
break;
}
printf("%5s | %6s | %5d | %9d | %10d | %15s\n",
codec, format, bit_depth, caps.nMaxWidth, caps.nMaxHeight, surface);
return 0;
}
int main(int argc, char *argv[])
{
CUcontext cuda_ctx;
CUcontext dummy;
int ret;
ret = cuda_load_functions(&cu, NULL);
if (ret != 0) {
fprintf(stderr, "Failed to load CUDA functions.\n");
return -1;
}
ret = cuvid_load_functions(&cv, NULL);
if (ret != 0) {
fprintf(stderr, "Failed to load NVDEC functions.\n");
return -1;
}
if (!cv->cuvidGetDecoderCaps) {
fprintf(stderr,
"The current nvidia driver is too old to perform a capability check.\n"
"The minimum required driver version is %s\n",
#if defined(_WIN32) || defined(__CYGWIN__)
"378.66");
#else
"378.13");
#endif
return -1;
}
CHECK_CU(cu->cuInit(0));
int count;
CHECK_CU(cu->cuDeviceGetCount(&count));
for (int i = 0; i < count; i++) {
CUdevice dev;
CHECK_CU(cu->cuDeviceGet(&dev, i));
char name[255];
CHECK_CU(cu->cuDeviceGetName(name, 255, dev));
printf("Device %d: %s\n", i, name);
printf("-----------------------------------------------------------------\n");
CHECK_CU(cu->cuCtxCreate(&cuda_ctx, CU_CTX_SCHED_BLOCKING_SYNC, dev));
printf("Codec | Chroma | Depth | Max Width | Max Height | Surface Formats\n");
printf("-----------------------------------------------------------------\n");
for (int c = 0; c < cudaVideoCodec_NumCodecs; c++) {
for (int f = 0; f < 4; f++) {
for (int b = 8; b < 14; b += 2) {
get_caps(c, f, b);
}
}
}
printf("-----------------------------------------------------------------\n\n");
cu->cuCtxPopCurrent(&dummy);
}
return 0;
}