libavcodec/dxva2_internal.h
85167c46
 /*
  * DXVA2 HW acceleration
  *
  * copyright (c) 2010 Laurent Aimar
  *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
180f9a09
 #ifndef AVCODEC_DXVA2_INTERNAL_H
 #define AVCODEC_DXVA2_INTERNAL_H
85167c46
 
a63ba973
 #define COBJMACROS
fa845061
 
 #include "config.h"
 
c5327df8
 /* define the proper COM entries before forcing desktop APIs */
 #include <objbase.h>
 
28fa58cf
 #if CONFIG_DXVA2
85167c46
 #include "dxva2.h"
70143a39
 #include "libavutil/hwcontext_dxva2.h"
6aa4ba71
 #endif
 #if CONFIG_D3D11VA
 #include "d3d11va.h"
70143a39
 #include "libavutil/hwcontext_d3d11va.h"
6aa4ba71
 #endif
 #if HAVE_DXVA_H
9b4b96c0
 /* When targeting WINAPI_FAMILY_PHONE_APP or WINAPI_FAMILY_APP, dxva.h
  * defines nothing. Force the struct definitions to be visible. */
c5327df8
 #undef WINAPI_FAMILY
 #define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
9b4b96c0
 #undef _CRT_BUILD_DESKTOP_APP
c5327df8
 #define _CRT_BUILD_DESKTOP_APP 0
fa845061
 #include <dxva.h>
 #endif
 
70143a39
 #include "libavutil/hwcontext.h"
 
85167c46
 #include "avcodec.h"
70143a39
 #include "internal.h"
85167c46
 
d8039ef8
 typedef void DECODER_BUFFER_DESC;
 
 typedef union {
94d07b31
 #if CONFIG_D3D11VA
d8039ef8
     struct AVD3D11VAContext  d3d11va;
94d07b31
 #endif
28fa58cf
 #if CONFIG_DXVA2
d8039ef8
     struct dxva_context      dxva2;
28fa58cf
 #endif
d8039ef8
 } AVDXVAContext;
 
70143a39
 typedef struct FFDXVASharedContext {
     AVBufferRef *decoder_ref;
 
     // FF_DXVA2_WORKAROUND_* flags
     uint64_t workaround;
 
     // E.g. AV_PIX_FMT_D3D11 (same as AVCodecContext.pix_fmt, except during init)
     enum AVPixelFormat pix_fmt;
 
     AVHWDeviceContext *device_ctx;
 
 #if CONFIG_D3D11VA
     ID3D11VideoDecoder             *d3d11_decoder;
     D3D11_VIDEO_DECODER_CONFIG      d3d11_config;
     ID3D11VideoDecoderOutputView  **d3d11_views;
     int                          nb_d3d11_views;
     ID3D11Texture2D                *d3d11_texture;
 #endif
 
 #if CONFIG_DXVA2
     IDirectXVideoDecoder           *dxva2_decoder;
     IDirectXVideoDecoderService    *dxva2_service;
     DXVA2_ConfigPictureDecode       dxva2_config;
 #endif
 
     // Legacy (but used by code outside of setup)
     // In generic mode, DXVA_CONTEXT() will return a pointer to this.
     AVDXVAContext ctx;
 } FFDXVASharedContext;
 
 #define DXVA_SHARED_CONTEXT(avctx) ((FFDXVASharedContext *)((avctx)->internal->hwaccel_priv_data))
 
 #define DXVA_CONTEXT(avctx) (AVDXVAContext *)((avctx)->hwaccel_context ? (avctx)->hwaccel_context : (&(DXVA_SHARED_CONTEXT(avctx)->ctx)))
ab28108a
 
94d07b31
 #define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va)
d8039ef8
 #define DXVA2_CONTEXT(ctx)   (&ctx->dxva2)
 
28fa58cf
 #if CONFIG_D3D11VA && CONFIG_DXVA2
ab28108a
 #define DXVA_CONTEXT_WORKAROUND(avctx, ctx)     (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.workaround : ctx->dxva2.workaround)
 #define DXVA_CONTEXT_COUNT(avctx, ctx)          (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.surface_count : ctx->dxva2.surface_count)
 #define DXVA_CONTEXT_DECODER(avctx, ctx)        (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.decoder : ctx->dxva2.decoder)
 #define DXVA_CONTEXT_REPORT_ID(avctx, ctx)      (*(ff_dxva2_is_d3d11(avctx) ? &ctx->d3d11va.report_id : &ctx->dxva2.report_id))
 #define DXVA_CONTEXT_CFG(avctx, ctx)            (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg : ctx->dxva2.cfg)
 #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx)  (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigBitstreamRaw : ctx->dxva2.cfg->ConfigBitstreamRaw)
 #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigIntraResidUnsigned : ctx->dxva2.cfg->ConfigIntraResidUnsigned)
 #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigResidDiffAccelerator : ctx->dxva2.cfg->ConfigResidDiffAccelerator)
77742c75
 #define DXVA_CONTEXT_VALID(avctx, ctx)          (DXVA_CONTEXT_DECODER(avctx, ctx) && \
0ac2d86c
                                                  DXVA_CONTEXT_CFG(avctx, ctx)     && \
ab28108a
                                                  (ff_dxva2_is_d3d11(avctx) || ctx->dxva2.surface_count))
28fa58cf
 #elif CONFIG_DXVA2
94d07b31
 #define DXVA_CONTEXT_WORKAROUND(avctx, ctx)     (ctx->dxva2.workaround)
 #define DXVA_CONTEXT_COUNT(avctx, ctx)          (ctx->dxva2.surface_count)
 #define DXVA_CONTEXT_DECODER(avctx, ctx)        (ctx->dxva2.decoder)
 #define DXVA_CONTEXT_REPORT_ID(avctx, ctx)      (*(&ctx->dxva2.report_id))
 #define DXVA_CONTEXT_CFG(avctx, ctx)            (ctx->dxva2.cfg)
 #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx)  (ctx->dxva2.cfg->ConfigBitstreamRaw)
 #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ctx->dxva2.cfg->ConfigIntraResidUnsigned)
 #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ctx->dxva2.cfg->ConfigResidDiffAccelerator)
77742c75
 #define DXVA_CONTEXT_VALID(avctx, ctx)          (ctx->dxva2.decoder && ctx->dxva2.cfg && ctx->dxva2.surface_count)
28fa58cf
 #elif CONFIG_D3D11VA
 #define DXVA_CONTEXT_WORKAROUND(avctx, ctx)     (ctx->d3d11va.workaround)
 #define DXVA_CONTEXT_COUNT(avctx, ctx)          (ctx->d3d11va.surface_count)
 #define DXVA_CONTEXT_DECODER(avctx, ctx)        (ctx->d3d11va.decoder)
 #define DXVA_CONTEXT_REPORT_ID(avctx, ctx)      (*(&ctx->d3d11va.report_id))
 #define DXVA_CONTEXT_CFG(avctx, ctx)            (ctx->d3d11va.cfg)
 #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx)  (ctx->d3d11va.cfg->ConfigBitstreamRaw)
 #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ctx->d3d11va.cfg->ConfigIntraResidUnsigned)
 #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ctx->d3d11va.cfg->ConfigResidDiffAccelerator)
8fb48659
 #define DXVA_CONTEXT_VALID(avctx, ctx)          (ctx->d3d11va.decoder && ctx->d3d11va.cfg)
94d07b31
 #endif
d8039ef8
 
 unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
                                     const AVDXVAContext *,
29be9b53
                                     const AVFrame *frame);
85167c46
 
d8039ef8
 int ff_dxva2_commit_buffer(AVCodecContext *, AVDXVAContext *,
                            DECODER_BUFFER_DESC *,
85167c46
                            unsigned type, const void *data, unsigned size,
                            unsigned mb_count);
 
 
29be9b53
 int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *,
85167c46
                               const void *pp, unsigned pp_size,
                               const void *qm, unsigned qm_size,
                               int (*commit_bs_si)(AVCodecContext *,
d8039ef8
                                                   DECODER_BUFFER_DESC *bs,
                                                   DECODER_BUFFER_DESC *slice));
85167c46
 
70143a39
 int ff_dxva2_decode_init(AVCodecContext *avctx);
 
 int ff_dxva2_decode_uninit(AVCodecContext *avctx);
 
b46a77f1
 int ff_dxva2_common_frame_params(AVCodecContext *avctx,
                                  AVBufferRef *hw_frames_ctx);
 
ab28108a
 int ff_dxva2_is_d3d11(const AVCodecContext *avctx);
 
180f9a09
 #endif /* AVCODEC_DXVA2_INTERNAL_H */