AddSaving

This commit is contained in:
danielgrabowski 2019-11-12 16:47:20 +01:00
parent 6f1cc96c16
commit 327faae0bc
8 changed files with 48 additions and 13 deletions

View File

@ -40,6 +40,7 @@ namespace Squirrowse.Client.Service
public async Task SendStreamAsync(IAsyncEnumerable<byte[]> asb)
{
if(!streamOn)return;
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
await session.SendAsync("UploadByteStream", asb);
@ -50,6 +51,7 @@ namespace Squirrowse.Client.Service
public async Task StartStream()
{
if (streamOn) return;
streamOn = true;
await SendStreamAsync(camera.GetFramesAsyncEnumerator());
}

View File

@ -11,8 +11,9 @@ namespace Squirrowse.Service.Hubs
Task RemoveUserByUserName(string agentName);
IEnumerable<User> getServerSideUsers();
bool CheckUser(string agentName);
bool StreamOn();
IEnumerable<User> getClientSideUsers();
IEnumerable<User> getAllUsers();
Task SaveData(IAsyncEnumerable<byte[]> stream);
}
}

View File

@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using OpenCvSharp;
using Squirrowse.Core.Models;
using Squirrowse.Core.Services;
namespace Squirrowse.Service.Hubs
{
@ -63,7 +66,7 @@ namespace Squirrowse.Service.Hubs
public async Task Startstream(string clientId)
{
manager.StreamOn() = true;
streamOn = true;
//var client = Clients.Client(clientId);
await Clients.Groups(Core.Models.Groups.normal.ToString()).SendAsync("Start");
// await client.SendAsync("Start");
@ -78,16 +81,25 @@ namespace Squirrowse.Service.Hubs
//await client.SendAsync("Stop");
}
public static bool streamOn { get; set; }
public async Task UploadByteStream(IAsyncEnumerable<byte[]> stream)
{
manager.SaveData(stream);
await foreach (var frame in stream)
{
logger.LogInformation($"Got frame size: {frame.Length} ");
if (!streamOn) continue;
logger.LogInformation($"Send frame of size: {frame.Length} to {Core.Models.Groups.superUser.ToString()}");
await Clients.Groups(Core.Models.Groups.superUser.ToString()).SendAsync("RecData", frame);
var frameStamp = frame.ConvertByteToMat();
string timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff",
CultureInfo.InvariantCulture);
Cv2.PutText(frameStamp, timestamp, new Point(1,480/2), HersheyFonts.HersheySimplex,0.5f,Scalar.Red);
logger.LogInformation($"{this.GetHashCode()}: send frame");
//logger.LogInformation($"Got frame size: {frame.Length} ");
//if (!streamOn) continue;
// logger.LogInformation($"Send frame of size: {frame.Length} to {Core.Models.Groups.superUser.ToString()}");
await Clients.Groups(Core.Models.Groups.superUser.ToString()).SendAsync("RecData", frameStamp.ConvertToJpgByte());
logger.LogInformation($"{this.GetHashCode()}: send data");
//await Task.Delay(100); //leave some delay for debug purpose
await Task.Delay(1000/30);
}
}

View File

@ -1,18 +1,17 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OpenCvSharp;
using Squirrowse.Core.Models;
using Squirrowse.Core.Services;
namespace Squirrowse.Service.Hubs
{
public class StreamManager : IStreamManager
{
private readonly List<User> _users = new List<User>(); //temporary
private bool stream;
public bool streamOn()
{
return stream;
}
public bool StreamOn { get; set; }
public Task AddUser(string connectionId, string userName, ConnectionType type)
{
_users.Add(new User(connectionId, userName, type));
@ -36,6 +35,7 @@ namespace Squirrowse.Service.Hubs
return _users.Where(user => user.UserType == ConnectionType.Server);
}
public IEnumerable<User> getClientSideUsers()
{
return _users.Where(user => user.UserType == ConnectionType.Client);
@ -51,5 +51,15 @@ namespace Squirrowse.Service.Hubs
var t = _users;
return _users;
}
public async Task SaveData(IAsyncEnumerable<byte[]> stream)
{
VideoWriter output = new VideoWriter("m.avi",FourCC.DIVX,30,new Size(640,480));
await foreach (var b in stream)
{
output.Write(b.ConvertByteToMat());
}
}
}
}

View File

@ -4,6 +4,16 @@
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="dll\openh264-1.8.0-win64.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="dll\openh264-1.8.0-win64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>

Binary file not shown.

BIN
Squirrowse.Service/dupa.avi Normal file

Binary file not shown.

BIN
Squirrowse.Service/dupa.mkv Normal file

Binary file not shown.