Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unity] Add try-catch when tcp socket is processing data received #100

Closed
wants to merge 11 commits into from
9 changes: 9 additions & 0 deletions Application/Models/Config/Configs/ProjectConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

namespace BocchiTracker.Config.Configs
{
public class CaptureSetting
{
public string? FFmpegPath { get; set; }

public SIPSorceryMedia.Abstractions.VideoCodecsEnum VideoCodecs { get; set; } = SIPSorceryMedia.Abstractions.VideoCodecsEnum.VP8;
}

public class MonitoredDirectoryConfig
{
public string? Directory { get; set; }
Expand Down Expand Up @@ -59,6 +66,8 @@ public class ProjectConfig

public string FileSaveDirectory { get; set; } = Path.Combine(Environment.CurrentDirectory, "FileSave");

public CaptureSetting CaptureSetting { get; set; } = new CaptureSetting();

public List<MonitoredDirectoryConfig> MonitoredDirectoryConfigs { get; set; } = new List<MonitoredDirectoryConfig>();

public string? CacheDirectory { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using BocchiTracker.ApplicationInfoCollector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BocchiTracker.IssueAssetCollector.Handlers.Movie
{
public class OBSStudioHandler : MovieHandler
{
public OBSStudioHandler(IFilenameGenerator inFilenameGenerator) : base(inFilenameGenerator)
{

}

public override void Handle(AppStatusBundle inAppStatusBundle, int inPID, string inOutput)

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/OBSStudioHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

'OBSStudioHandler.Handle(AppStatusBundle, int, string)': cannot override inherited member 'MovieHandler.Handle(AppStatusBundle, int, string)' because it is not marked virtual, abstract, or override

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/OBSStudioHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

'OBSStudioHandler.Handle(AppStatusBundle, int, string)': cannot override inherited member 'MovieHandler.Handle(AppStatusBundle, int, string)' because it is not marked virtual, abstract, or override

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/OBSStudioHandler.cs

View workflow job for this annotation

GitHub Actions / cover

'OBSStudioHandler.Handle(AppStatusBundle, int, string)': cannot override inherited member 'MovieHandler.Handle(AppStatusBundle, int, string)' because it is not marked virtual, abstract, or override

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/OBSStudioHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

'OBSStudioHandler.Handle(AppStatusBundle, int, string)': cannot override inherited member 'MovieHandler.Handle(AppStatusBundle, int, string)' because it is not marked virtual, abstract, or override

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/OBSStudioHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

'OBSStudioHandler.Handle(AppStatusBundle, int, string)': cannot override inherited member 'MovieHandler.Handle(AppStatusBundle, int, string)' because it is not marked virtual, abstract, or override
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using BocchiTracker.ApplicationInfoCollector;
using BocchiTracker.ModelEvent;
using Prism.Events;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Media3D;

Check failure on line 13 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

Check failure on line 13 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

Check failure on line 13 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / cover

The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

Check failure on line 13 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / cover

The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

Check failure on line 13 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

Check failure on line 13 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

Check failure on line 13 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

Check failure on line 13 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

namespace BocchiTracker.IssueAssetCollector.Handlers.Movie
{
public class GameCaptureFrameConvertMovieProcess

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

The namespace 'BocchiTracker.IssueAssetCollector.Handlers.Movie' already contains a definition for 'GameCaptureFrameConvertMovieProcess'

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

The namespace 'BocchiTracker.IssueAssetCollector.Handlers.Movie' already contains a definition for 'GameCaptureFrameConvertMovieProcess'

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / cover

The namespace 'BocchiTracker.IssueAssetCollector.Handlers.Movie' already contains a definition for 'GameCaptureFrameConvertMovieProcess'

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / cover

The namespace 'BocchiTracker.IssueAssetCollector.Handlers.Movie' already contains a definition for 'GameCaptureFrameConvertMovieProcess'

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

The namespace 'BocchiTracker.IssueAssetCollector.Handlers.Movie' already contains a definition for 'GameCaptureFrameConvertMovieProcess'

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

The namespace 'BocchiTracker.IssueAssetCollector.Handlers.Movie' already contains a definition for 'GameCaptureFrameConvertMovieProcess'

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

The namespace 'BocchiTracker.IssueAssetCollector.Handlers.Movie' already contains a definition for 'GameCaptureFrameConvertMovieProcess'

Check failure on line 17 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

The namespace 'BocchiTracker.IssueAssetCollector.Handlers.Movie' already contains a definition for 'GameCaptureFrameConvertMovieProcess'
{
public string Output { get; set; } = string.Empty;

private IEventAggregator _eventAggregator;

public GameCaptureFrameConvertMovieProcess(IEventAggregator inEventAggregator)

Check failure on line 23 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

Type 'GameCaptureFrameConvertMovieProcess' already defines a member called 'GameCaptureFrameConvertMovieProcess' with the same parameter types

Check failure on line 23 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / cover

Type 'GameCaptureFrameConvertMovieProcess' already defines a member called 'GameCaptureFrameConvertMovieProcess' with the same parameter types

Check failure on line 23 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / cover

Type 'GameCaptureFrameConvertMovieProcess' already defines a member called 'GameCaptureFrameConvertMovieProcess' with the same parameter types

Check failure on line 23 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

Type 'GameCaptureFrameConvertMovieProcess' already defines a member called 'GameCaptureFrameConvertMovieProcess' with the same parameter types

Check failure on line 23 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

Type 'GameCaptureFrameConvertMovieProcess' already defines a member called 'GameCaptureFrameConvertMovieProcess' with the same parameter types

Check failure on line 23 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

Type 'GameCaptureFrameConvertMovieProcess' already defines a member called 'GameCaptureFrameConvertMovieProcess' with the same parameter types

Check failure on line 23 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

Type 'GameCaptureFrameConvertMovieProcess' already defines a member called 'GameCaptureFrameConvertMovieProcess' with the same parameter types
{
_eventAggregator = inEventAggregator;
_eventAggregator
.GetEvent<GameCaptureFinishEvent>()
.Subscribe(Handle, ThreadOption.PublisherThread);
}

public void Handle(GameCaptureFinishEventParameter inParam)

Check failure on line 31 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

The type or namespace name 'GameCaptureFinishEventParameter' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 31 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

The type or namespace name 'GameCaptureFinishEventParameter' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 31 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / cover

The type or namespace name 'GameCaptureFinishEventParameter' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 31 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / cover

The type or namespace name 'GameCaptureFinishEventParameter' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 31 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

The type or namespace name 'GameCaptureFinishEventParameter' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 31 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

The type or namespace name 'GameCaptureFinishEventParameter' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 31 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

The type or namespace name 'GameCaptureFinishEventParameter' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 31 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

The type or namespace name 'GameCaptureFinishEventParameter' could not be found (are you missing a using directive or an assembly reference?)
{
var c = inParam.CaptureStreamParameter;
if (c == null) return;

int idx = 0;
unsafe
{
string output = Path.Combine(Output, "temp");
new DirectoryInfo(output).Create();

foreach (var frame in c.Frames.ToList())
{
if (frame.Data == null) continue;

Span<byte> dataSpan = new Span<byte>(frame.Data);
using (var image = new Image<Rgb24>(frame.Width, frame.Height))
{
for (int y = 0; y < frame.Height; y++)
{
for (int x = 0; x < frame.Width; x++)
{
var index = y * frame.Stride + x * 3;
var color = new Rgb24(dataSpan[index + 2], dataSpan[index + 1], dataSpan[index]);
image[x, y] = color;
}
}
image.Save(Path.Combine(output, $"{idx++}.png"));
}
}
}

//!< 連番テクスチャーをここで動画化する
//!< TODO

//!< ここで連番テクスチャを削除する
//!< TODO
}
}

public class WebRTCHandler : MovieHandler
{
private IEventAggregator _eventAggregator;
private GameCaptureFrameConvertMovieProcess _convert_movie_process;

public WebRTCHandler(IEventAggregator inEventAggregator, IFilenameGenerator inFilenameGenerator) : base(inFilenameGenerator)
{
_eventAggregator = inEventAggregator;
_convert_movie_process = new GameCaptureFrameConvertMovieProcess(inEventAggregator);
}

public override void Handle(AppStatusBundle inAppStatusBundle, int inPID, string inOutput)

Check failure on line 82 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-linux

'WebRTCHandler.Handle(AppStatusBundle, int, string)': cannot override inherited member 'MovieHandler.Handle(AppStatusBundle, int, string)' because it is not marked virtual, abstract, or override

Check failure on line 82 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / cover

'WebRTCHandler.Handle(AppStatusBundle, int, string)': cannot override inherited member 'MovieHandler.Handle(AppStatusBundle, int, string)' because it is not marked virtual, abstract, or override

Check failure on line 82 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-mac

'WebRTCHandler.Handle(AppStatusBundle, int, string)': cannot override inherited member 'MovieHandler.Handle(AppStatusBundle, int, string)' because it is not marked virtual, abstract, or override

Check failure on line 82 in Application/Models/IssueAssetCollector/Handlers/Movie/WebRTCHandler.cs

View workflow job for this annotation

GitHub Actions / build-windows

'WebRTCHandler.Handle(AppStatusBundle, int, string)': cannot override inherited member 'MovieHandler.Handle(AppStatusBundle, int, string)' because it is not marked virtual, abstract, or override
{
this._convert_movie_process.Output = Path.Combine(inOutput, _filenameGenerator.Generate(inAppStatusBundle) + ".mp4");

_eventAggregator
.GetEvent<RequestQueryEvent>()
.Publish(new ScreenshotRequestEventParameter(inAppStatusBundle.AppBasicInfo.ClientID));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ private IEnumerator Connect(string inIPAddress, int inPort)
yield break;
}

/// <summary>
/// Disconnects the socket.
/// </summary>
public void DisConnect()

private void OnDestroy()
{
if(IsConnect())
if (IsConnect())
{
socket.Disconnect(true);
}
}

/// <summary>
Expand Down Expand Up @@ -94,14 +94,18 @@ private IEnumerator ProcessReceiveData()
var task = socket.ReceiveAsync(receivedData, SocketFlags.None);
yield return new WaitUntil(() => task.IsCompleted);

int bytesRead = task.Result;
if (task.Result > 0)
try
{
Console.WriteLine("ProcessReceiveData::Success, size=" + bytesRead);
List<byte> receivedDataList = new List<byte>(receivedData);
receivedDataList.RemoveRange(bytesRead, receivedData.Length - bytesRead);
ReciveCallback?.Invoke(receivedDataList);
int bytesRead = task.Result;
if (task.Result > 0)
{
Console.WriteLine("ProcessReceiveData::Success, size=" + bytesRead);
List<byte> receivedDataList = new List<byte>(receivedData);
receivedDataList.RemoveRange(bytesRead, receivedData.Length - bytesRead);
ReciveCallback?.Invoke(receivedDataList);
}
}
catch { }
}

/// <summary>
Expand Down
Loading