WinGui: Fix another instance of the Caliburn vs Json.net sillyness where objects...
[HandBrake.git] / libhb / vadxva2.h
blobd095d0c931e42e91c3777bc7bb51d44de3a7707d
1 /* vadxva2.h
3 Copyright (c) 2003-2015 HandBrake Team
4 This file is part of the HandBrake source code
5 Homepage: <http://handbrake.fr/>.
6 It may be used under the terms of the GNU General Public License v2.
7 For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
9 Authors: Peng Gao <peng@multicorewareinc.com> <http://www.multicorewareinc.com/>
10 Li Cao <li@multicorewareinc.com> <http://www.multicorewareinc.com/>
14 #ifdef USE_HWD
16 #ifndef HB_VA_DXVA2_H
17 #define HB_VA_DXVA2_H
19 #include "hbffmpeg.h"
20 #include "d3d9.h"
21 #include "libavcodec/dxva2.h"
22 #include "dxva2api.h"
23 #include "common.h"
24 #include "opencl.h"
25 #include "openclwrapper.h"
27 #define HB_FOURCC( a, b, c, d ) ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
28 #define MAKEFOURCC( a, b, c, d ) ((DWORD)(BYTE)(a) | ((DWORD)(BYTE)(b) << 8) | ((DWORD)(BYTE)(c) << 16) | ((DWORD)(BYTE)(d) << 24 ))
29 #define HB_CODEC_YV12 HB_FOURCC( 'Y', 'V', '1', '2' )
30 #define HB_CODEC_NV12 HB_FOURCC( 'N', 'V', '1', '2' )
31 #define DXVA2_E_NOT_INITIALIZED MAKE_HRESULT( 1, 4, 4096 )
32 #define DXVA2_E_NEW_VIDEO_DEVICE MAKE_HRESULT( 1, 4, 4097 )
33 #define DXVA2_E_VIDEO_DEVICE_LOCKED MAKE_HRESULT( 1, 4, 4098 )
34 #define DXVA2_E_NOT_AVAILABLE MAKE_HRESULT( 1, 4, 4099 )
35 #define VA_DXVA2_MAX_SURFACE_COUNT (64)
37 static const GUID DXVA_NoEncrypt = { 0x1b81bed0, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
38 static const GUID IID_IDirectXVideoDecoderService = {0xfc51a551, 0xd5e7, 0x11d9, {0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02}};
39 static const GUID DXVA2_ModeMPEG2_MoComp = { 0xe6a9f44b, 0x61b0, 0x4563, {0x9e, 0xa4, 0x63, 0xd2, 0xa3, 0xc6, 0xfe, 0x66} };
40 static const GUID DXVA2_ModeMPEG2_IDCT = { 0xbf22ad00, 0x03ea, 0x4690, {0x80, 0x77, 0x47, 0x33, 0x46, 0x20, 0x9b, 0x7e} };
41 static const GUID DXVA2_ModeMPEG2_VLD = { 0xee27417f, 0x5e28, 0x4e65, {0xbe, 0xea, 0x1d, 0x26, 0xb5, 0x08, 0xad, 0xc9} };
42 static const GUID DXVA2_ModeH264_A = { 0x1b81be64, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
43 static const GUID DXVA2_ModeH264_B = { 0x1b81be65, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
44 static const GUID DXVA2_ModeH264_C = { 0x1b81be66, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
45 static const GUID DXVA2_ModeH264_D = { 0x1b81be67, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
46 static const GUID DXVA2_ModeH264_E = { 0x1b81be68, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
47 static const GUID DXVA2_ModeH264_F = { 0x1b81be69, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
48 static const GUID DXVADDI_Intel_ModeH264_A = { 0x604F8E64, 0x4951, 0x4c54, {0x88, 0xFE, 0xAB, 0xD2, 0x5C, 0x15, 0xB3, 0xD6} };
49 static const GUID DXVADDI_Intel_ModeH264_C = { 0x604F8E66, 0x4951, 0x4c54, {0x88, 0xFE, 0xAB, 0xD2, 0x5C, 0x15, 0xB3, 0xD6} };
50 static const GUID DXVADDI_Intel_ModeH264_E = { 0x604F8E68, 0x4951, 0x4c54, {0x88, 0xFE, 0xAB, 0xD2, 0x5C, 0x15, 0xB3, 0xD6} };
51 static const GUID DXVA2_ModeWMV8_A = { 0x1b81be80, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
52 static const GUID DXVA2_ModeWMV8_B = { 0x1b81be81, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
53 static const GUID DXVA2_ModeWMV9_A = { 0x1b81be90, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
54 static const GUID DXVA2_ModeWMV9_B = { 0x1b81be91, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
55 static const GUID DXVA2_ModeWMV9_C = { 0x1b81be94, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
56 static const GUID DXVA2_ModeVC1_A = { 0x1b81beA0, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
57 static const GUID DXVA2_ModeVC1_B = { 0x1b81beA1, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
58 static const GUID DXVA2_ModeVC1_C = { 0x1b81beA2, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
59 static const GUID DXVA2_ModeVC1_D = { 0x1b81beA3, 0xa0c7, 0x11d3, {0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5} };
60 static const GUID DXVA2_ModeHEVC_VLD_Main = { 0x5b11d51b, 0x2f4c,0x4452, {0xbc, 0xc3, 0x09, 0xf2, 0xa1, 0x16, 0x0c, 0xc0} };
62 typedef struct
64 LPDIRECT3DSURFACE9 d3d;
65 int refcount;
66 unsigned int order;
68 } hb_va_surface_t;
70 typedef struct
72 uint8_t *base;
73 uint8_t *buffer;
74 size_t size;
76 } hb_copy_cache_t;
78 typedef struct
80 const char *name;
81 D3DFORMAT format;
82 uint32_t codec;
84 } hb_d3d_format_t;
86 typedef struct
88 const char *name;
89 const GUID *guid;
90 int codec;
91 } hb_dx_mode_t;
93 typedef struct
95 char *description;
96 int codec_id;
97 uint32_t i_chroma;
98 int width;
99 int height;
100 HINSTANCE hd3d9_dll;
101 HINSTANCE hdxva2_dll;
102 D3DPRESENT_PARAMETERS d3dpp;
103 LPDIRECT3D9 d3dobj;
104 D3DADAPTER_IDENTIFIER9 d3dai;
105 LPDIRECT3DDEVICE9 d3ddev;
106 UINT token;
107 IDirect3DDeviceManager9 *devmng;
108 HANDLE device;
109 IDirectXVideoDecoderService *vs;
110 GUID input;
111 D3DFORMAT render;
112 DXVA2_ConfigPictureDecode cfg;
113 IDirectXVideoDecoder *decoder;
114 D3DFORMAT output;
115 struct dxva_context hw;
116 unsigned surface_count;
117 unsigned surface_order;
118 int surface_width;
119 int surface_height;
120 uint32_t surface_chroma;
121 hb_va_surface_t surface[VA_DXVA2_MAX_SURFACE_COUNT];
122 LPDIRECT3DSURFACE9 hw_surface[VA_DXVA2_MAX_SURFACE_COUNT];
123 IDirectXVideoProcessorService *ps;
124 IDirectXVideoProcessor *vp;
125 int64_t input_pts[2];
126 int64_t input_dts;
127 int do_job;
129 // running nv12toyuv kernel.
130 cl_kernel nv12toyuv;
131 cl_mem cl_mem_nv12;
132 cl_mem cl_mem_yuv;
133 uint8_t * nv12toyuv_tmp_in;
134 uint8_t * nv12toyuv_tmp_out;
135 } hb_va_dxva2_t;
137 typedef struct FilterLink_T
139 cl_mem cl_inbuf;
140 cl_mem cl_outbuf;
142 uint8_t *mem_inbuf;
143 uint8_t *mem_outbuf;
144 int width;
145 int height;
146 int linesizeY;
147 int linesizeUV;
148 int inmemdataflag;
149 int outmemdataflag;
150 int incldataflag;
151 int outcldataflag;
152 int framenum;
153 int outputSize;
154 } T_FilterLink;
156 static const hb_d3d_format_t d3d_formats[] =
158 { "YV12", MAKEFOURCC( 'Y', 'V', '1', '2' ), HB_CODEC_YV12 },
159 { "NV12", MAKEFOURCC( 'N', 'V', '1', '2' ), HB_CODEC_NV12 },
160 { NULL, 0, 0 }
163 static const hb_dx_mode_t dxva2_modes[] =
165 { "DXVA2_ModeMPEG2_VLD", &DXVA2_ModeMPEG2_VLD, AV_CODEC_ID_MPEG2VIDEO },
166 { "DXVA2_ModeMPEG2_MoComp", &DXVA2_ModeMPEG2_MoComp, 0 },
167 { "DXVA2_ModeMPEG2_IDCT", &DXVA2_ModeMPEG2_IDCT, 0 },
169 { "H.264 variable-length decoder (VLD), FGT", &DXVA2_ModeH264_F, AV_CODEC_ID_H264 },
170 { "H.264 VLD, no FGT", &DXVA2_ModeH264_E, AV_CODEC_ID_H264 },
171 { "H.264 VLD, no FGT (Intel)", &DXVADDI_Intel_ModeH264_E, AV_CODEC_ID_H264 },
172 { "H.264 IDCT, FGT", &DXVA2_ModeH264_D, 0 },
173 { "H.264 inverse discrete cosine transform (IDCT), no FGT", &DXVA2_ModeH264_C, 0 },
174 { "H.264 inverse discrete cosine transform (IDCT), no FGT (Intel)", &DXVADDI_Intel_ModeH264_C, 0 },
175 { "H.264 MoComp, FGT", &DXVA2_ModeH264_B, 0 },
176 { "H.264 motion compensation (MoComp), no FGT", &DXVA2_ModeH264_A, 0 },
177 { "H.264 motion compensation (MoComp), no FGT (Intel)", &DXVADDI_Intel_ModeH264_A, 0 },
179 { "Windows Media Video 8 MoComp", &DXVA2_ModeWMV8_B, 0 },
180 { "Windows Media Video 8 post processing", &DXVA2_ModeWMV8_A, 0 },
182 { "Windows Media Video 9 IDCT", &DXVA2_ModeWMV9_C, 0 },
183 { "Windows Media Video 9 MoComp", &DXVA2_ModeWMV9_B, 0 },
184 { "Windows Media Video 9 post processing", &DXVA2_ModeWMV9_A, 0 },
186 { "VC-1 VLD", &DXVA2_ModeVC1_D, AV_CODEC_ID_VC1 },
187 { "VC-1 VLD", &DXVA2_ModeVC1_D, AV_CODEC_ID_WMV3 },
188 { "VC-1 IDCT", &DXVA2_ModeVC1_C, 0 },
189 { "VC-1 MoComp", &DXVA2_ModeVC1_B, 0 },
190 { "VC-1 post processing", &DXVA2_ModeVC1_A, 0 },
192 { "DXVA2_ModeHEVC_VLD_Main", &DXVA2_ModeHEVC_VLD_Main, AV_CODEC_ID_HEVC },
194 { NULL, NULL, 0 }
197 int hb_va_get_frame_buf( hb_va_dxva2_t *dxva2, AVCodecContext *p_context, AVFrame *frame );
198 int hb_va_extract( hb_va_dxva2_t *dxva2, uint8_t *dst, AVFrame *frame, int job_w, int job_h, int *crop, hb_oclscale_t *os, int use_opencl, int use_decomb, int use_detelecine );
199 enum PixelFormat hb_ffmpeg_get_format( AVCodecContext *, const enum PixelFormat * );
200 hb_va_dxva2_t *hb_va_create_dxva2( hb_va_dxva2_t *dxva2, int codec_id );
201 void hb_va_new_dxva2( hb_va_dxva2_t *dxva2, AVCodecContext *p_context );
202 void hb_va_release( hb_va_dxva2_t *dxva2, AVFrame *frame );
203 void hb_va_close( hb_va_dxva2_t *dxva2 );
204 int hb_check_hwd_fmt( int fmt );
206 #endif // HB_VA_DXVA2_H
208 #endif // USE_HWD