1
0

Experimental - D3D11 support. Not fully functional vs2012 project not updated either.

git-svn-id: svn://svn.code.sf.net/p/qsdecoder/code/trunk/IntelQuickSyncDecoder@83 dfccccb7-dd81-40b7-a334-5a7ba89c2b1d
This commit is contained in:
egur 2013-05-15 22:49:18 +00:00
parent fcdd800ce9
commit bc28b896da
24 changed files with 1621 additions and 281 deletions

View File

@ -29,7 +29,7 @@
#pragma once
#define QS_DEC_DLL_NAME "IntelQuickSyncDecoder.dll"
#define QS_DEC_VERSION "v0.41"
#define QS_DEC_VERSION "v0.42"
// Forward declarations
struct IDirect3DDeviceManager9;
@ -142,8 +142,8 @@ struct CQsConfig
bool bDropDuplicateFrames : 1; // True: duplicated frames will be dropped
// False: when a frame is marked as duplicated it will be sent out with a modified time
// stamp based on the first frame and frame rate. Useful for transcoding.
unsigned reserved1 : 14;
bool bEnableD3D11 : 1; // Enable use of Direct3D 11.1 for HW acceleration (Windows 8 and newer OS)
unsigned reserved1 : 13;
};
};

View File

@ -14,8 +14,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,41,0,0
PRODUCTVERSION 0,41,0,0
FILEVERSION 0,42,0,0
PRODUCTVERSION 0,42,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -32,13 +32,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Intel Corp."
VALUE "FileDescription", "IntelQuickSyncDecoder DLL"
VALUE "FileVersion", "0.41.0.0"
VALUE "FileVersion", "0.42.0.0"
VALUE "InternalName", "IntelQuickSyncDecoder"
VALUE "LegalCopyright", "BSD lisence. © 2013 Intel ® Corp. By Eric Gur"
VALUE "LegalTrademarks", "Intel QuickSync Decoder"
VALUE "OriginalFilename", "IntelQuickSyncDecoder.dll"
VALUE "ProductName", "Intel QuickSync Decoder"
VALUE "ProductVersion", "0.41.0.0"
VALUE "ProductVersion", "0.42.0.0"
END
END
BLOCK "VarFileInfo"

View File

@ -29,24 +29,20 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@ -66,34 +62,33 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)obj\$(Configuration)_$(PlatformName)_VC2010\$(ProjectName)\</OutDir>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>MSDK\lib\$(PlatformName);$(LibraryPath)</LibraryPath>
<LinkIncremental>false</LinkIncremental>
<IntDir>$(SolutionDir)obj\$(Configuration)_$(PlatformName)_VC2010\$(ProjectName)\</IntDir>
<GenerateManifest>true</GenerateManifest>
<IncludePath>MSDK\include;$(IncludePath)</IncludePath>
<LibraryPath>MSDK\lib\$(PlatformName);$(LibraryPath)</LibraryPath>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>MSDK\lib\$(PlatformName);$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)obj\$(Configuration)_$(PlatformName)_VC2010\$(ProjectName)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Configuration)_$(PlatformName)_VC2010\$(ProjectName)\</IntDir>
<GenerateManifest>true</GenerateManifest>
<IncludePath>MSDK\include;$(IncludePath)</IncludePath>
<LibraryPath>MSDK\lib\$(PlatformName);$(LibraryPath)</LibraryPath>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>MSDK\lib\$(PlatformName);$(LibraryPath)</LibraryPath>
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)obj\$(Configuration)_$(PlatformName)_VC2010\</OutDir>
<IntDir>$(SolutionDir)obj\$(Configuration)_$(PlatformName)_VC2010\$(ProjectName)\</IntDir>
<GenerateManifest>true</GenerateManifest>
<IncludePath>MSDK\include;$(IncludePath)</IncludePath>
<LibraryPath>MSDK\lib\$(PlatformName);$(LibraryPath)</LibraryPath>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
@ -102,7 +97,7 @@
<OutDir>$(SolutionDir)obj\$(Configuration)_$(PlatformName)_VC2010\</OutDir>
<IntDir>$(SolutionDir)obj\$(Configuration)_$(PlatformName)_VC2010\$(ProjectName)\</IntDir>
<GenerateManifest>true</GenerateManifest>
<IncludePath>MSDK\include;$(IncludePath)</IncludePath>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>MSDK\lib\$(PlatformName);$(LibraryPath)</LibraryPath>
<IgnoreImportLibrary>false</IgnoreImportLibrary>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
@ -111,29 +106,26 @@
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;DEBUG;_DEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996;4245;4995</DisableSpecificWarnings>
<MinimalRebuild>false</MinimalRebuild>
<DisableSpecificWarnings>4996;4995</DisableSpecificWarnings>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<EnablePREfast>false</EnablePREfast>
<TreatWarningAsError>false</TreatWarningAsError>
<MinimalRebuild>false</MinimalRebuild>
<AdditionalIncludeDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Include;$(INTELMEDIASDK_WINSDK_PATH)\Include\um;$(INTELMEDIASDK_WINSDK_PATH)\Include\shared;MSDK\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>IntelQuickSyncDecoder.def</ModuleDefinitionFile>
<AdditionalDependencies>winmm.lib;uuid.lib;D3D9.lib;Dxva2.lib;libmfx.lib;strmiids.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib</IgnoreSpecificDefaultLibraries>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<AdditionalLibraryDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Lib;$(INTELMEDIASDK_WINSDK_PATH)\Lib\win8\um\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OutputFile>$(SolutionDir)bin\$(TargetName)$(TargetExt)</OutputFile>
<ProgramDatabaseFile>$(OutDir)$(TargetName).pdb</ProgramDatabaseFile>
<AdditionalDependencies>winmm.lib;uuid.lib;D3D9.lib;Dxva2.lib;libmfx.lib;strmiids.lib</AdditionalDependencies>
<Version>
</Version>
<IgnoreSpecificDefaultLibraries>LIBCMT.LIB</IgnoreSpecificDefaultLibraries>
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
</Link>
<ResourceCompile>
<Culture>0x0409</Culture>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@ -141,76 +133,76 @@
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;DEBUG;_DEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996;4245;4995</DisableSpecificWarnings>
<MinimalRebuild>false</MinimalRebuild>
<DisableSpecificWarnings>4996;4995</DisableSpecificWarnings>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MinimalRebuild>false</MinimalRebuild>
<TreatWarningAsError>true</TreatWarningAsError>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<EnablePREfast>false</EnablePREfast>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalIncludeDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Include;$(INTELMEDIASDK_WINSDK_PATH)\Include\um;$(INTELMEDIASDK_WINSDK_PATH)\Include\shared;MSDK\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>IntelQuickSyncDecoder.def</ModuleDefinitionFile>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<AdditionalDependencies>winmm.lib;uuid.lib;D3D9.lib;Dxva2.lib;libmfx.lib;strmiids.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib</IgnoreSpecificDefaultLibraries>
<AdditionalLibraryDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Lib\x64;$(INTELMEDIASDK_WINSDK_PATH)\Lib\win8\um\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OutputFile>$(SolutionDir)bin\$(TargetName)$(TargetExt)</OutputFile>
<ProgramDatabaseFile>$(OutDir)$(TargetName).pdb</ProgramDatabaseFile>
<AdditionalDependencies>winmm.lib;uuid.lib;D3D9.lib;Dxva2.lib;libmfx.lib;strmiids.lib</AdditionalDependencies>
<Version>
</Version>
<IgnoreSpecificDefaultLibraries>LIBCMT.LIB</IgnoreSpecificDefaultLibraries>
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
</Link>
<ResourceCompile>
<Culture>0x0409</Culture>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996;4995</DisableSpecificWarnings>
<WarningLevel>Level4</WarningLevel>
<AdditionalIncludeDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Include;$(INTELMEDIASDK_WINSDK_PATH)\Include\um;$(INTELMEDIASDK_WINSDK_PATH)\Include\shared;MSDK\include</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996;4245;4995</DisableSpecificWarnings>
<MinimalRebuild>false</MinimalRebuild>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<StringPooling>true</StringPooling>
<EnablePREfast>false</EnablePREfast>
<TreatWarningAsError>true</TreatWarningAsError>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>IntelQuickSyncDecoder.def</ModuleDefinitionFile>
<AdditionalDependencies>winmm.lib;uuid.lib;D3D9.lib;Dxva2.lib;libmfx.lib;strmiids.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Lib;$(INTELMEDIASDK_WINSDK_PATH)\Lib\win8\um\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OptimizeReferences>true</OptimizeReferences>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<OutputFile>$(SolutionDir)bin\$(TargetName)$(TargetExt)</OutputFile>
<ProgramDatabaseFile>$(OutDir)$(TargetName).pdb</ProgramDatabaseFile>
<AdditionalDependencies>winmm.lib;uuid.lib;D3D9.lib;Dxva2.lib;libmfx.lib;strmiids.lib</AdditionalDependencies>
<Version>
</Version>
<IgnoreSpecificDefaultLibraries>LIBCMTD.LIB</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<ResourceCompile>
<Culture>0x0409</Culture>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996;4995</DisableSpecificWarnings>
<WarningLevel>Level4</WarningLevel>
<AdditionalIncludeDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Include;$(INTELMEDIASDK_WINSDK_PATH)\Include\um;$(INTELMEDIASDK_WINSDK_PATH)\Include\shared;MSDK\include</AdditionalIncludeDirectories>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996;4245;4995</DisableSpecificWarnings>
<MinimalRebuild>false</MinimalRebuild>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<StringPooling>true</StringPooling>
<EnablePREfast>false</EnablePREfast>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AssemblerOutput>NoListing</AssemblerOutput>
<TreatWarningAsError>true</TreatWarningAsError>
@ -219,18 +211,20 @@
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<ModuleDefinitionFile>IntelQuickSyncDecoder.def</ModuleDefinitionFile>
<AdditionalDependencies>winmm.lib;uuid.lib;D3D9.lib;Dxva2.lib;libmfx.lib;strmiids.lib;d3d11.lib;dxgi.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Lib\x64;$(INTELMEDIASDK_WINSDK_PATH)\Lib\win8\um\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>IntelQuickSyncDecoder.def</ModuleDefinitionFile>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<OutputFile>$(SolutionDir)bin\$(TargetName)$(TargetExt)</OutputFile>
<ProgramDatabaseFile>$(OutDir)$(TargetName).pdb</ProgramDatabaseFile>
<AdditionalDependencies>winmm.lib;uuid.lib;D3D9.lib;Dxva2.lib;libmfx.lib;strmiids.lib</AdditionalDependencies>
<Version>
</Version>
<IgnoreSpecificDefaultLibraries>LIBCMTD.LIB</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<ResourceCompile>
<Culture>0x0409</Culture>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="IntelQuickSyncDecoder.def" />
@ -239,7 +233,11 @@
<ItemGroup>
<ClInclude Include="base_allocator.h" />
<ClInclude Include="CodecInfo.h" />
<ClInclude Include="d3d11_allocator.h" />
<ClInclude Include="d3d11_device.h" />
<ClInclude Include="d3d_device.h" />
<ClInclude Include="H264Nalu.h" />
<ClInclude Include="hw_device.h" />
<ClInclude Include="QuickSyncDecoder.h" />
<ClInclude Include="d3d_allocator.h" />
<ClInclude Include="IQuickSyncDecoder.h" />
@ -255,6 +253,9 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="base_alllocator.cpp" />
<ClCompile Include="d3d11_allocator.cpp" />
<ClCompile Include="d3d11_device.cpp" />
<ClCompile Include="d3d_device.cpp" />
<ClCompile Include="QuickSyncExports.cpp" />
<ClCompile Include="H264Nalu.cpp" />
<ClCompile Include="QuickSyncDecoder.cpp" />

View File

@ -10,47 +10,47 @@
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{0a386d10-f3de-44fa-855a-fa02aa8f04c8}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Allocators">
<UniqueIdentifier>{d0d35276-a574-4006-bb70-9350604f3e2c}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Allocators">
<UniqueIdentifier>{a0e0c84e-fde0-4d98-873b-2a47cf08f555}</UniqueIdentifier>
<UniqueIdentifier>{72d0b727-3294-44aa-9d82-62b45ffad724}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Utility">
<UniqueIdentifier>{28809b95-8c9e-4592-81f1-af707618bdcc}</UniqueIdentifier>
<UniqueIdentifier>{db3d63f1-bcc7-45a4-a77e-c82371e4a86b}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Allocators">
<UniqueIdentifier>{c57451da-9975-423e-9e1e-c8667c98c3a9}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Allocators">
<UniqueIdentifier>{f1fdd9a0-ea0d-4419-b2d6-4fa904080c16}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Utility">
<UniqueIdentifier>{9bc60ada-7b15-4dad-83d7-50c78f406f4e}</UniqueIdentifier>
<UniqueIdentifier>{d85caa20-ea42-474b-a316-3d0324321b2c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="QuickSync.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="frame_constructors.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="QuickSync_defs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TimeManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="QuickSyncDecoder.h">
<ClInclude Include="CodecInfo.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="H264Nalu.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="QuickSyncDecoder.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IQuickSyncDecoder.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CodecInfo.h">
<ClInclude Include="frame_constructors.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="QuickSync.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="QuickSync_defs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TimeManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
@ -59,10 +59,10 @@
<ClInclude Include="base_allocator.h">
<Filter>Header Files\Allocators</Filter>
</ClInclude>
<ClInclude Include="sysmem_allocator.h">
<ClInclude Include="d3d_allocator.h">
<Filter>Header Files\Allocators</Filter>
</ClInclude>
<ClInclude Include="d3d_allocator.h">
<ClInclude Include="sysmem_allocator.h">
<Filter>Header Files\Allocators</Filter>
</ClInclude>
<ClInclude Include="QuickSyncUtils.h">
@ -71,48 +71,71 @@
<ClInclude Include="QuickSyncVPP.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="d3d11_allocator.h">
<Filter>Header Files\Allocators</Filter>
</ClInclude>
<ClInclude Include="d3d11_device.h">
<Filter>Header Files\Allocators</Filter>
</ClInclude>
<ClInclude Include="hw_device.h">
<Filter>Header Files\Allocators</Filter>
</ClInclude>
<ClInclude Include="d3d_device.h">
<Filter>Header Files\Allocators</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="QuickSync.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="frame_constructors.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="QuickSyncDecoder.cpp">
<ClCompile Include="QuickSyncExports.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="H264Nalu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="QuickSyncDecoder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="frame_constructors.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="QuickSync.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TimeManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="QuickSyncExports.cpp">
<Filter>Source Files</Filter>
<ClCompile Include="QuickSyncUtils.cpp">
<Filter>Source Files\Utility</Filter>
</ClCompile>
<ClCompile Include="sysmem_allocator.cpp">
<ClCompile Include="base_alllocator.cpp">
<Filter>Source Files\Allocators</Filter>
</ClCompile>
<ClCompile Include="d3d_allocator.cpp">
<Filter>Source Files\Allocators</Filter>
</ClCompile>
<ClCompile Include="base_alllocator.cpp">
<ClCompile Include="sysmem_allocator.cpp">
<Filter>Source Files\Allocators</Filter>
</ClCompile>
<ClCompile Include="QuickSyncUtils.cpp">
<Filter>Source Files\Utility</Filter>
</ClCompile>
<ClCompile Include="QuickSyncVPP.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="d3d11_allocator.cpp">
<Filter>Source Files\Allocators</Filter>
</ClCompile>
<ClCompile Include="d3d11_device.cpp">
<Filter>Source Files\Allocators</Filter>
</ClCompile>
<ClCompile Include="d3d_device.cpp">
<Filter>Source Files\Allocators</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="IntelQuickSyncDecoder.def">
<Filter>Source Files</Filter>
</None>
<None Include="license.txt" />
<None Include="IntelQuickSyncDecoder.def" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="IntelQuickSyncDecoder.rc">

Binary file not shown.

Binary file not shown.

View File

@ -68,7 +68,6 @@ CQuickSync::CQuickSync() :
strcpy(m_CodecName, "Intel\xae QuickSync Decoder");
mfxStatus sts = MFX_ERR_NONE;
m_pDecoder = new CQuickSyncDecoder(sts);
MSDK_ZERO_VAR(m_DecVideoParams);
//m_DecVideoParams.AsyncDepth = 0; // Causes issues when 1 - in old drivers
@ -107,7 +106,11 @@ CQuickSync::CQuickSync() :
// m_Config.nVppDenoiseStrength = 16; // 0-64
// m_Config.bDropDuplicateFrames = true;
//m_Config.bEnableD3D11 = true;
m_pDecoder = new CQuickSyncDecoder(m_Config, sts);
m_OK = (sts == MFX_ERR_NONE);
}
@ -703,7 +706,7 @@ HRESULT CQuickSync::Decode(IMediaSample* pSample)
}
if (SUCCEEDED(hr) && !m_bNeedToFlush)
m_pFrameConstructor->SaveResidialData(&mfxBS);
m_pFrameConstructor->SaveResidualData(&mfxBS);
MSDK_SAFE_DELETE_ARRAY(mfxBS.Data);

View File

@ -31,30 +31,13 @@
#include "QuickSync_defs.h"
#include "QuickSyncUtils.h"
#include "QuickSyncDecoder.h"
#include "d3d_device.h"
#include "d3d11_device.h"
static int GetIntelAdapterId(IDirect3D9* pd3d)
{
MSDK_CHECK_POINTER(pd3d, 0);
unsigned adapterCount = (int)pd3d->GetAdapterCount();
D3DADAPTER_IDENTIFIER9 adIdentifier;
for (int i = adapterCount-1; i >= 0; --i)
{
HRESULT hr = pd3d->GetAdapterIdentifier(i, 0, &adIdentifier);
if (SUCCEEDED(hr))
{
// Look for Intel's vendor ID (8086h)
if (adIdentifier.VendorId == 0x8086)
return i;
}
}
return -1;
}
CQuickSyncDecoder::CQuickSyncDecoder(mfxStatus& sts) :
CQuickSyncDecoder::CQuickSyncDecoder(const CQsConfig& cfg, mfxStatus& sts) :
m_mfxVideoSession(NULL),
m_mfxImpl(MFX_IMPL_UNSUPPORTED),
m_Config(cfg),
m_pmfxDEC(0),
m_pVideoParams(0),
m_pFrameAllocator(NULL),
@ -62,20 +45,24 @@ CQuickSyncDecoder::CQuickSyncDecoder(mfxStatus& sts) :
m_nRequiredFramesNum(0),
m_nAuxFrameCount(0),
m_pRendererD3dDeviceManager(NULL),
m_pD3dDeviceManager(NULL),
m_pD3dDevice(NULL),
m_ResetToken(0)
m_HwDevice(NULL)
{
MSDK_ZERO_VAR(m_AllocResponse);
m_ApiVersion.Major = MIN_REQUIRED_API_VER_MAJOR;
m_ApiVersion.Minor = MIN_REQUIRED_API_VER_MINOR;
mfxIMPL impl = MFX_IMPL_AUTO_ANY;
impl |= (m_Config.bEnableD3D11) ? MFX_IMPL_VIA_D3D11 : MFX_IMPL_VIA_D3D9;
// Uncomment for SW emulation
// Uncomment for SW emulation (Media SDK software DLL must be present)
//impl = MFX_IMPL_SOFTWARE;
sts = InitSession(impl);
if (sts == MFX_ERR_NONE && !m_Config.bEnableD3D11 && 0 > GetIntelAdapterIdD3D9(NULL))
{
MSDK_TRACE("QsDecoder: can't create HW decoder, the iGPU is not connected to a screen!\n");
sts = MFX_ERR_UNSUPPORTED;
}
}
CQuickSyncDecoder::~CQuickSyncDecoder()
@ -105,6 +92,7 @@ mfxStatus CQuickSyncDecoder::InitSession(mfxIMPL impl)
m_bHwAcceleration = m_mfxImpl != MFX_IMPL_SOFTWARE;
m_bUseD3DAlloc = m_bHwAcceleration;
m_bUseD3D11Alloc = m_bUseD3DAlloc && ((m_mfxImpl & MFX_IMPL_VIA_D3D11) == MFX_IMPL_VIA_D3D11);
m_pmfxDEC = new MFXVideoDECODE((mfxSession)*m_mfxVideoSession);
MSDK_ZERO_MEMORY((void*)&m_LockedSurfaces, sizeof(m_LockedSurfaces));
@ -247,7 +235,11 @@ mfxStatus CQuickSyncDecoder::InternalReset(mfxVideoParam* pVideoParams, mfxU32 n
MSDK_CHECK_RESULT_P_RET(sts, MFX_ERR_NONE);
if (m_bUseD3DAlloc)
{
m_mfxVideoSession->SetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER, m_pD3dDeviceManager);
// get relevant handle from HW device and notify the session
mfxHandleType hType = (m_bUseD3D11Alloc) ? MFX_HANDLE_D3D11_DEVICE : MFX_HANDLE_D3D9_DEVICE_MANAGER;
mfxHDL h = m_HwDevice->GetHandle(hType);
m_mfxVideoSession->SetHandle(hType, h);
// Note - setting the session allocator can be done only once (per session)!
sts = m_mfxVideoSession->SetFrameAllocator(m_pFrameAllocator);
if (sts != MFX_ERR_NONE)
@ -380,92 +372,9 @@ mfxStatus CQuickSyncDecoder::Decode(mfxBitstream* pBS, mfxFrameSurface1*& pOutSu
return sts;
}
mfxStatus CQuickSyncDecoder::InitD3D()
{
if (!m_bUseD3DAlloc)
{
return MFX_ERR_NONE;
}
// Check if the d3d device is functional:
if (m_pD3dDeviceManager != NULL)
{
HRESULT hr = m_pD3dDevice->TestCooperativeLevel();
if (FAILED(hr))
{
CloseD3D();
}
else
{
return MFX_ERR_NONE;
}
}
// Create Direct3D
CComPtr<IDirect3D9> pd3d = Direct3DCreate9(D3D_SDK_VERSION);
UINT resetToken;
if (!pd3d)
{
return MFX_ERR_NULL_PTR;
}
static const POINT point = {0, 0};
const HWND hWnd = GetForegroundWindow();
if (hWnd == NULL)
{
MSDK_TRACE("QsDecoder: failed to create HWND.\n");
return MFX_ERR_DEVICE_FAILED;
}
D3DPRESENT_PARAMETERS d3dParams = {1, 1, D3DFMT_X8R8G8B8, 1, D3DMULTISAMPLE_NONE, 0, D3DSWAPEFFECT_DISCARD, hWnd, TRUE, FALSE, D3DFMT_UNKNOWN, 0, 0, D3DPRESENT_INTERVAL_IMMEDIATE};
// Find Intel adapter number - not always the default adapter
int adapterId = GetIntelAdapterId(pd3d);
if (adapterId < 0)
{
MSDK_TRACE("QsDecoder: didn't find an Intel GPU.\n");
return MFX_ERR_DEVICE_FAILED;
}
// Create d3d device
m_pD3dDevice = 0;
HRESULT hr = pd3d->CreateDevice(
adapterId,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
&d3dParams,
&m_pD3dDevice);
if (FAILED(hr) || !m_pD3dDevice)
{
MSDK_TRACE("QsDecoder: InitD3d CreateDevice failed!\n");
return MFX_ERR_DEVICE_FAILED;
}
// Create device manager
m_pD3dDeviceManager = NULL;
hr = DXVA2CreateDirect3DDeviceManager9(&resetToken, &m_pD3dDeviceManager);
if (FAILED(hr) || !m_pD3dDeviceManager)
{
MSDK_TRACE("QsDecoder: InitD3d DXVA2CreateDirect3DDeviceManager9 failed!\n");
return MFX_ERR_DEVICE_FAILED;
}
// Reset the d3d device
hr = m_pD3dDeviceManager->ResetDevice(m_pD3dDevice, resetToken);
if (FAILED(hr))
{
MSDK_TRACE("QsDecoder: InitD3d ResetDevice failed!\n");
return MFX_ERR_DEVICE_FAILED;
}
return MFX_ERR_NONE;
}
mfxStatus CQuickSyncDecoder::InitD3DFromRenderer()
{
/*
MSDK_VTRACE("QsDecoder: InitD3DFromRenderer\n");
// Get DirectX Object
@ -518,7 +427,7 @@ mfxStatus CQuickSyncDecoder::InitD3DFromRenderer()
}
// Find Intel adapter number - not always the default adapter
int adapterId = GetIntelAdapterId(pD3D);
int adapterId = GetIntelAdapterIdD3D9(pD3D);
if (adapterId < 0)
{
hr = E_FAIL;
@ -577,6 +486,8 @@ done:
}
return sts;
*/
return MFX_ERR_NONE;
}
void CQuickSyncDecoder::CloseD3D()
@ -586,13 +497,10 @@ void CQuickSyncDecoder::CloseD3D()
if (m_mfxVideoSession)
{
m_mfxVideoSession->SetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER, NULL);
m_mfxVideoSession->SetHandle(MFX_HANDLE_D3D11_DEVICE, NULL);
}
if (m_pD3dDevice)
{
MSDK_SAFE_RELEASE(m_pD3dDeviceManager);
MSDK_SAFE_RELEASE(m_pD3dDevice);
}
MSDK_SAFE_DELETE(m_HwDevice);
}
}
@ -642,37 +550,57 @@ mfxStatus CQuickSyncDecoder::CreateAllocator()
if (NULL == m_pVideoParams)
return MFX_ERR_NOT_INITIALIZED;
std::auto_ptr<D3DAllocatorParams> pParam(NULL);
std::auto_ptr<mfxAllocatorParams> pParam(NULL);
mfxStatus sts = MFX_ERR_NONE;
// Setup allocator - HW acceleration
if (m_bUseD3DAlloc)
{
m_pVideoParams->IOPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY | MFX_IOPATTERN_IN_VIDEO_MEMORY;
ASSERT (m_pD3dDeviceManager == NULL);
// Couldn't create our own device - probably a full screen exclusive player.
// We'll use the supplied renderer's device manager.
if (m_pRendererD3dDeviceManager)
int nAdapterID = GetMSDKAdapterNumber(*m_mfxVideoSession);
// D3D11 HW device
if (m_bUseD3D11Alloc)
{
sts = InitD3DFromRenderer();
m_HwDevice = new CD3D11Device();
if (MFX_ERR_NONE != (sts = m_HwDevice->Init(nAdapterID)))
{
MSDK_TRACE("QsDecoder: D3D11 init have failed!\n");
MSDK_SAFE_DELETE(m_HwDevice);
return sts;
}
D3D11AllocatorParams* p = new D3D11AllocatorParams;
p->pDevice = (ID3D11Device*)m_HwDevice->GetHandle(MFX_HANDLE_D3D11_DEVICE);
pParam.reset(p);
m_pFrameAllocator = new D3D11FrameAllocator();
}
// D3D9 HW device
else
{
sts = InitD3D();
// Having the D3D9 device manager from the renderer allows working in full screen exclusive mode
// This parameter can be NULL for other usages
m_HwDevice = new CD3D9Device(m_pRendererD3dDeviceManager);
if (MFX_ERR_NONE != (sts = m_HwDevice->Init(nAdapterID)))
{
MSDK_TRACE("QsDecoder: D3D9 init have failed!\n");
MSDK_SAFE_DELETE(m_HwDevice);
return sts;
}
D3DAllocatorParams* p = new D3DAllocatorParams;
p->pManager = (IDirect3DDeviceManager9*)m_HwDevice->GetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER);
pParam.reset(p);
m_pFrameAllocator = new D3DFrameAllocator();
}
if (sts != MFX_ERR_NONE)
{
MSDK_TRACE("QsDecoder: InitD3D failed!\n");
return sts;
}
m_mfxVideoSession->SetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER, m_pD3dDeviceManager);
pParam.reset(new D3DAllocatorParams);
pParam->pManager = m_pD3dDeviceManager;
m_pFrameAllocator = new D3DFrameAllocator();
// Set the pointer to the HW device (or device manager) to the session
mfxHandleType hType = (m_bUseD3D11Alloc) ? MFX_HANDLE_D3D11_DEVICE : MFX_HANDLE_D3D9_DEVICE_MANAGER;
mfxHDL h = m_HwDevice->GetHandle(hType);
m_mfxVideoSession->SetHandle(hType, h);
}
// Setup allocator - No HW acceleration
else
@ -718,6 +646,16 @@ mfxStatus CQuickSyncDecoder::UnlockFrame(mfxFrameSurface1* pSurface, mfxFrameDat
return m_pFrameAllocator->Unlock(m_pFrameAllocator, pSurface->Data.MemId, pFrameData);
}
IDirect3DDeviceManager9* CQuickSyncDecoder::GetD3DDeviceManager()
{
if (!m_bUseD3D11Alloc && m_HwDevice != NULL)
{
return (IDirect3DDeviceManager9*)m_HwDevice->GetHandle(MFX_HANDLE_DIRECT3D_DEVICE_MANAGER9);
}
return NULL;
}
bool CQuickSyncDecoder::SetD3DDeviceManager(IDirect3DDeviceManager9* pDeviceManager)
{
if (m_pRendererD3dDeviceManager == pDeviceManager)

View File

@ -28,7 +28,9 @@
#pragma once
#include "hw_device.h"
#include "d3d_allocator.h"
#include "d3d11_allocator.h"
#include "sysmem_allocator.h"
typedef std::deque<mfxFrameSurface1*> TSurfaceQueue;
@ -36,7 +38,7 @@ typedef std::deque<mfxFrameSurface1*> TSurfaceQueue;
class CQuickSyncDecoder
{
public:
CQuickSyncDecoder(mfxStatus& sts);
CQuickSyncDecoder(const CQsConfig& cfg, mfxStatus& sts);
~CQuickSyncDecoder();
mfxStatus Init(mfxVideoParam* pVideoParams, mfxU32 nPitch)
@ -51,11 +53,7 @@ public:
mfxStatus Decode(mfxBitstream* pBS, mfxFrameSurface1*& pOutSurface);
mfxStatus GetVideoParams(mfxVideoParam* pVideoParams);
IDirect3DDeviceManager9* GetD3DDeviceManager()
{
return m_pD3dDeviceManager;
}
IDirect3DDeviceManager9* GetD3DDeviceManager();
bool SetD3DDeviceManager(IDirect3DDeviceManager9* pDeviceManager);
mfxStatus CreateAllocator();
@ -161,7 +159,6 @@ protected:
mfxStatus InternalReset(mfxVideoParam* pVideoParams, mfxU32 nPitch, bool bInited);
mfxStatus InitSession(mfxIMPL impl);
void CloseSession();
mfxStatus InitD3D();
mfxStatus InitD3DFromRenderer();
void CloseD3D();
@ -183,13 +180,12 @@ protected:
mfxFrameAllocResponse m_AllocResponse;
mfxU16 m_nRequiredFramesNum;
bool m_bUseD3DAlloc;
bool m_bUseD3D11Alloc;
mfxU16 m_nAuxFrameCount;
// D3D/DXVA interfaces
IDirect3DDeviceManager9* m_pRendererD3dDeviceManager;
IDirect3DDeviceManager9* m_pD3dDeviceManager;
IDirect3DDevice9* m_pD3dDevice;
UINT m_ResetToken;
CHWDevice* m_HwDevice;
TSurfaceQueue m_OutputSurfaceQueue;
volatile LONG m_LockedSurfaces[MAX_SURFACES];

View File

@ -88,7 +88,7 @@ DWORD __stdcall check()
{
mfxVersion apiVersion = {1, 1};
MFXVideoSession* pSession = new MFXVideoSession;
mfxIMPL impl = MFX_IMPL_AUTO_ANY;
mfxIMPL impl = MFX_IMPL_AUTO_ANY | MFX_IMPL_VIA_ANY;
mfxStatus sts = pSession->Init(impl, &apiVersion);
MSDK_CHECK_NOT_EQUAL(sts, MFX_ERR_NONE, QS_CAP_UNSUPPORTED);
pSession->QueryIMPL(&impl);

View File

@ -34,6 +34,23 @@
static bool s_SSE4_1_enabled = IsSSE41Enabled();
static bool s_AVX2_enabled = IsAVX2Enabled();
static const
struct
{
// actual implementation
mfxIMPL impl;
// adapter's number
int adapterID;
} implTypes[] =
{
{MFX_IMPL_HARDWARE, 0},
{MFX_IMPL_SOFTWARE, -1},
{MFX_IMPL_HARDWARE2, 1},
{MFX_IMPL_HARDWARE3, 2},
{MFX_IMPL_HARDWARE4, 3}
};
// gpu_memcpy_sse41 is a memcpy style function that copied data very fast from a
// GPU tiled memory (uncached speculative write back memory)
// Performance tip: page offset (12 lsb) of both addresses should be different
@ -477,3 +494,67 @@ void* mt_gpu_memcpy(void* d, const void* s, size_t size)
mt_copy(d, s, size, gpu_memcpy_avx2) :
mt_copy(d, s, size, gpu_memcpy_sse41);
}
int GetIntelAdapterIdD3D9(IDirect3D9* _pd3d)
{
CComPtr<IDirect3D9> pd3d = _pd3d;
if (!pd3d)
{
pd3d = Direct3DCreate9(D3D_SDK_VERSION);
if (!pd3d) return -1;
}
unsigned adapterCount = (int)pd3d->GetAdapterCount();
D3DADAPTER_IDENTIFIER9 adIdentifier;
for (int i = adapterCount-1; i >= 0; --i)
{
HRESULT hr = pd3d->GetAdapterIdentifier(i, 0, &adIdentifier);
if (SUCCEEDED(hr))
{
// Look for Intel's vendor ID (8086h)
if (adIdentifier.VendorId == 0x8086)
return i;
}
}
return -1;
}
// Get the ID of the adapter (GPU) associated with an MSDK session, -1 for SW session
int GetMSDKAdapterNumber(mfxSession session)
{
int adapterNum = -1; // SW
mfxIMPL impl = MFX_IMPL_SOFTWARE; // default in case no HW IMPL is found
// we don't care for error codes in further code; if something goes wrong we fall back to the default adapter
if (session)
{
MFXQueryIMPL(session, &impl);
}
else
{
// an auxiliary session, internal for this function
mfxSession auxSession;
memset(&auxSession, 0, sizeof(auxSession));
mfxVersion ver = {1, 1}; // minimum API version which supports multiple devices
MFXInit(MFX_IMPL_HARDWARE_ANY, &ver, &auxSession);
MFXQueryIMPL(auxSession, &impl);
MFXClose(auxSession);
}
// extract the base implementation type
mfxIMPL baseImpl = MFX_IMPL_BASETYPE(impl);
// get corresponding adapter number
for (mfxU8 i = 0; i < sizeof(implTypes)/sizeof(implTypes[0]); ++i)
{
if (implTypes[i].impl == baseImpl)
{
adapterNum = implTypes[i].adapterID;
break;
}
}
return adapterNum;
}

View File

@ -62,6 +62,12 @@ bool IsAVX2Enabled();
// Set current thread name in VS debugger
void SetThreadName(LPCSTR szThreadName, DWORD dwThreadID = -1 /* current thread */);
// Get an Intel GPU ID using Direct3D9 (screen must be connected to Intel GPU)
int GetIntelAdapterIdD3D9(IDirect3D9* _pd3d);
// Get the ID of the adapter (GPU) associated with an MSDK session, -1 for SW session
int GetMSDKAdapterNumber(mfxSession session);
#ifdef _DEBUG
// Print assert to debugger output
void DebugAssert(const TCHAR *pCondition,const TCHAR *pFileName, int iLine);

View File

@ -67,6 +67,8 @@
#define MSDK_ALIGN16(SZ) ((SZ + 15) & (~15)) // round up to a multiple of 16
#define MSDK_ALIGN32(SZ) ((SZ + 31) & (~31)) // round up to a multiple of 32
#define MSDK_MEMCPY_VAR(dstVarName, src, count) memcpy_s(&(dstVarName), sizeof(dstVarName), (src), (count))
#ifdef _DEBUG
# define ASSERT(_x_) { if (!(_x_)) DebugAssert(_T(#_x_),_T(__FILE__),__LINE__); }
#else

463
d3d11_allocator.cpp Normal file
View File

@ -0,0 +1,463 @@
/*
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* Neither the name of INTEL CORPORATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdafx.h"
#include "QuickSync_defs.h"
#if MFX_D3D11_SUPPORT
#include "d3d11_allocator.h"
#define D3DFMT_NV12 (DXGI_FORMAT)MAKEFOURCC('N','V','1','2')
#define D3DFMT_YV12 (DXGI_FORMAT)MAKEFOURCC('Y','V','1','2')
//for generating sequence of mfx handles
template <typename T>
struct sequence {
T x;
sequence(T seed) : x(seed) { }
};
template <>
struct sequence<mfxHDL> {
mfxHDL x;
sequence(mfxHDL seed) : x(seed) { }
mfxHDL operator ()()
{
mfxHDL y = x;
x = (mfxHDL)(1 + (size_t)(x));
return y;
}
};
D3D11FrameAllocator::D3D11FrameAllocator()
{
m_pDeviceContext = NULL;
}
D3D11FrameAllocator::~D3D11FrameAllocator()
{
Close();
}
D3D11FrameAllocator::TextureSubResource D3D11FrameAllocator::GetResourceFromMid(mfxMemId mid)
{
size_t index = (size_t)MFXReadWriteMid(mid).raw() - 1;
if(m_memIdMap.size() <= index)
return TextureSubResource();
//reverse iterator dereferencing
TextureResource * p = &(*m_memIdMap[index]);
if (!p->bAlloc)
return TextureSubResource();
return TextureSubResource(p, mid);
}
mfxStatus D3D11FrameAllocator::Init(mfxAllocatorParams *pParams)
{
D3D11AllocatorParams *pd3d11Params = 0;
pd3d11Params = dynamic_cast<D3D11AllocatorParams *>(pParams);
if (NULL == pd3d11Params ||
NULL == pd3d11Params->pDevice)
{
return MFX_ERR_NOT_INITIALIZED;
}
m_initParams = *pd3d11Params;
MSDK_SAFE_RELEASE(m_pDeviceContext);
pd3d11Params->pDevice->GetImmediateContext(&m_pDeviceContext);
return MFX_ERR_NONE;
}
mfxStatus D3D11FrameAllocator::Close()
{
mfxStatus sts = BaseFrameAllocator::Close();
for(referenceType i = m_resourcesByRequest.begin(); i != m_resourcesByRequest.end(); i++)
{
i->Release();
}
m_resourcesByRequest.clear();
m_memIdMap.clear();
MSDK_SAFE_RELEASE(m_pDeviceContext);
return sts;
}
mfxStatus D3D11FrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
{
HRESULT hRes = S_OK;
D3D11_TEXTURE2D_DESC desc = {0};
D3D11_MAPPED_SUBRESOURCE lockedRect = {0};
//check that texture exists
TextureSubResource sr = GetResourceFromMid(mid);
if (!sr.GetTexture())
return MFX_ERR_LOCK_MEMORY;
D3D11_MAP mapType = D3D11_MAP_READ;
UINT mapFlags = D3D11_MAP_FLAG_DO_NOT_WAIT;
{
if (NULL == sr.GetStaging())
{
hRes = m_pDeviceContext->Map(sr.GetTexture(), sr.GetSubResource(), D3D11_MAP_READ, D3D11_MAP_FLAG_DO_NOT_WAIT, &lockedRect);
desc.Format = DXGI_FORMAT_P8;
}
else
{
sr.GetTexture()->GetDesc(&desc);
if (DXGI_FORMAT_NV12 != desc.Format &&
DXGI_FORMAT_420_OPAQUE != desc.Format &&
DXGI_FORMAT_YUY2 != desc.Format &&
DXGI_FORMAT_P8 != desc.Format &&
DXGI_FORMAT_B8G8R8A8_UNORM != desc.Format)
{
return MFX_ERR_LOCK_MEMORY;
}
//coping data only in case user wants to read from stored surface
{
if (MFXReadWriteMid(mid, MFXReadWriteMid::reuse).isRead())
{
m_pDeviceContext->CopySubresourceRegion(sr.GetStaging(), 0, 0, 0, 0, sr.GetTexture(), sr.GetSubResource(), NULL);
}
do
{
hRes = m_pDeviceContext->Map(sr.GetStaging(), 0, mapType, mapFlags, &lockedRect);
if (S_OK != hRes && DXGI_ERROR_WAS_STILL_DRAWING != hRes)
{
printf("ERROR: m_pDeviceContext->Map = 0x%X\n", hRes);
}
}
while (DXGI_ERROR_WAS_STILL_DRAWING == hRes);
}
}
}
if (FAILED(hRes))
return MFX_ERR_LOCK_MEMORY;
switch (desc.Format)
{
case DXGI_FORMAT_NV12:
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
ptr->Y = (mfxU8 *)lockedRect.pData;
ptr->U = (mfxU8 *)lockedRect.pData + desc.Height * lockedRect.RowPitch;
ptr->V = ptr->U + 1;
break;
case DXGI_FORMAT_420_OPAQUE: // can be unsupported by standard ms guid
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
ptr->Y = (mfxU8 *)lockedRect.pData;
ptr->V = ptr->Y + desc.Height * lockedRect.RowPitch;
ptr->U = ptr->V + (desc.Height * lockedRect.RowPitch) / 4;
break;
case DXGI_FORMAT_YUY2:
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
ptr->Y = (mfxU8 *)lockedRect.pData;
ptr->U = ptr->Y + 1;
ptr->V = ptr->Y + 3;
break;
case DXGI_FORMAT_P8 :
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
ptr->Y = (mfxU8 *)lockedRect.pData;
ptr->U = 0;
ptr->V = 0;
break;
case DXGI_FORMAT_B8G8R8A8_UNORM :
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
ptr->B = (mfxU8 *)lockedRect.pData;
ptr->G = ptr->B + 1;
ptr->R = ptr->B + 2;
ptr->A = ptr->B + 3;
break;
default:
return MFX_ERR_LOCK_MEMORY;
}
return MFX_ERR_NONE;
}
mfxStatus D3D11FrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData *ptr)
{
//check that texture exists
TextureSubResource sr = GetResourceFromMid(mid);
if (!sr.GetTexture())
return MFX_ERR_LOCK_MEMORY;
if (NULL == sr.GetStaging())
{
m_pDeviceContext->Unmap(sr.GetTexture(), sr.GetSubResource());
}
else
{
m_pDeviceContext->Unmap(sr.GetStaging(), 0);
//only if user wrote something to texture
if (MFXReadWriteMid(mid, MFXReadWriteMid::reuse).isWrite())
{
m_pDeviceContext->CopySubresourceRegion(sr.GetTexture(), sr.GetSubResource(), 0, 0, 0, sr.GetStaging(), 0, NULL);
}
}
if (ptr)
{
ptr->Pitch=0;
ptr->U=ptr->V=ptr->Y=0;
ptr->A=ptr->R=ptr->G=ptr->B=0;
}
return MFX_ERR_NONE;
}
mfxStatus D3D11FrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL *handle)
{
if (NULL == handle)
return MFX_ERR_INVALID_HANDLE;
TextureSubResource sr = GetResourceFromMid(mid);
if (!sr.GetTexture())
return MFX_ERR_INVALID_HANDLE;
mfxHDLPair *pPair = (mfxHDLPair*)handle;
pPair->first = sr.GetTexture();
pPair->second = (mfxHDL)(UINT_PTR)sr.GetSubResource();
return MFX_ERR_NONE;
}
mfxStatus D3D11FrameAllocator::CheckRequestType(mfxFrameAllocRequest *request)
{
mfxStatus sts = BaseFrameAllocator::CheckRequestType(request);
if (MFX_ERR_NONE != sts)
return sts;
if ((request->Type & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)) != 0)
return MFX_ERR_NONE;
else
return MFX_ERR_UNSUPPORTED;
}
mfxStatus D3D11FrameAllocator::ReleaseResponse(mfxFrameAllocResponse *response)
{
if (NULL == response)
return MFX_ERR_NULL_PTR;
if (response->mids && 0 != response->NumFrameActual)
{
//check whether texture exsist
TextureSubResource sr = GetResourceFromMid(response->mids[0]);
if (!sr.GetTexture())
return MFX_ERR_NULL_PTR;
sr.Release();
//if texture is last it is possible to remove also all handles from map to reduce fragmentation
//search for allocated chunk
if (m_resourcesByRequest.end() == std::find_if(m_resourcesByRequest.begin(), m_resourcesByRequest.end(), TextureResource::isAllocated))
{
m_resourcesByRequest.clear();
m_memIdMap.clear();
}
}
return MFX_ERR_NONE;
}
mfxStatus D3D11FrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
{
HRESULT hRes;
DXGI_FORMAT colorFormat = ConverColortFormat(request->Info.FourCC);
if (DXGI_FORMAT_UNKNOWN == colorFormat)
{
return MFX_ERR_UNSUPPORTED;
}
TextureResource newTexture;
if (request->Info.FourCC == MFX_FOURCC_P8)
{
D3D11_BUFFER_DESC desc = { 0 };
desc.ByteWidth = request->Info.Width * request->Info.Height;
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.MiscFlags = 0;
desc.StructureByteStride = 0;
ID3D11Buffer * buffer = 0;
hRes = m_initParams.pDevice->CreateBuffer(&desc, 0, &buffer);
if (FAILED(hRes))
return MFX_ERR_MEMORY_ALLOC;
newTexture.textures.push_back(reinterpret_cast<ID3D11Texture2D *>(buffer));
}
else
{
D3D11_TEXTURE2D_DESC desc = {0};
desc.Width = request->Info.Width;
desc.Height = request->Info.Height;
desc.MipLevels = 1;
//number of subresources is 1 in case of not single texture
desc.ArraySize = m_initParams.bUseSingleTexture ? request->NumFrameSuggested : 1;
desc.Format = ConverColortFormat(request->Info.FourCC);
desc.SampleDesc.Count = 1;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.MiscFlags = m_initParams.uncompressedResourceMiscFlags;
desc.BindFlags = D3D11_BIND_DECODER;
if ( (MFX_MEMTYPE_FROM_VPPIN & request->Type) && (DXGI_FORMAT_YUY2 == desc.Format) ||
(DXGI_FORMAT_B8G8R8A8_UNORM == desc.Format) )
{
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
if (desc.ArraySize > 2)
return MFX_ERR_MEMORY_ALLOC;
}
if ( (MFX_MEMTYPE_FROM_VPPOUT & request->Type) ||
(MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & request->Type))
{
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
if (desc.ArraySize > 2)
return MFX_ERR_MEMORY_ALLOC;
}
if( DXGI_FORMAT_P8 == desc.Format )
{
desc.BindFlags = 0;
}
ID3D11Texture2D* pTexture2D;
for(size_t i = 0; i < request->NumFrameSuggested / desc.ArraySize; i++)
{
hRes = m_initParams.pDevice->CreateTexture2D(&desc, NULL, &pTexture2D);
if (FAILED(hRes))
{
printf("CreateTexture2D(%d) failed, hr = \n", i, hRes);
return MFX_ERR_MEMORY_ALLOC;
}
newTexture.textures.push_back(pTexture2D);
}
desc.ArraySize = 1;
desc.Usage = D3D11_USAGE_STAGING;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.BindFlags = 0;
desc.MiscFlags = 0;
for(size_t i = 0; i < request->NumFrameSuggested; i++)
{
hRes = m_initParams.pDevice->CreateTexture2D(&desc, NULL, &pTexture2D);
if (FAILED(hRes))
{
printf("Create staging texture(%d) failed hr = \n", i, hRes);
return MFX_ERR_MEMORY_ALLOC;
}
newTexture.stagingTexture.push_back(pTexture2D);
}
}
// mapping to self created handles array, starting from zero or from last assigned handle + 1
sequence<mfxHDL> seq_initializer(m_resourcesByRequest.empty() ? 0 : m_resourcesByRequest.back().outerMids.back());
//incrementing starting index
//1. 0(NULL) is invalid memid
//2. back is last index not new one
seq_initializer();
std::generate_n(std::back_inserter(newTexture.outerMids), request->NumFrameSuggested, seq_initializer);
//saving texture resources
m_resourcesByRequest.push_back(newTexture);
//providing pointer to mids externally
response->mids = &m_resourcesByRequest.back().outerMids.front();
response->NumFrameActual = request->NumFrameSuggested;
//iterator prior end()
std::list <TextureResource>::iterator it_last = m_resourcesByRequest.end();
//fill map
std::fill_n(std::back_inserter(m_memIdMap), request->NumFrameSuggested, --it_last);
return MFX_ERR_NONE;
}
DXGI_FORMAT D3D11FrameAllocator::ConverColortFormat(mfxU32 fourcc)
{
switch (fourcc)
{
case MFX_FOURCC_NV12:
return DXGI_FORMAT_NV12;
case MFX_FOURCC_YUY2:
return DXGI_FORMAT_YUY2;
case MFX_FOURCC_RGB4:
return DXGI_FORMAT_B8G8R8A8_UNORM;
case MFX_FOURCC_P8:
case MFX_FOURCC_P8_TEXTURE:
return DXGI_FORMAT_P8;
default:
return DXGI_FORMAT_UNKNOWN;
}
}
#endif //#if MFX_D3D11_SUPPORT

255
d3d11_allocator.h Normal file
View File

@ -0,0 +1,255 @@
/*
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* Neither the name of INTEL CORPORATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "base_allocator.h"
//application can provide either generic mid from surface or this wrapper
//wrapper distinguishes from generic mid by highest 1 bit
//if it set then remained pointer points to extended structure of memid
//64 bits system layout
/*----+-----------------------------------------------------------+
|b63=1|63 bits remained for pointer to extended structure of memid|
|b63=0|63 bits from original mfxMemId |
+-----+----------------------------------------------------------*/
//32 bits system layout
/*--+---+--------------------------------------------+
|b31=1|31 bits remained for pointer to extended memid|
|b31=0|31 bits remained for surface pointer |
+---+---+-------------------------------------------*/
//#pragma warning (disable:4293)
class MFXReadWriteMid
{
static const uintptr_t bits_offset = std::numeric_limits<uintptr_t>::digits - 1;
static const uintptr_t clear_mask = ~((uintptr_t)1 << bits_offset);
public:
enum
{
//if flag not set it means that read and write
not_set = 0,
reuse = 1,
read = 2,
write = 4,
};
//here mfxmemid might be as MFXReadWriteMid or mfxMemId memid
MFXReadWriteMid(mfxMemId mid, mfxU8 flag = not_set)
{
//setup mid
m_mid_to_report = (mfxMemId)((uintptr_t)&m_mid | ((uintptr_t)1 << bits_offset));
if (0 != ((uintptr_t)mid >> bits_offset))
{
//it points to extended structure
mfxMedIdEx * pMemIdExt = reinterpret_cast<mfxMedIdEx *>((uintptr_t)mid & clear_mask);
m_mid.pId = pMemIdExt->pId;
if (reuse == flag)
{
m_mid.read_write = pMemIdExt->read_write;
}
else
{
m_mid.read_write = flag;
}
}
else
{
m_mid.pId = mid;
if (reuse == flag)
m_mid.read_write = not_set;
else
m_mid.read_write = flag;
}
}
bool isRead() const
{
return 0 != (m_mid.read_write & read) || !m_mid.read_write;
}
bool isWrite() const
{
return 0 != (m_mid.read_write & write) || !m_mid.read_write;
}
/// returns original memid without read write flags
mfxMemId raw() const
{
return m_mid.pId;
}
operator mfxMemId() const
{
return m_mid_to_report;
}
private:
struct mfxMedIdEx
{
mfxMemId pId;
mfxU8 read_write;
};
mfxMedIdEx m_mid;
mfxMemId m_mid_to_report;
};
struct ID3D11VideoDevice;
struct ID3D11VideoContext;
struct D3D11AllocatorParams : mfxAllocatorParams
{
ID3D11Device *pDevice;
bool bUseSingleTexture;
DWORD uncompressedResourceMiscFlags;
D3D11AllocatorParams()
: pDevice()
, bUseSingleTexture()
, uncompressedResourceMiscFlags()
{
}
};
class D3D11FrameAllocator: public BaseFrameAllocator
{
public:
D3D11FrameAllocator();
virtual ~D3D11FrameAllocator();
virtual mfxStatus Init(mfxAllocatorParams *pParams);
virtual mfxStatus Close();
virtual ID3D11Device * GetD3D11Device()
{
return m_initParams.pDevice;
};
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData *ptr);
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData *ptr);
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL *handle);
protected:
static DXGI_FORMAT ConverColortFormat(mfxU32 fourcc);
virtual mfxStatus CheckRequestType(mfxFrameAllocRequest *request);
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse *response);
virtual mfxStatus AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
D3D11AllocatorParams m_initParams;
ID3D11DeviceContext *m_pDeviceContext;
struct TextureResource
{
std::vector<mfxMemId> outerMids;
std::vector<ID3D11Texture2D*> textures;
std::vector<ID3D11Texture2D*> stagingTexture;
bool bAlloc;
TextureResource()
: bAlloc(true)
{
}
static bool isAllocated (TextureResource & that)
{
return that.bAlloc;
}
ID3D11Texture2D* GetTexture(mfxMemId id)
{
if (outerMids.empty())
return NULL;
return textures[((uintptr_t)id - (uintptr_t)outerMids.front()) % textures.size()];
}
UINT GetSubResource(mfxMemId id)
{
if (outerMids.empty())
return NULL;
return (UINT)(((uintptr_t)id - (uintptr_t)outerMids.front()) / textures.size());
}
void Release()
{
size_t i = 0;
for(i = 0; i < textures.size(); i++)
{
textures[i]->Release();
}
textures.clear();
for(i = 0; i < stagingTexture.size(); i++)
{
stagingTexture[i]->Release();
}
stagingTexture.clear();
//marking texture as deallocated
bAlloc = false;
}
};
class TextureSubResource
{
TextureResource * m_pTarget;
ID3D11Texture2D * m_pTexture;
ID3D11Texture2D * m_pStaging;
UINT m_subResource;
public:
TextureSubResource(TextureResource * pTarget = NULL, mfxMemId id = 0)
: m_pTarget(pTarget)
, m_pTexture()
, m_subResource()
{
if (NULL != m_pTarget && !m_pTarget->outerMids.empty())
{
ptrdiff_t idx = (uintptr_t)MFXReadWriteMid(id).raw() - (uintptr_t)m_pTarget->outerMids.front();
m_pTexture = m_pTarget->textures[idx % m_pTarget->textures.size()];
m_subResource = (UINT)(idx / m_pTarget->textures.size());
m_pStaging = m_pTarget->stagingTexture.empty() ? NULL : m_pTarget->stagingTexture[idx];
}
}
ID3D11Texture2D* GetStaging()const
{
return m_pStaging;
}
ID3D11Texture2D* GetTexture()const
{
return m_pTexture;
}
UINT GetSubResource()const
{
return m_subResource;
}
void Release()
{
if (NULL != m_pTarget)
m_pTarget->Release();
}
};
TextureSubResource GetResourceFromMid(mfxMemId);
std::list <TextureResource> m_resourcesByRequest;//each alloc request generates new item in list
typedef std::list <TextureResource>::iterator referenceType;
std::vector<referenceType> m_memIdMap;
};

130
d3d11_device.cpp Normal file
View File

@ -0,0 +1,130 @@
/*
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* Neither the name of INTEL CORPORATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdafx.h"
#include "QuickSync_defs.h"
#include "d3d11_device.h"
#if MFX_D3D11_SUPPORT
CD3D11Device::CD3D11Device()
{
}
CD3D11Device::~CD3D11Device()
{
Close();
}
mfxStatus CD3D11Device::FillSCD(mfxHDL hWindow, DXGI_SWAP_CHAIN_DESC& scd)
{
scd.Windowed = TRUE;
scd.OutputWindow = (HWND)hWindow;
scd.SampleDesc.Count = 1;
scd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.BufferCount = 1;
return MFX_ERR_NONE;
}
mfxStatus CD3D11Device::Init(int nAdapterNum)
{
mfxStatus sts = MFX_ERR_NONE;
HRESULT hres = S_OK;
static D3D_FEATURE_LEVEL FeatureLevels[] = {
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0
};
D3D_FEATURE_LEVEL pFeatureLevelsOut;
hres = CreateDXGIFactory(__uuidof(IDXGIFactory2), (void**)(&m_pDXGIFactory) );
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
hres = m_pDXGIFactory->EnumAdapters(nAdapterNum,&m_pAdapter);
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
hres = D3D11CreateDevice(m_pAdapter ,
D3D_DRIVER_TYPE_UNKNOWN,
NULL,
0,
FeatureLevels,
MSDK_ARRAY_LEN(FeatureLevels),
D3D11_SDK_VERSION,
&m_pD3D11Device,
&pFeatureLevelsOut,
&m_pD3D11Ctx);
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
m_pDXGIDev = m_pD3D11Device;
m_pDX11VideoDevice = m_pD3D11Device;
m_pVideoContext = m_pD3D11Ctx;
MSDK_CHECK_POINTER(m_pDXGIDev.p, MFX_ERR_NULL_PTR);
MSDK_CHECK_POINTER(m_pDX11VideoDevice.p, MFX_ERR_NULL_PTR);
MSDK_CHECK_POINTER(m_pVideoContext.p, MFX_ERR_NULL_PTR);
// turn on multithreading for the Context
CComQIPtr<ID3D10Multithread> p_mt(m_pVideoContext);
if (p_mt)
p_mt->SetMultithreadProtected(true);
else
return MFX_ERR_DEVICE_FAILED;
return sts;
}
mfxStatus CD3D11Device::Reset()
{
return MFX_ERR_NONE;
}
mfxHDL CD3D11Device::GetHandle(mfxHandleType type)
{
if (MFX_HANDLE_D3D11_DEVICE == type)
{
return (mfxHDL)m_pD3D11Device.p;
}
return NULL;
}
void CD3D11Device::Close()
{
Reset();
}
#endif // #if MFX_D3D11_SUPPORT

56
d3d11_device.h Normal file
View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* Neither the name of INTEL CORPORATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#if MFX_D3D11_SUPPORT
#include "hw_device.h"
class CD3D11Device: public CHWDevice
{
public:
CD3D11Device();
virtual ~CD3D11Device();
virtual mfxStatus Init(int nAdapterNum);
virtual mfxStatus Reset();
virtual mfxHDL GetHandle(mfxHandleType type);
virtual void Close();
protected:
virtual mfxStatus FillSCD(mfxHDL hWindow, DXGI_SWAP_CHAIN_DESC& scd);
CComPtr<ID3D11Device> m_pD3D11Device;
CComPtr<ID3D11DeviceContext> m_pD3D11Ctx;
CComQIPtr<ID3D11VideoDevice> m_pDX11VideoDevice;
CComQIPtr<ID3D11VideoContext> m_pVideoContext;
CComQIPtr<IDXGIDevice1> m_pDXGIDev;
CComQIPtr<IDXGIAdapter> m_pAdapter;
CComPtr<IDXGIFactory2> m_pDXGIFactory;
};
#endif //#if MFX_D3D11_SUPPORT

View File

@ -28,8 +28,6 @@
#pragma once
#include <atlbase.h>
#include <dxva2api.h>
#include "base_allocator.h"
enum eTypeHandle

284
d3d_device.cpp Normal file
View File

@ -0,0 +1,284 @@
/*
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* Neither the name of INTEL CORPORATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdafx.h"
#include "QuickSync_defs.h"
#include "QuickSyncUtils.h"
//prefast singnature used in combaseapi.h
#ifndef _PREFAST_
#pragma warning(disable:4068)
#endif
#include "d3d_device.h"
CD3D9Device::CD3D9Device(IDirect3DDeviceManager9* pDeviceManager9) :
m_pDeviceManager9(pDeviceManager9)
{
m_pD3D9 = NULL;
m_pD3DD9 = NULL;
MSDK_ZERO_VAR(m_D3DPP);
m_ResetToken = 0;
}
mfxStatus CD3D9Device::FillD3DPP(mfxHDL hWindow, D3DPRESENT_PARAMETERS &D3DPP)
{
mfxStatus sts = MFX_ERR_NONE;
D3DPP.Windowed = true;
D3DPP.hDeviceWindow = (HWND)hWindow;
D3DPP.Flags = D3DPRESENTFLAG_VIDEO;
D3DPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
D3DPP.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // note that this setting leads to an implicit timeBeginPeriod call
D3DPP.BackBufferCount = 1;
D3DPP.BackBufferFormat = D3DFMT_X8R8G8B8;
D3DPP.BackBufferWidth = 1;
D3DPP.BackBufferHeight = 1;
//
// Mark the back buffer lockable if software DXVA2 could be used.
// This is because software DXVA2 device requires a lockable render target
// for the optimal performance.
//
D3DPP.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD;
return sts;
}
mfxStatus CD3D9Device::Init(int nAdapterNum)
{
if (m_pDeviceManager9)
{
return InitFromRenderer(nAdapterNum);
}
else
{
return InitFromScratch(nAdapterNum);
}
}
mfxStatus CD3D9Device::Reset()
{
HRESULT hr = NO_ERROR;
D3DPRESENT_PARAMETERS d3dpp=m_D3DPP;
ZeroMemory(&d3dpp, sizeof(d3dpp));
D3DDISPLAYMODE d3dmodeTemp;
m_pD3DD9->GetDisplayMode(0, &d3dmodeTemp);
d3dpp.BackBufferWidth = d3dmodeTemp.Width;
d3dpp.BackBufferHeight = d3dmodeTemp.Height;
// Reset will change the parameters, so use a copy instead.
D3DPRESENT_PARAMETERS d3dppTmp=d3dpp;
hr = m_pD3DD9->Reset(&d3dppTmp);
if (FAILED(hr))
return MFX_ERR_UNDEFINED_BEHAVIOR;
m_D3DPP = d3dpp;
hr = m_pDeviceManager9->ResetDevice(m_pD3DD9, m_ResetToken);
if (FAILED(hr))
return MFX_ERR_UNDEFINED_BEHAVIOR;
return MFX_ERR_NONE;
}
void CD3D9Device::Close()
{
MSDK_SAFE_RELEASE(m_pDeviceManager9);
MSDK_SAFE_RELEASE(m_pD3DD9);
MSDK_SAFE_RELEASE(m_pD3D9);
}
CD3D9Device::~CD3D9Device()
{
Close();
}
mfxHDL CD3D9Device::GetHandle(mfxHandleType type)
{
if (MFX_HANDLE_DIRECT3D_DEVICE_MANAGER9 == type)
{
return (mfxHDL)m_pDeviceManager9;
}
return NULL;
}
mfxStatus CD3D9Device::InitFromScratch(int nAdapterNum)
{
mfxStatus sts = MFX_ERR_NONE;
HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &m_pD3D9);
if (!m_pD3D9 || FAILED(hr))
return MFX_ERR_DEVICE_FAILED;
ZeroMemory(&m_D3DPP, sizeof(m_D3DPP));
sts = FillD3DPP(NULL, m_D3DPP);
MSDK_CHECK_NOT_EQUAL(sts, MFX_ERR_NONE, sts);
hr = m_pD3D9->CreateDevice(
nAdapterNum,
D3DDEVTYPE_HAL,
NULL,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
&m_D3DPP,
&m_pD3DD9);
if (FAILED(hr))
return MFX_ERR_NULL_PTR;
UINT resetToken = 0;
hr = DXVA2CreateDirect3DDeviceManager9(&resetToken, &m_pDeviceManager9);
if (FAILED(hr))
return MFX_ERR_NULL_PTR;
hr = m_pDeviceManager9->ResetDevice(m_pD3DD9, resetToken);
if (FAILED(hr))
return MFX_ERR_UNDEFINED_BEHAVIOR;
m_ResetToken = resetToken;
return sts;
}
mfxStatus CD3D9Device::InitFromRenderer(int nAdapterNum)
{
mfxStatus sts = MFX_ERR_NONE;
IDirect3DDeviceManager9* extD3DManager = m_pDeviceManager9;
m_pDeviceManager9 = NULL;
// Get DirectX Object
HANDLE hDevice;
IDirect3DDevice9* pDevice = NULL;
CComPtr<IDirect3D9> pD3D;
D3DDEVICE_CREATION_PARAMETERS devParames;
ZeroMemory(&m_D3DPP, sizeof(m_D3DPP));
sts = FillD3DPP(NULL, m_D3DPP);
MSDK_CHECK_NOT_EQUAL(sts, MFX_ERR_NONE, sts);
HRESULT hr = extD3DManager->OpenDeviceHandle(&hDevice);
if (FAILED(hr))
{
MSDK_TRACE("QsDecoder: failed to open device handle!\n");
goto done;
}
hr = extD3DManager->LockDevice(hDevice, &pDevice, TRUE);
if (FAILED(hr) || NULL == pDevice)
{
MSDK_TRACE("QsDecoder: failed to lock device!\n");
switch (hr)
{
case DXVA2_E_NEW_VIDEO_DEVICE:
MSDK_TRACE("QsDecoder: The device handle is invalid.!\n");
break;
case DXVA2_E_NOT_INITIALIZED:
MSDK_TRACE("QsDecoder: The Direct3D device manager was not initialized.!\n");
break;
case E_HANDLE:
MSDK_TRACE("QsDecoder: The specified handle is not a Direct3D device handle.!\n");
break;
default:
MSDK_TRACE("QsDecoder: Unknown error %x\n", hr);
}
goto done;
}
hr = pDevice->GetDirect3D(&pD3D);
if (FAILED(hr))
{
MSDK_TRACE("QsDecoder: failed to get D3D9 object!\n");
goto done;
}
hr = pDevice->GetCreationParameters(&devParames);
if (FAILED(hr))
{
MSDK_TRACE("QsDecoder: failed to get device creation params!\n");
goto done;
}
// Create d3d device
m_pD3DD9 = 0;
m_D3DPP.hDeviceWindow = devParames.hFocusWindow;
hr = pD3D->CreateDevice(
nAdapterNum,
D3DDEVTYPE_HAL,
devParames.hFocusWindow,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
&m_D3DPP,
&m_pD3DD9);
if (FAILED(hr) || !m_pD3DD9)
{
hr = E_FAIL;
MSDK_TRACE("QsDecoder: InitD3d CreateDevice failed!\n");
goto done;
}
// Create device manager
hr = DXVA2CreateDirect3DDeviceManager9(&m_ResetToken, &m_pDeviceManager9);
if (FAILED(hr) || !m_pDeviceManager9)
{
hr = E_FAIL;
MSDK_TRACE("QsDecoder: InitD3d DXVA2CreateDirect3DDeviceManager9 failed!\n");
goto done;
}
// Reset the d3d device
hr = m_pDeviceManager9->ResetDevice(m_pD3DD9, m_ResetToken);
if (FAILED(hr))
{
hr = E_FAIL;
MSDK_TRACE("QsDecoder: InitD3d ResetDevice failed!\n");
goto done;
}
// Cleanup
done:
if (FAILED(hr))
{
sts = MFX_ERR_DEVICE_FAILED;
}
MSDK_SAFE_RELEASE(pDevice);
if (hDevice != NULL)
{
extD3DManager->UnlockDevice(hDevice, FALSE);
extD3DManager->CloseDeviceHandle(hDevice);
}
return sts;
}

59
d3d_device.h Normal file
View File

@ -0,0 +1,59 @@
/* ****************************************************************************** *\
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or nondisclosure
agreement with Intel Corporation and may not be copied or disclosed except in
accordance with the terms of that agreement
Copyright(c) 2011 - 2012 Intel Corporation. All Rights Reserved.
\* ****************************************************************************** */
#pragma once
#include "hw_device.h"
#pragma warning(disable : 4201)
#include <d3d9.h>
#include <dxva2api.h>
#include <dxva.h>
#include <windows.h>
enum {
MFX_HANDLE_GFXS3DCONTROL = 0x100 /* A handle to the IGFXS3DControl instance */
}; //mfxHandleType
#define OVERLAY_BACKBUFFER_FORMAT D3DFMT_X8R8G8B8
#define VIDEO_MAIN_FORMAT D3DFMT_YUY2
class IGFXS3DControl;
/** Direct3D 9 device implementation.
@note Can be initilized for only 1 or two 2 views. Handle to
MFX_HANDLE_GFXS3DCONTROL must be set prior if initializing for 2 views.
@note Device always set D3DPRESENT_PARAMETERS::Windowed to TRUE.
*/
class CD3D9Device : public CHWDevice
{
public:
CD3D9Device(IDirect3DDeviceManager9* pDeviceManager9);
virtual ~CD3D9Device();
virtual mfxStatus Init(int nAdapterNum);
virtual mfxStatus Reset();
virtual mfxHDL GetHandle(mfxHandleType type);
virtual void Close();
protected:
virtual mfxStatus FillD3DPP(mfxHDL hWindow, D3DPRESENT_PARAMETERS &D3DPP);
mfxStatus InitFromScratch(int nAdapterNum);
mfxStatus InitFromRenderer(int nAdapterNum);
private:
IDirect3D9Ex* m_pD3D9;
IDirect3DDevice9* m_pD3DD9;
IDirect3DDeviceManager9* m_pDeviceManager9;
D3DPRESENT_PARAMETERS m_D3DPP;
UINT m_ResetToken;
};

View File

@ -58,21 +58,21 @@ CFrameConstructor::CFrameConstructor()
{
m_bSeqHeaderInserted = false;
m_bDvdStripPackets = false;
MSDK_ZERO_VAR(m_ResidialBS);
MSDK_ZERO_VAR(m_ResidualBS);
MSDK_ZERO_VAR(m_Headers);
m_ResidialBS.MaxLength = 100;
m_ResidialBS.Data = new mfxU8[m_ResidialBS.MaxLength];
m_ResidualBS.MaxLength = 100;
m_ResidualBS.Data = new mfxU8[m_ResidualBS.MaxLength];
}
CFrameConstructor::~CFrameConstructor()
{
delete[] m_ResidialBS.Data;
delete[] m_ResidualBS.Data;
delete[] m_Headers.Data;
}
void CFrameConstructor::Reset()
{
m_ResidialBS.DataOffset = m_ResidialBS.DataLength = 0;
m_ResidualBS.DataOffset = m_ResidualBS.DataLength = 0;
m_bSeqHeaderInserted = false;
}
@ -85,26 +85,26 @@ void CFrameConstructor::UpdateTimeStamp(IMediaSample* pSample, mfxBitstream* pBS
MFX_TIME_STAMP_INVALID;
}
void CFrameConstructor::SaveResidialData(mfxBitstream* pBS)
void CFrameConstructor::SaveResidualData(mfxBitstream* pBS)
{
MSDK_CHECK_POINTER_NO_RET(pBS);
// m_ResidialBS must be empty
ASSERT(m_ResidialBS.DataLength == 0);
m_ResidialBS.DataOffset = 0;
m_ResidialBS.DataLength = pBS->DataLength;
// m_ResidualBS must be empty
ASSERT(m_ResidualBS.DataLength == 0);
m_ResidualBS.DataOffset = 0;
m_ResidualBS.DataLength = pBS->DataLength;
// Check if a bigger buffer is needed
if (pBS->DataLength > m_ResidialBS.MaxLength)
if (pBS->DataLength > m_ResidualBS.MaxLength)
{
delete[] m_ResidialBS.Data;
delete[] m_ResidualBS.Data;
mfxU32 newSize = pBS->DataLength;
m_ResidialBS.Data = new mfxU8[newSize];
MSDK_CHECK_POINTER_NO_RET(m_ResidialBS.Data);
m_ResidialBS.MaxLength = newSize;
m_ResidualBS.Data = new mfxU8[newSize];
MSDK_CHECK_POINTER_NO_RET(m_ResidualBS.Data);
m_ResidualBS.MaxLength = newSize;
}
ASSERT(pBS->DataOffset + pBS->DataLength <= pBS->MaxLength);
memcpy(m_ResidialBS.Data, pBS->Data + pBS->DataOffset, pBS->DataLength);
memcpy(m_ResidualBS.Data, pBS->Data + pBS->DataOffset, pBS->DataLength);
}
mfxStatus CFrameConstructor::ConstructHeaders(
@ -149,9 +149,9 @@ mfxStatus CFrameConstructor::ConstructHeaders(
mfxStatus CFrameConstructor::ConstructFrame(IMediaSample* pSample, mfxBitstream* pBS)
{
mfxStatus sts = MFX_ERR_NONE;
mfxU8* pDataBuffer = NULL;
int nDataSize = 0;
mfxStatus sts = MFX_ERR_NONE;
mfxU8* pDataBuffer = NULL;
int nDataSize = 0;
MSDK_CHECK_POINTER(pSample, MFX_ERR_NULL_PTR);
nDataSize = pSample->GetActualDataLength();
@ -169,7 +169,7 @@ mfxStatus CFrameConstructor::ConstructFrame(IMediaSample* pSample, mfxBitstream*
}
// Prefix the sequence headers if needed
size_t newDataSize = nDataSize + m_ResidialBS.DataLength +
size_t newDataSize = nDataSize + m_ResidualBS.DataLength +
((m_bSeqHeaderInserted) ? 0 : m_Headers.DataLength);
pBS->MaxLength = pBS->DataLength = (mfxU32)newDataSize;
@ -291,11 +291,11 @@ void CFrameConstructor::StripDvdPacket(BYTE*& p, int& len)
void CFrameConstructor::WriteResidualData(mfxU8*& pData)
{
if (m_ResidialBS.DataLength)
if (m_ResidualBS.DataLength)
{
memcpy(pData, m_ResidialBS.Data, m_ResidialBS.DataLength);
pData += m_ResidialBS.DataLength;
m_ResidialBS.DataLength = 0;
memcpy(pData, m_ResidualBS.Data, m_ResidualBS.DataLength);
pData += m_ResidualBS.DataLength;
m_ResidualBS.DataLength = 0;
}
}
@ -380,7 +380,7 @@ mfxStatus CVC1FrameConstructor::ConstructFrame(IMediaSample* pSample, mfxBitstre
UpdateTimeStamp(pSample, pBS);
// Prefix the sequence headers if needed
size_t newDataSize = nDataSize + m_ResidialBS.DataLength +
size_t newDataSize = nDataSize + m_ResidualBS.DataLength +
((m_bSeqHeaderInserted) ? 0 : m_Headers.DataLength) + // Add headers size
8; // Add upto 8 bytes for extra start codes
@ -599,7 +599,7 @@ mfxStatus CAVCFrameConstructor::ConstructFrame(IMediaSample* pSample, mfxBitstre
// Update data size
nDataSize = (mfxU32)m_TempBuffer.size();
pDataBuffer = &m_TempBuffer.front();
size_t newDataSize = nDataSize + m_ResidialBS.DataLength +
size_t newDataSize = nDataSize + m_ResidualBS.DataLength +
((m_bSeqHeaderInserted) ? 0 : m_Headers.DataLength);
mfxU8* pData = pBS->Data = new mfxU8[newDataSize];

View File

@ -36,7 +36,7 @@ public:
virtual mfxStatus ConstructHeaders(VIDEOINFOHEADER2* vih, const GUID& guidFormat, size_t nMtSize, size_t nVideoInfoSize);
virtual mfxStatus ConstructFrame(IMediaSample* pSample, mfxBitstream* pBS);
virtual void Reset();
void SaveResidialData(mfxBitstream* pBS);
void SaveResidualData(mfxBitstream* pBS);
inline mfxBitstream& GetHeaders() { return m_Headers; }
void SetDvdPacketStripping(bool stripPackets) { m_bDvdStripPackets = stripPackets; }
@ -50,7 +50,7 @@ protected:
bool m_bSeqHeaderInserted;
bool m_bDvdStripPackets;
mfxBitstream m_Headers;
mfxBitstream m_ResidialBS;
mfxBitstream m_ResidualBS;
};
////////////////////////////////////////////////////////////////////////////////////////////

29
hw_device.h Normal file
View File

@ -0,0 +1,29 @@
/* ****************************************************************************** *\
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or nondisclosure
agreement with Intel Corporation and may not be copied or disclosed except in
accordance with the terms of that agreement
Copyright(c) 2011 - 2012 Intel Corporation. All Rights Reserved.
\* ****************************************************************************** */
#pragma once
#include "mfxvideo++.h"
/// Base class for hw device
class CHWDevice
{
public:
virtual ~CHWDevice(){}
/** Initializes device for requested processing.
@param[in] nAdapterNum ID of adapter to use
*/
virtual mfxStatus Init(int nAdapterNum) = 0;
/// Reset device.
virtual mfxStatus Reset() = 0;
/// Get handle can be used for MFX session SetHandle calls
virtual mfxHDL GetHandle(mfxHandleType type) = 0;
virtual void Close() = 0;
};

View File

@ -14,9 +14,24 @@
// Platform SDK
#include <d3d9.h>
#include <d3d11.h>
#include <dshow.h>
#include <dvdmedia.h>
#include <initguid.h>
#include <atlbase.h>
#include <dxva2api.h>
#include <dxgi1_2.h>
#include <sdkddkver.h>
#if (NTDDI_VERSION >= NTDDI_VERSION_FROM_WIN32_WINNT2(0x0602)) // >= _WIN32_WINNT_WIN8
#define MFX_D3D11_SUPPORT 1 // Enable D3D11 support if SDK allows
#pragma message("\nIntel QuickSync Decoder is built with D3D11 support\n")
#else
#define MFX_D3D11_SUPPORT 0
#pragma message("\nWarning: Intel QuickSync Decoder is built without D3D11 support!")
#pragma message("\tMust have Windows SDK 8.0 installed and environment variable INTELMEDIASDK_WINSDK_PATH")
#pragma message("\tshould point to it.")
#pragma message("\te.g. \"C:\\Program Files (x86)\\Windows Kits\\8.0\"")
#endif
// Intel Media SDK
#include <mfxvideo++.h>
@ -26,8 +41,9 @@
#include <vector>
#include <deque>
#include <set>
#include <algorithm>
#include <array>
#include <limits>
#include <map>
// PPL
#include <ppl.h>