dxva2_internal.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * DXVA2 HW acceleration
  3. *
  4. * copyright (c) 2010 Laurent Aimar
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_DXVA2_INTERNAL_H
  23. #define AVCODEC_DXVA2_INTERNAL_H
  24. #define COBJMACROS
  25. #include "config.h"
  26. /* define the proper COM entries before forcing desktop APIs */
  27. #include <objbase.h>
  28. #if CONFIG_DXVA2
  29. #include "dxva2.h"
  30. #include "libavutil/hwcontext_dxva2.h"
  31. #endif
  32. #if CONFIG_D3D11VA
  33. #include "d3d11va.h"
  34. #include "libavutil/hwcontext_d3d11va.h"
  35. #endif
  36. #if HAVE_DXVA_H
  37. /* When targeting WINAPI_FAMILY_PHONE_APP or WINAPI_FAMILY_APP, dxva.h
  38. * defines nothing. Force the struct definitions to be visible. */
  39. #undef WINAPI_FAMILY
  40. #define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
  41. #undef _CRT_BUILD_DESKTOP_APP
  42. #define _CRT_BUILD_DESKTOP_APP 0
  43. #include <dxva.h>
  44. #endif
  45. #include "libavutil/hwcontext.h"
  46. #include "avcodec.h"
  47. #include "internal.h"
  48. typedef void DECODER_BUFFER_DESC;
  49. typedef union {
  50. #if CONFIG_D3D11VA
  51. struct AVD3D11VAContext d3d11va;
  52. #endif
  53. #if CONFIG_DXVA2
  54. struct dxva_context dxva2;
  55. #endif
  56. } AVDXVAContext;
  57. typedef struct FFDXVASharedContext {
  58. AVBufferRef *decoder_ref;
  59. // FF_DXVA2_WORKAROUND_* flags
  60. uint64_t workaround;
  61. // E.g. AV_PIX_FMT_D3D11 (same as AVCodecContext.pix_fmt, except during init)
  62. enum AVPixelFormat pix_fmt;
  63. AVHWDeviceContext *device_ctx;
  64. #if CONFIG_D3D11VA
  65. ID3D11VideoDecoder *d3d11_decoder;
  66. D3D11_VIDEO_DECODER_CONFIG d3d11_config;
  67. ID3D11VideoDecoderOutputView **d3d11_views;
  68. int nb_d3d11_views;
  69. ID3D11Texture2D *d3d11_texture;
  70. #endif
  71. #if CONFIG_DXVA2
  72. IDirectXVideoDecoder *dxva2_decoder;
  73. IDirectXVideoDecoderService *dxva2_service;
  74. DXVA2_ConfigPictureDecode dxva2_config;
  75. #endif
  76. // Legacy (but used by code outside of setup)
  77. // In generic mode, DXVA_CONTEXT() will return a pointer to this.
  78. AVDXVAContext ctx;
  79. } FFDXVASharedContext;
  80. #define DXVA_SHARED_CONTEXT(avctx) ((FFDXVASharedContext *)((avctx)->internal->hwaccel_priv_data))
  81. #define DXVA_CONTEXT(avctx) (AVDXVAContext *)((avctx)->hwaccel_context ? (avctx)->hwaccel_context : (&(DXVA_SHARED_CONTEXT(avctx)->ctx)))
  82. #define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va)
  83. #define DXVA2_CONTEXT(ctx) (&ctx->dxva2)
  84. #if CONFIG_D3D11VA && CONFIG_DXVA2
  85. #define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.workaround : ctx->dxva2.workaround)
  86. #define DXVA_CONTEXT_COUNT(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.surface_count : ctx->dxva2.surface_count)
  87. #define DXVA_CONTEXT_DECODER(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? (void *)ctx->d3d11va.decoder : (void *)ctx->dxva2.decoder)
  88. #define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(ff_dxva2_is_d3d11(avctx) ? &ctx->d3d11va.report_id : &ctx->dxva2.report_id))
  89. #define DXVA_CONTEXT_CFG(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? (void *)ctx->d3d11va.cfg : (void *)ctx->dxva2.cfg)
  90. #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigBitstreamRaw : ctx->dxva2.cfg->ConfigBitstreamRaw)
  91. #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigIntraResidUnsigned : ctx->dxva2.cfg->ConfigIntraResidUnsigned)
  92. #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigResidDiffAccelerator : ctx->dxva2.cfg->ConfigResidDiffAccelerator)
  93. #define DXVA_CONTEXT_VALID(avctx, ctx) (DXVA_CONTEXT_DECODER(avctx, ctx) && \
  94. DXVA_CONTEXT_CFG(avctx, ctx) && \
  95. (ff_dxva2_is_d3d11(avctx) || ctx->dxva2.surface_count))
  96. #elif CONFIG_DXVA2
  97. #define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ctx->dxva2.workaround)
  98. #define DXVA_CONTEXT_COUNT(avctx, ctx) (ctx->dxva2.surface_count)
  99. #define DXVA_CONTEXT_DECODER(avctx, ctx) (ctx->dxva2.decoder)
  100. #define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(&ctx->dxva2.report_id))
  101. #define DXVA_CONTEXT_CFG(avctx, ctx) (ctx->dxva2.cfg)
  102. #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (ctx->dxva2.cfg->ConfigBitstreamRaw)
  103. #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ctx->dxva2.cfg->ConfigIntraResidUnsigned)
  104. #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ctx->dxva2.cfg->ConfigResidDiffAccelerator)
  105. #define DXVA_CONTEXT_VALID(avctx, ctx) (ctx->dxva2.decoder && ctx->dxva2.cfg && ctx->dxva2.surface_count)
  106. #elif CONFIG_D3D11VA
  107. #define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ctx->d3d11va.workaround)
  108. #define DXVA_CONTEXT_COUNT(avctx, ctx) (ctx->d3d11va.surface_count)
  109. #define DXVA_CONTEXT_DECODER(avctx, ctx) (ctx->d3d11va.decoder)
  110. #define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(&ctx->d3d11va.report_id))
  111. #define DXVA_CONTEXT_CFG(avctx, ctx) (ctx->d3d11va.cfg)
  112. #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (ctx->d3d11va.cfg->ConfigBitstreamRaw)
  113. #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ctx->d3d11va.cfg->ConfigIntraResidUnsigned)
  114. #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ctx->d3d11va.cfg->ConfigResidDiffAccelerator)
  115. #define DXVA_CONTEXT_VALID(avctx, ctx) (ctx->d3d11va.decoder && ctx->d3d11va.cfg)
  116. #endif
  117. unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
  118. const AVDXVAContext *,
  119. const AVFrame *frame);
  120. int ff_dxva2_commit_buffer(AVCodecContext *, AVDXVAContext *,
  121. DECODER_BUFFER_DESC *,
  122. unsigned type, const void *data, unsigned size,
  123. unsigned mb_count);
  124. int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *,
  125. const void *pp, unsigned pp_size,
  126. const void *qm, unsigned qm_size,
  127. int (*commit_bs_si)(AVCodecContext *,
  128. DECODER_BUFFER_DESC *bs,
  129. DECODER_BUFFER_DESC *slice));
  130. int ff_dxva2_decode_init(AVCodecContext *avctx);
  131. int ff_dxva2_decode_uninit(AVCodecContext *avctx);
  132. int ff_dxva2_common_frame_params(AVCodecContext *avctx,
  133. AVBufferRef *hw_frames_ctx);
  134. int ff_dxva2_is_d3d11(const AVCodecContext *avctx);
  135. #endif /* AVCODEC_DXVA2_INTERNAL_H */