]> git.sesse.net Git - ffmpeg/blob - libavcodec/dxva2_internal.h
Merge commit 'b0e6b3f4777910d61083976aa9fc78a1e0731aae'
[ffmpeg] / libavcodec / dxva2_internal.h
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
23 #ifndef AVCODEC_DXVA2_INTERNAL_H
24 #define AVCODEC_DXVA2_INTERNAL_H
25
26 #define COBJMACROS
27
28 #include "config.h"
29
30 /* define the proper COM entries before forcing desktop APIs */
31 #include <objbase.h>
32
33 #if CONFIG_DXVA2
34 #include "dxva2.h"
35 /* When targeting WINAPI_FAMILY_PHONE_APP or WINAPI_FAMILY_APP, dxva.h
36  * defines nothing. Force the struct definitions to be visible. */
37 #undef WINAPI_FAMILY
38 #define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
39 #undef _CRT_BUILD_DESKTOP_APP
40 #define _CRT_BUILD_DESKTOP_APP 0
41 #include <dxva.h>
42 #endif
43 #if CONFIG_D3D11VA
44 #include "d3d11va.h"
45 #endif
46
47 #include "avcodec.h"
48
49 typedef void DECODER_BUFFER_DESC;
50
51 typedef union {
52 #if CONFIG_D3D11VA
53     struct AVD3D11VAContext  d3d11va;
54 #endif
55 #if CONFIG_DXVA2
56     struct dxva_context      dxva2;
57 #endif
58 } AVDXVAContext;
59
60 #define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va)
61 #define DXVA2_CONTEXT(ctx)   (&ctx->dxva2)
62
63 #if CONFIG_D3D11VA && CONFIG_DXVA2
64 #define DXVA_CONTEXT_WORKAROUND(avctx, ctx)     (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.workaround : ctx->dxva2.workaround)
65 #define DXVA_CONTEXT_COUNT(avctx, ctx)          (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.surface_count : ctx->dxva2.surface_count)
66 #define DXVA_CONTEXT_DECODER(avctx, ctx)        (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.decoder : ctx->dxva2.decoder)
67 #define DXVA_CONTEXT_REPORT_ID(avctx, ctx)      (*(avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? &ctx->d3d11va.report_id : &ctx->dxva2.report_id))
68 #define DXVA_CONTEXT_CFG(avctx, ctx)            (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg : ctx->dxva2.cfg)
69 #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx)  (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg->ConfigBitstreamRaw : ctx->dxva2.cfg->ConfigBitstreamRaw)
70 #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg->ConfigIntraResidUnsigned : ctx->dxva2.cfg->ConfigIntraResidUnsigned)
71 #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg->ConfigResidDiffAccelerator : ctx->dxva2.cfg->ConfigResidDiffAccelerator)
72 #define DXVA_CONTEXT_VALID(avctx, ctx)          (DXVA_CONTEXT_DECODER(avctx, ctx) && \
73                                                  DXVA_CONTEXT_CFG(avctx, ctx) && \
74                                                  (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD || ctx->dxva2.surface_count))
75 #elif CONFIG_DXVA2
76 #define DXVA_CONTEXT_WORKAROUND(avctx, ctx)     (ctx->dxva2.workaround)
77 #define DXVA_CONTEXT_COUNT(avctx, ctx)          (ctx->dxva2.surface_count)
78 #define DXVA_CONTEXT_DECODER(avctx, ctx)        (ctx->dxva2.decoder)
79 #define DXVA_CONTEXT_REPORT_ID(avctx, ctx)      (*(&ctx->dxva2.report_id))
80 #define DXVA_CONTEXT_CFG(avctx, ctx)            (ctx->dxva2.cfg)
81 #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx)  (ctx->dxva2.cfg->ConfigBitstreamRaw)
82 #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ctx->dxva2.cfg->ConfigIntraResidUnsigned)
83 #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ctx->dxva2.cfg->ConfigResidDiffAccelerator)
84 #define DXVA_CONTEXT_VALID(avctx, ctx)          (ctx->dxva2.decoder && ctx->dxva2.cfg && ctx->dxva2.surface_count)
85 #elif CONFIG_D3D11VA
86 #define DXVA_CONTEXT_WORKAROUND(avctx, ctx)     (ctx->d3d11va.workaround)
87 #define DXVA_CONTEXT_COUNT(avctx, ctx)          (ctx->d3d11va.surface_count)
88 #define DXVA_CONTEXT_DECODER(avctx, ctx)        (ctx->d3d11va.decoder)
89 #define DXVA_CONTEXT_REPORT_ID(avctx, ctx)      (*(&ctx->d3d11va.report_id))
90 #define DXVA_CONTEXT_CFG(avctx, ctx)            (ctx->d3d11va.cfg)
91 #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx)  (ctx->d3d11va.cfg->ConfigBitstreamRaw)
92 #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ctx->d3d11va.cfg->ConfigIntraResidUnsigned)
93 #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ctx->d3d11va.cfg->ConfigResidDiffAccelerator)
94 #define DXVA_CONTEXT_VALID(avctx, ctx)          (ctx->d3d11va.decoder && ctx->d3d11va.cfg)
95 #endif
96
97 unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
98                                     const AVDXVAContext *,
99                                     const AVFrame *frame);
100
101 int ff_dxva2_commit_buffer(AVCodecContext *, AVDXVAContext *,
102                            DECODER_BUFFER_DESC *,
103                            unsigned type, const void *data, unsigned size,
104                            unsigned mb_count);
105
106
107 int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *,
108                               const void *pp, unsigned pp_size,
109                               const void *qm, unsigned qm_size,
110                               int (*commit_bs_si)(AVCodecContext *,
111                                                   DECODER_BUFFER_DESC *bs,
112                                                   DECODER_BUFFER_DESC *slice));
113
114 #endif /* AVCODEC_DXVA2_INTERNAL_H */