Unified · Split
| @@ -12,6 +12,7 @@ version <next>: · 11 unmodified lines | ||
| 12 | 12 | - VP8 in Ogg demuxing |
| 13 | 13 | - OpenH264 encoder wrapper |
| 14 | 14 | - Support DNx100 (960x720@8) |
| 15 | +- Direct3D11-accelerated decoding | |
| 15 | 16 | - DXVA2-accelerated HEVC decoding |
| 16 | 17 | - AAC ELD 480 decoding |
| 17 | 18 | - Intel QSV-accelerated H.264 decoding |
| @@ -133,6 +133,7 @@ Component options: · 132 unmodified lines | ||
| 133 | 133 | --disable-faan disable floating point AAN (I)DCT code |
| 134 | 134 | |
| 135 | 135 | Hardware accelerators: |
| 136 | + --enable-d3d11va enable D3D11VA code | |
| 136 | 137 | --enable-dxva2 enable DXVA2 code |
| 137 | 138 | --enable-vaapi enable VAAPI code |
| 138 | 139 | --enable-vda enable VDA code |
| @@ -1206,6 +1207,7 @@ FEATURE_LIST=" · 1067 unmodified lines | ||
| 1206 | 1207 | " |
| 1207 | 1208 | |
| 1208 | 1209 | HWACCEL_LIST=" |
| 1210 | + d3d11va | |
| 1209 | 1211 | dxva2 |
| 1210 | 1212 | vaapi |
| 1211 | 1213 | vda |
| @@ -1396,6 +1398,7 @@ HEADERS_LIST=" · 184 unmodified lines | ||
| 1396 | 1398 | dev_video_meteor_ioctl_meteor_h |
| 1397 | 1399 | direct_h |
| 1398 | 1400 | dlfcn_h |
| 1401 | + d3d11_h | |
| 1399 | 1402 | dxva_h |
| 1400 | 1403 | gsm_h |
| 1401 | 1404 | io_h |
| @@ -1551,6 +1554,8 @@ HAVE_LIST=" · 149 unmodified lines | ||
| 1551 | 1554 | $TYPES_LIST |
| 1552 | 1555 | atomics_native |
| 1553 | 1556 | dos_paths |
| 1557 | + d3d11_cobj | |
| 1558 | + d3d11va_lib | |
| 1554 | 1559 | dxva2_lib |
| 1555 | 1560 | libc_msvcrt |
| 1556 | 1561 | libdc1394_1 |
| @@ -1965,6 +1970,7 @@ zmbv_decoder_deps="zlib" · 408 unmodified lines | ||
| 1965 | 1970 | zmbv_encoder_deps="zlib" |
| 1966 | 1971 | |
| 1967 | 1972 | # hardware accelerators |
| 1973 | +d3d11va_deps="d3d11_h dxva_h" | |
| 1968 | 1974 | dxva2_deps="dxva2api_h" |
| 1969 | 1975 | vaapi_deps="va_va_h" |
| 1970 | 1976 | vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads" |
| @@ -1975,6 +1981,8 @@ h263_vaapi_hwaccel_deps="vaapi" · 4 unmodified lines | ||
| 1975 | 1981 | h263_vaapi_hwaccel_select="h263_decoder" |
| 1976 | 1982 | h263_vdpau_hwaccel_deps="vdpau" |
| 1977 | 1983 | h263_vdpau_hwaccel_select="h263_decoder" |
| 1984 | +h264_d3d11va_hwaccel_deps="d3d11va" | |
| 1985 | +h264_d3d11va_hwaccel_select="h264_decoder" | |
| 1978 | 1986 | h264_dxva2_hwaccel_deps="dxva2" |
| 1979 | 1987 | h264_dxva2_hwaccel_select="h264_decoder" |
| 1980 | 1988 | h264_mmal_decoder_deps="mmal" |
| @@ -1990,10 +1998,14 @@ h264_vda_old_hwaccel_deps="vda" · 9 unmodified lines | ||
| 1990 | 1998 | h264_vda_old_hwaccel_select="h264_decoder" |
| 1991 | 1999 | h264_vdpau_hwaccel_deps="vdpau" |
| 1992 | 2000 | h264_vdpau_hwaccel_select="h264_decoder" |
| 2001 | +hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC" | |
| 2002 | +hevc_d3d11va_hwaccel_select="hevc_decoder" | |
| 1993 | 2003 | hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC" |
| 1994 | 2004 | hevc_dxva2_hwaccel_select="hevc_decoder" |
| 1995 | 2005 | mpeg1_vdpau_hwaccel_deps="vdpau" |
| 1996 | 2006 | mpeg1_vdpau_hwaccel_select="mpeg1video_decoder" |
| 2007 | +mpeg2_d3d11va_hwaccel_deps="d3d11va" | |
| 2008 | +mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder" | |
| 1997 | 2009 | mpeg2_dxva2_hwaccel_deps="dxva2" |
| 1998 | 2010 | mpeg2_dxva2_hwaccel_select="mpeg2video_decoder" |
| 1999 | 2011 | mpeg2_vaapi_hwaccel_deps="vaapi" |
| @@ -2004,12 +2016,15 @@ mpeg4_vaapi_hwaccel_deps="vaapi" · 4 unmodified lines | ||
| 2004 | 2016 | mpeg4_vaapi_hwaccel_select="mpeg4_decoder" |
| 2005 | 2017 | mpeg4_vdpau_hwaccel_deps="vdpau" |
| 2006 | 2018 | mpeg4_vdpau_hwaccel_select="mpeg4_decoder" |
| 2019 | +vc1_d3d11va_hwaccel_deps="d3d11va" | |
| 2020 | +vc1_d3d11va_hwaccel_select="vc1_decoder" | |
| 2007 | 2021 | vc1_dxva2_hwaccel_deps="dxva2" |
| 2008 | 2022 | vc1_dxva2_hwaccel_select="vc1_decoder" |
| 2009 | 2023 | vc1_vaapi_hwaccel_deps="vaapi" |
| 2010 | 2024 | vc1_vaapi_hwaccel_select="vc1_decoder" |
| 2011 | 2025 | vc1_vdpau_hwaccel_deps="vdpau" |
| 2012 | 2026 | vc1_vdpau_hwaccel_select="vc1_decoder" |
| 2027 | +wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel" | |
| 2013 | 2028 | wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel" |
| 2014 | 2029 | wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel" |
| 2015 | 2030 | wmv3_vdpau_hwaccel_select="vc1_vdpau_hwaccel" |
| @@ -2288,7 +2303,7 @@ enable swscale_alpha · 272 unmodified lines | ||
| 2288 | 2303 | enable valgrind_backtrace |
| 2289 | 2304 | |
| 2290 | 2305 | # By default, enable only those hwaccels that have no external dependencies. |
| 2291 | −enable dxva2 vda vdpau | |
| 2306 | +enable d3d11va dxva2 vda vdpau | |
| 2292 | 2307 | |
| 2293 | 2308 | # build settings |
| 2294 | 2309 | SHFLAGS='-shared -Wl,-soname,$$(@F)' |
| @@ -4155,6 +4170,7 @@ check_struct windows.h "CONDITION_VARIABLE" Ptr · 1860 unmodified lines | ||
| 4155 | 4170 | |
| 4156 | 4171 | check_header direct.h |
| 4157 | 4172 | check_header dlfcn.h |
| 4173 | +check_header d3d11.h | |
| 4158 | 4174 | check_header dxva.h |
| 4159 | 4175 | check_header dxva2api.h |
| 4160 | 4176 | check_header io.h |
| @@ -4372,6 +4388,15 @@ if enabled x11grab; then · 211 unmodified lines | ||
| 4372 | 4388 | require Xfixes X11/extensions/Xfixes.h XFixesGetCursorImage -lXfixes |
| 4373 | 4389 | fi |
| 4374 | 4390 | |
| 4391 | +enabled d3d11_h && | |
| 4392 | + check_cc <<EOF && enable d3d11_cobj | |
| 4393 | +#define _WIN32_WINNT 0x0600 | |
| 4394 | +#define COBJMACROS | |
| 4395 | +#include <windows.h> | |
| 4396 | +#include <d3d11.h> | |
| 4397 | +int main(void) { ID3D11VideoDecoder *o = NULL; ID3D11VideoDecoder_Release(o); return 0; } | |
| 4398 | +EOF | |
| 4399 | + | |
| 4375 | 4400 | enabled vaapi && enabled xlib && |
| 4376 | 4401 | check_lib2 "va/va.h va/va_x11.h" vaGetDisplay -lva -lva-x11 && |
| 4377 | 4402 | enable vaapi_x11 |
| @@ -4593,6 +4618,10 @@ check_deps $CONFIG_LIST \ · 215 unmodified lines | ||
| 4593 | 4618 | $HAVE_LIST \ |
| 4594 | 4619 | $ALL_COMPONENTS \ |
| 4595 | 4620 | |
| 4621 | +enabled_all d3d11va d3d11_cobj CoTaskMemFree && | |
| 4622 | + prepend avconv_libs $($ldflags_filter "-lole32") && | |
| 4623 | + enable d3d11va_lib | |
| 4624 | + | |
| 4596 | 4625 | enabled_all dxva2 CoTaskMemFree && |
| 4597 | 4626 | prepend avconv_libs $($ldflags_filter "-lole32") && |
| 4598 | 4627 | enable dxva2_lib |
| @@ -3,6 +3,7 @@ NAME = avcodec · 2 unmodified lines | ||
| 3 | 3 | HEADERS = avcodec.h \ |
| 4 | 4 | avfft.h \ |
| 5 | 5 | dv_profile.h \ |
| 6 | + d3d11va.h \ | |
| 6 | 7 | dxva2.h \ |
| 7 | 8 | qsv.h \ |
| 8 | 9 | vaapi.h \ |
| @@ -557,6 +558,7 @@ OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o adpcm_data.o · 548 unmodified lines | ||
| 557 | 558 | OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcmenc.o adpcm_data.o |
| 558 | 559 | |
| 559 | 560 | # hardware accelerators |
| 561 | +OBJS-$(CONFIG_D3D11VA) += dxva2.o | |
| 560 | 562 | OBJS-$(CONFIG_DXVA2) += dxva2.o |
| 561 | 563 | OBJS-$(CONFIG_VAAPI) += vaapi.o |
| 562 | 564 | OBJS-$(CONFIG_VDA) += vda.o |
| @@ -564,17 +566,21 @@ OBJS-$(CONFIG_VDPAU) += vdpau.o · 1 unmodified line | ||
| 564 | 566 | |
| 565 | 567 | OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o |
| 566 | 568 | OBJS-$(CONFIG_H263_VDPAU_HWACCEL) += vdpau_mpeg4.o |
| 569 | +OBJS-$(CONFIG_H264_D3D11VA_HWACCEL) += dxva2_h264.o | |
| 567 | 570 | OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o |
| 568 | 571 | OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o |
| 569 | 572 | OBJS-$(CONFIG_H264_VDA_HWACCEL) += vda_h264.o |
| 570 | 573 | OBJS-$(CONFIG_H264_VDPAU_HWACCEL) += vdpau_h264.o |
| 574 | +OBJS-$(CONFIG_HEVC_D3D11VA_HWACCEL) += dxva2_hevc.o | |
| 571 | 575 | OBJS-$(CONFIG_HEVC_DXVA2_HWACCEL) += dxva2_hevc.o |
| 572 | 576 | OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL) += vdpau_mpeg12.o |
| 577 | +OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL) += dxva2_mpeg2.o | |
| 573 | 578 | OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL) += dxva2_mpeg2.o |
| 574 | 579 | OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL) += vaapi_mpeg2.o |
| 575 | 580 | OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL) += vdpau_mpeg12.o |
| 576 | 581 | OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL) += vaapi_mpeg4.o |
| 577 | 582 | OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL) += vdpau_mpeg4.o |
| 583 | +OBJS-$(CONFIG_VC1_D3D11VA_HWACCEL) += dxva2_vc1.o | |
| 578 | 584 | OBJS-$(CONFIG_VC1_DXVA2_HWACCEL) += dxva2_vc1.o |
| 579 | 585 | OBJS-$(CONFIG_VC1_VAAPI_HWACCEL) += vaapi_vc1.o |
| 580 | 586 | OBJS-$(CONFIG_VC1_VDPAU_HWACCEL) += vdpau_vc1.o |
| @@ -723,6 +729,7 @@ SKIPHEADERS += %_tablegen.h \ · 142 unmodified lines | ||
| 723 | 729 | tableprint.h \ |
| 724 | 730 | $(ARCH)/vp56_arith.h \ |
| 725 | 731 | |
| 732 | +SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h | |
| 726 | 733 | SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h |
| 727 | 734 | SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h |
| 728 | 735 | SKIPHEADERS-$(CONFIG_MPEG_XVMC_DECODER) += xvmc.h |
| @@ -76,6 +76,7 @@ void avcodec_register_all(void) · 75 unmodified lines | ||
| 76 | 76 | /* hardware accelerators */ |
| 77 | 77 | REGISTER_HWACCEL(H263_VAAPI, h263_vaapi); |
| 78 | 78 | REGISTER_HWACCEL(H263_VDPAU, h263_vdpau); |
| 79 | + REGISTER_HWACCEL(H264_D3D11VA, h264_d3d11va); | |
| 79 | 80 | REGISTER_HWACCEL(H264_DXVA2, h264_dxva2); |
| 80 | 81 | REGISTER_HWACCEL(H264_MMAL, h264_mmal); |
| 81 | 82 | REGISTER_HWACCEL(H264_QSV, h264_qsv); |
| @@ -83,16 +84,20 @@ void avcodec_register_all(void) · 1 unmodified line | ||
| 83 | 84 | REGISTER_HWACCEL(H264_VDA, h264_vda); |
| 84 | 85 | REGISTER_HWACCEL(H264_VDA_OLD, h264_vda_old); |
| 85 | 86 | REGISTER_HWACCEL(H264_VDPAU, h264_vdpau); |
| 87 | + REGISTER_HWACCEL(HEVC_D3D11VA, hevc_d3d11va); | |
| 86 | 88 | REGISTER_HWACCEL(HEVC_DXVA2, hevc_dxva2); |
| 87 | 89 | REGISTER_HWACCEL(MPEG1_VDPAU, mpeg1_vdpau); |
| 90 | + REGISTER_HWACCEL(MPEG2_D3D11VA, mpeg2_d3d11va); | |
| 88 | 91 | REGISTER_HWACCEL(MPEG2_DXVA2, mpeg2_dxva2); |
| 89 | 92 | REGISTER_HWACCEL(MPEG2_VAAPI, mpeg2_vaapi); |
| 90 | 93 | REGISTER_HWACCEL(MPEG2_VDPAU, mpeg2_vdpau); |
| 91 | 94 | REGISTER_HWACCEL(MPEG4_VAAPI, mpeg4_vaapi); |
| 92 | 95 | REGISTER_HWACCEL(MPEG4_VDPAU, mpeg4_vdpau); |
| 96 | + REGISTER_HWACCEL(VC1_D3D11VA, vc1_d3d11va); | |
| 93 | 97 | REGISTER_HWACCEL(VC1_DXVA2, vc1_dxva2); |
| 94 | 98 | REGISTER_HWACCEL(VC1_VAAPI, vc1_vaapi); |
| 95 | 99 | REGISTER_HWACCEL(VC1_VDPAU, vc1_vdpau); |
| 100 | + REGISTER_HWACCEL(WMV3_D3D11VA, wmv3_d3d11va); | |
| 96 | 101 | REGISTER_HWACCEL(WMV3_DXVA2, wmv3_dxva2); |
| 97 | 102 | REGISTER_HWACCEL(WMV3_VAAPI, wmv3_vaapi); |
| 98 | 103 | REGISTER_HWACCEL(WMV3_VDPAU, wmv3_vdpau); |
| @@ -0,0 +1,98 @@ | ||
| 1 | +/* | |
| 2 | + * Direct3D11 HW acceleration | |
| 3 | + * | |
| 4 | + * copyright (c) 2009 Laurent Aimar | |
| 5 | + * copyright (c) 2015 Steve Lhomme | |
| 6 | + * | |
| 7 | + * This file is part of Libav. | |
| 8 | + * | |
| 9 | + * Libav is free software; you can redistribute it and/or | |
| 10 | + * modify it under the terms of the GNU Lesser General Public | |
| 11 | + * License as published by the Free Software Foundation; either | |
| 12 | + * version 2.1 of the License, or (at your option) any later version. | |
| 13 | + * | |
| 14 | + * Libav is distributed in the hope that it will be useful, | |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 | + * Lesser General Public License for more details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU Lesser General Public | |
| 20 | + * License along with Libav; if not, write to the Free Software | |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 22 | + */ | |
| 23 | + | |
| 24 | +#ifndef AVCODEC_D3D11VA_H | |
| 25 | +#define AVCODEC_D3D11VA_H | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * @file | |
| 29 | + * @ingroup lavc_codec_hwaccel_d3d11va | |
| 30 | + * Public libavcodec D3D11VA header. | |
| 31 | + */ | |
| 32 | + | |
| 33 | +#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600 | |
| 34 | +#undef _WIN32_WINNT | |
| 35 | +#define _WIN32_WINNT 0x0600 | |
| 36 | +#endif | |
| 37 | + | |
| 38 | +#include <stdint.h> | |
| 39 | +#include <d3d11.h> | |
| 40 | + | |
| 41 | +/** | |
| 42 | + * @defgroup lavc_codec_hwaccel_d3d11va Direct3D11 | |
| 43 | + * @ingroup lavc_codec_hwaccel | |
| 44 | + * | |
| 45 | + * @{ | |
| 46 | + */ | |
| 47 | + | |
| 48 | +#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for Direct3D11 and old UVD/UVD+ ATI video cards | |
| 49 | +#define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO 2 ///< Work around for Direct3D11 and old Intel GPUs with ClearVideo interface | |
| 50 | + | |
| 51 | +/** | |
| 52 | + * This structure is used to provides the necessary configurations and data | |
| 53 | + * to the Direct3D11 Libav HWAccel implementation. | |
| 54 | + * | |
| 55 | + * The application must make it available as AVCodecContext.hwaccel_context. | |
| 56 | + */ | |
| 57 | +struct AVD3D11VAContext { | |
| 58 | + /** | |
| 59 | + * D3D11 decoder object | |
| 60 | + */ | |
| 61 | + ID3D11VideoDecoder *decoder; | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * D3D11 VideoContext | |
| 65 | + */ | |
| 66 | + ID3D11VideoContext *video_context; | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * D3D11 configuration used to create the decoder | |
| 70 | + */ | |
| 71 | + D3D11_VIDEO_DECODER_CONFIG *cfg; | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * The number of surface in the surface array | |
| 75 | + */ | |
| 76 | + unsigned surface_count; | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * The array of Direct3D surfaces used to create the decoder | |
| 80 | + */ | |
| 81 | + ID3D11VideoDecoderOutputView **surface; | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * A bit field configuring the workarounds needed for using the decoder | |
| 85 | + */ | |
| 86 | + uint64_t workaround; | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * Private to the Libav AVHWAccel implementation | |
| 90 | + */ | |
| 91 | + unsigned report_id; | |
| 92 | +}; | |
| 93 | + | |
| 94 | +/** | |
| 95 | + * @} | |
| 96 | + */ | |
| 97 | + | |
| 98 | +#endif /* AVCODEC_D3D11VA_H */ | |
| @@ -35,14 +35,15 @@ void *ff_dxva2_get_surface(const AVFrame *frame) · 34 unmodified lines | ||
| 35 | 35 | return frame->data[3]; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | −unsigned ff_dxva2_get_surface_index(const struct dxva_context *ctx, | |
| 38 | +unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx, | |
| 39 | + const AVDXVAContext *ctx, | |
| 39 | 40 | const AVFrame *frame) |
| 40 | 41 | { |
| 41 | 42 | void *surface = ff_dxva2_get_surface(frame); |
| 42 | 43 | unsigned i; |
| 43 | 44 | |
| 44 | − for (i = 0; i < ctx->surface_count; i++) | |
| 45 | − if (ctx->surface[i] == surface) | |
| 45 | + for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++) | |
| 46 | + if (DXVA_CONTEXT_SURFACE(avctx, ctx, i) == surface) | |
| 46 | 47 | return i; |
| 47 | 48 | |
| 48 | 49 | assert(0); |
| @@ -50,8 +51,8 @@ unsigned ff_dxva2_get_surface_index(const struct dxva_context *ctx, · 1 unmodified line | ||
| 50 | 51 | } |
| 51 | 52 | |
| 52 | 53 | int ff_dxva2_commit_buffer(AVCodecContext *avctx, |
| 53 | − struct dxva_context *ctx, | |
| 54 | − DXVA2_DecodeBufferDesc *dsc, | |
| 54 | + AVDXVAContext *ctx, | |
| 55 | + DECODER_BUFFER_DESC *dsc, | |
| 55 | 56 | unsigned type, const void *data, unsigned size, |
| 56 | 57 | unsigned mb_count) |
| 57 | 58 | { |
| @@ -60,8 +61,18 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, · 2 unmodified lines | ||
| 60 | 61 | int result; |
| 61 | 62 | HRESULT hr; |
| 62 | 63 | |
| 63 | − hr = IDirectXVideoDecoder_GetBuffer(ctx->decoder, type, | |
| 64 | − &dxva_data, &dxva_size); | |
| 64 | +#if CONFIG_D3D11VA | |
| 65 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) | |
| 66 | + hr = ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, | |
| 67 | + D3D11VA_CONTEXT(ctx)->decoder, | |
| 68 | + type, | |
| 69 | + &dxva_size, &dxva_data); | |
| 70 | +#endif | |
| 71 | +#if CONFIG_DXVA2 | |
| 72 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) | |
| 73 | + hr = IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder, type, | |
| 74 | + &dxva_data, &dxva_size); | |
| 75 | +#endif | |
| 65 | 76 | if (FAILED(hr)) { |
| 66 | 77 | av_log(avctx, AV_LOG_ERROR, "Failed to get a buffer for %u: 0x%lx\n", |
| 67 | 78 | type, hr); |
| @@ -70,10 +81,24 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, · 2 unmodified lines | ||
| 70 | 81 | if (size <= dxva_size) { |
| 71 | 82 | memcpy(dxva_data, data, size); |
| 72 | 83 | |
| 73 | − memset(dsc, 0, sizeof(*dsc)); | |
| 74 | − dsc->CompressedBufferType = type; | |
| 75 | − dsc->DataSize = size; | |
| 76 | − dsc->NumMBsInBuffer = mb_count; | |
| 84 | +#if CONFIG_D3D11VA | |
| 85 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 86 | + D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = dsc; | |
| 87 | + memset(dsc11, 0, sizeof(*dsc11)); | |
| 88 | + dsc11->BufferType = type; | |
| 89 | + dsc11->DataSize = size; | |
| 90 | + dsc11->NumMBsInBuffer = mb_count; | |
| 91 | + } | |
| 92 | +#endif | |
| 93 | +#if CONFIG_DXVA2 | |
| 94 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 95 | + DXVA2_DecodeBufferDesc *dsc2 = dsc; | |
| 96 | + memset(dsc2, 0, sizeof(*dsc2)); | |
| 97 | + dsc2->CompressedBufferType = type; | |
| 98 | + dsc2->DataSize = size; | |
| 99 | + dsc2->NumMBsInBuffer = mb_count; | |
| 100 | + } | |
| 101 | +#endif | |
| 77 | 102 | |
| 78 | 103 | result = 0; |
| 79 | 104 | } else { |
| @@ -81,7 +106,14 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, · 1 unmodified line | ||
| 81 | 106 | result = -1; |
| 82 | 107 | } |
| 83 | 108 | |
| 84 | − hr = IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, type); | |
| 109 | +#if CONFIG_D3D11VA | |
| 110 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) | |
| 111 | + hr = ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type); | |
| 112 | +#endif | |
| 113 | +#if CONFIG_DXVA2 | |
| 114 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) | |
| 115 | + hr = IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type); | |
| 116 | +#endif | |
| 85 | 117 | if (FAILED(hr)) { |
| 86 | 118 | av_log(avctx, AV_LOG_ERROR, |
| 87 | 119 | "Failed to release buffer type %u: 0x%lx\n", |
| @@ -95,20 +127,31 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, · 7 unmodified lines | ||
| 95 | 127 | const void *pp, unsigned pp_size, |
| 96 | 128 | const void *qm, unsigned qm_size, |
| 97 | 129 | int (*commit_bs_si)(AVCodecContext *, |
| 98 | − DXVA2_DecodeBufferDesc *bs, | |
| 99 | − DXVA2_DecodeBufferDesc *slice)) | |
| 130 | + DECODER_BUFFER_DESC *bs, | |
| 131 | + DECODER_BUFFER_DESC *slice)) | |
| 100 | 132 | { |
| 101 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 133 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 102 | 134 | unsigned buffer_count = 0; |
| 103 | − DXVA2_DecodeBufferDesc buffer[4]; | |
| 104 | − DXVA2_DecodeExecuteParams exec = { 0 }; | |
| 135 | + D3D11_VIDEO_DECODER_BUFFER_DESC buffer11[4]; | |
| 136 | + DXVA2_DecodeBufferDesc buffer2[4]; | |
| 137 | + DECODER_BUFFER_DESC *buffer,*buffer_slice; | |
| 105 | 138 | int result, runs = 0; |
| 106 | 139 | HRESULT hr; |
| 140 | + unsigned type; | |
| 107 | 141 | |
| 108 | 142 | do { |
| 109 | − hr = IDirectXVideoDecoder_BeginFrame(ctx->decoder, | |
| 110 | − ff_dxva2_get_surface(frame), | |
| 111 | − NULL); | |
| 143 | +#if CONFIG_D3D11VA | |
| 144 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) | |
| 145 | + hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, | |
| 146 | + ff_dxva2_get_surface(frame), | |
| 147 | + 0, NULL); | |
| 148 | +#endif | |
| 149 | +#if CONFIG_DXVA2 | |
| 150 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) | |
| 151 | + hr = IDirectXVideoDecoder_BeginFrame(DXVA2_CONTEXT(ctx)->decoder, | |
| 152 | + ff_dxva2_get_surface(frame), | |
| 153 | + NULL); | |
| 154 | +#endif | |
| 112 | 155 | if (hr == E_PENDING) |
| 113 | 156 | av_usleep(2000); |
| 114 | 157 | } while (hr == E_PENDING && ++runs < 50); |
| @@ -118,8 +161,20 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, · 3 unmodified lines | ||
| 118 | 161 | return -1; |
| 119 | 162 | } |
| 120 | 163 | |
| 121 | − result = ff_dxva2_commit_buffer(avctx, ctx, &buffer[buffer_count], | |
| 122 | − DXVA2_PictureParametersBufferType, | |
| 164 | +#if CONFIG_D3D11VA | |
| 165 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 166 | + buffer = &buffer11[buffer_count]; | |
| 167 | + type = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS; | |
| 168 | + } | |
| 169 | +#endif | |
| 170 | +#if CONFIG_DXVA2 | |
| 171 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 172 | + buffer = &buffer2[buffer_count]; | |
| 173 | + type = DXVA2_PictureParametersBufferType; | |
| 174 | + } | |
| 175 | +#endif | |
| 176 | + result = ff_dxva2_commit_buffer(avctx, ctx, buffer, | |
| 177 | + type, | |
| 123 | 178 | pp, pp_size, 0); |
| 124 | 179 | if (result) { |
| 125 | 180 | av_log(avctx, AV_LOG_ERROR, |
| @@ -129,8 +184,20 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, · 3 unmodified lines | ||
| 129 | 184 | buffer_count++; |
| 130 | 185 | |
| 131 | 186 | if (qm_size > 0) { |
| 132 | − result = ff_dxva2_commit_buffer(avctx, ctx, &buffer[buffer_count], | |
| 133 | − DXVA2_InverseQuantizationMatrixBufferType, | |
| 187 | +#if CONFIG_D3D11VA | |
| 188 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 189 | + buffer = &buffer11[buffer_count]; | |
| 190 | + type = D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX; | |
| 191 | + } | |
| 192 | +#endif | |
| 193 | +#if CONFIG_DXVA2 | |
| 194 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 195 | + buffer = &buffer2[buffer_count]; | |
| 196 | + type = DXVA2_InverseQuantizationMatrixBufferType; | |
| 197 | + } | |
| 198 | +#endif | |
| 199 | + result = ff_dxva2_commit_buffer(avctx, ctx, buffer, | |
| 200 | + type, | |
| 134 | 201 | qm, qm_size, 0); |
| 135 | 202 | if (result) { |
| 136 | 203 | av_log(avctx, AV_LOG_ERROR, |
| @@ -140,9 +207,22 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, · 3 unmodified lines | ||
| 140 | 207 | buffer_count++; |
| 141 | 208 | } |
| 142 | 209 | |
| 210 | +#if CONFIG_D3D11VA | |
| 211 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 212 | + buffer = &buffer11[buffer_count + 0]; | |
| 213 | + buffer_slice = &buffer11[buffer_count + 1]; | |
| 214 | + } | |
| 215 | +#endif | |
| 216 | +#if CONFIG_DXVA2 | |
| 217 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 218 | + buffer = &buffer2[buffer_count + 0]; | |
| 219 | + buffer_slice = &buffer2[buffer_count + 1]; | |
| 220 | + } | |
| 221 | +#endif | |
| 222 | + | |
| 143 | 223 | result = commit_bs_si(avctx, |
| 144 | − &buffer[buffer_count + 0], | |
| 145 | − &buffer[buffer_count + 1]); | |
| 224 | + buffer, | |
| 225 | + buffer_slice); | |
| 146 | 226 | if (result) { |
| 147 | 227 | av_log(avctx, AV_LOG_ERROR, |
| 148 | 228 | "Failed to add bitstream or slice control buffer\n"); |
| @@ -154,17 +234,36 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, · 5 unmodified lines | ||
| 154 | 234 | |
| 155 | 235 | assert(buffer_count == 1 + (qm_size > 0) + 2); |
| 156 | 236 | |
| 157 | − exec.NumCompBuffers = buffer_count; | |
| 158 | − exec.pCompressedBuffers = buffer; | |
| 159 | − exec.pExtensionData = NULL; | |
| 160 | − hr = IDirectXVideoDecoder_Execute(ctx->decoder, &exec); | |
| 237 | +#if CONFIG_D3D11VA | |
| 238 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) | |
| 239 | + hr = ID3D11VideoContext_SubmitDecoderBuffers(D3D11VA_CONTEXT(ctx)->video_context, | |
| 240 | + D3D11VA_CONTEXT(ctx)->decoder, | |
| 241 | + buffer_count, buffer11); | |
| 242 | +#endif | |
| 243 | +#if CONFIG_DXVA2 | |
| 244 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 245 | + DXVA2_DecodeExecuteParams exec = { | |
| 246 | + .NumCompBuffers = buffer_count, | |
| 247 | + .pCompressedBuffers = buffer2, | |
| 248 | + .pExtensionData = NULL, | |
| 249 | + }; | |
| 250 | + hr = IDirectXVideoDecoder_Execute(DXVA2_CONTEXT(ctx)->decoder, &exec); | |
| 251 | + } | |
| 252 | +#endif | |
| 161 | 253 | if (FAILED(hr)) { |
| 162 | 254 | av_log(avctx, AV_LOG_ERROR, "Failed to execute: 0x%lx\n", hr); |
| 163 | 255 | result = -1; |
| 164 | 256 | } |
| 165 | 257 | |
| 166 | 258 | end: |
| 167 | − hr = IDirectXVideoDecoder_EndFrame(ctx->decoder, NULL); | |
| 259 | +#if CONFIG_D3D11VA | |
| 260 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) | |
| 261 | + hr = ID3D11VideoContext_DecoderEndFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder); | |
| 262 | +#endif | |
| 263 | +#if CONFIG_DXVA2 | |
| 264 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) | |
| 265 | + hr = IDirectXVideoDecoder_EndFrame(DXVA2_CONTEXT(ctx)->decoder, NULL); | |
| 266 | +#endif | |
| 168 | 267 | if (FAILED(hr)) { |
| 169 | 268 | av_log(avctx, AV_LOG_ERROR, "Failed to end frame: 0x%lx\n", hr); |
| 170 | 269 | result = -1; |
| @@ -42,7 +42,7 @@ static void fill_picture_entry(DXVA_PicEntry_H264 *pic, · 41 unmodified lines | ||
| 42 | 42 | pic->bPicEntry = index | (flag << 7); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | −static void fill_picture_parameters(struct dxva_context *ctx, const H264Context *h, | |
| 45 | +static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, const H264Context *h, | |
| 46 | 46 | DXVA_PicParams_H264 *pp) |
| 47 | 47 | { |
| 48 | 48 | const H264Picture *current_picture = h->cur_pic_ptr; |
| @@ -51,7 +51,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context · 2 unmodified lines | ||
| 51 | 51 | memset(pp, 0, sizeof(*pp)); |
| 52 | 52 | /* Configure current picture */ |
| 53 | 53 | fill_picture_entry(&pp->CurrPic, |
| 54 | − ff_dxva2_get_surface_index(ctx, current_picture->f), | |
| 54 | + ff_dxva2_get_surface_index(avctx, ctx, current_picture->f), | |
| 55 | 55 | h->picture_structure == PICT_BOTTOM_FIELD); |
| 56 | 56 | /* Configure the set of references */ |
| 57 | 57 | pp->UsedForReferenceFlags = 0; |
| @@ -67,7 +67,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context · 9 unmodified lines | ||
| 67 | 67 | } |
| 68 | 68 | if (r) { |
| 69 | 69 | fill_picture_entry(&pp->RefFrameList[i], |
| 70 | − ff_dxva2_get_surface_index(ctx, r->f), | |
| 70 | + ff_dxva2_get_surface_index(avctx, ctx, r->f), | |
| 71 | 71 | r->long_ref != 0); |
| 72 | 72 | |
| 73 | 73 | if ((r->reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX) |
| @@ -114,13 +114,13 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context · 40 unmodified lines | ||
| 114 | 114 | |
| 115 | 115 | pp->bit_depth_luma_minus8 = h->sps.bit_depth_luma - 8; |
| 116 | 116 | pp->bit_depth_chroma_minus8 = h->sps.bit_depth_chroma - 8; |
| 117 | − if (ctx->workaround & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) | |
| 117 | + if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) | |
| 118 | 118 | pp->Reserved16Bits = 0; |
| 119 | − else if (ctx->workaround & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO) | |
| 119 | + else if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO) | |
| 120 | 120 | pp->Reserved16Bits = 0x34c; |
| 121 | 121 | else |
| 122 | 122 | pp->Reserved16Bits = 3; /* FIXME is there a way to detect the right mode ? */ |
| 123 | − pp->StatusReportFeedbackNumber = 1 + ctx->report_id++; | |
| 123 | + pp->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(avctx, ctx)++; | |
| 124 | 124 | pp->CurrFieldOrderCnt[0] = 0; |
| 125 | 125 | if ((h->picture_structure & PICT_TOP_FIELD) && |
| 126 | 126 | current_picture->field_poc[0] != INT_MAX) |
| @@ -156,11 +156,11 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context · 29 unmodified lines | ||
| 156 | 156 | //pp->SliceGroupMap[810]; /* XXX not implemented by Libav */ |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | −static void fill_scaling_lists(struct dxva_context *ctx, const H264Context *h, DXVA_Qmatrix_H264 *qm) | |
| 159 | +static void fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext *ctx, const H264Context *h, DXVA_Qmatrix_H264 *qm) | |
| 160 | 160 | { |
| 161 | 161 | unsigned i, j; |
| 162 | 162 | memset(qm, 0, sizeof(*qm)); |
| 163 | − if (ctx->workaround & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) { | |
| 163 | + if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) { | |
| 164 | 164 | for (i = 0; i < 6; i++) |
| 165 | 165 | for (j = 0; j < 16; j++) |
| 166 | 166 | qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][j]; |
| @@ -181,11 +181,11 @@ static void fill_scaling_lists(struct dxva_context *ctx, const H264Context *h, D · 14 unmodified lines | ||
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | −static int is_slice_short(struct dxva_context *ctx) | |
| 184 | +static int is_slice_short(const AVCodecContext *avctx, AVDXVAContext *ctx) | |
| 185 | 185 | { |
| 186 | − assert(ctx->cfg->ConfigBitstreamRaw == 1 || | |
| 187 | − ctx->cfg->ConfigBitstreamRaw == 2); | |
| 188 | − return ctx->cfg->ConfigBitstreamRaw == 2; | |
| 186 | + assert(DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 1 || | |
| 187 | + DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 2); | |
| 188 | + return DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) == 2; | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | static void fill_slice_short(DXVA_Slice_H264_Short *slice, |
| @@ -212,7 +212,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, · 20 unmodified lines | ||
| 212 | 212 | { |
| 213 | 213 | const H264Context *h = avctx->priv_data; |
| 214 | 214 | H264SliceContext *sl = &h->slice_ctx[0]; |
| 215 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 215 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 216 | 216 | unsigned list; |
| 217 | 217 | |
| 218 | 218 | memset(slice, 0, sizeof(*slice)); |
| @@ -243,10 +243,10 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, · 24 unmodified lines | ||
| 243 | 243 | const H264Picture *r = sl->ref_list[list][i].parent; |
| 244 | 244 | unsigned plane; |
| 245 | 245 | unsigned index; |
| 246 | − if (ctx->workaround & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO) | |
| 247 | − index = ff_dxva2_get_surface_index(ctx, r->f); | |
| 246 | + if (DXVA_CONTEXT_WORKAROUND(avctx, ctx) & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO) | |
| 247 | + index = ff_dxva2_get_surface_index(avctx, ctx, r->f); | |
| 248 | 248 | else |
| 249 | − index = get_refpic_index(pp, ff_dxva2_get_surface_index(ctx, r->f)); | |
| 249 | + index = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, r->f)); | |
| 250 | 250 | fill_picture_entry(&slice->RefPicList[list][i], index, |
| 251 | 251 | r->reference == PICT_BOTTOM_FIELD); |
| 252 | 252 | for (plane = 0; plane < 3; plane++) { |
| @@ -289,12 +289,12 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, · 36 unmodified lines | ||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, |
| 292 | − DXVA2_DecodeBufferDesc *bs, | |
| 293 | − DXVA2_DecodeBufferDesc *sc) | |
| 292 | + DECODER_BUFFER_DESC *bs, | |
| 293 | + DECODER_BUFFER_DESC *sc) | |
| 294 | 294 | { |
| 295 | 295 | const H264Context *h = avctx->priv_data; |
| 296 | 296 | const unsigned mb_count = h->mb_width * h->mb_height; |
| 297 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 297 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 298 | 298 | const H264Picture *current_picture = h->cur_pic_ptr; |
| 299 | 299 | struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private; |
| 300 | 300 | DXVA_Slice_H264_Short *slice = NULL; |
| @@ -305,12 +305,28 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 4 unmodified lines | ||
| 305 | 305 | unsigned slice_size; |
| 306 | 306 | unsigned padding; |
| 307 | 307 | unsigned i; |
| 308 | + unsigned type; | |
| 308 | 309 | |
| 309 | 310 | /* Create an annex B bitstream buffer with only slice NAL and finalize slice */ |
| 310 | − if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder, | |
| 311 | − DXVA2_BitStreamDateBufferType, | |
| 312 | − &dxva_data_ptr, &dxva_size))) | |
| 313 | − return -1; | |
| 311 | +#if CONFIG_D3D11VA | |
| 312 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 313 | + type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM; | |
| 314 | + if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, | |
| 315 | + D3D11VA_CONTEXT(ctx)->decoder, | |
| 316 | + type, | |
| 317 | + &dxva_size, &dxva_data_ptr))) | |
| 318 | + return -1; | |
| 319 | + } | |
| 320 | +#endif | |
| 321 | +#if CONFIG_DXVA2 | |
| 322 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 323 | + type = DXVA2_BitStreamDateBufferType; | |
| 324 | + if (FAILED(IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder, | |
| 325 | + type, | |
| 326 | + &dxva_data_ptr, &dxva_size))) | |
| 327 | + return -1; | |
| 328 | + } | |
| 329 | +#endif | |
| 314 | 330 | |
| 315 | 331 | dxva_data = dxva_data_ptr; |
| 316 | 332 | current = dxva_data; |
| @@ -326,7 +342,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 9 unmodified lines | ||
| 326 | 342 | assert(offsetof(DXVA_Slice_H264_Short, SliceBytesInBuffer) == |
| 327 | 343 | offsetof(DXVA_Slice_H264_Long, SliceBytesInBuffer)); |
| 328 | 344 | |
| 329 | − if (is_slice_short(ctx)) | |
| 345 | + if (is_slice_short(avctx, ctx)) | |
| 330 | 346 | slice = &ctx_pic->slice_short[i]; |
| 331 | 347 | else |
| 332 | 348 | slice = (DXVA_Slice_H264_Short*)&ctx_pic->slice_long[i]; |
| @@ -341,7 +357,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 8 unmodified lines | ||
| 341 | 357 | slice->BSNALunitDataLocation = current - dxva_data; |
| 342 | 358 | slice->SliceBytesInBuffer = start_code_size + size; |
| 343 | 359 | |
| 344 | − if (!is_slice_short(ctx)) { | |
| 360 | + if (!is_slice_short(avctx, ctx)) { | |
| 345 | 361 | DXVA_Slice_H264_Long *slice_long = (DXVA_Slice_H264_Long*)slice; |
| 346 | 362 | if (i < ctx_pic->slice_count - 1) |
| 347 | 363 | slice_long->NumMbsForSlice = |
| @@ -363,18 +379,43 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 15 unmodified lines | ||
| 363 | 379 | |
| 364 | 380 | slice->SliceBytesInBuffer += padding; |
| 365 | 381 | } |
| 366 | − if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, | |
| 367 | − DXVA2_BitStreamDateBufferType))) | |
| 368 | − return -1; | |
| 382 | +#if CONFIG_D3D11VA | |
| 383 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) | |
| 384 | + if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type))) | |
| 385 | + return -1; | |
| 386 | +#endif | |
| 387 | +#if CONFIG_DXVA2 | |
| 388 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) | |
| 389 | + if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type))) | |
| 390 | + return -1; | |
| 391 | +#endif | |
| 369 | 392 | if (i < ctx_pic->slice_count) |
| 370 | 393 | return -1; |
| 371 | 394 | |
| 372 | − memset(bs, 0, sizeof(*bs)); | |
| 373 | − bs->CompressedBufferType = DXVA2_BitStreamDateBufferType; | |
| 374 | − bs->DataSize = current - dxva_data; | |
| 375 | − bs->NumMBsInBuffer = mb_count; | |
| 395 | +#if CONFIG_D3D11VA | |
| 396 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 397 | + D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs; | |
| 398 | + memset(dsc11, 0, sizeof(*dsc11)); | |
| 399 | + dsc11->BufferType = type; | |
| 400 | + dsc11->DataSize = current - dxva_data; | |
| 401 | + dsc11->NumMBsInBuffer = mb_count; | |
| 376 | 402 | |
| 377 | − if (is_slice_short(ctx)) { | |
| 403 | + type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL; | |
| 404 | + } | |
| 405 | +#endif | |
| 406 | +#if CONFIG_DXVA2 | |
| 407 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 408 | + DXVA2_DecodeBufferDesc *dsc2 = bs; | |
| 409 | + memset(dsc2, 0, sizeof(*dsc2)); | |
| 410 | + dsc2->CompressedBufferType = type; | |
| 411 | + dsc2->DataSize = current - dxva_data; | |
| 412 | + dsc2->NumMBsInBuffer = mb_count; | |
| 413 | + | |
| 414 | + type = DXVA2_SliceControlBufferType; | |
| 415 | + } | |
| 416 | +#endif | |
| 417 | + | |
| 418 | + if (is_slice_short(avctx, ctx)) { | |
| 378 | 419 | slice_data = ctx_pic->slice_short; |
| 379 | 420 | slice_size = ctx_pic->slice_count * sizeof(*ctx_pic->slice_short); |
| 380 | 421 | } else { |
| @@ -383,7 +424,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 2 unmodified lines | ||
| 383 | 424 | } |
| 384 | 425 | assert((bs->DataSize & 127) == 0); |
| 385 | 426 | return ff_dxva2_commit_buffer(avctx, ctx, sc, |
| 386 | − DXVA2_SliceControlBufferType, | |
| 427 | + type, | |
| 387 | 428 | slice_data, slice_size, mb_count); |
| 388 | 429 | } |
| 389 | 430 | |
| @@ -393,18 +434,20 @@ static int dxva2_h264_start_frame(AVCodecContext *avctx, · 3 unmodified lines | ||
| 393 | 434 | av_unused uint32_t size) |
| 394 | 435 | { |
| 395 | 436 | const H264Context *h = avctx->priv_data; |
| 396 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 437 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 397 | 438 | struct dxva2_picture_context *ctx_pic = h->cur_pic_ptr->hwaccel_picture_private; |
| 398 | 439 | |
| 399 | − if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) | |
| 440 | + if (DXVA_CONTEXT_DECODER(avctx, ctx) == NULL || | |
| 441 | + DXVA_CONTEXT_CFG(avctx, ctx) == NULL || | |
| 442 | + DXVA_CONTEXT_COUNT(avctx, ctx) <= 0) | |
| 400 | 443 | return -1; |
| 401 | 444 | assert(ctx_pic); |
| 402 | 445 | |
| 403 | 446 | /* Fill up DXVA_PicParams_H264 */ |
| 404 | − fill_picture_parameters(ctx, h, &ctx_pic->pp); | |
| 447 | + fill_picture_parameters(avctx, ctx, h, &ctx_pic->pp); | |
| 405 | 448 | |
| 406 | 449 | /* Fill up DXVA_Qmatrix_H264 */ |
| 407 | − fill_scaling_lists(ctx, h, &ctx_pic->qm); | |
| 450 | + fill_scaling_lists(avctx, ctx, h, &ctx_pic->qm); | |
| 408 | 451 | |
| 409 | 452 | ctx_pic->slice_count = 0; |
| 410 | 453 | ctx_pic->bitstream_size = 0; |
| @@ -418,7 +461,7 @@ static int dxva2_h264_decode_slice(AVCodecContext *avctx, · 7 unmodified lines | ||
| 418 | 461 | { |
| 419 | 462 | const H264Context *h = avctx->priv_data; |
| 420 | 463 | const H264SliceContext *sl = &h->slice_ctx[0]; |
| 421 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 464 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 422 | 465 | const H264Picture *current_picture = h->cur_pic_ptr; |
| 423 | 466 | struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private; |
| 424 | 467 | unsigned position; |
| @@ -431,7 +474,7 @@ static int dxva2_h264_decode_slice(AVCodecContext *avctx, · 6 unmodified lines | ||
| 431 | 474 | ctx_pic->bitstream_size += size; |
| 432 | 475 | |
| 433 | 476 | position = buffer - ctx_pic->bitstream; |
| 434 | − if (is_slice_short(ctx)) | |
| 477 | + if (is_slice_short(avctx, ctx)) | |
| 435 | 478 | fill_slice_short(&ctx_pic->slice_short[ctx_pic->slice_count], |
| 436 | 479 | position, size); |
| 437 | 480 | else |
| @@ -463,6 +506,7 @@ static int dxva2_h264_end_frame(AVCodecContext *avctx) · 25 unmodified lines | ||
| 463 | 506 | return ret; |
| 464 | 507 | } |
| 465 | 508 | |
| 509 | +#if CONFIG_H264_DXVA2_HWACCEL | |
| 466 | 510 | AVHWAccel ff_h264_dxva2_hwaccel = { |
| 467 | 511 | .name = "h264_dxva2", |
| 468 | 512 | .type = AVMEDIA_TYPE_VIDEO, |
| @@ -473,3 +517,17 @@ AVHWAccel ff_h264_dxva2_hwaccel = { · 4 unmodified lines | ||
| 473 | 517 | .end_frame = dxva2_h264_end_frame, |
| 474 | 518 | .frame_priv_data_size = sizeof(struct dxva2_picture_context), |
| 475 | 519 | }; |
| 520 | +#endif | |
| 521 | + | |
| 522 | +#if CONFIG_H264_D3D11VA_HWACCEL | |
| 523 | +AVHWAccel ff_h264_d3d11va_hwaccel = { | |
| 524 | + .name = "h264_d3d11va", | |
| 525 | + .type = AVMEDIA_TYPE_VIDEO, | |
| 526 | + .id = AV_CODEC_ID_H264, | |
| 527 | + .pix_fmt = AV_PIX_FMT_D3D11VA_VLD, | |
| 528 | + .start_frame = dxva2_h264_start_frame, | |
| 529 | + .decode_slice = dxva2_h264_decode_slice, | |
| 530 | + .end_frame = dxva2_h264_end_frame, | |
| 531 | + .frame_priv_data_size = sizeof(struct dxva2_picture_context), | |
| 532 | +}; | |
| 533 | +#endif | |
| @@ -53,7 +53,7 @@ static int get_refpic_index(const DXVA_PicParams_HEVC *pp, int surface_index) · 52 unmodified lines | ||
| 53 | 53 | return 0xff; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | −static void fill_picture_parameters(struct dxva_context *ctx, const HEVCContext *h, | |
| 56 | +static void fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *ctx, const HEVCContext *h, | |
| 57 | 57 | DXVA_PicParams_HEVC *pp) |
| 58 | 58 | { |
| 59 | 59 | const HEVCFrame *current_picture = h->ref; |
| @@ -73,7 +73,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const HEVCContext · 13 unmodified lines | ||
| 73 | 73 | (0 << 14) | |
| 74 | 74 | (0 << 15); |
| 75 | 75 | |
| 76 | − fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(ctx, current_picture->frame), 0); | |
| 76 | + fill_picture_entry(&pp->CurrPic, ff_dxva2_get_surface_index(avctx, ctx, current_picture->frame), 0); | |
| 77 | 77 | |
| 78 | 78 | pp->sps_max_dec_pic_buffering_minus1 = h->sps->temporal_layer[h->sps->max_sub_layers - 1].max_dec_pic_buffering - 1; |
| 79 | 79 | pp->log2_min_luma_coding_block_size_minus3 = h->sps->log2_min_cb_size - 3; |
| @@ -165,7 +165,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const HEVCContext · 85 unmodified lines | ||
| 165 | 165 | for (i = 0, j = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) { |
| 166 | 166 | const HEVCFrame *frame = &h->DPB[i]; |
| 167 | 167 | if (frame != current_picture && (frame->flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) { |
| 168 | − fill_picture_entry(&pp->RefPicList[j], ff_dxva2_get_surface_index(ctx, frame->frame), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF)); | |
| 168 | + fill_picture_entry(&pp->RefPicList[j], ff_dxva2_get_surface_index(avctx, ctx, frame->frame), !!(frame->flags & HEVC_FRAME_FLAG_LONG_REF)); | |
| 169 | 169 | pp->PicOrderCntValList[j] = frame->poc; |
| 170 | 170 | j++; |
| 171 | 171 | } |
| @@ -176,7 +176,7 @@ static void fill_picture_parameters(struct dxva_context *ctx, const HEVCContext · 4 unmodified lines | ||
| 176 | 176 | av_assert0(rpl->nb_refs <= FF_ARRAY_ELEMS(pp->ref_list)); \ |
| 177 | 177 | for (j = 0, k = 0; j < rpl->nb_refs; j++) { \ |
| 178 | 178 | if (rpl->ref[j]) { \ |
| 179 | − pp->ref_list[k] = get_refpic_index(pp, ff_dxva2_get_surface_index(ctx, rpl->ref[j]->frame)); \ | |
| 179 | + pp->ref_list[k] = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, rpl->ref[j]->frame)); \ | |
| 180 | 180 | k++; \ |
| 181 | 181 | } \ |
| 182 | 182 | } \ |
| @@ -187,10 +187,10 @@ static void fill_picture_parameters(struct dxva_context *ctx, const HEVCContext · 4 unmodified lines | ||
| 187 | 187 | DO_REF_LIST(ST_CURR_AFT, RefPicSetStCurrAfter); |
| 188 | 188 | DO_REF_LIST(LT_CURR, RefPicSetLtCurr); |
| 189 | 189 | |
| 190 | − pp->StatusReportFeedbackNumber = 1 + ctx->report_id++; | |
| 190 | + pp->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(avctx, ctx)++; | |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | −static void fill_scaling_lists(struct dxva_context *ctx, const HEVCContext *h, DXVA_Qmatrix_HEVC *qm) | |
| 193 | +static void fill_scaling_lists(AVDXVAContext *ctx, const HEVCContext *h, DXVA_Qmatrix_HEVC *qm) | |
| 194 | 194 | { |
| 195 | 195 | unsigned i, j, pos; |
| 196 | 196 | const ScalingList *sl = h->pps->scaling_list_data_present_flag ? |
| @@ -228,11 +228,11 @@ static void fill_slice_short(DXVA_Slice_HEVC_Short *slice, · 31 unmodified lines | ||
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, |
| 231 | − DXVA2_DecodeBufferDesc *bs, | |
| 232 | − DXVA2_DecodeBufferDesc *sc) | |
| 231 | + DECODER_BUFFER_DESC *bs, | |
| 232 | + DECODER_BUFFER_DESC *sc) | |
| 233 | 233 | { |
| 234 | 234 | const HEVCContext *h = avctx->priv_data; |
| 235 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 235 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 236 | 236 | const HEVCFrame *current_picture = h->ref; |
| 237 | 237 | struct hevc_dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private; |
| 238 | 238 | DXVA_Slice_HEVC_Short *slice = NULL; |
| @@ -243,12 +243,28 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 4 unmodified lines | ||
| 243 | 243 | unsigned slice_size; |
| 244 | 244 | unsigned padding; |
| 245 | 245 | unsigned i; |
| 246 | + unsigned type; | |
| 246 | 247 | |
| 247 | 248 | /* Create an annex B bitstream buffer with only slice NAL and finalize slice */ |
| 248 | − if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder, | |
| 249 | − DXVA2_BitStreamDateBufferType, | |
| 250 | − &dxva_data_ptr, &dxva_size))) | |
| 251 | − return -1; | |
| 249 | +#if CONFIG_D3D11VA | |
| 250 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 251 | + type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM; | |
| 252 | + if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, | |
| 253 | + D3D11VA_CONTEXT(ctx)->decoder, | |
| 254 | + type, | |
| 255 | + &dxva_size, &dxva_data_ptr))) | |
| 256 | + return -1; | |
| 257 | + } | |
| 258 | +#endif | |
| 259 | +#if CONFIG_DXVA2 | |
| 260 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 261 | + type = DXVA2_BitStreamDateBufferType; | |
| 262 | + if (FAILED(IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder, | |
| 263 | + type, | |
| 264 | + &dxva_data_ptr, &dxva_size))) | |
| 265 | + return -1; | |
| 266 | + } | |
| 267 | +#endif | |
| 252 | 268 | |
| 253 | 269 | dxva_data = dxva_data_ptr; |
| 254 | 270 | current = dxva_data; |
| @@ -284,23 +300,48 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 29 unmodified lines | ||
| 284 | 300 | |
| 285 | 301 | slice->SliceBytesInBuffer += padding; |
| 286 | 302 | } |
| 287 | − if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, | |
| 288 | − DXVA2_BitStreamDateBufferType))) | |
| 289 | − return -1; | |
| 303 | +#if CONFIG_D3D11VA | |
| 304 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) | |
| 305 | + if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type))) | |
| 306 | + return -1; | |
| 307 | +#endif | |
| 308 | +#if CONFIG_DXVA2 | |
| 309 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) | |
| 310 | + if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type))) | |
| 311 | + return -1; | |
| 312 | +#endif | |
| 290 | 313 | if (i < ctx_pic->slice_count) |
| 291 | 314 | return -1; |
| 292 | 315 | |
| 293 | − memset(bs, 0, sizeof(*bs)); | |
| 294 | − bs->CompressedBufferType = DXVA2_BitStreamDateBufferType; | |
| 295 | − bs->DataSize = current - dxva_data; | |
| 296 | − bs->NumMBsInBuffer = 0; | |
| 316 | +#if CONFIG_D3D11VA | |
| 317 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 318 | + D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs; | |
| 319 | + memset(dsc11, 0, sizeof(*dsc11)); | |
| 320 | + dsc11->BufferType = type; | |
| 321 | + dsc11->DataSize = current - dxva_data; | |
| 322 | + dsc11->NumMBsInBuffer = 0; | |
| 323 | + | |
| 324 | + type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL; | |
| 325 | + } | |
| 326 | +#endif | |
| 327 | +#if CONFIG_DXVA2 | |
| 328 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 329 | + DXVA2_DecodeBufferDesc *dsc2 = bs; | |
| 330 | + memset(dsc2, 0, sizeof(*dsc2)); | |
| 331 | + dsc2->CompressedBufferType = type; | |
| 332 | + dsc2->DataSize = current - dxva_data; | |
| 333 | + dsc2->NumMBsInBuffer = 0; | |
| 334 | + | |
| 335 | + type = DXVA2_SliceControlBufferType; | |
| 336 | + } | |
| 337 | +#endif | |
| 297 | 338 | |
| 298 | 339 | slice_data = ctx_pic->slice_short; |
| 299 | 340 | slice_size = ctx_pic->slice_count * sizeof(*ctx_pic->slice_short); |
| 300 | 341 | |
| 301 | − av_assert0((bs->DataSize & 127) == 0); | |
| 342 | + av_assert0(((current - dxva_data) & 127) == 0); | |
| 302 | 343 | return ff_dxva2_commit_buffer(avctx, ctx, sc, |
| 303 | − DXVA2_SliceControlBufferType, | |
| 344 | + type, | |
| 304 | 345 | slice_data, slice_size, 0); |
| 305 | 346 | } |
| 306 | 347 | |
| @@ -310,15 +351,17 @@ static int dxva2_hevc_start_frame(AVCodecContext *avctx, · 3 unmodified lines | ||
| 310 | 351 | av_unused uint32_t size) |
| 311 | 352 | { |
| 312 | 353 | const HEVCContext *h = avctx->priv_data; |
| 313 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 354 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 314 | 355 | struct hevc_dxva2_picture_context *ctx_pic = h->ref->hwaccel_picture_private; |
| 315 | 356 | |
| 316 | − if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) | |
| 357 | + if (DXVA_CONTEXT_DECODER(avctx, ctx) == NULL || | |
| 358 | + DXVA_CONTEXT_CFG(avctx, ctx) == NULL || | |
| 359 | + DXVA_CONTEXT_COUNT(avctx, ctx) <= 0) | |
| 317 | 360 | return -1; |
| 318 | 361 | av_assert0(ctx_pic); |
| 319 | 362 | |
| 320 | 363 | /* Fill up DXVA_PicParams_HEVC */ |
| 321 | − fill_picture_parameters(ctx, h, &ctx_pic->pp); | |
| 364 | + fill_picture_parameters(avctx, ctx, h, &ctx_pic->pp); | |
| 322 | 365 | |
| 323 | 366 | /* Fill up DXVA_Qmatrix_HEVC */ |
| 324 | 367 | fill_scaling_lists(ctx, h, &ctx_pic->qm); |
| @@ -369,6 +412,7 @@ static int dxva2_hevc_end_frame(AVCodecContext *avctx) · 44 unmodified lines | ||
| 369 | 412 | return ret; |
| 370 | 413 | } |
| 371 | 414 | |
| 415 | +#if CONFIG_HEVC_DXVA2_HWACCEL | |
| 372 | 416 | AVHWAccel ff_hevc_dxva2_hwaccel = { |
| 373 | 417 | .name = "hevc_dxva2", |
| 374 | 418 | .type = AVMEDIA_TYPE_VIDEO, |
| @@ -379,3 +423,17 @@ AVHWAccel ff_hevc_dxva2_hwaccel = { · 4 unmodified lines | ||
| 379 | 423 | .end_frame = dxva2_hevc_end_frame, |
| 380 | 424 | .frame_priv_data_size = sizeof(struct hevc_dxva2_picture_context), |
| 381 | 425 | }; |
| 426 | +#endif | |
| 427 | + | |
| 428 | +#if CONFIG_HEVC_D3D11VA_HWACCEL | |
| 429 | +AVHWAccel ff_hevc_d3d11va_hwaccel = { | |
| 430 | + .name = "hevc_d3d11va", | |
| 431 | + .type = AVMEDIA_TYPE_VIDEO, | |
| 432 | + .id = AV_CODEC_ID_HEVC, | |
| 433 | + .pix_fmt = AV_PIX_FMT_D3D11VA_VLD, | |
| 434 | + .start_frame = dxva2_hevc_start_frame, | |
| 435 | + .decode_slice = dxva2_hevc_decode_slice, | |
| 436 | + .end_frame = dxva2_hevc_end_frame, | |
| 437 | + .frame_priv_data_size = sizeof(struct hevc_dxva2_picture_context), | |
| 438 | +}; | |
| 439 | +#endif | |
| @@ -28,6 +28,7 @@ · 27 unmodified lines | ||
| 28 | 28 | #include "config.h" |
| 29 | 29 | |
| 30 | 30 | #include "dxva2.h" |
| 31 | +#include "d3d11va.h" | |
| 31 | 32 | #if HAVE_DXVA_H |
| 32 | 33 | #include <dxva.h> |
| 33 | 34 | #endif |
| @@ -35,13 +36,34 @@ · 1 unmodified line | ||
| 35 | 36 | #include "avcodec.h" |
| 36 | 37 | #include "mpegvideo.h" |
| 37 | 38 | |
| 39 | +typedef void DECODER_BUFFER_DESC; | |
| 40 | + | |
| 41 | +typedef union { | |
| 42 | + struct AVD3D11VAContext d3d11va; | |
| 43 | + struct dxva_context dxva2; | |
| 44 | +} AVDXVAContext; | |
| 45 | + | |
| 46 | +#define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va) | |
| 47 | +#define DXVA2_CONTEXT(ctx) (&ctx->dxva2) | |
| 48 | + | |
| 49 | +#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.workaround : ctx->dxva2.workaround) | |
| 50 | +#define DXVA_CONTEXT_COUNT(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.surface_count : ctx->dxva2.surface_count) | |
| 51 | +#define DXVA_CONTEXT_SURFACE(avctx, ctx, i) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.surface[i] : ctx->dxva2.surface[i]) | |
| 52 | +#define DXVA_CONTEXT_DECODER(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.decoder : ctx->dxva2.decoder) | |
| 53 | +#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? &ctx->d3d11va.report_id : &ctx->dxva2.report_id)) | |
| 54 | +#define DXVA_CONTEXT_CFG(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg : ctx->dxva2.cfg) | |
| 55 | +#define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg->ConfigBitstreamRaw : ctx->dxva2.cfg->ConfigBitstreamRaw) | |
| 56 | +#define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg->ConfigIntraResidUnsigned : ctx->dxva2.cfg->ConfigIntraResidUnsigned) | |
| 57 | +#define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg->ConfigResidDiffAccelerator : ctx->dxva2.cfg->ConfigResidDiffAccelerator) | |
| 58 | + | |
| 38 | 59 | void *ff_dxva2_get_surface(const AVFrame *frame); |
| 39 | 60 | |
| 40 | −unsigned ff_dxva2_get_surface_index(const struct dxva_context *, | |
| 61 | +unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx, | |
| 62 | + const AVDXVAContext *, | |
| 41 | 63 | const AVFrame *frame); |
| 42 | 64 | |
| 43 | −int ff_dxva2_commit_buffer(AVCodecContext *, struct dxva_context *, | |
| 44 | − DXVA2_DecodeBufferDesc *, | |
| 65 | +int ff_dxva2_commit_buffer(AVCodecContext *, AVDXVAContext *, | |
| 66 | + DECODER_BUFFER_DESC *, | |
| 45 | 67 | unsigned type, const void *data, unsigned size, |
| 46 | 68 | unsigned mb_count); |
| 47 | 69 | |
| @@ -50,7 +72,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *, · 2 unmodified lines | ||
| 50 | 72 | const void *pp, unsigned pp_size, |
| 51 | 73 | const void *qm, unsigned qm_size, |
| 52 | 74 | int (*commit_bs_si)(AVCodecContext *, |
| 53 | − DXVA2_DecodeBufferDesc *bs, | |
| 54 | − DXVA2_DecodeBufferDesc *slice)); | |
| 75 | + DECODER_BUFFER_DESC *bs, | |
| 76 | + DECODER_BUFFER_DESC *slice)); | |
| 55 | 77 | |
| 56 | 78 | #endif /* AVCODEC_DXVA_INTERNAL_H */ |
| @@ -36,7 +36,7 @@ struct dxva2_picture_context { · 35 unmodified lines | ||
| 36 | 36 | }; |
| 37 | 37 | |
| 38 | 38 | static void fill_picture_parameters(AVCodecContext *avctx, |
| 39 | − struct dxva_context *ctx, | |
| 39 | + AVDXVAContext *ctx, | |
| 40 | 40 | const struct MpegEncContext *s, |
| 41 | 41 | DXVA_PictureParameters *pp) |
| 42 | 42 | { |
| @@ -44,14 +44,14 @@ static void fill_picture_parameters(AVCodecContext *avctx, · 1 unmodified line | ||
| 44 | 44 | int is_field = s->picture_structure != PICT_FRAME; |
| 45 | 45 | |
| 46 | 46 | memset(pp, 0, sizeof(*pp)); |
| 47 | − pp->wDecodedPictureIndex = ff_dxva2_get_surface_index(ctx, current_picture->f); | |
| 47 | + pp->wDecodedPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, current_picture->f); | |
| 48 | 48 | pp->wDeblockedPictureIndex = 0; |
| 49 | 49 | if (s->pict_type != AV_PICTURE_TYPE_I) |
| 50 | − pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, s->last_picture.f); | |
| 50 | + pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_picture.f); | |
| 51 | 51 | else |
| 52 | 52 | pp->wForwardRefPictureIndex = 0xffff; |
| 53 | 53 | if (s->pict_type == AV_PICTURE_TYPE_B) |
| 54 | − pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, s->next_picture.f); | |
| 54 | + pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_picture.f); | |
| 55 | 55 | else |
| 56 | 56 | pp->wBackwardRefPictureIndex = 0xffff; |
| 57 | 57 | pp->wPicWidthInMBminus1 = s->mb_width - 1; |
| @@ -102,7 +102,7 @@ static void fill_picture_parameters(AVCodecContext *avctx, · 44 unmodified lines | ||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | static void fill_quantization_matrices(AVCodecContext *avctx, |
| 105 | − struct dxva_context *ctx, | |
| 105 | + AVDXVAContext *ctx, | |
| 106 | 106 | const struct MpegEncContext *s, |
| 107 | 107 | DXVA_QmatrixData *qm) |
| 108 | 108 | { |
| @@ -147,11 +147,11 @@ static void fill_slice(AVCodecContext *avctx, · 38 unmodified lines | ||
| 147 | 147 | slice->wMBbitOffset = 4 * 8 + get_bits_count(&gb); |
| 148 | 148 | } |
| 149 | 149 | static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, |
| 150 | − DXVA2_DecodeBufferDesc *bs, | |
| 151 | − DXVA2_DecodeBufferDesc *sc) | |
| 150 | + DECODER_BUFFER_DESC *bs, | |
| 151 | + DECODER_BUFFER_DESC *sc) | |
| 152 | 152 | { |
| 153 | 153 | const struct MpegEncContext *s = avctx->priv_data; |
| 154 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 154 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 155 | 155 | struct dxva2_picture_context *ctx_pic = |
| 156 | 156 | s->current_picture_ptr->hwaccel_picture_private; |
| 157 | 157 | const int is_field = s->picture_structure != PICT_FRAME; |
| @@ -160,11 +160,27 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 2 unmodified lines | ||
| 160 | 160 | uint8_t *dxva_data, *current, *end; |
| 161 | 161 | unsigned dxva_size; |
| 162 | 162 | unsigned i; |
| 163 | + unsigned type; | |
| 163 | 164 | |
| 164 | − if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder, | |
| 165 | − DXVA2_BitStreamDateBufferType, | |
| 166 | − &dxva_data_ptr, &dxva_size))) | |
| 167 | − return -1; | |
| 165 | +#if CONFIG_D3D11VA | |
| 166 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 167 | + type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM; | |
| 168 | + if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, | |
| 169 | + D3D11VA_CONTEXT(ctx)->decoder, | |
| 170 | + type, | |
| 171 | + &dxva_size, &dxva_data_ptr))) | |
| 172 | + return -1; | |
| 173 | + } | |
| 174 | +#endif | |
| 175 | +#if CONFIG_DXVA2 | |
| 176 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 177 | + type = DXVA2_BitStreamDateBufferType; | |
| 178 | + if (FAILED(IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder, | |
| 179 | + type, | |
| 180 | + &dxva_data_ptr, &dxva_size))) | |
| 181 | + return -1; | |
| 182 | + } | |
| 183 | +#endif | |
| 168 | 184 | |
| 169 | 185 | dxva_data = dxva_data_ptr; |
| 170 | 186 | current = dxva_data; |
| @@ -190,19 +206,44 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 19 unmodified lines | ||
| 190 | 206 | memcpy(current, &ctx_pic->bitstream[position], size); |
| 191 | 207 | current += size; |
| 192 | 208 | } |
| 193 | − if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, | |
| 194 | − DXVA2_BitStreamDateBufferType))) | |
| 195 | − return -1; | |
| 209 | +#if CONFIG_D3D11VA | |
| 210 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) | |
| 211 | + if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type))) | |
| 212 | + return -1; | |
| 213 | +#endif | |
| 214 | +#if CONFIG_DXVA2 | |
| 215 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) | |
| 216 | + if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type))) | |
| 217 | + return -1; | |
| 218 | +#endif | |
| 196 | 219 | if (i < ctx_pic->slice_count) |
| 197 | 220 | return -1; |
| 198 | 221 | |
| 199 | − memset(bs, 0, sizeof(*bs)); | |
| 200 | − bs->CompressedBufferType = DXVA2_BitStreamDateBufferType; | |
| 201 | − bs->DataSize = current - dxva_data; | |
| 202 | − bs->NumMBsInBuffer = mb_count; | |
| 222 | +#if CONFIG_D3D11VA | |
| 223 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 224 | + D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs; | |
| 225 | + memset(dsc11, 0, sizeof(*dsc11)); | |
| 226 | + dsc11->BufferType = type; | |
| 227 | + dsc11->DataSize = current - dxva_data; | |
| 228 | + dsc11->NumMBsInBuffer = mb_count; | |
| 229 | + | |
| 230 | + type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL; | |
| 231 | + } | |
| 232 | +#endif | |
| 233 | +#if CONFIG_DXVA2 | |
| 234 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 235 | + DXVA2_DecodeBufferDesc *dsc2 = bs; | |
| 236 | + memset(dsc2, 0, sizeof(*dsc2)); | |
| 237 | + dsc2->CompressedBufferType = type; | |
| 238 | + dsc2->DataSize = current - dxva_data; | |
| 239 | + dsc2->NumMBsInBuffer = mb_count; | |
| 240 | + | |
| 241 | + type = DXVA2_SliceControlBufferType; | |
| 242 | + } | |
| 243 | +#endif | |
| 203 | 244 | |
| 204 | 245 | return ff_dxva2_commit_buffer(avctx, ctx, sc, |
| 205 | − DXVA2_SliceControlBufferType, | |
| 246 | + type, | |
| 206 | 247 | ctx_pic->slice, |
| 207 | 248 | ctx_pic->slice_count * sizeof(*ctx_pic->slice), |
| 208 | 249 | mb_count); |
| @@ -213,11 +254,13 @@ static int dxva2_mpeg2_start_frame(AVCodecContext *avctx, · 4 unmodified lines | ||
| 213 | 254 | av_unused uint32_t size) |
| 214 | 255 | { |
| 215 | 256 | const struct MpegEncContext *s = avctx->priv_data; |
| 216 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 257 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 217 | 258 | struct dxva2_picture_context *ctx_pic = |
| 218 | 259 | s->current_picture_ptr->hwaccel_picture_private; |
| 219 | 260 | |
| 220 | − if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) | |
| 261 | + if (DXVA_CONTEXT_DECODER(avctx, ctx) == NULL || | |
| 262 | + DXVA_CONTEXT_CFG(avctx, ctx) == NULL || | |
| 263 | + DXVA_CONTEXT_COUNT(avctx, ctx) <= 0) | |
| 221 | 264 | return -1; |
| 222 | 265 | assert(ctx_pic); |
| 223 | 266 | |
| @@ -271,6 +314,7 @@ static int dxva2_mpeg2_end_frame(AVCodecContext *avctx) · 47 unmodified lines | ||
| 271 | 314 | return ret; |
| 272 | 315 | } |
| 273 | 316 | |
| 317 | +#if CONFIG_MPEG2_DXVA2_HWACCEL | |
| 274 | 318 | AVHWAccel ff_mpeg2_dxva2_hwaccel = { |
| 275 | 319 | .name = "mpeg2_dxva2", |
| 276 | 320 | .type = AVMEDIA_TYPE_VIDEO, |
| @@ -281,3 +325,17 @@ AVHWAccel ff_mpeg2_dxva2_hwaccel = { · 4 unmodified lines | ||
| 281 | 325 | .end_frame = dxva2_mpeg2_end_frame, |
| 282 | 326 | .frame_priv_data_size = sizeof(struct dxva2_picture_context), |
| 283 | 327 | }; |
| 328 | +#endif | |
| 329 | + | |
| 330 | +#if CONFIG_MPEG2_D3D11VA_HWACCEL | |
| 331 | +AVHWAccel ff_mpeg2_d3d11va_hwaccel = { | |
| 332 | + .name = "mpeg2_d3d11va", | |
| 333 | + .type = AVMEDIA_TYPE_VIDEO, | |
| 334 | + .id = AV_CODEC_ID_MPEG2VIDEO, | |
| 335 | + .pix_fmt = AV_PIX_FMT_D3D11VA_VLD, | |
| 336 | + .start_frame = dxva2_mpeg2_start_frame, | |
| 337 | + .decode_slice = dxva2_mpeg2_decode_slice, | |
| 338 | + .end_frame = dxva2_mpeg2_end_frame, | |
| 339 | + .frame_priv_data_size = sizeof(struct dxva2_picture_context), | |
| 340 | +}; | |
| 341 | +#endif | |
| @@ -34,7 +34,7 @@ struct dxva2_picture_context { · 33 unmodified lines | ||
| 34 | 34 | }; |
| 35 | 35 | |
| 36 | 36 | static void fill_picture_parameters(AVCodecContext *avctx, |
| 37 | − struct dxva_context *ctx, const VC1Context *v, | |
| 37 | + AVDXVAContext *ctx, const VC1Context *v, | |
| 38 | 38 | DXVA_PictureParameters *pp) |
| 39 | 39 | { |
| 40 | 40 | const MpegEncContext *s = &v->s; |
| @@ -42,13 +42,13 @@ static void fill_picture_parameters(AVCodecContext *avctx, · 1 unmodified line | ||
| 42 | 42 | |
| 43 | 43 | memset(pp, 0, sizeof(*pp)); |
| 44 | 44 | pp->wDecodedPictureIndex = |
| 45 | − pp->wDeblockedPictureIndex = ff_dxva2_get_surface_index(ctx, current_picture->f); | |
| 45 | + pp->wDeblockedPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, current_picture->f); | |
| 46 | 46 | if (s->pict_type != AV_PICTURE_TYPE_I && !v->bi_type) |
| 47 | − pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, s->last_picture.f); | |
| 47 | + pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_picture.f); | |
| 48 | 48 | else |
| 49 | 49 | pp->wForwardRefPictureIndex = 0xffff; |
| 50 | 50 | if (s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type) |
| 51 | − pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, s->next_picture.f); | |
| 51 | + pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_picture.f); | |
| 52 | 52 | else |
| 53 | 53 | pp->wBackwardRefPictureIndex = 0xffff; |
| 54 | 54 | if (v->profile == PROFILE_ADVANCED) { |
| @@ -73,8 +73,8 @@ static void fill_picture_parameters(AVCodecContext *avctx, · 18 unmodified lines | ||
| 73 | 73 | pp->bPicIntra = s->pict_type == AV_PICTURE_TYPE_I || v->bi_type; |
| 74 | 74 | pp->bPicBackwardPrediction = s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type; |
| 75 | 75 | pp->bBidirectionalAveragingMode = (1 << 7) | |
| 76 | − ((ctx->cfg->ConfigIntraResidUnsigned != 0) << 6) | | |
| 77 | − ((ctx->cfg->ConfigResidDiffAccelerator != 0) << 5) | | |
| 76 | + ((DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) != 0) << 6) | | |
| 77 | + ((DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) != 0) << 5) | | |
| 78 | 78 | ((v->lumscale != 32 || v->lumshift != 0) << 4) | |
| 79 | 79 | ((v->profile == PROFILE_ADVANCED) << 3); |
| 80 | 80 | pp->bMVprecisionAndChromaRelation = ((v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) << 3) | |
| @@ -82,11 +82,11 @@ static void fill_picture_parameters(AVCodecContext *avctx, · 1 unmodified line | ||
| 82 | 82 | (0 << 1) | |
| 83 | 83 | (!s->quarter_sample ); |
| 84 | 84 | pp->bChromaFormat = v->chromaformat; |
| 85 | − ctx->report_id++; | |
| 86 | − if (ctx->report_id >= (1 << 16)) | |
| 87 | − ctx->report_id = 1; | |
| 88 | − pp->bPicScanFixed = ctx->report_id >> 8; | |
| 89 | − pp->bPicScanMethod = ctx->report_id & 0xff; | |
| 85 | + DXVA_CONTEXT_REPORT_ID(avctx, ctx)++; | |
| 86 | + if (DXVA_CONTEXT_REPORT_ID(avctx, ctx) >= (1 << 16)) | |
| 87 | + DXVA_CONTEXT_REPORT_ID(avctx, ctx) = 1; | |
| 88 | + pp->bPicScanFixed = DXVA_CONTEXT_REPORT_ID(avctx, ctx) >> 8; | |
| 89 | + pp->bPicScanMethod = DXVA_CONTEXT_REPORT_ID(avctx, ctx) & 0xff; | |
| 90 | 90 | pp->bPicReadbackRequests = 0; |
| 91 | 91 | pp->bRcontrol = v->rnd; |
| 92 | 92 | pp->bPicSpatialResid8 = (v->panscanflag << 7) | |
| @@ -157,11 +157,11 @@ static void fill_slice(AVCodecContext *avctx, DXVA_SliceInfo *slice, · 64 unmodified lines | ||
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, |
| 160 | − DXVA2_DecodeBufferDesc *bs, | |
| 161 | − DXVA2_DecodeBufferDesc *sc) | |
| 160 | + DECODER_BUFFER_DESC *bs, | |
| 161 | + DECODER_BUFFER_DESC *sc) | |
| 162 | 162 | { |
| 163 | 163 | const VC1Context *v = avctx->priv_data; |
| 164 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 164 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 165 | 165 | const MpegEncContext *s = &v->s; |
| 166 | 166 | struct dxva2_picture_context *ctx_pic = s->current_picture_ptr->hwaccel_picture_private; |
| 167 | 167 | |
| @@ -177,11 +177,27 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 9 unmodified lines | ||
| 177 | 177 | uint8_t *dxva_data; |
| 178 | 178 | unsigned dxva_size; |
| 179 | 179 | int result; |
| 180 | + unsigned type; | |
| 180 | 181 | |
| 181 | − if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder, | |
| 182 | − DXVA2_BitStreamDateBufferType, | |
| 183 | − &dxva_data_ptr, &dxva_size))) | |
| 184 | − return -1; | |
| 182 | +#if CONFIG_D3D11VA | |
| 183 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 184 | + type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM; | |
| 185 | + if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, | |
| 186 | + D3D11VA_CONTEXT(ctx)->decoder, | |
| 187 | + type, | |
| 188 | + &dxva_size, &dxva_data_ptr))) | |
| 189 | + return -1; | |
| 190 | + } | |
| 191 | +#endif | |
| 192 | +#if CONFIG_DXVA2 | |
| 193 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 194 | + type = DXVA2_BitStreamDateBufferType; | |
| 195 | + if (FAILED(IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder, | |
| 196 | + type, | |
| 197 | + &dxva_data_ptr, &dxva_size))) | |
| 198 | + return -1; | |
| 199 | + } | |
| 200 | +#endif | |
| 185 | 201 | |
| 186 | 202 | dxva_data = dxva_data_ptr; |
| 187 | 203 | result = data_size <= dxva_size ? 0 : -1; |
| @@ -194,21 +210,46 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 6 unmodified lines | ||
| 194 | 210 | memset(dxva_data + start_code_size + slice_size, 0, padding); |
| 195 | 211 | slice->dwSliceBitsInBuffer = 8 * data_size; |
| 196 | 212 | } |
| 197 | − if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, | |
| 198 | − DXVA2_BitStreamDateBufferType))) | |
| 199 | − return -1; | |
| 213 | +#if CONFIG_D3D11VA | |
| 214 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) | |
| 215 | + if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type))) | |
| 216 | + return -1; | |
| 217 | +#endif | |
| 218 | +#if CONFIG_DXVA2 | |
| 219 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) | |
| 220 | + if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type))) | |
| 221 | + return -1; | |
| 222 | +#endif | |
| 200 | 223 | if (result) |
| 201 | 224 | return result; |
| 202 | 225 | |
| 203 | − memset(bs, 0, sizeof(*bs)); | |
| 204 | − bs->CompressedBufferType = DXVA2_BitStreamDateBufferType; | |
| 205 | − bs->DataSize = data_size; | |
| 206 | − bs->NumMBsInBuffer = s->mb_width * s->mb_height; | |
| 207 | − assert((bs->DataSize & 127) == 0); | |
| 226 | +#if CONFIG_D3D11VA | |
| 227 | + if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { | |
| 228 | + D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs; | |
| 229 | + memset(dsc11, 0, sizeof(*dsc11)); | |
| 230 | + dsc11->BufferType = type; | |
| 231 | + dsc11->DataSize = data_size; | |
| 232 | + dsc11->NumMBsInBuffer = s->mb_width * s->mb_height; | |
| 233 | + | |
| 234 | + type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL; | |
| 235 | + } | |
| 236 | +#endif | |
| 237 | +#if CONFIG_DXVA2 | |
| 238 | + if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { | |
| 239 | + DXVA2_DecodeBufferDesc *dsc2 = bs; | |
| 240 | + memset(dsc2, 0, sizeof(*dsc2)); | |
| 241 | + dsc2->CompressedBufferType = type; | |
| 242 | + dsc2->DataSize = data_size; | |
| 243 | + dsc2->NumMBsInBuffer = s->mb_width * s->mb_height; | |
| 244 | + | |
| 245 | + type = DXVA2_SliceControlBufferType; | |
| 246 | + } | |
| 247 | +#endif | |
| 248 | + assert((data_size & 127) == 0); | |
| 208 | 249 | |
| 209 | 250 | return ff_dxva2_commit_buffer(avctx, ctx, sc, |
| 210 | − DXVA2_SliceControlBufferType, | |
| 211 | − slice, sizeof(*slice), bs->NumMBsInBuffer); | |
| 251 | + type, | |
| 252 | + slice, sizeof(*slice), s->mb_width * s->mb_height); | |
| 212 | 253 | } |
| 213 | 254 | |
| 214 | 255 | static int dxva2_vc1_start_frame(AVCodecContext *avctx, |
| @@ -216,10 +257,12 @@ static int dxva2_vc1_start_frame(AVCodecContext *avctx, · 1 unmodified line | ||
| 216 | 257 | av_unused uint32_t size) |
| 217 | 258 | { |
| 218 | 259 | const VC1Context *v = avctx->priv_data; |
| 219 | − struct dxva_context *ctx = avctx->hwaccel_context; | |
| 260 | + AVDXVAContext *ctx = avctx->hwaccel_context; | |
| 220 | 261 | struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->hwaccel_picture_private; |
| 221 | 262 | |
| 222 | − if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) | |
| 263 | + if (DXVA_CONTEXT_DECODER(avctx, ctx) == NULL || | |
| 264 | + DXVA_CONTEXT_CFG(avctx, ctx) == NULL || | |
| 265 | + DXVA_CONTEXT_COUNT(avctx, ctx) <= 0) | |
| 223 | 266 | return -1; |
| 224 | 267 | assert(ctx_pic); |
| 225 | 268 | |
| @@ -285,6 +328,7 @@ AVHWAccel ff_wmv3_dxva2_hwaccel = { · 59 unmodified lines | ||
| 285 | 328 | }; |
| 286 | 329 | #endif |
| 287 | 330 | |
| 331 | +#if CONFIG_VC1_DXVA2_HWACCEL | |
| 288 | 332 | AVHWAccel ff_vc1_dxva2_hwaccel = { |
| 289 | 333 | .name = "vc1_dxva2", |
| 290 | 334 | .type = AVMEDIA_TYPE_VIDEO, |
| @@ -295,3 +339,30 @@ AVHWAccel ff_vc1_dxva2_hwaccel = { · 4 unmodified lines | ||
| 295 | 339 | .end_frame = dxva2_vc1_end_frame, |
| 296 | 340 | .frame_priv_data_size = sizeof(struct dxva2_picture_context), |
| 297 | 341 | }; |
| 342 | +#endif | |
| 343 | + | |
| 344 | +#if CONFIG_WMV3_D3D11VA_HWACCEL | |
| 345 | +AVHWAccel ff_wmv3_d3d11va_hwaccel = { | |
| 346 | + .name = "wmv3_d3d11va", | |
| 347 | + .type = AVMEDIA_TYPE_VIDEO, | |
| 348 | + .id = AV_CODEC_ID_WMV3, | |
| 349 | + .pix_fmt = AV_PIX_FMT_D3D11VA_VLD, | |
| 350 | + .start_frame = dxva2_vc1_start_frame, | |
| 351 | + .decode_slice = dxva2_vc1_decode_slice, | |
| 352 | + .end_frame = dxva2_vc1_end_frame, | |
| 353 | + .frame_priv_data_size = sizeof(struct dxva2_picture_context), | |
| 354 | +}; | |
| 355 | +#endif | |
| 356 | + | |
| 357 | +#if CONFIG_VC1_D3D11VA_HWACCEL | |
| 358 | +AVHWAccel ff_vc1_d3d11va_hwaccel = { | |
| 359 | + .name = "vc1_d3d11va", | |
| 360 | + .type = AVMEDIA_TYPE_VIDEO, | |
| 361 | + .id = AV_CODEC_ID_VC1, | |
| 362 | + .pix_fmt = AV_PIX_FMT_D3D11VA_VLD, | |
| 363 | + .start_frame = dxva2_vc1_start_frame, | |
| 364 | + .decode_slice = dxva2_vc1_decode_slice, | |
| 365 | + .end_frame = dxva2_vc1_end_frame, | |
| 366 | + .frame_priv_data_size = sizeof(struct dxva2_picture_context), | |
| 367 | +}; | |
| 368 | +#endif | |
| @@ -861,6 +861,9 @@ static enum AVPixelFormat get_pixel_format(H264Context *h) · 860 unmodified lines | ||
| 861 | 861 | #if CONFIG_H264_DXVA2_HWACCEL |
| 862 | 862 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; |
| 863 | 863 | #endif |
| 864 | +#if CONFIG_H264_D3D11VA_HWACCEL | |
| 865 | + *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | |
| 866 | +#endif | |
| 864 | 867 | #if CONFIG_H264_VAAPI_HWACCEL |
| 865 | 868 | *fmt++ = AV_PIX_FMT_VAAPI_VLD; |
| 866 | 869 | #endif |
| @@ -445,6 +445,9 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps) · 444 unmodified lines | ||
| 445 | 445 | if (sps->pix_fmt == AV_PIX_FMT_YUV420P || sps->pix_fmt == AV_PIX_FMT_YUVJ420P) { |
| 446 | 446 | #if CONFIG_HEVC_DXVA2_HWACCEL |
| 447 | 447 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; |
| 448 | +#endif | |
| 449 | +#if CONFIG_HEVC_D3D11VA_HWACCEL | |
| 450 | + *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | |
| 448 | 451 | #endif |
| 449 | 452 | } |
| 450 | 453 | |
| @@ -1173,6 +1173,9 @@ static const enum AVPixelFormat mpeg12_hwaccel_pixfmt_list_420[] = { · 1172 unmodified lines | ||
| 1173 | 1173 | #if CONFIG_MPEG2_DXVA2_HWACCEL |
| 1174 | 1174 | AV_PIX_FMT_DXVA2_VLD, |
| 1175 | 1175 | #endif |
| 1176 | +#if CONFIG_MPEG2_D3D11VA_HWACCEL | |
| 1177 | + AV_PIX_FMT_D3D11VA_VLD, | |
| 1178 | +#endif | |
| 1176 | 1179 | #if CONFIG_MPEG2_VAAPI_HWACCEL |
| 1177 | 1180 | AV_PIX_FMT_VAAPI_VLD, |
| 1178 | 1181 | #endif |
| @@ -954,6 +954,9 @@ static const enum AVPixelFormat vc1_hwaccel_pixfmt_list_420[] = { · 953 unmodified lines | ||
| 954 | 954 | #if CONFIG_VC1_DXVA2_HWACCEL |
| 955 | 955 | AV_PIX_FMT_DXVA2_VLD, |
| 956 | 956 | #endif |
| 957 | +#if CONFIG_VC1_D3D11VA_HWACCEL | |
| 958 | + AV_PIX_FMT_D3D11VA_VLD, | |
| 959 | +#endif | |
| 957 | 960 | #if CONFIG_VC1_VAAPI_HWACCEL |
| 958 | 961 | AV_PIX_FMT_VAAPI_VLD, |
| 959 | 962 | #endif |
| @@ -29,7 +29,7 @@ · 28 unmodified lines | ||
| 29 | 29 | #include "libavutil/version.h" |
| 30 | 30 | |
| 31 | 31 | #define LIBAVCODEC_VERSION_MAJOR 56 |
| 32 | −#define LIBAVCODEC_VERSION_MINOR 24 | |
| 32 | +#define LIBAVCODEC_VERSION_MINOR 25 | |
| 33 | 33 | #define LIBAVCODEC_VERSION_MICRO 0 |
| 34 | 34 | |
| 35 | 35 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| @@ -1333,6 +1333,12 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = { · 1332 unmodified lines | ||
| 1333 | 1333 | }, |
| 1334 | 1334 | .flags = AV_PIX_FMT_FLAG_BE | AV_PIX_FMT_FLAG_PLANAR, |
| 1335 | 1335 | }, |
| 1336 | + [AV_PIX_FMT_D3D11VA_VLD] = { | |
| 1337 | + .name = "d3d11va_vld", | |
| 1338 | + .log2_chroma_w = 1, | |
| 1339 | + .log2_chroma_h = 1, | |
| 1340 | + .flags = AV_PIX_FMT_FLAG_HWACCEL, | |
| 1341 | + }, | |
| 1336 | 1342 | [AV_PIX_FMT_DXVA2_VLD] = { |
| 1337 | 1343 | .name = "dxva2_vld", |
| 1338 | 1344 | .log2_chroma_w = 1, |
| @@ -220,6 +220,8 @@ enum AVPixelFormat { · 219 unmodified lines | ||
| 220 | 220 | */ |
| 221 | 221 | AV_PIX_FMT_MMAL, |
| 222 | 222 | |
| 223 | + AV_PIX_FMT_D3D11VA_VLD, ///< HW decoding through Direct3D11, Picture.data[3] contains a ID3D11VideoDecoderOutputView pointer | |
| 224 | + | |
| 223 | 225 | AV_PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions |
| 224 | 226 | |
| 225 | 227 | #if FF_API_PIX_FMT |
| @@ -54,7 +54,7 @@ · 53 unmodified lines | ||
| 54 | 54 | */ |
| 55 | 55 | |
| 56 | 56 | #define LIBAVUTIL_VERSION_MAJOR 54 |
| 57 | −#define LIBAVUTIL_VERSION_MINOR 12 | |
| 57 | +#define LIBAVUTIL_VERSION_MINOR 13 | |
| 58 | 58 | #define LIBAVUTIL_VERSION_MICRO 1 |
| 59 | 59 | |
| 60 | 60 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |