Skip to content

Commit 6cd2d8f

Browse files
committed
added avx2 support check
1 parent 6f19ea9 commit 6cd2d8f

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

EncoderTest/EncoderTest.csproj

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<Prefer32Bit>false</Prefer32Bit>
3636
</PropertyGroup>
3737
<ItemGroup>
38+
<Reference Include="H264Sharp64">
39+
<HintPath>..\x64\Release\H264Sharp64.dll</HintPath>
40+
</Reference>
3841
<Reference Include="System" />
3942
<Reference Include="System.Core" />
4043
<Reference Include="System.Drawing" />
@@ -63,11 +66,5 @@
6366
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6467
</Content>
6568
</ItemGroup>
66-
<ItemGroup>
67-
<ProjectReference Include="..\H264Sharp\H264Sharp.vcxproj">
68-
<Project>{372f0cee-61ce-42ae-b820-523972d864ac}</Project>
69-
<Name>H264Sharp</Name>
70-
</ProjectReference>
71-
</ItemGroup>
7269
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7370
</Project>

H264Sharp/Decoder.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,18 @@ namespace H264Sharp {
2626
{
2727
// Try to load converter library, if cant find we use the C++/ClI version.
2828
const wchar_t* converterDll = is64Bit() ? L"Converter64.dll" : L"Converter32.dll";
29+
HMODULE lib = NULL;
30+
const DWORD Avx2 = 40;
31+
if (!IsProcessorFeaturePresent(Avx2))
32+
{
33+
std::cout << "Unable to use ConverterDLL because AVX2 instructions are not supported! Falling back to CLI convertors" << std::endl;
34+
}
35+
else
36+
{
37+
lib = LoadLibrary(converterDll);
2938

30-
HMODULE lib = LoadLibrary(converterDll);
39+
}
40+
3141
if (lib != NULL)
3242
{
3343
Bgra2Yuv420 = (Yuv2Rgb)GetProcAddress(lib, "Yuv420P2RGB_");
@@ -36,7 +46,7 @@ namespace H264Sharp {
3646
}
3747
else {
3848
auto ss = is64Bit() ? "Converter64.dll" : "Converter32.dll";
39-
std::cout << "Unable to load " << ss << ", make sure to include it on your executable path. Falling back to CLI convertors" << std::endl;
49+
std::cout << "Decoder: Unable to load " << ss << ", make sure to include it on your executable path. Falling back to CLI convertors" << std::endl;
4050
Bgra2Yuv420 = (Yuv2Rgb)Yuv420P2Rgb;
4151
}
4252

@@ -186,7 +196,8 @@ namespace H264Sharp {
186196
rc = decoder->DecodeFrame2(frame, length, buffer, &bufInfo);
187197

188198
rcc = (DecodingState)rc;
189-
if (rc!=0 ) return yuv;
199+
//if (rc!=0 ) return yuv;
200+
190201
//if (HasFlag(rc, dsRefLost) ) return yuv;
191202
if (bufInfo.iBufferStatus != 1) return yuv;
192203

H264Sharp/Encoder.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ namespace H264Sharp {
2626
void Encoder::Create(const wchar_t* dllname)
2727
{
2828
const wchar_t* converterDll = is64Bit() ? L"Converter64.dll" : L"Converter32.dll";
29-
30-
HMODULE lib = LoadLibrary(converterDll);
29+
const DWORD Avx2 = 40;
30+
HMODULE lib = NULL;
31+
if (!IsProcessorFeaturePresent(Avx2))
32+
{
33+
std::cout << "Unable to use ConverterDLL because AVX2 instructions are not supported! Falling back to CLI convertors" << std::endl;
34+
}
35+
else
36+
{
37+
lib = LoadLibrary(converterDll);
38+
}
3139
if (lib != NULL)
3240
{
3341
Bgra2Yuv420 = (Covert2Yuv420)GetProcAddress(lib, "BGRAtoYUV420Planar_");
@@ -48,7 +56,7 @@ namespace H264Sharp {
4856
}
4957
else {
5058
auto ss = is64Bit() ? "Converter64.dll" : "Converter32.dll";
51-
std::cout << "Unable to load " << ss << ", make sure to include it on your executable path. Falling back to CLI convertors" << std::endl;
59+
std::cout << "Encoder: Unable to load " << ss << ", make sure to include it on your executable path. Falling back to CLI convertors" << std::endl;
5260
Bgra2Yuv420 = BGRAtoYUV420Planar;
5361
Bgr2Yuv420 = BGRtoYUV420Planar;
5462
Rgba2Yuv420 = RGBtoYUV420Planar;
@@ -231,7 +239,9 @@ namespace H264Sharp {
231239
pic->pData[2] = pic->pData[1] + (width * height >> 2);
232240

233241
bsi = new SFrameBSInfo();
234-
242+
bool t = true;
243+
encoder->SetOption(ENCODER_OPTION_ENABLE_SSEI, &t);
244+
std::cout << "Encoder Set" << std::endl;
235245
return 0;
236246
};
237247

0 commit comments

Comments
 (0)