stream service

This commit is contained in:
ziomus5555 2019-11-01 19:04:24 +01:00
parent 3de1b04cb4
commit 3de7aaab87
7 changed files with 95 additions and 3 deletions

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using OpenCvSharp;
namespace Squirrowse.Client.Service
{
public class CameraService : ICameraService
{
public VideoCapture GetCamera()
{
throw new NotImplementedException();
}
public Task<Mat> GetFrame(VideoCapture video)
{
throw new NotImplementedException();
}
}
}

View File

@ -14,8 +14,9 @@ namespace Squirrowse.Client.Service
.AddMessagePackProtocol()
.WithAutomaticReconnect()
.Build();
}
public HubConnection EstablishHubConnection() => _connection;
public HubConnection Connect() => _connection;
}
}

View File

@ -0,0 +1,14 @@
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Squirrowse.Client.Service
{
public interface ICameraService
{
public VideoCapture GetCamera();
public Task<Mat> GetFrame(VideoCapture video);
}
}

View File

@ -4,7 +4,7 @@ namespace Squirrowse.Client.Service
{
public interface IConnectionManager
{
HubConnection EstablishHubConnection();
HubConnection Connect();
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Squirrowse.Client.Service
{
public interface IStreamService
{
Task SendStreamAsync(IAsyncEnumerable<byte[]> asb);
}
}

View File

@ -0,0 +1,38 @@
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Squirrowse.Client.Service
{
public class StreamService : IStreamService
{
private readonly IConnectionManager connectionManager;
private readonly ILogger<StreamService> logger;
public StreamService(ILogger<StreamService> logger, IConnectionManager connectionManager)
{
this.connectionManager = connectionManager;
this.logger = logger;
}
public async Task SendStreamAsync(IAsyncEnumerable<byte[]> asb)
{
var con = connectionManager.Connect();
try
{
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
await con.StartAsync();
await con.SendAsync("UploadByteStream", asb, default);
}
finally
{
logger.LogInformation($"{nameof(SendStreamAsync)} End stream");
await con.StopAsync();
}
}
}
}

View File

@ -5,16 +5,19 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Squirrowse.Client.Service;
namespace Squirrowse.Client
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
private readonly IStreamService _streamService;
public Worker(ILogger<Worker> logger)
public Worker(ILogger<Worker> logger, IStreamService streamService)
{
_logger = logger;
_streamService = streamService;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@ -22,6 +25,7 @@ namespace Squirrowse.Client
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
await Task.Delay(1000, stoppingToken);
}
}