You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.5KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVCODEC_NVENC_H
  19. #define AVCODEC_NVENC_H
  20. #include <cuda.h>
  21. #include <nvEncodeAPI.h>
  22. #include "libavutil/fifo.h"
  23. #include "libavutil/opt.h"
  24. #include "avcodec.h"
  25. typedef struct NVENCInputSurface {
  26. NV_ENC_INPUT_PTR in;
  27. NV_ENC_BUFFER_FORMAT format;
  28. int locked;
  29. } NVENCInputSurface;
  30. typedef struct NVENCOutputSurface {
  31. NV_ENC_OUTPUT_PTR out;
  32. NVENCInputSurface *in;
  33. int busy;
  34. } NVENCOutputSurface;
  35. typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags);
  36. typedef CUresult(CUDAAPI *PCUDEVICEGETCOUNT)(int *count);
  37. typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal);
  38. typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev);
  39. typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev);
  40. typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev);
  41. typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx);
  42. typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx);
  43. typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
  44. typedef struct NVENCLibraryContext
  45. {
  46. void *cuda;
  47. void *nvenc;
  48. PCUINIT cu_init;
  49. PCUDEVICEGETCOUNT cu_device_get_count;
  50. PCUDEVICEGET cu_device_get;
  51. PCUDEVICEGETNAME cu_device_get_name;
  52. PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability;
  53. PCUCTXCREATE cu_ctx_create;
  54. PCUCTXPOPCURRENT cu_ctx_pop_current;
  55. PCUCTXDESTROY cu_ctx_destroy;
  56. NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
  57. } NVENCLibraryContext;
  58. enum {
  59. PRESET_DEFAULT,
  60. PRESET_HP,
  61. PRESET_HQ,
  62. PRESET_BD ,
  63. PRESET_LOW_LATENCY_DEFAULT ,
  64. PRESET_LOW_LATENCY_HQ ,
  65. PRESET_LOW_LATENCY_HP,
  66. PRESET_LOSSLESS_DEFAULT,
  67. PRESET_LOSSLESS_HP,
  68. };
  69. enum {
  70. NV_ENC_H264_PROFILE_BASELINE,
  71. NV_ENC_H264_PROFILE_MAIN,
  72. NV_ENC_H264_PROFILE_HIGH,
  73. NV_ENC_H264_PROFILE_HIGH_444,
  74. NV_ENC_H264_PROFILE_CONSTRAINED_HIGH,
  75. };
  76. enum {
  77. NVENC_LOWLATENCY = 1,
  78. NVENC_LOSSLESS,
  79. };
  80. enum {
  81. LIST_DEVICES = -2,
  82. ANY_DEVICE,
  83. };
  84. typedef struct NVENCContext {
  85. AVClass *class;
  86. NVENCLibraryContext nvel;
  87. NV_ENC_INITIALIZE_PARAMS params;
  88. NV_ENC_CONFIG config;
  89. CUcontext cu_context;
  90. int nb_surfaces;
  91. NVENCInputSurface *in;
  92. NVENCOutputSurface *out;
  93. AVFifoBuffer *timestamps;
  94. AVFifoBuffer *pending, *ready;
  95. int64_t last_dts;
  96. void *nvenc_ctx;
  97. int preset;
  98. int profile;
  99. int level;
  100. int tier;
  101. int rc;
  102. int device;
  103. int flags;
  104. } NVENCContext;
  105. int ff_nvenc_encode_init(AVCodecContext *avctx);
  106. int ff_nvenc_encode_close(AVCodecContext *avctx);
  107. int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  108. const AVFrame *frame, int *got_packet);
  109. #endif /* AVCODEC_NVENC_H */