diff options
author | Hendrik Leppkes <h.leppkes@gmail.com> | 2017-08-05 16:15:10 +0300 |
---|---|---|
committer | Hendrik Leppkes <h.leppkes@gmail.com> | 2017-08-05 16:19:29 +0300 |
commit | a1f078cecc80bf8f057cb1e8b69d6b7f539e7618 (patch) | |
tree | db724af78ac6044732b208d2b5708373a1de5328 | |
parent | 154fd871b4483171ce8bda9ef0e9746e21d27829 (diff) |
dxva2: factor reusable functions into a common dxva module
-rw-r--r-- | decoder/LAVVideo/LAVVideo.vcxproj | 2 | ||||
-rw-r--r-- | decoder/LAVVideo/LAVVideo.vcxproj.filters | 6 | ||||
-rw-r--r-- | decoder/LAVVideo/decoders/dxva2/dxva_common.cpp | 156 | ||||
-rw-r--r-- | decoder/LAVVideo/decoders/dxva2/dxva_common.h | 37 | ||||
-rw-r--r-- | decoder/LAVVideo/decoders/dxva2dec.cpp | 164 | ||||
-rw-r--r-- | decoder/LAVVideo/decoders/dxva2dec.h | 3 |
6 files changed, 214 insertions, 154 deletions
diff --git a/decoder/LAVVideo/LAVVideo.vcxproj b/decoder/LAVVideo/LAVVideo.vcxproj index 54f2d6f1..476dc466 100644 --- a/decoder/LAVVideo/LAVVideo.vcxproj +++ b/decoder/LAVVideo/LAVVideo.vcxproj @@ -104,6 +104,7 @@ <ClCompile Include="decoders\cuvid.cpp" /> <ClCompile Include="decoders\dxva2dec.cpp" /> <ClCompile Include="decoders\dxva2\DXVA2SurfaceAllocator.cpp" /> + <ClCompile Include="decoders\dxva2\dxva_common.cpp" /> <ClCompile Include="decoders\msdk_mvc.cpp" /> <ClCompile Include="decoders\pixfmt.cpp" /> <ClCompile Include="decoders\quicksync.cpp" /> @@ -150,6 +151,7 @@ <ClInclude Include="decoders\DecBase.h" /> <ClInclude Include="decoders\dxva2dec.h" /> <ClInclude Include="decoders\dxva2\DXVA2SurfaceAllocator.h" /> + <ClInclude Include="decoders\dxva2\dxva_common.h" /> <ClInclude Include="decoders\ILAVDecoder.h" /> <ClInclude Include="decoders\msdk_mvc.h" /> <ClInclude Include="decoders\quicksync.h" /> diff --git a/decoder/LAVVideo/LAVVideo.vcxproj.filters b/decoder/LAVVideo/LAVVideo.vcxproj.filters index d32e0a40..586de304 100644 --- a/decoder/LAVVideo/LAVVideo.vcxproj.filters +++ b/decoder/LAVVideo/LAVVideo.vcxproj.filters @@ -165,6 +165,9 @@ <ClCompile Include="DecodeManager.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="decoders\dxva2\dxva_common.cpp"> + <Filter>Source Files\decoders\dxva2</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="stdafx.h"> @@ -269,6 +272,9 @@ <ClInclude Include="DecodeManager.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="decoders\dxva2\dxva_common.h"> + <Filter>Header Files\decoders\dxva2</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ResourceCompile Include="LAVVideo.rc"> diff --git a/decoder/LAVVideo/decoders/dxva2/dxva_common.cpp b/decoder/LAVVideo/decoders/dxva2/dxva_common.cpp new file mode 100644 index 00000000..9d454df4 --- /dev/null +++ b/decoder/LAVVideo/decoders/dxva2/dxva_common.cpp @@ -0,0 +1,156 @@ +/* +* Copyright (C) 2011-2017 Hendrik Leppkes +* http://www.1f0.de +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "stdafx.h" +#include "dxva_common.h" +#include "moreuuids.h" + +#define DXVA_SURFACE_BASE_ALIGN 16 + +DWORD dxva_align_dimensions(AVCodecID codec, DWORD dim) +{ + int align = DXVA_SURFACE_BASE_ALIGN; + + // MPEG-2 needs higher alignment on Intel cards, and it doesn't seem to harm anything to do it for all cards. + if (codec == AV_CODEC_ID_MPEG2VIDEO) + align <<= 1; + else if (codec == AV_CODEC_ID_HEVC) + align = 128; + + return FFALIGN(dim, align); +} + +//////////////////////////////////////////////////////////////////////////////// +// Codec Maps +//////////////////////////////////////////////////////////////////////////////// + +/* +DXVA2 Codec Mappings, as defined by VLC +*/ + +static const int prof_mpeg2_main[] = { FF_PROFILE_MPEG2_SIMPLE, FF_PROFILE_MPEG2_MAIN, FF_PROFILE_UNKNOWN }; +static const int prof_h264_high[] = { FF_PROFILE_H264_CONSTRAINED_BASELINE, FF_PROFILE_H264_MAIN, FF_PROFILE_H264_HIGH, FF_PROFILE_UNKNOWN }; +static const int prof_hevc_main[] = { FF_PROFILE_HEVC_MAIN, FF_PROFILE_UNKNOWN }; +static const int prof_hevc_main10[] = { FF_PROFILE_HEVC_MAIN_10, FF_PROFILE_UNKNOWN }; +static const int prof_vp9_0[] = { FF_PROFILE_VP9_0, FF_PROFILE_UNKNOWN }; +static const int prof_vp9_2_10bit[] = { FF_PROFILE_VP9_2, FF_PROFILE_UNKNOWN }; + +/* XXX Prefered modes must come first */ +const dxva_mode_t dxva_modes[] = { + /* MPEG-1/2 */ + { "MPEG-2 variable-length decoder", &DXVA2_ModeMPEG2_VLD, AV_CODEC_ID_MPEG2VIDEO, prof_mpeg2_main }, + { "MPEG-2 & MPEG-1 variable-length decoder", &DXVA2_ModeMPEG2and1_VLD, AV_CODEC_ID_MPEG2VIDEO, prof_mpeg2_main }, + { "MPEG-2 motion compensation", &DXVA2_ModeMPEG2_MoComp, 0 }, + { "MPEG-2 inverse discrete cosine transform", &DXVA2_ModeMPEG2_IDCT, 0 }, + + { "MPEG-1 variable-length decoder", &DXVA2_ModeMPEG1_VLD, 0 }, + + /* H.264 */ + { "H.264 variable-length decoder, film grain technology", &DXVA2_ModeH264_F, AV_CODEC_ID_H264, prof_h264_high }, + { "H.264 variable-length decoder, no film grain technology", &DXVA2_ModeH264_E, AV_CODEC_ID_H264, prof_h264_high }, + { "H.264 variable-length decoder, no film grain technology, FMO/ASO", &DXVA_ModeH264_VLD_WithFMOASO_NoFGT, AV_CODEC_ID_H264, prof_h264_high }, + { "H.264 variable-length decoder, no film grain technology, Flash", &DXVA_ModeH264_VLD_NoFGT_Flash, AV_CODEC_ID_H264, prof_h264_high }, + + { "H.264 inverse discrete cosine transform, film grain technology", &DXVA2_ModeH264_D, 0 }, + { "H.264 inverse discrete cosine transform, no film grain technology", &DXVA2_ModeH264_C, 0 }, + + { "H.264 motion compensation, film grain technology", &DXVA2_ModeH264_B, 0 }, + { "H.264 motion compensation, no film grain technology", &DXVA2_ModeH264_A, 0 }, + + /* WMV */ + { "Windows Media Video 8 motion compensation", &DXVA2_ModeWMV8_B, 0 }, + { "Windows Media Video 8 post processing", &DXVA2_ModeWMV8_A, 0 }, + + { "Windows Media Video 9 IDCT", &DXVA2_ModeWMV9_C, 0 }, + { "Windows Media Video 9 motion compensation", &DXVA2_ModeWMV9_B, 0 }, + { "Windows Media Video 9 post processing", &DXVA2_ModeWMV9_A, 0 }, + + /* VC-1 */ + { "VC-1 variable-length decoder (2010)", &DXVA2_ModeVC1_D2010, AV_CODEC_ID_VC1 }, + { "VC-1 variable-length decoder (2010)", &DXVA2_ModeVC1_D2010, AV_CODEC_ID_WMV3 }, + { "VC-1 variable-length decoder", &DXVA2_ModeVC1_D, AV_CODEC_ID_VC1 }, + { "VC-1 variable-length decoder", &DXVA2_ModeVC1_D, AV_CODEC_ID_WMV3 }, + + { "VC-1 inverse discrete cosine transform", &DXVA2_ModeVC1_C, 0 }, + { "VC-1 motion compensation", &DXVA2_ModeVC1_B, 0 }, + { "VC-1 post processing", &DXVA2_ModeVC1_A, 0 }, + + /* MPEG4-ASP */ + { "MPEG-4 Part 2 nVidia bitstream decoder", &DXVA_nVidia_MPEG4_ASP, 0 }, + { "MPEG-4 Part 2 variable-length decoder, Simple Profile", &DXVA_ModeMPEG4pt2_VLD_Simple, 0 }, + { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, no GMC", &DXVA_ModeMPEG4pt2_VLD_AdvSimple_NoGMC, 0 }, + { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, GMC", &DXVA_ModeMPEG4pt2_VLD_AdvSimple_GMC, 0 }, + { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, Avivo", &DXVA_ModeMPEG4pt2_VLD_AdvSimple_Avivo, 0 }, + + /* H.264 MVC */ + { "H.264 MVC variable-length decoder, stereo, progressive", &DXVA_ModeH264_VLD_Stereo_Progressive_NoFGT, 0 }, + { "H.264 MVC variable-length decoder, stereo", &DXVA_ModeH264_VLD_Stereo_NoFGT, 0 }, + { "H.264 MVC variable-length decoder, multiview", &DXVA_ModeH264_VLD_Multiview_NoFGT, 0 }, + + /* H.264 SVC */ + { "H.264 SVC variable-length decoder, baseline", &DXVA_ModeH264_VLD_SVC_Scalable_Baseline, 0 }, + { "H.264 SVC variable-length decoder, constrained baseline", &DXVA_ModeH264_VLD_SVC_Restricted_Scalable_Baseline, 0 }, + { "H.264 SVC variable-length decoder, high", &DXVA_ModeH264_VLD_SVC_Scalable_High, 0 }, + { "H.264 SVC variable-length decoder, constrained high progressive", &DXVA_ModeH264_VLD_SVC_Restricted_Scalable_High_Progressive, 0 }, + + /* HEVC / H.265 */ + { "HEVC / H.265 variable-length decoder, main", &DXVA_ModeHEVC_VLD_Main, AV_CODEC_ID_HEVC, prof_hevc_main }, + { "HEVC / H.265 variable-length decoder, main10", &DXVA_ModeHEVC_VLD_Main10, AV_CODEC_ID_HEVC, prof_hevc_main10, 1 }, + + /* VP8/9 */ + { "VP9 variable-length decoder, profile 0", &DXVA_ModeVP9_VLD_Profile0, AV_CODEC_ID_VP9, prof_vp9_0 }, + { "VP9 variable-length decoder, 10bit, profile 2", &DXVA_ModeVP9_VLD_10bit_Profile2, AV_CODEC_ID_VP9, prof_vp9_2_10bit, 1 }, + { "VP8 variable-length decoder", &DXVA_ModeVP8_VLD, 0 }, + + /* Intel specific modes (only useful on older GPUs) */ + { "H.264 variable-length decoder, no film grain technology (Intel ClearVideo)", &DXVADDI_Intel_ModeH264_E, AV_CODEC_ID_H264, prof_h264_high }, + { "H.264 inverse discrete cosine transform, no film grain technology (Intel)", &DXVADDI_Intel_ModeH264_C, 0 }, + { "H.264 motion compensation, no film grain technology (Intel)", &DXVADDI_Intel_ModeH264_A, 0 }, + { "VC-1 variable-length decoder 2 (Intel)", &DXVA_Intel_VC1_ClearVideo_2, 0 }, + { "VC-1 variable-length decoder (Intel)", &DXVA_Intel_VC1_ClearVideo, 0 }, + + { nullptr, nullptr, 0 } +}; + +const dxva_mode_t *get_dxva_mode_from_guid(const GUID *guid) +{ + for (unsigned i = 0; dxva_modes[i].name; i++) { + if (IsEqualGUID(*dxva_modes[i].guid, *guid)) + return &dxva_modes[i]; + } + return nullptr; +} + +int check_dxva_mode_compatibility(const dxva_mode_t *mode, int codec, int profile) +{ + if (mode->codec != codec) + return 0; + + if (mode->profiles && profile != FF_PROFILE_UNKNOWN) + { + for (int i = 0; mode->profiles[i] != FF_PROFILE_UNKNOWN; i++) + { + if (mode->profiles[i] == profile) + return 1; + } + return 0; + } + + return 1; +} diff --git a/decoder/LAVVideo/decoders/dxva2/dxva_common.h b/decoder/LAVVideo/decoders/dxva2/dxva_common.h new file mode 100644 index 00000000..f9e1b94f --- /dev/null +++ b/decoder/LAVVideo/decoders/dxva2/dxva_common.h @@ -0,0 +1,37 @@ +/* +* Copyright (C) 2011-2017 Hendrik Leppkes +* http://www.1f0.de +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +/* Align dimensions for hardware and codec requirements */ +DWORD dxva_align_dimensions(AVCodecID codec, DWORD dim); + +/* hardware mode description */ +typedef struct { + const char *name; + const GUID *guid; + int codec; + const int *profiles; + int high_bit_depth; +} dxva_mode_t; + +extern const dxva_mode_t dxva_modes[]; + +const dxva_mode_t *get_dxva_mode_from_guid(const GUID *guid); +int check_dxva_mode_compatibility(const dxva_mode_t *mode, int codec, int profile); diff --git a/decoder/LAVVideo/decoders/dxva2dec.cpp b/decoder/LAVVideo/decoders/dxva2dec.cpp index 97e1c975..a1e87753 100644 --- a/decoder/LAVVideo/decoders/dxva2dec.cpp +++ b/decoder/LAVVideo/decoders/dxva2dec.cpp @@ -21,6 +21,7 @@ #include "stdafx.h" #include "dxva2dec.h" +#include "dxva2/dxva_common.h" #include "dxva2/DXVA2SurfaceAllocator.h" #include "moreuuids.h" #include "Media.h" @@ -81,132 +82,6 @@ done: return hr; } -//////////////////////////////////////////////////////////////////////////////// -// Codec Maps -//////////////////////////////////////////////////////////////////////////////// - -/* -DXVA2 Codec Mappings, as defined by VLC -*/ -typedef struct { - const char *name; - const GUID *guid; - int codec; - const int *profiles; - int high_bit_depth; -} dxva2_mode_t; - -static const int prof_mpeg2_main[] = { FF_PROFILE_MPEG2_SIMPLE, FF_PROFILE_MPEG2_MAIN, FF_PROFILE_UNKNOWN }; -static const int prof_h264_high[] = { FF_PROFILE_H264_CONSTRAINED_BASELINE, FF_PROFILE_H264_MAIN, FF_PROFILE_H264_HIGH, FF_PROFILE_UNKNOWN }; -static const int prof_hevc_main[] = { FF_PROFILE_HEVC_MAIN, FF_PROFILE_UNKNOWN }; -static const int prof_hevc_main10[] = { FF_PROFILE_HEVC_MAIN_10, FF_PROFILE_UNKNOWN }; -static const int prof_vp9_0[] = { FF_PROFILE_VP9_0, FF_PROFILE_UNKNOWN }; -static const int prof_vp9_2_10bit[] = { FF_PROFILE_VP9_2, FF_PROFILE_UNKNOWN }; - -/* XXX Prefered modes must come first */ -static const dxva2_mode_t dxva2_modes[] = { - /* MPEG-1/2 */ - { "MPEG-2 variable-length decoder", &DXVA2_ModeMPEG2_VLD, AV_CODEC_ID_MPEG2VIDEO, prof_mpeg2_main }, - { "MPEG-2 & MPEG-1 variable-length decoder", &DXVA2_ModeMPEG2and1_VLD, AV_CODEC_ID_MPEG2VIDEO, prof_mpeg2_main }, - { "MPEG-2 motion compensation", &DXVA2_ModeMPEG2_MoComp, 0 }, - { "MPEG-2 inverse discrete cosine transform", &DXVA2_ModeMPEG2_IDCT, 0 }, - - { "MPEG-1 variable-length decoder", &DXVA2_ModeMPEG1_VLD, 0 }, - - /* H.264 */ - { "H.264 variable-length decoder, film grain technology", &DXVA2_ModeH264_F, AV_CODEC_ID_H264, prof_h264_high }, - { "H.264 variable-length decoder, no film grain technology", &DXVA2_ModeH264_E, AV_CODEC_ID_H264, prof_h264_high }, - { "H.264 variable-length decoder, no film grain technology, FMO/ASO", &DXVA_ModeH264_VLD_WithFMOASO_NoFGT, AV_CODEC_ID_H264, prof_h264_high }, - { "H.264 variable-length decoder, no film grain technology, Flash", &DXVA_ModeH264_VLD_NoFGT_Flash, AV_CODEC_ID_H264, prof_h264_high }, - - { "H.264 inverse discrete cosine transform, film grain technology", &DXVA2_ModeH264_D, 0 }, - { "H.264 inverse discrete cosine transform, no film grain technology", &DXVA2_ModeH264_C, 0 }, - - { "H.264 motion compensation, film grain technology", &DXVA2_ModeH264_B, 0 }, - { "H.264 motion compensation, no film grain technology", &DXVA2_ModeH264_A, 0 }, - - /* WMV */ - { "Windows Media Video 8 motion compensation", &DXVA2_ModeWMV8_B, 0 }, - { "Windows Media Video 8 post processing", &DXVA2_ModeWMV8_A, 0 }, - - { "Windows Media Video 9 IDCT", &DXVA2_ModeWMV9_C, 0 }, - { "Windows Media Video 9 motion compensation", &DXVA2_ModeWMV9_B, 0 }, - { "Windows Media Video 9 post processing", &DXVA2_ModeWMV9_A, 0 }, - - /* VC-1 */ - { "VC-1 variable-length decoder (2010)", &DXVA2_ModeVC1_D2010, AV_CODEC_ID_VC1 }, - { "VC-1 variable-length decoder (2010)", &DXVA2_ModeVC1_D2010, AV_CODEC_ID_WMV3 }, - { "VC-1 variable-length decoder", &DXVA2_ModeVC1_D, AV_CODEC_ID_VC1 }, - { "VC-1 variable-length decoder", &DXVA2_ModeVC1_D, AV_CODEC_ID_WMV3 }, - - { "VC-1 inverse discrete cosine transform", &DXVA2_ModeVC1_C, 0 }, - { "VC-1 motion compensation", &DXVA2_ModeVC1_B, 0 }, - { "VC-1 post processing", &DXVA2_ModeVC1_A, 0 }, - - /* MPEG4-ASP */ - { "MPEG-4 Part 2 nVidia bitstream decoder", &DXVA_nVidia_MPEG4_ASP, 0 }, - { "MPEG-4 Part 2 variable-length decoder, Simple Profile", &DXVA_ModeMPEG4pt2_VLD_Simple, 0 }, - { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, no GMC", &DXVA_ModeMPEG4pt2_VLD_AdvSimple_NoGMC, 0 }, - { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, GMC", &DXVA_ModeMPEG4pt2_VLD_AdvSimple_GMC, 0 }, - { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, Avivo", &DXVA_ModeMPEG4pt2_VLD_AdvSimple_Avivo, 0 }, - - /* H.264 MVC */ - { "H.264 MVC variable-length decoder, stereo, progressive", &DXVA_ModeH264_VLD_Stereo_Progressive_NoFGT, 0 }, - { "H.264 MVC variable-length decoder, stereo", &DXVA_ModeH264_VLD_Stereo_NoFGT, 0 }, - { "H.264 MVC variable-length decoder, multiview", &DXVA_ModeH264_VLD_Multiview_NoFGT, 0 }, - - /* H.264 SVC */ - { "H.264 SVC variable-length decoder, baseline", &DXVA_ModeH264_VLD_SVC_Scalable_Baseline, 0 }, - { "H.264 SVC variable-length decoder, constrained baseline", &DXVA_ModeH264_VLD_SVC_Restricted_Scalable_Baseline, 0 }, - { "H.264 SVC variable-length decoder, high", &DXVA_ModeH264_VLD_SVC_Scalable_High, 0 }, - { "H.264 SVC variable-length decoder, constrained high progressive", &DXVA_ModeH264_VLD_SVC_Restricted_Scalable_High_Progressive, 0 }, - - /* HEVC / H.265 */ - { "HEVC / H.265 variable-length decoder, main", &DXVA_ModeHEVC_VLD_Main, AV_CODEC_ID_HEVC, prof_hevc_main }, - { "HEVC / H.265 variable-length decoder, main10", &DXVA_ModeHEVC_VLD_Main10, AV_CODEC_ID_HEVC, prof_hevc_main10, 1 }, - - /* VP8/9 */ - { "VP9 variable-length decoder, profile 0", &DXVA_ModeVP9_VLD_Profile0, AV_CODEC_ID_VP9, prof_vp9_0 }, - { "VP9 variable-length decoder, 10bit, profile 2", &DXVA_ModeVP9_VLD_10bit_Profile2, AV_CODEC_ID_VP9, prof_vp9_2_10bit, 1 }, - { "VP8 variable-length decoder", &DXVA_ModeVP8_VLD, 0 }, - - /* Intel specific modes (only useful on older GPUs) */ - { "H.264 variable-length decoder, no film grain technology (Intel ClearVideo)", &DXVADDI_Intel_ModeH264_E, AV_CODEC_ID_H264, prof_h264_high }, - { "H.264 inverse discrete cosine transform, no film grain technology (Intel)", &DXVADDI_Intel_ModeH264_C, 0 }, - { "H.264 motion compensation, no film grain technology (Intel)", &DXVADDI_Intel_ModeH264_A, 0 }, - { "VC-1 variable-length decoder 2 (Intel)", &DXVA_Intel_VC1_ClearVideo_2, 0 }, - { "VC-1 variable-length decoder (Intel)", &DXVA_Intel_VC1_ClearVideo, 0 }, - - { nullptr, nullptr, 0 } -}; - -static const dxva2_mode_t *DXVA2FindMode(const GUID *guid) -{ - for (unsigned i = 0; dxva2_modes[i].name; i++) { - if (IsEqualGUID(*dxva2_modes[i].guid, *guid)) - return &dxva2_modes[i]; - } - return nullptr; -} - -static int check_dxva_mode_compatibility(const dxva2_mode_t *mode, int codec, int profile) -{ - if (mode->codec != codec) - return 0; - - if (mode->profiles && profile != FF_PROFILE_UNKNOWN) - { - for (int i = 0; mode->profiles[i] != FF_PROFILE_UNKNOWN; i++) - { - if (mode->profiles[i] == profile) - return 1; - } - return 0; - } - - return 1; -} - // List of PCI Device ID of ATI cards with UVD or UVD+ decoding block. static DWORD UVDDeviceID [] = { 0x94C7, // ATI Radeon HD 2350 @@ -404,8 +279,8 @@ STDMETHODIMP CDecDXVA2::PostConnect(IPin *pPin) if (m_bNative) { if (!m_pDecoder) { // If this is the first call, re-align surfaces, as the requirements may only be known now - m_dwSurfaceWidth = GetAlignedDimension(m_pAVCtx->coded_width); - m_dwSurfaceHeight = GetAlignedDimension(m_pAVCtx->coded_height); + m_dwSurfaceWidth = dxva_align_dimensions(m_pAVCtx->codec_id, m_pAVCtx->coded_width); + m_dwSurfaceHeight = dxva_align_dimensions(m_pAVCtx->codec_id, m_pAVCtx->coded_height); } CMediaType mt = m_pCallback->GetOutputMediaType(); @@ -574,7 +449,7 @@ HRESULT CDecDXVA2::FindVideoServiceConversion(AVCodecID codec, int profile, GUID DbgLog((LOG_TRACE, 10, L"-> Enumerating supported DXVA2 modes (count: %d)", count)); for(unsigned i = 0; i < count; i++) { const GUID *g = &input_list[i]; - const dxva2_mode_t *mode = DXVA2FindMode(g); + const dxva_mode_t *mode = get_dxva_mode_from_guid(g); if (mode) { DbgLog((LOG_TRACE, 10, L" -> %S", mode->name)); } else { @@ -583,8 +458,8 @@ HRESULT CDecDXVA2::FindVideoServiceConversion(AVCodecID codec, int profile, GUID } /* Iterate over our priority list */ - for (unsigned i = 0; dxva2_modes[i].name; i++) { - const dxva2_mode_t *mode = &dxva2_modes[i]; + for (unsigned i = 0; dxva_modes[i].name; i++) { + const dxva_mode_t *mode = &dxva_modes[i]; if (!check_dxva_mode_compatibility(mode, codec, profile)) continue; @@ -1009,19 +884,6 @@ STDMETHODIMP CDecDXVA2::Init() return S_OK; } -DWORD CDecDXVA2::GetAlignedDimension(DWORD dim) -{ - int align = DXVA2_SURFACE_BASE_ALIGN; - - // MPEG-2 needs higher alignment on Intel cards, and it doesn't seem to harm anything to do it for all cards. - if (m_nCodecId == AV_CODEC_ID_MPEG2VIDEO) - align <<= 1; - else if (m_nCodecId == AV_CODEC_ID_HEVC) - align = 128; - - return FFALIGN(dim, align); -} - #define H264_CHECK_PROFILE(profile) \ (((profile) & ~FF_PROFILE_H264_CONSTRAINED) <= FF_PROFILE_H264_HIGH) @@ -1106,8 +968,8 @@ STDMETHODIMP CDecDXVA2::InitDecoder(AVCodecID codec, const CMediaType *pmt) return E_FAIL; } - m_dwSurfaceWidth = GetAlignedDimension(m_pAVCtx->coded_width); - m_dwSurfaceHeight = GetAlignedDimension(m_pAVCtx->coded_height); + m_dwSurfaceWidth = dxva_align_dimensions(m_pAVCtx->codec_id, m_pAVCtx->coded_width); + m_dwSurfaceHeight = dxva_align_dimensions(m_pAVCtx->codec_id, m_pAVCtx->coded_height); m_eSurfaceFormat = output; if (FAILED(CheckHWCompatConditions(input))) { @@ -1205,8 +1067,8 @@ HRESULT CDecDXVA2::CreateDXVA2Decoder(int nSurfaces, IDirect3DSurface9 **ppSurfa FindVideoServiceConversion(m_pAVCtx->codec_id, m_pAVCtx->profile, &input, &output); if (!nSurfaces) { - m_dwSurfaceWidth = GetAlignedDimension(m_pAVCtx->coded_width); - m_dwSurfaceHeight = GetAlignedDimension(m_pAVCtx->coded_height); + m_dwSurfaceWidth = dxva_align_dimensions(m_pAVCtx->codec_id, m_pAVCtx->coded_width); + m_dwSurfaceHeight = dxva_align_dimensions(m_pAVCtx->codec_id, m_pAVCtx->coded_height); m_eSurfaceFormat = output; m_DecoderPixelFormat = m_pAVCtx->sw_pix_fmt; @@ -1354,7 +1216,7 @@ HRESULT CDecDXVA2::ReInitDXVA2Decoder(AVCodecContext *c) if (m_bInInit) return S_FALSE; - if (!m_pDecoder || GetAlignedDimension(c->coded_width) != m_dwSurfaceWidth || GetAlignedDimension(c->coded_height) != m_dwSurfaceHeight || m_DecoderPixelFormat != c->sw_pix_fmt) { + if (!m_pDecoder || dxva_align_dimensions(c->codec_id, c->coded_width) != m_dwSurfaceWidth || dxva_align_dimensions(c->codec_id, c->coded_height) != m_dwSurfaceHeight || m_DecoderPixelFormat != c->sw_pix_fmt) { DbgLog((LOG_TRACE, 10, L"No DXVA2 Decoder or image dimensions changed -> Re-Allocating resources")); if (!m_pDecoder && m_bNative && !m_pDXVA2Allocator) { ASSERT(0); @@ -1362,8 +1224,8 @@ HRESULT CDecDXVA2::ReInitDXVA2Decoder(AVCodecContext *c) } else if (m_bNative) { avcodec_flush_buffers(c); - m_dwSurfaceWidth = GetAlignedDimension(c->coded_width); - m_dwSurfaceHeight = GetAlignedDimension(c->coded_height); + m_dwSurfaceWidth = dxva_align_dimensions(c->codec_id, c->coded_width); + m_dwSurfaceHeight = dxva_align_dimensions(c->codec_id, c->coded_height); m_DecoderPixelFormat = c->sw_pix_fmt; GUID input; diff --git a/decoder/LAVVideo/decoders/dxva2dec.h b/decoder/LAVVideo/decoders/dxva2dec.h index 04718dfd..a2d3fed8 100644 --- a/decoder/LAVVideo/decoders/dxva2dec.h +++ b/decoder/LAVVideo/decoders/dxva2dec.h @@ -24,7 +24,6 @@ #define DXVA2_MAX_SURFACES 64 #define DXVA2_QUEUE_SURFACES 4 -#define DXVA2_SURFACE_BASE_ALIGN 16 typedef HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **); typedef HRESULT WINAPI pCreateDeviceManager9(UINT *pResetToken, IDirect3DDeviceManager9 **); @@ -103,8 +102,6 @@ private: STDMETHODIMP FlushDisplayQueue(BOOL bDeliver); STDMETHODIMP FlushFromAllocator(); - DWORD GetAlignedDimension(DWORD dim); - private: friend class CDXVA2SurfaceAllocator; BOOL m_bNative = FALSE; |