Skip to content

Commit 3f6337b

Browse files
committed
Neon first draft
1 parent b90ba59 commit 3f6337b

22 files changed

+49563
-37
lines changed

Examples/CrossPlatformTest/CrossPlatformTest.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<PublishAot>False</PublishAot>
9+
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
910
<!--<RuntimeIdentifier>win-x86</RuntimeIdentifier>-->
1011

1112
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\H264Sharp\H264Sharp.csproj" />
16+
</ItemGroup>
1217

1318
<ItemGroup>
1419
<None Update="H264SharpNative-linux64.so">

Examples/CrossPlatformTest/Program.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ internal class Program
1414
*/
1515
static void Main(string[] args)
1616
{
17+
H264Encoder.EnableDebugPrints = true;
18+
H264Decoder.EnableDebugPrints = true;
19+
Converter.EnableNEON = false;
20+
Converter.NumThreads = 1;
21+
1722
H264Encoder encoder = new H264Encoder();
1823
H264Decoder decoder = new H264Decoder();
1924

20-
encoder.ConverterNumberOfThreads = 4;
21-
decoder.ConverterNumberOfThreads = 4;
22-
decoder.EnableSSEYUVConversion = true;
25+
2326

2427
decoder.Initialize();
2528

@@ -32,9 +35,22 @@ static void Main(string[] args)
3235
var bytes = File.ReadAllBytes("RawBgr.bin");
3336
var data = new ImageData(ImageType.Bgra, 1920, 1080, 1920*4, bytes);
3437

35-
36-
37-
38+
//Converter.EnableNEON = false;
39+
40+
YuvImage yuvImage = new YuvImage(w, h);
41+
RgbImage rgb = new RgbImage(w, h);
42+
Converter.Rgbx2Yuv(data, yuvImage);
43+
Converter.Yuv2Rgb(yuvImage, rgb);
44+
byte[] dat = new byte[w * h * 3];
45+
46+
unsafe
47+
{
48+
fixed (byte* dataPtr = dat)
49+
Buffer.MemoryCopy((byte*)rgb.ImageBytes.ToPointer(), dataPtr, dat.Length, dat.Length);
50+
}
51+
File.WriteAllBytes("Output.bin", dat);
52+
53+
3854

3955
RgbImage rgbb = new RgbImage(w, h);
4056
for (int j = 0; j < 1000; j++)
-19 KB
Binary file not shown.

Examples/H264SharpNativePInvoke/H264SharpNativePInvoke.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,8 @@
4545
<None Update="openh264-2.4.1-win64.dll">
4646
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4747
</None>
48+
<None Update="Output.bin">
49+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
50+
</None>
4851
</ItemGroup>
4952
</Project>

Examples/H264SharpNativePInvoke/Output.bin

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

Examples/H264SharpNativePInvoke/Program.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,71 @@
33
using System.Diagnostics;
44
using System.Drawing;
55
using System.Drawing.Imaging;
6+
using System.Runtime.InteropServices;
67

78
namespace H264PInvoke
89
{
910
#pragma warning disable CA1416 // Validate platform compatibility
1011

1112
internal class Program
1213
{
14+
static Bitmap RawRgbToBitmap(byte[] rawRgbData, int width, int height)
15+
{
16+
if (rawRgbData.Length != width * height * 3)
17+
throw new ArgumentException("The size of the raw RGB data does not match the specified dimensions.");
18+
19+
// Create a new Bitmap
20+
Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
21+
22+
// Lock the Bitmap's bits for writing
23+
BitmapData bitmapData = bitmap.LockBits(
24+
new Rectangle(0, 0, width, height),
25+
ImageLockMode.WriteOnly,
26+
PixelFormat.Format24bppRgb);
27+
28+
// Copy the raw RGB data into the Bitmap's memory
29+
IntPtr ptr = bitmapData.Scan0;
30+
int stride = bitmapData.Stride;
31+
int offset = stride - width * 3;
32+
33+
// Handle cases where stride is not equal to width * 3
34+
if (offset == 0)
35+
{
36+
Marshal.Copy(rawRgbData, 0, ptr, rawRgbData.Length);
37+
}
38+
else
39+
{
40+
// Copy row by row if stride padding exists
41+
for (int y = 0; y < height; y++)
42+
{
43+
Marshal.Copy(rawRgbData, y * width * 3, ptr + y * stride, width * 3);
44+
}
45+
}
46+
47+
// Unlock the Bitmap's bits
48+
bitmap.UnlockBits(bitmapData);
49+
50+
return bitmap;
51+
}
1352
static unsafe void Main(string[] args)
1453
{
54+
55+
var bytes = File.ReadAllBytes("Output.bin");
56+
57+
Bitmap bp = RawRgbToBitmap(bytes, 1920, 1080);
58+
bp.Save("CVR.bmp");
59+
60+
61+
62+
return;
63+
64+
65+
H264Encoder.EnableDebugPrints = true;
66+
H264Decoder.EnableDebugPrints = true;
1567
Converter.EnableSSE = true;
1668
Converter.NumThreads = 4;
17-
Defines.UseCustomThreadPool = true;
18-
//BencmarkConverter();
69+
Converter.UseCustomThreadPool = false;
70+
// BencmarkConverter();
1971
//return;
2072
// You can change version or specify the path for cisco dll.
2173

Examples/H264SharpNativePInvoke/RawBgr.bin

Lines changed: 49091 additions & 0 deletions
Large diffs are not rendered by default.

H264Sharp/Converter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class Converter
1010
{
1111

1212
public static int NumThreads { set => Defines.Native.ConverterSetNumThreads(value); }
13+
public static bool UseCustomThreadPool { set => Defines.Native.EnableCustomPool(value ? 1 : 0); }
14+
1315
public static bool EnableSSE { set => Defines.Native.EnableSSE(value?1:0); }
1416
public static bool EnableNEON { set => Defines.Native.EnableNEON(value?1:0); }
1517
/// <summary>

H264Sharp/Defines.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace H264Sharp
88
public class Defines
99
{
1010
internal readonly static NativeBindings Native = new NativeBindings();
11-
public static bool UseCustomThreadPool { set => Native.EnableCustomPool(value ? 1 : 0); }
1211

1312
static Defines()
1413
{

H264SharpNative/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ add_library (CMakeProject1 SHARED
4747
"Yuv2Rgb.h"
4848
"Rgb2Yuv.h"
4949
"Converter.cpp"
50-
"Decoder.cpp"
50+
"Decoder.cpp"
5151
"dllmain.cpp"
5252
"Encoder.cpp"
5353
"ImageTypes.cpp"
5454
"pch.cpp"
5555
"Yuv2Rgb.cpp"
5656
"Yuv2RgbSSE.cpp"
57+
"Yuv2RgbNEON.cpp"
5758
"ThreadPool.cpp"
5859
"Rgb2Yuv.cpp")
5960

@@ -71,5 +72,5 @@ set_target_properties(CMakeProject1 PROPERTIES SUFFIX ".so")
7172
#set_target_properties(CMakeProject1 PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
7273
# arm-32
7374
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --target=arm-linux-gnueabihf")
74-
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=arm-linux-gnueabihf")
75+
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=arm-linux-gnueabihf")
7576
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --target=arm-linux-gnueabihf")

0 commit comments

Comments
 (0)