Skip to content

Commit

Permalink
Merge branch 'philipl:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Saentist authored Jan 9, 2022
2 parents b62db24 + cddaedd commit 5a44ab8
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 132 deletions.
38 changes: 0 additions & 38 deletions .gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions Makefile.am

This file was deleted.

12 changes: 0 additions & 12 deletions autogen.sh

This file was deleted.

20 changes: 0 additions & 20 deletions configure.ac

This file was deleted.

14 changes: 14 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
project('nv-video-info',
'c',
version : '1.0',
license: 'LGPL2.1+',
default_options : [
'c_std=c11',
'warning_level=0'
]
)

ffnvcodec = dependency('ffnvcodec', version: '>= 9.1.23.0')

executable('nvdecinfo', ['nvdecinfo.c'], dependencies: [ffnvcodec], install: true)
executable('nvencinfo', ['nvencinfo.c'], dependencies: [ffnvcodec], install: true)
103 changes: 50 additions & 53 deletions nvencinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ static int nvenc_map_error(NVENCSTATUS err, const char **desc)
return -1;
}

static int nvenc_print_error(NVENCSTATUS err,
const char *error_string)
{
const char *desc;
int ret;
ret = nvenc_map_error(err, &desc);
printf("%s: %s (%d)\n", error_string, desc, err);
return ret;
}

static int check_nv(NVENCSTATUS err, const char *func)
{
const char *err_string;
Expand Down Expand Up @@ -145,6 +135,9 @@ static const cap_t nvenc_limits[] = {
{ NV_ENC_CAPS_LEVEL_MIN, "Min Encoding Level" },
{ NV_ENC_CAPS_NUM_MAX_BFRAMES, "Max No. of B-Frames" },
{ NV_ENC_CAPS_NUM_MAX_LTR_FRAMES, "Maxmimum LT Reference Frames" },
#if NVENCAPI_MAJOR_VERSION > 10
{ NV_ENC_CAPS_NUM_ENCODER_ENGINES, "Number of Encoder Engines" },
#endif
};

static const cap_t nvenc_caps[] = {
Expand Down Expand Up @@ -188,6 +181,10 @@ static const cap_t nvenc_caps[] = {
{ NV_ENC_CAPS_SUPPORT_BFRAME_REF_MODE, "Supports B-Frames as References" },
{ NV_ENC_CAPS_SUPPORT_EMPHASIS_LEVEL_MAP, "Supports Emphasis Level Map" },
{ NV_ENC_CAPS_SUPPORT_MULTIPLE_REF_FRAMES, "Supports Multiple Reference Frames" },
#if NVENCAPI_MAJOR_VERSION > 11 || (NVENCAPI_MAJOR_VERSION == 11 && NVENCAPI_MINOR_VERSION > 0)
{ NV_ENC_CAPS_SUPPORT_ALPHA_LAYER_ENCODING, "Supports Alpha Layer Encoding" },
{ NV_ENC_CAPS_SINGLE_SLICE_INTRA_REFRESH, "Supports Single Slice Intra Refresh" },
#endif
};

static const struct {
Expand Down Expand Up @@ -279,7 +276,6 @@ static void nvenc_print_driver_requirement()

static int nvenc_load_libraries()
{
NVENCSTATUS err;
uint32_t nvenc_max_ver;
int ret;

Expand Down Expand Up @@ -324,7 +320,7 @@ static int print_formats(void *encoder, GUID *guids, int guid_count)
}

for (int i = 0; i < guid_count; i++) {
int count = 0;
uint32_t count = 0;
CHECK_NV(nv_funcs.nvEncGetInputFormatCount(encoder, guids[i], &count));

NV_ENC_BUFFER_FORMAT *formats = malloc(count * sizeof(NV_ENC_BUFFER_FORMAT));
Expand All @@ -340,16 +336,16 @@ static int print_formats(void *encoder, GUID *guids, int guid_count)
free(formats);
}

printf(" Input Buffer Formats | | |\n");
printf("----------------------------------------------------------\n");
printf(" Input Buffer Formats | | |\n");
printf("-------------------------------------------------------------\n");
for (int i = 0; i < FF_ARRAY_ELEMS(nvenc_formats); i++) {
printf("%34s |", nvenc_formats[i].desc);
printf("%35s |", nvenc_formats[i].desc);
for (int j = 0; j < guid_count; j++) {
printf("%9s |", (formats_for_guid[j] & nvenc_formats[i].fmt) ? "x" : ".");
printf("%10s |", (formats_for_guid[j] & nvenc_formats[i].fmt) ? "x" : ".");
}
printf("\n");
}
printf("----------------------------------------------------------\n");
printf("-------------------------------------------------------------\n");


free(formats_for_guid);
Expand Down Expand Up @@ -382,25 +378,26 @@ static int get_profiles(void *encoder, GUID encodeGUID, const char **profiles, u

static int print_profiles(void *encoder, GUID *guids, int count)
{
printf("----------------------------------------------------------\n");
printf(" Profiles | | |\n");
printf("----------------------------------------------------------\n");
printf("-------------------------------------------------------------\n");
printf(" Profiles | | |\n");
printf("-------------------------------------------------------------\n");

const char *profileGuids[count][FF_ARRAY_ELEMS(nvenc_profiles)];
uint32_t profileCount[count];
uint32_t max = 0;

for (int i = 0; i < count; i++) {
get_profiles(encoder, guids[i], profileGuids[i], &profileCount[i]);
max = MAX(max, profileCount[i]);
}

uint32_t max = MAX(profileCount[0], profileCount[1]);
for (int i = 0; i < max; i++) {
printf("%34s |", "");
printf("%35s |", "");
for (int j = 0; j < count; j++) {
if (i < profileCount[j]) {
printf("%9s |", profileGuids[j][i]);
printf("%10s |", profileGuids[j][i]);
} else {
printf("%9s |", "");
printf("%10s |", "");
}
}
printf("\n");
Expand Down Expand Up @@ -434,25 +431,26 @@ static int get_presets(void *encoder, GUID encodeGUID, const char **presets, uin

static int print_presets(void *encoder, GUID *guids, int count)
{
printf("----------------------------------------------------------\n");
printf(" Presets | | |\n");
printf("----------------------------------------------------------\n");
printf("-------------------------------------------------------------\n");
printf(" Presets | | |\n");
printf("-------------------------------------------------------------\n");

const char *presetGuids[count][FF_ARRAY_ELEMS(nvenc_presets)];
uint32_t presetCount[count];
uint32_t max = 0;

for (int i = 0; i < count; i++) {
get_presets(encoder, guids[i], presetGuids[i], &presetCount[i]);
max = MAX(max, presetCount[i]);
}

uint32_t max = MAX(presetCount[0], presetCount[1]);
for (int i = 0; i < max; i++) {
printf("%34s |", "");
printf("%35s |", "");
for (int j = 0; j < count; j++) {
if (i < presetCount[j]) {
printf("%9s |", presetGuids[j][i]);
printf("%10s |", presetGuids[j][i]);
} else {
printf("%9s |", "");
printf("%10s |", "");
}
}
printf("\n");
Expand All @@ -477,36 +475,36 @@ static int get_cap(void *encoder, GUID *guid, NV_ENC_CAPS cap)

static int print_caps(void *encoder, GUID *guids, int count)
{
int ret;

printf(" Limits | | |\n");
printf("----------------------------------------------------------\n");
printf(" Limits | | |\n");
printf("-------------------------------------------------------------\n");
for (int i = 0; i < FF_ARRAY_ELEMS(nvenc_limits); i++) {
printf("%34s |", nvenc_limits[i].desc);
printf("%35s |", nvenc_limits[i].desc);
for (int j = 0; j < count; j++) {
ret = get_cap(encoder, &guids[j], nvenc_limits[i].cap);
printf("%9d |", ret);
int ret = get_cap(encoder, &guids[j], nvenc_limits[i].cap);
printf("%10d |", ret);
}
printf("\n");
}

printf("----------------------------------------------------------\n");
printf(" Capabilities | | |\n");
printf("----------------------------------------------------------\n");
printf("-------------------------------------------------------------\n");
printf(" Capabilities | | |\n");
printf("-------------------------------------------------------------\n");
for (int i = 0; i < FF_ARRAY_ELEMS(nvenc_caps); i++) {
printf("%34s |", nvenc_caps[i].desc);
printf("%35s |", nvenc_caps[i].desc);
for (int j = 0; j < count; j++) {
ret = get_cap(encoder, &guids[j], nvenc_caps[i].cap);
printf("%9d |", ret);
int ret = get_cap(encoder, &guids[j], nvenc_caps[i].cap);
printf("%10d |", ret);
}
printf("\n");
}

return 0;
}


static int print_codecs(void *encoder)
{
int count = 0;
uint32_t count = 0;
CHECK_NV(nv_funcs.nvEncGetEncodeGUIDCount(encoder, &count));

GUID *guids = malloc(count * sizeof(GUID));
Expand All @@ -516,18 +514,18 @@ static int print_codecs(void *encoder)

CHECK_NV(nv_funcs.nvEncGetEncodeGUIDs(encoder, guids, count, &count));

printf("==========================================================\n");
printf(" Codec |");
printf("=============================================================\n");
printf(" Codec |");
for (int i = 0; i < count; i++) {
if (memcmp(&guids[i], &NV_ENC_CODEC_H264_GUID, 16) == 0) {
printf(" H264 |");
printf(" H264 |");
} else if (memcmp(&guids[i], &NV_ENC_CODEC_HEVC_GUID, 16) == 0) {
printf(" HEVC |");
printf(" HEVC |");
} else {
printf(" Unknown |");
printf(" Unknown |");
}
}
printf("\n==========================================================\n");
printf("\n=============================================================\n");
CHECK_NV(print_formats(encoder, guids, count));
CHECK_NV(print_caps(encoder, guids, count));
CHECK_NV(print_profiles(encoder, guids, count));
Expand All @@ -542,7 +540,6 @@ static int print_codecs(void *encoder)
static int print_nvenc_capabilities(CUcontext cuda_ctx)
{
NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS params = { 0 };
NVENCSTATUS ret;
void *nvencoder;

params.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
Expand Down Expand Up @@ -585,7 +582,7 @@ int main(int argc, char *argv[])

CHECK_CU(cu->cuCtxCreate(&cuda_ctx, CU_CTX_SCHED_BLOCKING_SYNC, dev));
print_nvenc_capabilities(cuda_ctx);
printf("==========================================================\n\n");
printf("=============================================================\n\n");
cu->cuCtxPopCurrent(&dummy);
}

Expand Down

0 comments on commit 5a44ab8

Please sign in to comment.