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/>
21 #include "libavcodec/dxva2.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} };
64 LPDIRECT3DSURFACE9 d3d
;
101 HINSTANCE hdxva2_dll
;
102 D3DPRESENT_PARAMETERS d3dpp
;
104 D3DADAPTER_IDENTIFIER9 d3dai
;
105 LPDIRECT3DDEVICE9 d3ddev
;
107 IDirect3DDeviceManager9
*devmng
;
109 IDirectXVideoDecoderService
*vs
;
112 DXVA2_ConfigPictureDecode cfg
;
113 IDirectXVideoDecoder
*decoder
;
115 struct dxva_context hw
;
116 unsigned surface_count
;
117 unsigned surface_order
;
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];
129 // running nv12toyuv kernel.
133 uint8_t * nv12toyuv_tmp_in
;
134 uint8_t * nv12toyuv_tmp_out
;
137 typedef struct FilterLink_T
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
},
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
},
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