Skip to content

Commit 94b78d9

Browse files
Merge pull request #13 from ReferenceType/develop
Merge before release
2 parents 9268ee0 + c2ca579 commit 94b78d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1615
-50268
lines changed

Examples/AVRecord/AVRecord.csproj

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
1010
</PropertyGroup>
1111

12+
<ItemGroup>
13+
<None Remove="H264SharpNative-win64.dll" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<Content Include="H264SharpNative-win64.dll">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
<PackagePath>\lib\$(TargetFramework)</PackagePath>
20+
<Pack>true</Pack>
21+
</Content>
22+
</ItemGroup>
23+
1224
<ItemGroup>
1325
<PackageReference Include="NAudio" Version="2.2.1" />
1426
<PackageReference Include="OpenCvSharp4" Version="4.9.0.20240103" />
@@ -24,9 +36,6 @@
2436
</ItemGroup>
2537

2638
<ItemGroup>
27-
<None Update="H264SharpNative-win64.dll">
28-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29-
</None>
3039
<None Update="openh264-2.4.1-win64.dll">
3140
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3241
</None>
83 KB
Binary file not shown.

Examples/AVRecord/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<Label Content="Num threads"></Label>
2828
<Slider AutoToolTipPlacement="TopLeft" ValueChanged="Slider_ValueChanged2" Minimum="0" Maximum="32" Value="4" ></Slider>
2929

30-
<CheckBox Content="Enable SSE" IsChecked="True" Checked="SSEChecked" Unchecked="SSEUnChecked"></CheckBox>
30+
<CheckBox Content="Enable AVX" IsChecked="True" Checked="AVXChecked" Unchecked="AVXUnChecked"></CheckBox>
3131
<CheckBox Content="CVConversion" Checked="CVChecked" Unchecked="CVUnChecked"></CheckBox>
3232
<CheckBox Content="Enable Loss" Checked="LossChecked" Unchecked="LossUnChecked"></CheckBox>
3333
<CheckBox Content="Enable Jitter" Checked="JitterChecked" Unchecked="JitterUnChecked"></CheckBox>

Examples/AVRecord/MainWindow.xaml.cs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public partial class MainWindow :System.Windows.Window
2525
private H264Decoder decoder;
2626
private Stream s;
2727
private AviWriter writer;
28-
const int w = 640;
29-
const int h = 480;
28+
const int w = 1920;
29+
const int h = 1080;
3030
object mtex = new object();
3131
int numThreads = 4;
32+
ConverterConfig config = ConverterConfig.Default;
3233
public MainWindow()
3334
{
3435
Environment.SetEnvironmentVariable("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0");
35-
//Cv2.SetNumThreads(32);
3636

3737
encoder = new H264Encoder();
3838
var param = encoder.GetDefaultParameters();
@@ -100,9 +100,11 @@ public MainWindow()
100100
decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_TYPE.VIDEO_BITSTREAM_SVC;
101101
decoder.Initialize(decParam);
102102

103-
Converter.EnableSSE = true;
104-
Converter.NumThreads = 0;
105-
103+
config.EnableAvx2 = 1;
104+
config.NumThreads = 1;
105+
Converter.SetConfig(config);
106+
Cv2.SetNumThreads(1);
107+
106108
InitializeComponent();
107109

108110
}
@@ -150,13 +152,11 @@ private void Stop(object sender, RoutedEventArgs e)
150152
private void CaptureCam()
151153
{
152154
var capture = new VideoCapture(0, VideoCaptureAPIs.WINRT);
155+
156+
capture.Open(0);
153157
capture.FrameWidth = w;
154158
capture.FrameHeight = h;
155159
capture.Fps = 30;
156-
capture.Open(0);
157-
//capture.FrameWidth = w;
158-
//capture.FrameHeight = h;
159-
//capture.Fps = 30;
160160
Mat frame = new Mat();
161161
Thread t = new Thread(() =>
162162
{
@@ -253,6 +253,7 @@ private unsafe void MatAvailable(Mat frame)
253253
Stopwatch s = Stopwatch.StartNew();
254254
bool encodedSuccess = false;
255255
H264Sharp.EncodedData[] ec;
256+
256257
if (enablecv)
257258
{
258259
var src = InputArray.Create(frame);
@@ -263,12 +264,12 @@ private unsafe void MatAvailable(Mat frame)
263264
}
264265
else
265266
{
266-
var g = new ImageData(ImageType.Bgr,frame.Width,frame.Height,(int)frame.Step(), new IntPtr(frame.DataPointer));
267+
var g = new ImageData(ImageType.Bgr, frame.Width, frame.Height, (int)frame.Step(), new IntPtr(frame.DataPointer));
267268
encodedSuccess = encoder.Encode(g, out ec);
268269
}
269-
270+
271+
270272
ctr++;
271-
272273
if (encodedSuccess)
273274
{
274275
var len = ec.Sum(x => x.Length); ;
@@ -558,27 +559,40 @@ private void ParallelConverterChecked(object sender, RoutedEventArgs e)
558559
{
559560
if (encoder == null)
560561
return;
561-
Converter.NumThreads = ((CheckBox)sender).IsChecked ?? false ? numThreads : 0 ;
562+
563+
var t = ((CheckBox)sender).IsChecked ?? false ? numThreads : 0;
564+
565+
config.NumThreads = t;
566+
Converter.SetConfig(config);
567+
Cv2.SetNumThreads(t);
568+
562569
}
563570
private void ParallelConverterUnChecked(object sender, RoutedEventArgs e)
564571
{
565572
if (encoder == null)
566573
return;
567-
Converter.NumThreads = ((CheckBox)sender).IsChecked ?? false ? numThreads : 0;
574+
var t = ((CheckBox)sender).IsChecked ?? false ? numThreads : 0;
575+
config.NumThreads = t;
576+
Converter.SetConfig(config);
577+
Cv2.SetNumThreads(t);
568578
}
569579

570-
private void SSEChecked(object sender, RoutedEventArgs e)
580+
private void AVXChecked(object sender, RoutedEventArgs e)
571581
{
572582
if (decoder == null)
573583
return;
574-
Converter.EnableSSE = ((CheckBox)sender).IsChecked ?? false;
584+
var avx = ((CheckBox)sender).IsChecked ?? false;
585+
config.EnableAvx2 = avx?1:0;
586+
Converter.SetConfig(config);
575587

576588
}
577-
private void SSEUnChecked(object sender, RoutedEventArgs e)
589+
private void AVXUnChecked(object sender, RoutedEventArgs e)
578590
{
579591
if (decoder == null)
580592
return;
581-
Converter.EnableSSE = ((CheckBox)sender).IsChecked ?? false;
593+
var avx = ((CheckBox)sender).IsChecked ?? false;
594+
config.EnableAvx2 = avx ? 1 : 0;
595+
Converter.SetConfig(config);
582596

583597
}
584598

Examples/CrossPlatformTest/CrossPlatformTest.csproj

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@
1111

1212
</PropertyGroup>
1313

14+
<ItemGroup>
15+
<None Remove="H264SharpNative-win64.dll" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<Content Include="H264SharpNative-win64.dll">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
<PackagePath>\lib\$(TargetFramework)</PackagePath>
22+
<Pack>true</Pack>
23+
</Content>
24+
<Content Include="openh264-2.4.1-win64.dll">
25+
<PackagePath>\lib\$(TargetFramework)</PackagePath>
26+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
27+
<Pack>true</Pack>
28+
</Content>
29+
</ItemGroup>
30+
1431
<ItemGroup>
1532
<ProjectReference Include="..\..\H264Sharp\H264Sharp.csproj" />
1633
</ItemGroup>
1734

1835
<ItemGroup>
19-
<None Update="H264SharpNative-linux64.so">
20-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21-
</None>
22-
<None Update="H264SharpNative-win64.dll">
23-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24-
</None>
2536
<None Update="libopenh264-2.4.1-linux64.7.so">
2637
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2738
</None>
Binary file not shown.

Examples/CrossPlatformTest/Program.cs

Lines changed: 18 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,44 @@
11
using H264Sharp;
22
using System.Diagnostics;
33
using System.Drawing;
4+
using System.Runtime.InteropServices;
45

56
namespace CrossPlatformTest
67
{
78
internal class Program
89
{
9-
//TODO test on linux with the opt none removal
10-
1110
/*
1211
* Loads a raw rgba and encodes -> decodes.
1312
* I publish this for linux and add ncessary .so files on out dir.
1413
*/
1514
static void Main(string[] args)
1615
{
17-
18-
Converter.EnableNEON = true;
19-
Converter.NumThreads = 1;
16+
Console.WriteLine(RuntimeInformation.OSDescription);
17+
Console.WriteLine(RuntimeInformation.ProcessArchitecture);
18+
19+
var config = ConverterConfig.Default;
20+
config.EnableSSE = 1;
21+
config.EnableNeon = 1;
22+
config.EnableAvx2 = 1;
23+
config.NumThreads = 4;
24+
Converter.SetConfig(config);
2025

2126
H264Encoder encoder = new H264Encoder();
2227
H264Decoder decoder = new H264Decoder();
2328

24-
25-
2629
decoder.Initialize();
2730

28-
var w = 1920;
29-
var h = 1080;
30-
encoder.Initialize(w, h, 200_000_000, 30, ConfigType.CameraCaptureAdvanced);
31-
Console.WriteLine("Initialised Encoder");
32-
33-
Stopwatch sw = Stopwatch.StartNew();
3431
var bytes = File.ReadAllBytes("RawBgr.bin");
35-
var data = new ImageData(ImageType.Bgra, 1920, 1080, 1920*4, bytes);
36-
37-
//Converter.EnableNEON = false;
38-
39-
YuvImage yuvImage = new YuvImage(w, h);
40-
RgbImage rgb = new RgbImage(w, h);
41-
42-
var ss1 = Stopwatch.StartNew();
43-
Converter.Rgbx2Yuv(data, yuvImage);
44-
Converter.Yuv2Rgb(yuvImage, rgb);
45-
ss1.Stop();
46-
47-
Console.WriteLine("Conv 1: " + ss1.ElapsedMilliseconds);
48-
byte[] dat = new byte[w * h * 3];
49-
50-
unsafe
51-
{
52-
fixed (byte* dataPtr = dat)
53-
Buffer.MemoryCopy((byte*)rgb.ImageBytes.ToPointer(), dataPtr, dat.Length, dat.Length);
54-
}
55-
File.WriteAllBytes("Output.bin", dat);
56-
57-
Converter.Rgb2Yuv(rgb, yuvImage);
58-
Converter.Yuv2Rgb(yuvImage, rgb);
59-
unsafe
60-
{
61-
fixed (byte* dataPtr = dat)
62-
Buffer.MemoryCopy((byte*)rgb.ImageBytes.ToPointer(), dataPtr, dat.Length, dat.Length);
63-
}
64-
File.WriteAllBytes("Output1.bin", dat);
32+
var data = new ImageData(ImageType.Bgra, 1920, 1080, 1920 * 4, bytes);
33+
int w = data.Width;
34+
int h = data.Height;
6535

66-
67-
var ss2 = Stopwatch.StartNew();
68-
69-
for (int i = 0; i < 50; i++)
70-
{
71-
bytes = File.ReadAllBytes("RawBgr.bin");
72-
data = new ImageData(ImageType.Bgra, 1920, 1080, 1920 * 4, bytes);
73-
74-
ss2.Restart();
75-
Converter.Rgbx2Yuv(data, yuvImage);
76-
ss2.Stop();
77-
Console.WriteLine("Conv1: " + ss2.ElapsedMilliseconds);
78-
Thread.Sleep(100);
79-
80-
ss2.Restart();
81-
Converter.Yuv2Rgb(yuvImage, rgb);
82-
ss2.Stop();
83-
Console.WriteLine("Conv2: " + ss2.ElapsedMilliseconds);
84-
Thread.Sleep(100);
85-
86-
87-
}
88-
89-
90-
var ss = Stopwatch.StartNew();
91-
for (int i = 0; i < 1000; i++)
92-
{
93-
Converter.Rgbx2Yuv(data, yuvImage);
94-
Converter.Yuv2Rgb(yuvImage, rgb);
95-
}
96-
ss.Stop();
97-
Console.WriteLine("Conv: " + ss.ElapsedMilliseconds);
36+
encoder.Initialize(w, h, 200_000_000, 30, ConfigType.CameraBasic);
9837

9938
RgbImage rgbb = new RgbImage(w, h);
100-
for (int i = 0; i <= 200; i++)
39+
Stopwatch sw = Stopwatch.StartNew();
40+
41+
for (int i = 0; i <= 1000; i++)
10142
{
10243

10344
if (!encoder.Encode(data, out EncodedData[] ec))
@@ -121,6 +62,7 @@ static void Main(string[] args)
12162
//Console.WriteLine($"F:{encoded.FrameType} size: {encoded.Length}");
12263
// Bitmap result = RgbToBitmap(rgbb);
12364
// result.Save("Ok1.bmp");
65+
12466
}
12567

12668
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Examples/H264SharpNativePInvoke/H264SharpNativePInvoke.csproj

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
</PropertyGroup>
1010

11+
<ItemGroup>
12+
<None Remove="H264SharpNative-win64.dll" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<Content Include="H264SharpNative-win64.dll">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
<PackagePath>\lib\$(TargetFramework)</PackagePath>
19+
<Pack>true</Pack>
20+
</Content>
21+
</ItemGroup>
22+
1123
<ItemGroup>
1224
<PackageReference Include="System.Drawing.Common" Version="8.0.1" />
1325
</ItemGroup>
@@ -18,9 +30,6 @@
1830
</ItemGroup>
1931

2032
<ItemGroup>
21-
<None Update="H264SharpNative-win64.dll">
22-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23-
</None>
2433
<None Update="ocean 1280x720.jpg">
2534
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2635
</None>
@@ -45,5 +54,8 @@
4554
<None Update="openh264-2.4.1-win64.dll">
4655
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4756
</None>
57+
<None Update="Output1.bin">
58+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
59+
</None>
4860
</ItemGroup>
4961
</Project>

0 commit comments

Comments
 (0)