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.

139 lines
3.6KB

  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 "config.h"
  23. #include "libavutil/fifo.h"
  24. #include "libavutil/opt.h"
  25. #include "avcodec.h"
  26. typedef struct NVENCFrame {
  27. NV_ENC_INPUT_PTR in;
  28. NV_ENC_OUTPUT_PTR out;
  29. NV_ENC_BUFFER_FORMAT format;
  30. int locked;
  31. } NVENCFrame;
  32. typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags);
  33. typedef CUresult(CUDAAPI *PCUDEVICEGETCOUNT)(int *count);
  34. typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal);
  35. typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev);
  36. typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev);
  37. typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev);
  38. typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx);
  39. typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx);
  40. typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
  41. typedef struct NVENCLibraryContext
  42. {
  43. #if !CONFIG_CUDA
  44. void *cuda;
  45. #endif
  46. void *nvenc;
  47. PCUINIT cu_init;
  48. PCUDEVICEGETCOUNT cu_device_get_count;
  49. PCUDEVICEGET cu_device_get;
  50. PCUDEVICEGETNAME cu_device_get_name;
  51. PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability;
  52. PCUCTXCREATE cu_ctx_create;
  53. PCUCTXPOPCURRENT cu_ctx_pop_current;
  54. PCUCTXDESTROY cu_ctx_destroy;
  55. NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
  56. } NVENCLibraryContext;
  57. enum {
  58. PRESET_DEFAULT,
  59. PRESET_HP,
  60. PRESET_HQ,
  61. PRESET_BD ,
  62. PRESET_LOW_LATENCY_DEFAULT ,
  63. PRESET_LOW_LATENCY_HQ ,
  64. PRESET_LOW_LATENCY_HP,
  65. PRESET_LOSSLESS_DEFAULT,
  66. PRESET_LOSSLESS_HP,
  67. };
  68. enum {
  69. NV_ENC_H264_PROFILE_BASELINE,
  70. NV_ENC_H264_PROFILE_MAIN,
  71. NV_ENC_H264_PROFILE_HIGH,
  72. NV_ENC_H264_PROFILE_HIGH_444,
  73. NV_ENC_H264_PROFILE_CONSTRAINED_HIGH,
  74. };
  75. enum {
  76. NVENC_LOWLATENCY = 1,
  77. NVENC_LOSSLESS,
  78. };
  79. enum {
  80. LIST_DEVICES = -2,
  81. ANY_DEVICE,
  82. };
  83. typedef struct NVENCContext {
  84. AVClass *class;
  85. NVENCLibraryContext nvel;
  86. NV_ENC_INITIALIZE_PARAMS params;
  87. NV_ENC_CONFIG config;
  88. CUcontext cu_context;
  89. int nb_surfaces;
  90. NVENCFrame *frames;
  91. AVFifoBuffer *timestamps;
  92. AVFifoBuffer *pending, *ready;
  93. /* timestamps of the first two frames, for computing the first dts
  94. * when b-frames are present */
  95. int64_t initial_pts[2];
  96. int first_packet_output;
  97. void *nvenc_ctx;
  98. int preset;
  99. int profile;
  100. int level;
  101. int tier;
  102. int rc;
  103. int device;
  104. int flags;
  105. } NVENCContext;
  106. int ff_nvenc_encode_init(AVCodecContext *avctx);
  107. int ff_nvenc_encode_close(AVCodecContext *avctx);
  108. int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  109. const AVFrame *frame, int *got_packet);
  110. extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
  111. #endif /* AVCODEC_NVENC_H */