Compare commits

...

3 Commits

8 changed files with 74 additions and 70 deletions

9
Directory.Build.props Normal file
View File

@ -0,0 +1,9 @@
<Project>
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>

22
Directory.Packages.props Normal file
View File

@ -0,0 +1,22 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Avalonia" Version="12.1.2" />
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="12.1.2" />
<PackageVersion Include="Avalonia.Desktop" Version="12.1.2" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="12.1.2" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="12.1.2" />
<PackageVersion Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageVersion Include="FFmpeg.AutoGen" Version="9.0.1.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.12" />
<PackageVersion Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.24.4" />
<PackageVersion Include="Onnxify" Version="0.3.11" />
<PackageVersion Include="OpenCvSharp4" Version="4.13.0.20260627" />
<PackageVersion Include="OpenCvSharp4.runtime.win" Version="4.13.0.20260627" />
<PackageVersion Include="Spectre.Console" Version="0.57.2" />
<PackageVersion Include="UltraFaceDotNet" Version="1.0.0.2" />
</ItemGroup>
</Project>

View File

@ -1,62 +1,42 @@
namespace Splitter_UI.Services;
using System.Buffers;
namespace Splitter_UI.Services;
public sealed class BufferPool : IBufferPool
{
public sealed class Entry
public sealed class Entry : IDisposable
{
private bool _disposed;
public readonly int Width;
public readonly int Height;
public readonly byte[] Bgr;
public readonly byte[] Bgra;
public Entry(int w, int h)
public byte[] Bgr;
public byte[] Bgra;
internal Entry(int w, int h)
{
Width = w;
Height = h;
Bgr = new byte[w * h * 3];
Bgra = new byte[w * h * 4];
Bgr = ArrayPool<byte>.Shared.Rent(w * h * 3);
Bgra = ArrayPool<byte>.Shared.Rent(w * h * 4);
}
override public string ToString() => $"Entry({Width}x{Height})";
}
private readonly Dictionary<(int w, int h), LinkedListNode<Entry>> _map;
private readonly LinkedList<Entry> _lru;
private readonly int _capacity;
private readonly Lock _lock = new();
public BufferPool()
public void Dispose()
{
_capacity = 8;
_map = new Dictionary<(int w, int h), LinkedListNode<Entry>>(_capacity);
_lru = new LinkedList<Entry>();
if (_disposed) return;
_disposed = true;
ArrayPool<byte>.Shared.Return(Bgr);
ArrayPool<byte>.Shared.Return(Bgra);
}
public override string ToString() => $"Entry({Width}x{Height})";
}
public Entry Get(int w, int h)
{
var key = (w, h);
if (_map.TryGetValue(key, out var node))
{
_lru.Remove(node);
_lru.AddLast(node);
return node.Value;
}
var created = new Entry(w, h);
var newNode = new LinkedListNode<Entry>(created);
_lru.AddLast(newNode);
_map[key] = newNode;
if (_lru.Count > _capacity)
{
var first = _lru.First!;
_lru.RemoveFirst();
_map.Remove((first.Value.Width, first.Value.Height));
}
return created;
return new Entry(w, h);
}
}

View File

@ -22,7 +22,7 @@ public sealed class MatToBitmapConverter(IBufferPool _pool) : IMatToBitmapConver
lock (_sync)
{
var entry = _pool.Get(w, h);
using var entry = _pool.Get(w, h);
var src = mat;
if (!src.IsContinuous())
@ -65,7 +65,7 @@ public sealed class MatToBitmapConverter(IBufferPool _pool) : IMatToBitmapConver
public Bitmap Convert(byte[] bgr, int width, int height, Bitmap? existing = null)
{
var entry = _pool.Get(width, height);
using var entry = _pool.Get(width, height);
ConvertBgrToBgra(bgr, entry.Bgra, width, height);
if (existing is WriteableBitmap wb &&

View File

@ -59,7 +59,7 @@ public sealed class ThumbnailService : IThumbnailService
height ??= ThumbHeight;
skip ??= TimeSpan.Zero;
var entry = _pool.Get(width.Value, height.Value);
using var entry = _pool.Get(width.Value, height.Value);
var ok = await DecodeFrameAsync(
entry.Bgr,

View File

@ -1,10 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
@ -18,17 +14,17 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="12.0.4" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="12.0.0" />
<PackageReference Include="Avalonia.Desktop" Version="12.0.4" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.0.4" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.0.4" />
<PackageReference Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3">
<PackageReference Include="Avalonia" />
<PackageReference Include="Avalonia.Controls.DataGrid" />
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.Themes.Fluent" />
<PackageReference Include="Avalonia.Fonts.Inter" />
<PackageReference Include="AvaloniaUI.DiagnosticsSupport">
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.9" />
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
</ItemGroup>
<ItemGroup>

View File

@ -47,6 +47,7 @@ public sealed class CameraController
_cropHeight = cropHeight;
_kalman = kalman;
_cmd = cmd;
DefaultCenter = new Point2f(videoWidth * _cmd.GravitateTo.X, videoHeight * _cmd.GravitateTo.Y);
_cameraCenter = DefaultCenter;
_state = TrackState.Tracking;
@ -58,7 +59,7 @@ public sealed class CameraController
_kalman.Reset(_cameraCenter);
}
private Point2f DefaultCenter => _cmd.GravitateTo;
private Point2f DefaultCenter { get; set; }
public int LostFrames => _lostFrames;
public Point2f CameraCenter => _cameraCenter;
@ -148,7 +149,7 @@ public sealed class CameraController
smoothedCenter = _kalman.Update(objectCenter);
var driftEasing = 0.01f;
var fallbackCenter = new Point2f(_videoWidth / 2f, _videoHeight / 2f);
var fallbackCenter = DefaultCenter;
_cameraCenter = new Point2f(
_cameraCenter.X + (fallbackCenter.X - _cameraCenter.X) * driftEasing,

View File

@ -2,10 +2,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
@ -57,13 +53,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FFmpeg.AutoGen" Version="8.1.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.24.4" />
<PackageReference Include="Onnxify" Version="0.3.4" />
<PackageReference Include="OpenCvSharp4" Version="4.13.0.20260602" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.13.0.20260602" />
<PackageReference Include="Spectre.Console" Version="0.57.0" />
<PackageReference Include="UltraFaceDotNet" Version="1.0.0.2" />
<PackageReference Include="FFmpeg.AutoGen" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" />
<PackageReference Include="Onnxify" />
<PackageReference Include="OpenCvSharp4" />
<PackageReference Include="OpenCvSharp4.runtime.win" />
<PackageReference Include="Spectre.Console" />
<PackageReference Include="UltraFaceDotNet" />
</ItemGroup>
</Project>