nvenc-helpers.h 1.9 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 \
  9. ((NVENCAPI_MAJOR_VERSION << 4) | NVENCAPI_MINOR_VERSION)
  10. #if NVENCAPI_MAJOR_VERSION > 12 || NVENCAPI_MINOR_VERSION >= 1
  11. #define NVENC_12_1_OR_LATER
  12. #endif
  13. #if NVENCAPI_MAJOR_VERSION > 12 || NVENCAPI_MINOR_VERSION >= 2
  14. #define NVENC_12_2_OR_LATER
  15. #endif
  16. enum codec_type {
  17. CODEC_H264,
  18. CODEC_HEVC,
  19. CODEC_AV1,
  20. };
  21. static const char *get_codec_name(enum codec_type type)
  22. {
  23. switch (type) {
  24. case CODEC_H264:
  25. return "H264";
  26. case CODEC_HEVC:
  27. return "HEVC";
  28. case CODEC_AV1:
  29. return "AV1";
  30. }
  31. return "Unknown";
  32. }
  33. struct encoder_caps {
  34. int bframes;
  35. int bref_modes;
  36. int engines;
  37. int max_width;
  38. int max_height;
  39. /* These don't seem to work correctly, thanks NVIDIA. */
  40. int temporal_filter;
  41. int lookahead_level;
  42. bool dyn_bitrate;
  43. bool lookahead;
  44. bool lossless;
  45. bool temporal_aq;
  46. /* Yeah... */
  47. bool ten_bit;
  48. bool four_four_four;
  49. };
  50. typedef NVENCSTATUS(NVENCAPI *NV_CREATE_INSTANCE_FUNC)(
  51. NV_ENCODE_API_FUNCTION_LIST *);
  52. extern NV_ENCODE_API_FUNCTION_LIST nv;
  53. extern NV_CREATE_INSTANCE_FUNC nv_create_instance;
  54. const char *nv_error_name(NVENCSTATUS err);
  55. bool init_nvenc(obs_encoder_t *encoder);
  56. bool nv_fail2(obs_encoder_t *encoder, void *session, const char *format, ...);
  57. bool nv_failed2(obs_encoder_t *encoder, void *session, NVENCSTATUS err,
  58. const char *func, const char *call);
  59. struct encoder_caps *get_encoder_caps(enum codec_type codec);
  60. int num_encoder_devices(void);
  61. bool is_codec_supported(enum codec_type codec);
  62. bool has_broken_split_encoding(void);
  63. void register_encoders(void);
  64. void register_compat_encoders(void);
  65. #define nv_fail(encoder, format, ...) \
  66. nv_fail2(encoder, enc->session, format, ##__VA_ARGS__)
  67. #define nv_failed(encoder, err, func, call) \
  68. nv_failed2(encoder, enc->session, err, func, call)