hwconfig.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVCODEC_HWCONFIG_H
  19. #define AVCODEC_HWCONFIG_H
  20. #include "avcodec.h"
  21. #include "hwaccels.h"
  22. #define HWACCEL_CAP_ASYNC_SAFE (1 << 0)
  23. typedef struct AVCodecHWConfigInternal {
  24. /**
  25. * This is the structure which will be returned to the user by
  26. * avcodec_get_hw_config().
  27. */
  28. AVCodecHWConfig public;
  29. /**
  30. * If this configuration uses a hwaccel, a pointer to it.
  31. * If not, NULL.
  32. */
  33. const AVHWAccel *hwaccel;
  34. } AVCodecHWConfigInternal;
  35. // These macros are used to simplify AVCodecHWConfigInternal definitions.
  36. #define HW_CONFIG_HWACCEL(device, frames, ad_hoc, format, device_type_, name) \
  37. &(const AVCodecHWConfigInternal) { \
  38. .public = { \
  39. .pix_fmt = AV_PIX_FMT_ ## format, \
  40. .methods = (device ? AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX : 0) | \
  41. (frames ? AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX : 0) | \
  42. (ad_hoc ? AV_CODEC_HW_CONFIG_METHOD_AD_HOC : 0), \
  43. .device_type = AV_HWDEVICE_TYPE_ ## device_type_, \
  44. }, \
  45. .hwaccel = &name, \
  46. }
  47. #define HW_CONFIG_INTERNAL(format) \
  48. &(const AVCodecHWConfigInternal) { \
  49. .public = { \
  50. .pix_fmt = AV_PIX_FMT_ ## format, \
  51. .methods = AV_CODEC_HW_CONFIG_METHOD_INTERNAL, \
  52. .device_type = AV_HWDEVICE_TYPE_NONE, \
  53. }, \
  54. .hwaccel = NULL, \
  55. }
  56. #define HWACCEL_DXVA2(codec) \
  57. HW_CONFIG_HWACCEL(1, 1, 1, DXVA2_VLD, DXVA2, ff_ ## codec ## _dxva2_hwaccel)
  58. #define HWACCEL_D3D11VA2(codec) \
  59. HW_CONFIG_HWACCEL(1, 1, 0, D3D11, D3D11VA, ff_ ## codec ## _d3d11va2_hwaccel)
  60. #define HWACCEL_NVDEC(codec) \
  61. HW_CONFIG_HWACCEL(1, 1, 0, CUDA, CUDA, ff_ ## codec ## _nvdec_hwaccel)
  62. #define HWACCEL_VAAPI(codec) \
  63. HW_CONFIG_HWACCEL(1, 1, 1, VAAPI, VAAPI, ff_ ## codec ## _vaapi_hwaccel)
  64. #define HWACCEL_VDPAU(codec) \
  65. HW_CONFIG_HWACCEL(1, 1, 1, VDPAU, VDPAU, ff_ ## codec ## _vdpau_hwaccel)
  66. #define HWACCEL_VIDEOTOOLBOX(codec) \
  67. HW_CONFIG_HWACCEL(1, 1, 1, VIDEOTOOLBOX, VIDEOTOOLBOX, ff_ ## codec ## _videotoolbox_hwaccel)
  68. #define HWACCEL_D3D11VA(codec) \
  69. HW_CONFIG_HWACCEL(0, 0, 1, D3D11VA_VLD, NONE, ff_ ## codec ## _d3d11va_hwaccel)
  70. #define HWACCEL_XVMC(codec) \
  71. HW_CONFIG_HWACCEL(0, 0, 1, XVMC, NONE, ff_ ## codec ## _xvmc_hwaccel)
  72. #define HW_CONFIG_ENCODER(device, frames, ad_hoc, format, device_type_) \
  73. &(const AVCodecHWConfigInternal) { \
  74. .public = { \
  75. .pix_fmt = AV_PIX_FMT_ ## format, \
  76. .methods = (device ? AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX : 0) | \
  77. (frames ? AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX : 0) | \
  78. (ad_hoc ? AV_CODEC_HW_CONFIG_METHOD_AD_HOC : 0), \
  79. .device_type = AV_HWDEVICE_TYPE_ ## device_type_, \
  80. }, \
  81. .hwaccel = NULL, \
  82. }
  83. #define HW_CONFIG_ENCODER_DEVICE(format, device_type_) \
  84. HW_CONFIG_ENCODER(1, 0, 0, format, device_type_)
  85. #define HW_CONFIG_ENCODER_FRAMES(format, device_type_) \
  86. HW_CONFIG_ENCODER(0, 1, 0, format, device_type_)
  87. #endif /* AVCODEC_HWCONFIG_H */