From 9f3902f107343f2690dce7ac7fef7c66887692b1 Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler Date: Fri, 13 Apr 2018 09:36:49 +0200 Subject: [PATCH] avcodec/nv{enc,dec}: use sane version checking macro For some odd reason, the Nvidia version macros puts the minor version in the msb, so comparing against it is impossible. --- libavcodec/nvdec.h | 9 +++++++++ libavcodec/nvdec_hevc.c | 2 +- libavcodec/nvenc.c | 2 +- libavcodec/nvenc.h | 5 ++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libavcodec/nvdec.h b/libavcodec/nvdec.h index 90578d5a1c..85a0fcf725 100644 --- a/libavcodec/nvdec.h +++ b/libavcodec/nvdec.h @@ -32,6 +32,15 @@ #include "avcodec.h" +#if defined(NVDECAPI_MAJOR_VERSION) && defined(NVDECAPI_MINOR_VERSION) +# define NVDECAPI_CHECK_VERSION(major, minor) \ + ((major) < NVDECAPI_MAJOR_VERSION || ((major) == NVDECAPI_MAJOR_VERSION && (minor) <= NVDECAPI_MINOR_VERSION)) +#else +/* version macros were added in SDK 8.1 ffnvcodec */ +# define NVDECAPI_CHECK_VERSION(major, minor) \ + ((major) < 8 || ((major) == 8 && (minor) <= 0)) +#endif + typedef struct NVDECFrame { unsigned int idx; AVBufferRef *idx_ref; diff --git a/libavcodec/nvdec_hevc.c b/libavcodec/nvdec_hevc.c index ba54d210e8..e89256d75a 100644 --- a/libavcodec/nvdec_hevc.c +++ b/libavcodec/nvdec_hevc.c @@ -107,7 +107,7 @@ static int nvdec_hevc_start_frame(AVCodecContext *avctx, .log2_diff_max_min_pcm_luma_coding_block_size = sps->pcm.log2_max_pcm_cb_size - sps->pcm.log2_min_pcm_cb_size, .pcm_sample_bit_depth_luma_minus1 = sps->pcm_enabled_flag ? sps->pcm.bit_depth - 1 : 0, .pcm_sample_bit_depth_chroma_minus1 = sps->pcm_enabled_flag ? sps->pcm.bit_depth_chroma - 1 : 0, -#if defined(NVDECAPI_VERSION) && NVDECAPI_VERSION >= 0x01000008 +#if NVDECAPI_CHECK_VERSION(8, 1) .log2_max_transform_skip_block_size_minus2 = pps->log2_max_transform_skip_block_size - 2, .log2_sao_offset_scale_luma = pps->log2_sao_offset_scale_luma, .log2_sao_offset_scale_chroma = pps->log2_sao_offset_scale_chroma, diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 9d07c260d0..c14112c366 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -119,7 +119,7 @@ static int nvenc_print_error(void *log_ctx, NVENCSTATUS err, static void nvenc_print_driver_requirement(AVCodecContext *avctx, int level) { -#if NVENCAPI_VERSION >= 0x01000008 +#if NVENCAPI_CHECK_VERSION(8, 1) # if defined(_WIN32) || defined(__CYGWIN__) const char *minver = "390.77"; # else diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index 2d6e781739..c7506d6a15 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -40,8 +40,11 @@ typedef void ID3D11Device; #define RC_MODE_DEPRECATED 0x800000 #define RCD(rc_mode) ((rc_mode) | RC_MODE_DEPRECATED) +#define NVENCAPI_CHECK_VERSION(major, minor) \ + ((major) < NVENCAPI_MAJOR_VERSION || ((major) == NVENCAPI_MAJOR_VERSION && (minor) <= NVENCAPI_MINOR_VERSION)) + // SDK 8.1 compile time feature checks -#if NVENCAPI_VERSION >= 0x01000008 +#if NVENCAPI_CHECK_VERSION(8, 1) #define NVENC_HAVE_BFRAME_REF_MODE #define NVENC_HAVE_QP_MAP_MODE #endif -- GitLab