nvenc-helpers.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #ifdef _WIN32
  3. #define WIN32_LEAN_AND_MEAN
  4. #include <windows.h>
  5. #endif
  6. #include <obs-module.h>
  7. #include <ffnvcodec/nvEncodeAPI.h>
  8. #define NVCODEC_CONFIGURED_VERSION ((NVENCAPI_MAJOR_VERSION << 4) | NVENCAPI_MINOR_VERSION)
  9. #if NVENCAPI_MAJOR_VERSION > 12 || NVENCAPI_MINOR_VERSION >= 1
  10. #define NVENC_12_1_OR_LATER
  11. #endif
  12. #if NVENCAPI_MAJOR_VERSION > 12 || NVENCAPI_MINOR_VERSION >= 2
  13. #define NVENC_12_2_OR_LATER
  14. #endif
  15. #if NVENCAPI_MAJOR_VERSION >= 13
  16. #define NVENC_13_0_OR_LATER
  17. #endif
  18. enum codec_type {
  19. CODEC_H264,
  20. CODEC_HEVC,
  21. CODEC_AV1,
  22. };
  23. static const char *get_codec_name(enum codec_type type)
  24. {
  25. switch (type) {
  26. case CODEC_H264:
  27. return "H264";
  28. case CODEC_HEVC:
  29. return "HEVC";
  30. case CODEC_AV1:
  31. return "AV1";
  32. }
  33. return "Unknown";
  34. }
  35. struct encoder_caps {
  36. int bframes;
  37. int bref_modes;
  38. int engines;
  39. int max_width;
  40. int max_height;
  41. int temporal_filter; /* Broken prior to the 551.21 driver. */
  42. int lookahead_level; /* Broken prior to the 570.20 driver. */
  43. bool dyn_bitrate;
  44. bool lookahead;
  45. bool lossless;
  46. bool temporal_aq;
  47. bool uhq;
  48. /* Yeah... */
  49. bool ten_bit;
  50. bool four_four_four;
  51. bool four_two_two;
  52. };
  53. typedef NVENCSTATUS(NVENCAPI *NV_CREATE_INSTANCE_FUNC)(NV_ENCODE_API_FUNCTION_LIST *);
  54. extern NV_ENCODE_API_FUNCTION_LIST nv;
  55. extern NV_CREATE_INSTANCE_FUNC nv_create_instance;
  56. const char *nv_error_name(NVENCSTATUS err);
  57. bool init_nvenc(obs_encoder_t *encoder);
  58. bool nv_fail2(obs_encoder_t *encoder, void *session, const char *format, ...);
  59. bool nv_failed2(obs_encoder_t *encoder, void *session, NVENCSTATUS err, const char *func, const char *call);
  60. struct encoder_caps *get_encoder_caps(enum codec_type codec);
  61. int num_encoder_devices(void);
  62. bool is_codec_supported(enum codec_type codec);
  63. bool has_broken_split_encoding(void);
  64. void register_encoders(void);
  65. void register_compat_encoders(void);
  66. #define nv_fail(encoder, format, ...) nv_fail2(encoder, enc->session, format, ##__VA_ARGS__)
  67. #define nv_failed(encoder, err, func, call) nv_failed2(encoder, enc->session, err, func, call)