Skip to content

Commit 4c4a41c

Browse files
committed
fix for wchar_t* portability
1 parent a0f9b9b commit 4c4a41c

23 files changed

+49308
-93
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<PublishAot>False</PublishAot>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\H264Sharp\H264Sharp.csproj" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="H264SharpNative-linux64.so">
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
</None>
19+
<None Update="H264SharpNative-win64.dll">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</None>
22+
<None Update="libopenh264-2.4.1-linux64.7.so">
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
</None>
25+
<None Update="openh264-2.4.1-win64.dll">
26+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
27+
</None>
28+
<None Update="RawBgr.bin">
29+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30+
</None>
31+
</ItemGroup>
32+
33+
</Project>

H264Sharp/runtimes/linux64/native/H264SharpNative-linux64.so.so renamed to CrossPlatformTest/H264SharpNative-linux64.so

File renamed without changes.
192 KB
Binary file not shown.

CrossPlatformTest/Program.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using H264Sharp;
2+
using System.Diagnostics;
3+
using System.Drawing;
4+
5+
namespace CrossPlatformTest
6+
{
7+
internal class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
//Defines.CiscoDllName64bit = "openh264-2.4.0-win64.dll";
12+
//Defines.CiscoDllName32bit = "openh264-2.4.0-win32.dll";
13+
14+
H264Encoder encoder = new H264Encoder();
15+
H264Decoder decoder = new H264Decoder();
16+
17+
encoder.ConverterNumberOfThreads = 4;
18+
decoder.ConverterNumberOfThreads = 4;
19+
decoder.EnableSSEYUVConversion = true;
20+
21+
decoder.Initialize();
22+
23+
24+
var w = 1920;
25+
var h = 1080;
26+
encoder.Initialize(w, h, 200_000_000, 30, ConfigType.CameraBasic);
27+
Console.WriteLine("Initialised Encoder");
28+
29+
Stopwatch sw = Stopwatch.StartNew();
30+
var bytes = File.ReadAllBytes("RawBgr.bin");
31+
var data = new ImageData(ImageType.Bgra, 1920, 1080, 1920*4, bytes);
32+
33+
//Converter converter = new Converter();
34+
//RgbImage to = new RgbImage(data.Width / 2, data.Height / 2);
35+
//converter.Downscale(data,to,2);
36+
//var bb = RgbToBitmap(to);
37+
//bb.Save("Dowmscaled.bmp");
38+
39+
RgbImage rgbb = new RgbImage(w, h);
40+
for (int j = 0; j < 1000; j++)
41+
{
42+
43+
if (!encoder.Encode(data, out EncodedData[] ec))
44+
{
45+
Console.WriteLine("skipped");
46+
continue;
47+
}
48+
49+
//encoder.ForceIntraFrame();
50+
//encoder.SetMaxBitrate(2000000);
51+
//encoder.SetTargetFps(16.9f);
52+
53+
foreach (var encoded in ec)
54+
{
55+
bool keyframe = encoded.FrameType == FrameType.I || encoded.FrameType == FrameType.IDR;
56+
//encoded.GetBytes();
57+
//encoded.CopyTo(buffer,offset);
58+
59+
if (decoder.Decode(encoded, noDelay: true, out DecodingState ds, ref rgbb))
60+
{
61+
//Console.WriteLine($"F:{encoded.FrameType} size: {encoded.Length}");
62+
// Bitmap result = RgbToBitmap(rgbb);
63+
// result.Save("Ok1.bmp");
64+
}
65+
66+
}
67+
68+
69+
}
70+
sw.Stop();
71+
Console.WriteLine(sw.ElapsedMilliseconds);
72+
73+
encoder.Dispose();
74+
decoder.Dispose();
75+
Console.ReadLine();
76+
}
77+
78+
79+
80+
81+
82+
83+
84+
}
85+
86+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"CrossPlatformTest": {
4+
"commandName": "Project",
5+
"nativeDebugging": true
6+
}
7+
}
8+
}

CrossPlatformTest/RawBgr.bin

Lines changed: 49091 additions & 0 deletions
Large diffs are not rendered by default.
1.65 MB
Binary file not shown.
952 KB
Binary file not shown.

Examples/H264SharpNativePInvoke/Program.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Drawing.Imaging;
66
using System.Runtime.CompilerServices;
77
using System.Runtime.InteropServices;
8+
using System.Security.Cryptography;
89
using System.Text;
910

1011
namespace H264PInvoke
@@ -38,15 +39,14 @@ static void Main(string[] args)
3839

3940
Stopwatch sw = Stopwatch.StartNew();
4041
var data = BitmapToImageData(bmp);
41-
4242
//Converter converter = new Converter();
4343
//RgbImage to = new RgbImage(data.Width / 2, data.Height / 2);
4444
//converter.Downscale(data,to,2);
4545
//var bb = RgbToBitmap(to);
4646
//bb.Save("Dowmscaled.bmp");
47-
47+
4848
RgbImage rgbb = new RgbImage(w, h);
49-
for (int j = 0; j < 1000; j++)
49+
for (int j = 0; j < 1; j++)
5050
{
5151

5252
if(!encoder.Encode(data, out EncodedData[] ec))
@@ -68,8 +68,8 @@ static void Main(string[] args)
6868
if (decoder.Decode(encoded, noDelay: true, out DecodingState ds, ref rgbb))
6969
{
7070
//Console.WriteLine($"F:{encoded.FrameType} size: {encoded.Length}");
71-
// Bitmap result = RgbToBitmap(rgbb);
72-
// result.Save("Ok1.bmp");
71+
Bitmap result = RgbToBitmap(rgbb);
72+
result.Save("Ok1.bmp");
7373
}
7474

7575
}
@@ -165,7 +165,18 @@ private static ImageData BitmapToImageData(Bitmap bmp)
165165
// }
166166

167167

168+
var bytes = new byte[bmpData.Stride * height];
169+
unsafe
170+
{
171+
fixed (byte* ptr = bytes)
172+
{
173+
Buffer.MemoryCopy((byte*)bmpScan, ptr, bytes.Length, bytes.Length);
174+
175+
}
168176

177+
}
178+
File.WriteAllBytes("RawBgr.bin",bytes);
179+
img = new ImageData(ImageType.Bgra, width, height, bmpData.Stride, bytes);
169180

170181
bmp.UnlockBits(bmpData);
171182
return img;

H264Sharp/Converter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Runtime.InteropServices;
4-
using System.Text;
53

64
namespace H264Sharp
75
{

0 commit comments

Comments
 (0)