diff --git a/Squirrowse.Client/Program.cs b/Squirrowse.Client/Program.cs index a3d978e..483029b 100644 --- a/Squirrowse.Client/Program.cs +++ b/Squirrowse.Client/Program.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Squirrowse.Client.Service; namespace Squirrowse.Client { @@ -19,6 +20,7 @@ namespace Squirrowse.Client .ConfigureServices((hostContext, services) => { services.AddHostedService(); + services.AddTransient();//keep as transient for now }); } } diff --git a/Squirrowse.Client/Service/ConnectionManager.cs b/Squirrowse.Client/Service/ConnectionManager.cs new file mode 100644 index 0000000..5ce3ae9 --- /dev/null +++ b/Squirrowse.Client/Service/ConnectionManager.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNetCore.SignalR.Client; +using Microsoft.Extensions.DependencyInjection; + +namespace Squirrowse.Client.Service +{ + public class ConnectionManager : IConnectionManager + { + private readonly HubConnection _connection; + + public ConnectionManager(string url, int port) + { + _connection = new HubConnectionBuilder() + .WithUrl($"{url}:{port}/StreamHub") + .AddMessagePackProtocol() + .WithAutomaticReconnect() + .Build(); + } + + public HubConnection EstablishHubConnection() => _connection; + } +} \ No newline at end of file diff --git a/Squirrowse.Client/Service/IConnectionManager.cs b/Squirrowse.Client/Service/IConnectionManager.cs new file mode 100644 index 0000000..f5d208f --- /dev/null +++ b/Squirrowse.Client/Service/IConnectionManager.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.SignalR.Client; + +namespace Squirrowse.Client.Service +{ + public interface IConnectionManager + { + HubConnection EstablishHubConnection(); + + } +} \ No newline at end of file diff --git a/Squirrowse.Core.Tests/ImgExtensionTests.cs b/Squirrowse.Core.Tests/ImgExtensionTests.cs new file mode 100644 index 0000000..4fe9d7a --- /dev/null +++ b/Squirrowse.Core.Tests/ImgExtensionTests.cs @@ -0,0 +1,34 @@ +using FluentAssertions; +using OpenCvSharp; +using Squirrowse.Core.Services; +using Xunit; + +namespace Squirrowse.Core.Tests +{ + public class ImgExtensionTests + { + private readonly Mat sampleMat = new Mat(500, 600, MatType.CV_8UC3); + + [SkippableFact] + public void ByteShouldBeConvertedToMat() + { + // + Skip.If(true, "Cannot use fluent assertion in this kind of test (compare pointer to obj)"); + // + var bytes = sampleMat.ConvertToJpgByte(); + + var reMet = bytes.ConvertByteToMat(); + + reMet.Should().BeEquivalentTo(sampleMat); + } + + [Fact] + public void MatShouldBeConvertedToByteArr() + { + var newByteArr = sampleMat.ConvertToJpgByte(); + + newByteArr.Should().BeOfType(typeof(byte[])); + newByteArr.Should().NotBeNullOrEmpty(); + } + } +} \ No newline at end of file diff --git a/Squirrowse.Core.Tests/Squirrowse.Core.Tests.csproj b/Squirrowse.Core.Tests/Squirrowse.Core.Tests.csproj new file mode 100644 index 0000000..a12cfb3 --- /dev/null +++ b/Squirrowse.Core.Tests/Squirrowse.Core.Tests.csproj @@ -0,0 +1,23 @@ + + + + netcoreapp3.0 + + false + + + + + + + + + + + + + + + + + diff --git a/Squirrowse.Core/CoreModule.cs b/Squirrowse.Core/CoreModule.cs new file mode 100644 index 0000000..693e5c8 --- /dev/null +++ b/Squirrowse.Core/CoreModule.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace Squirrowse.Core +{ + public static class CoreModule + { + public static IServiceCollection AddCoreModule(this IServiceCollection services) + { + services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); + + return services; + } + } +} diff --git a/Squirrowse.Core/Models/VideoFrame.cs b/Squirrowse.Core/Models/VideoFrame.cs new file mode 100644 index 0000000..f2aab3c --- /dev/null +++ b/Squirrowse.Core/Models/VideoFrame.cs @@ -0,0 +1,12 @@ +using System; + +namespace Squirrowse.Client.Models +{ + public class VideoFrame + { + public byte[] FrameBytes { get; set; } + public DateTime TimeStamp => DateTime.Now; + public Guid id => Guid.NewGuid(); + public string Issuer { get; set; } + } +} \ No newline at end of file diff --git a/Squirrowse.Core/Services/ImgExtensions.cs b/Squirrowse.Core/Services/ImgExtensions.cs new file mode 100644 index 0000000..1d73542 --- /dev/null +++ b/Squirrowse.Core/Services/ImgExtensions.cs @@ -0,0 +1,21 @@ +using System.Linq; +using System.Runtime.CompilerServices; +using OpenCvSharp; + +namespace Squirrowse.Core.Services +{ + public static class ImgExtensions + { + public static byte[] ConvertToJpgByte(this Mat mat) + { + Cv2.ImEncode(".jpg", mat, out var imgbuffer);//no need to dispose + return imgbuffer.Any() ? imgbuffer : new byte[] { }; + } + + public static Mat ConvertByteToMat(this byte[] bytearr) + { + using var tempMat = Cv2.ImDecode(bytearr, ImreadModes.Unchanged); //keep as disposable + return tempMat ?? new Mat(); + } + } +} \ No newline at end of file diff --git a/Squirrowse.Core/Squirrowse.Core.csproj b/Squirrowse.Core/Squirrowse.Core.csproj new file mode 100644 index 0000000..2400b66 --- /dev/null +++ b/Squirrowse.Core/Squirrowse.Core.csproj @@ -0,0 +1,11 @@ + + + + netcoreapp3.0 + + + + + + + diff --git a/Squirrowse.sln b/Squirrowse.sln index 0841d41..08317ed 100644 --- a/Squirrowse.sln +++ b/Squirrowse.sln @@ -3,9 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29411.108 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrowse.Service", "Squirrowse.Service\Squirrowse.Service.csproj", "{8C085621-BAAA-4E96-B027-561BC18751EE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrowse.Service", "Squirrowse.Service\Squirrowse.Service.csproj", "{8C085621-BAAA-4E96-B027-561BC18751EE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrowse.Client", "Squirrowse.Client\Squirrowse.Client.csproj", "{558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrowse.Client", "Squirrowse.Client\Squirrowse.Client.csproj", "{558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrowse.Core", "Squirrowse.Core\Squirrowse.Core.csproj", "{D0989FCC-484E-4ADB-BA5E-1020894F9C09}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{BB569A06-F4D1-4927-87AB-86C4BD2AFBC5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrowse.Core.Tests", "Squirrowse.Core.Tests\Squirrowse.Core.Tests.csproj", "{CFA96677-EAA7-4871-AAD8-E6336973366F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,10 +27,21 @@ Global {558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}.Release|Any CPU.Build.0 = Release|Any CPU + {D0989FCC-484E-4ADB-BA5E-1020894F9C09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D0989FCC-484E-4ADB-BA5E-1020894F9C09}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D0989FCC-484E-4ADB-BA5E-1020894F9C09}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D0989FCC-484E-4ADB-BA5E-1020894F9C09}.Release|Any CPU.Build.0 = Release|Any CPU + {CFA96677-EAA7-4871-AAD8-E6336973366F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFA96677-EAA7-4871-AAD8-E6336973366F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFA96677-EAA7-4871-AAD8-E6336973366F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFA96677-EAA7-4871-AAD8-E6336973366F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {CFA96677-EAA7-4871-AAD8-E6336973366F} = {BB569A06-F4D1-4927-87AB-86C4BD2AFBC5} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1CC5C3B8-3825-4EB5-ACFF-73B4CAC8945D} EndGlobalSection