nvenc: Make sure that enum and array index match

And use a macro to reduce the boilerplate.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Signed-off-by: Diego Biurrun <diego@biurrun.de>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:
Luca Barbato 2016-09-24 17:54:57 +02:00
parent 12004a9a7f
commit 352741b5ea
1 changed files with 14 additions and 9 deletions

View File

@ -459,18 +459,21 @@ typedef struct GUIDTuple {
int flags; int flags;
} GUIDTuple; } GUIDTuple;
#define PRESET(name, ...) \
[PRESET_ ## name] = { NV_ENC_PRESET_ ## name ## _GUID, __VA_ARGS__ }
static int nvec_map_preset(NVENCContext *ctx) static int nvec_map_preset(NVENCContext *ctx)
{ {
GUIDTuple presets[] = { GUIDTuple presets[] = {
{ NV_ENC_PRESET_DEFAULT_GUID }, PRESET(DEFAULT),
{ NV_ENC_PRESET_HP_GUID }, PRESET(HP),
{ NV_ENC_PRESET_HQ_GUID }, PRESET(HQ),
{ NV_ENC_PRESET_BD_GUID }, PRESET(BD),
{ NV_ENC_PRESET_LOW_LATENCY_DEFAULT_GUID, NVENC_LOWLATENCY }, PRESET(LOW_LATENCY_DEFAULT, NVENC_LOWLATENCY),
{ NV_ENC_PRESET_LOW_LATENCY_HP_GUID, NVENC_LOWLATENCY }, PRESET(LOW_LATENCY_HP, NVENC_LOWLATENCY),
{ NV_ENC_PRESET_LOW_LATENCY_HQ_GUID, NVENC_LOWLATENCY }, PRESET(LOW_LATENCY_HQ, NVENC_LOWLATENCY),
{ NV_ENC_PRESET_LOSSLESS_DEFAULT_GUID, NVENC_LOSSLESS }, PRESET(LOSSLESS_DEFAULT, NVENC_LOSSLESS),
{ NV_ENC_PRESET_LOSSLESS_HP_GUID, NVENC_LOSSLESS }, PRESET(LOSSLESS_HP, NVENC_LOSSLESS),
{ { 0 } } { { 0 } }
}; };
@ -482,6 +485,8 @@ static int nvec_map_preset(NVENCContext *ctx)
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
#undef PRESET
static void set_constqp(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc) static void set_constqp(AVCodecContext *avctx, NV_ENC_RC_PARAMS *rc)
{ {
rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP; rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;