Commit 4a00ee08 authored by Ing. Jiří Fryč's avatar Ing. Jiří Fryč

new version

parent 46e398a0
No preview for this file type
......@@ -34,6 +34,44 @@ namespace KazetaNode
Program.Network.TestConnection();
}
}
class CmdModules : Command
{
public override string[] Aliases => new string[] { "modules" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
ConsoleP.AppendLine("Modules:");
ConsoleP.AppendLine(" - Capture", Program.Capture != null ? "@green" : "@red", Program.Capture != null ? "Enabled" : "Disabled");
ConsoleP.AppendLine(" - Persist", Program.Persist != null ? "@green" : "@red", Program.Persist != null ? "Enabled" : "Disabled");
ConsoleP.AppendLine(" - Process", Program.Process != null ? "@green" : "@red", Program.Process != null ? "Enabled" : "Disabled");
ConsoleP.AppendLine(" - Deliver", Program.Deliver != null ? "@green" : "@red", Program.Deliver != null ? "Enabled" : "Disabled");
}
}
class CmdClear : Command
{
public override string[] Aliases => new string[] { "clear" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
ConsoleP.Clear();
}
}
class CmdLibraries : Command
{
public override string[] Aliases => new string[] { "libraries" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
ConsoleP.AppendDelimeter();
ConsoleP.AppendCols(new int[] { 20, 30, 10, 10 }, "Id", "Name","Version","State");
ConsoleP.AppendDelimeter();
foreach (var lib in Program.Libraries)
{
ConsoleP.AppendCols(new int[] { 20,30,10,10 },lib.Id, lib.Name, lib.Version, "@green", "Enabled");
}
ConsoleP.AppendDelimeter();
}
}
class CmdNetworkDiscovery : Command
{
public override string[] Aliases => new string[] { "network-discovery" };
......@@ -43,7 +81,8 @@ namespace KazetaNode
ConsoleP.AppendLine("Starting network discovery protocol... (Timeout 5s)");
Postman.SendToChannel(Channels.Discovery, new DiscoveryMessage()).ExpectMultiple().Timeout(5_000)
.During(msg=> {
ConsoleP.AppendLine("Disovered node '" + msg.Sender + "':");
DiscoveryReplyMessage m = (DiscoveryReplyMessage) msg;
ConsoleP.AppendLine("Discovered node '" + msg.Sender + "':","@green",m.Capture?"Capture ":"",m.Process?"Process ":"",m.Persist?"Persist ":"",m.Deliver?"Deliver":"");
})
.Then(msgs=>{
ConsoleP.AppendLine("Network discovery protocol ended.");
......@@ -95,27 +134,34 @@ namespace KazetaNode
{
if (line[i].Equals(' '))
{
if (mode == 0) continue;
if (mode == 1) { input.Parameters.Add(name, null); name = ""; mode = 0; continue; }
if (mode == 2) { input.Parameters.Add(name, value); name = ""; value = ""; mode = 0; continue; }
if (mode == 4) { input.Arguments.Add(value); value = ""; mode = 0; continue; }
if (mode == 0) { i++; continue; }
if (mode == 1) { i++; input.Parameters.Add(name, null); name = ""; mode = 0; continue; }
if (mode == 2) { i++; input.Parameters.Add(name, value); name = ""; value = ""; mode = 0; continue; }
if (mode == 4) { i++; input.Arguments.Add(value); value = ""; mode = 0; continue; }
}
else if (mode==0 && line[i].Equals('-'))
{
i++;
mode = 1; continue;
}
else if (mode == 1 && line[i].Equals('='))
{
i++;
mode = 2; continue;
}
else if ((mode == 2 || mode == 4) && line[i].Equals('"'))
{
i++;
mode++; continue;
}
else if (line[i].Equals('"') && value.Length>0 && !value[value.Length-1].Equals('\\'))
{
if (mode == 3) { input.Parameters.Add(name, value); name = ""; value = ""; mode = 0; continue; }
if (mode == 5) { input.Arguments.Add(value); value = ""; mode = 0; continue; }
if (mode == 3)
{
i++; input.Parameters.Add(name, value); name = ""; value = ""; mode = 0; continue; }
if (mode == 5)
{
i++; input.Arguments.Add(value); value = ""; mode = 0; continue; }
}
if(mode==0) { mode = 4; value += line[i]; }
......@@ -123,7 +169,7 @@ namespace KazetaNode
else { value += line[i]; }
i++;
}
if (value.Length > 0)
if (value.Length > 0 || name.Length>0)
if (mode >= 4)
input.Arguments.Add(value);
else
......
......@@ -39,5 +39,9 @@ namespace KazetaNode.Coms
}
class DiscoveryReplyMessage : IMessage
{
public bool Capture { get; set; }
public bool Persist { get; set; }
public bool Process { get; set; }
public bool Deliver { get; set; }
}
}
......@@ -68,7 +68,7 @@ namespace KazetaNode.Coms
public static void DiscoveryReply(IMessage msg)
{
Program.Network.channel.BasicPublish("", QUEUE_PREFIX+msg.Sender, null, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new DiscoveryReplyMessage() { ResponseId = msg.MessageId,Sender=Program.NodeId })));
Program.Network.channel.BasicPublish("", QUEUE_PREFIX+msg.Sender, null, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new DiscoveryReplyMessage() { ResponseId = msg.MessageId,Sender=Program.NodeId, Capture=Program.Capture!=null,Process=Program.Process!=null,Persist=Program.Persist!=null, Deliver=Program.Deliver!=null })));
}
public void Connect()
......
......@@ -118,7 +118,7 @@ namespace KazetaNode
char ch = ' ';
foreach (var r in res)
{
if(r.Length<i)
if(r.Length<=i)
{
kill=true; break;
}
......@@ -170,6 +170,18 @@ namespace KazetaNode
}
}
internal static void Clear()
{
Console.Clear();
LinePrefix = "kazeta@" + Program.NodeId + ": ";
Console.Write(LinePrefix);
History.Add(Line);
HistoryPos = History.Count;
Line = "";
LinePos = 0;
}
public static void ClearLine(int pos=0)
{
Console.SetCursorPosition(0, Console.CursorTop-pos);
......@@ -201,6 +213,8 @@ namespace KazetaNode
case "@black": Console.ForegroundColor = ConsoleColor.Black; break;
case "@green": Console.ForegroundColor = ConsoleColor.Green; break;
case "@white": Console.ForegroundColor = ConsoleColor.White; break;
case "@darkgreen": Console.ForegroundColor = ConsoleColor.DarkGreen; break;
case "@darkblue": Console.ForegroundColor = ConsoleColor.DarkBlue; break;
case "@blue": Console.ForegroundColor = ConsoleColor.Blue; break;
case "@yellow": Console.ForegroundColor = ConsoleColor.Yellow; break;
case "@gray": Console.ForegroundColor = ConsoleColor.Gray; break;
......@@ -224,6 +238,8 @@ namespace KazetaNode
case "@green": Console.ForegroundColor = ConsoleColor.Green; break;
case "@white": Console.ForegroundColor = ConsoleColor.White; break;
case "@blue": Console.ForegroundColor = ConsoleColor.Blue; break;
case "@darkgreen": Console.ForegroundColor = ConsoleColor.DarkGreen; break;
case "@darkblue": Console.ForegroundColor = ConsoleColor.DarkBlue; break;
case "@yellow": Console.ForegroundColor = ConsoleColor.Yellow; break;
case "@gray": Console.ForegroundColor = ConsoleColor.Gray; break;
default: Console.Write(item); break;
......
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace KazetaNode.Helpers
{
class Shell
{
public static ShellResult Execute(string filename,string arguments,int? miliseconds = null)
public static ShellResult Execute(string filename, string arguments, int? miliseconds = null)
{
Process process = new Process()
{
......@@ -20,22 +16,27 @@ namespace KazetaNode.Helpers
RedirectStandardInput = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
if (miliseconds == null)
{
process.WaitForExit();
}
else
{
process.WaitForExit((int)miliseconds);
}
return new ShellResult()
{
Output = process.StandardOutput,
Error = process.StandardError,
ExitCode=process.ExitCode
ExitCode = process.ExitCode
};
}
}
class ShellResult
......
......@@ -5,7 +5,7 @@ using System.Text;
namespace KazetaNode.Helpers
{
public static class StringExtension
public static class Extensions
{
public static void OutputToConsole(this string str)
{
......@@ -15,6 +15,13 @@ namespace KazetaNode.Helpers
Console.WriteLine(str);
Console.Write("kazeta@" + Program.NodeId + ": ");
}
public static DateTime GetNextWeekday(this DateTime date,DayOfWeek day)
{
DateTime result = date.AddDays(1);
while (result.DayOfWeek != day)
result = result.AddDays(1);
return result;
}
public static string HashSha256(this string str)
{
var crypt = new SHA256Managed();
......
......@@ -26,8 +26,6 @@
<ItemGroup>
<Folder Include="Libraries\BlackMagicVideoHub\" />
<Folder Include="Libraries\TaskScheduler\" />
<Folder Include="Libraries\Visca\" />
</ItemGroup>
<ItemGroup>
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>C:\Users\frycj\Documents\Projekty\kazeta\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -29,7 +29,11 @@ namespace KazetaNode.Libraries
new Ffmpeg.Ffmpeg(),
new KosApi.KosApi(libraryConfig?["kosapi"]),
new Room.Room(),
new LocalStorage.LocalStorage(libraryConfig?["localstorage"])
new LocalStorage.LocalStorage(libraryConfig?["localstorage"]),
new Visca.Visca(),
new TaskScheduler.TaskScheduler(),
new FileShare.FileShare(),
new ArtNet.ArtNet()
};
return libraries;
}
......
......@@ -23,13 +23,13 @@ namespace KazetaNode.Libraries.Ffmpeg
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return "Libraries/Ffmpeg/ffmpeg.exe";
return "";
return "ffmpeg";
} }
public override string Name { get => "ffmpeg"; }
public override string Version { get => "1.0"; }
public override string Id => throw new NotImplementedException();
public override string Id => "ffmpeg";
public override List<Command> Commands => new List<Command>() { new CmdNdiFindSources(), new CmdNdiTakeScreenshot(),new CmdNdiCapture() };
......@@ -64,7 +64,10 @@ namespace KazetaNode.Libraries.Ffmpeg
Ip = match.Groups[4].Value,
});
}
ConsoleP.AppendLine("Found " + list.Count + " NDI sources:");
if(list.Count==0)
ConsoleP.AppendLine("Found 0 NDI sources");
else
ConsoleP.AppendLine("Found " + list.Count + " NDI sources:");
foreach(NdiSource source in list)
ConsoleP.AppendLine(" - "+source.Id+" ("+source.Ip+")");
}
......
using System;
using System.Collections.Generic;
using System.Text;
using KazetaNode.Coms;
namespace KazetaNode.Libraries.FileShare
{
class FileShare : AbstractLibrary
{
public override string Id => "fileshare";
public override string Name => "File Share";
public override string Version => "1.0";
using System;
using System.Collections.Generic;
using System.Text;
using KazetaNode.Coms;
namespace KazetaNode.Libraries.FileShare
{
class FileShare : AbstractLibrary
{
public override string Id => "fileshare";
public override string Name => "File Share";
public override string Version => "1.0";
public override List<Command> Commands => new List<Command>() { };
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>();
public override AbstractLibraryInstance CreateCaptureInstance()
{
throw new NotImplementedException();
}
public void SendProjectToNode(string node,string project_id)
{
}
}
}
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>();
public override AbstractLibraryInstance CreateCaptureInstance()
{
throw new NotImplementedException();
}
public void SendProjectToNode(string node,string project_id)
{
}
}
}
using System;
using KazetaNode.Coms;
using KazetaNode.Helpers;
using KazetaNode.Libraries.TaskScheduler;
using KazetaNode.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static KazetaNode.Helpers.Extensions;
namespace KazetaNode.Libraries.KosApi
{
......@@ -58,17 +64,117 @@ namespace KazetaNode.Libraries.KosApi
ConsoleP.AppendDelimeter();
}
}
class CmdKosApiCaptureSingleCourse : Command<KosApi>
class CmdKosApiCaptureCourseEvent : Command<KosApi>
{
public CmdKosApiCaptureSingleCourse(KosApi library) : base(library)
public CmdKosApiCaptureCourseEvent(KosApi library) : base(library)
{
}
public override string[] Aliases => new string[] { "kosapi-capture-single"};
public override string[] Aliases => new string[] { "kosapi-course-capture"};
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
throw new NotImplementedException();
if (input.Arguments.Count != 1 && input.Arguments.Count != 3)
{
ConsoleP.AppendLine("@red", "Help: kosapi-course-capture {code} ");
ConsoleP.AppendLine("@red", "Syntax: kosapi-course-capture {code} {parallelid} {numberofweeks}");
return;
}
var res = library.Endpoint.CourseInfoAsync(input.Arguments[0]); // B4M36ESW
res.Wait();
var course = res.Result;
if (course == null)
{
ConsoleP.AppendLine("Course with code '" + input.Arguments[0] + "' not found");
return;
}
int id = 0;
if (input.Arguments.Count == 1)
{
ConsoleP.AppendDelimeter();
ConsoleP.AppendCols(new int[] { 5, 10, 10, 10, 10, 10 }, "ID", "Type", "Day", "Room", "From", "To");
ConsoleP.AppendDelimeter();
foreach (var par in course.Parallels)
ConsoleP.AppendCols(new int[] { 5, 10, 10, 10, 10, 10 }, id++ + "", par.Type.ToString(), par.Day.ToString(), Program.GetLibrary<Room.Room>().RoomExist(par.RoomId) ? "@green" : "@red", par.RoomId, "@reset", par.FromHM[0] + ":" + par.FromHM[1], par.ToHM[0] + ":" + par.ToHM[1]);
ConsoleP.AppendDelimeter();
return;
}
id = int.Parse(input.Arguments[1]);
var parallel = course.Parallels[id];
if (input.Arguments.Count == 2)
{
ConsoleP.AppendLine("@red", "Missing number of weeks");
ConsoleP.AppendLine("@red", "Syntax: kosapi-course-capture {code} {parallelid} {numberofweeks}");
return;
}
id = int.Parse(input.Arguments[2]);
List<Project> projects = new List<Project>();
while (id > 0)
{
Project project = new Project
{
Author = Program.NodeId
};
project.Id = ProjectIdGenerator.Generate(parallel.RoomId, project.Capture.From.Year, project.Capture.From.Month, project.Capture.From.Day, project.Capture.From.Hour, "kosapi");
project.Stage = ProjectStage.NOT_STARTED;
project.Capture.From = DateTime.Now.GetNextWeekday(parallel.Day).Date + new TimeSpan(parallel.FromHM[0], parallel.FromHM[1], 0);
project.Capture.To = DateTime.Now.GetNextWeekday(parallel.Day).Date + new TimeSpan(parallel.ToHM[0], parallel.ToHM[1], 0);
project.Capture.Quality = project.Capture.Quality = VideoQuality.V1080p;
project.Capture.Room = parallel.RoomId;
project.Capture.Mode = CaptureMode.ALL;
project.Process.MappedFiles.Add(new ProjectProcessMappedFiles()
{
FileName = "output_1080.mp4",
Quality = VideoQuality.V1080p
});
project.Process.MappedFiles.Add(new ProjectProcessMappedFiles()
{
FileName = "output_720.mp4",
Quality = VideoQuality.V720p
});
project.Process.MappedFiles.Add(new ProjectProcessMappedFiles()
{
FileName = "output_480.mp4",
Quality = VideoQuality.V480p
});
project.Process.Script.Add("ffmpeg -i %primary_video% -i %primary_audio% -c:a aac -c:v libx264 -strict experimental merged.mp4");
project.Process.Script.Add("ffmpeg -i merged.mp4 -filter:v scale=1080:-1 output_1080.mp4");
project.Process.Script.Add("ffmpeg -i merged.mp4 -filter:v scale=720:-1 output_720.mp4");
project.Process.Script.Add("ffmpeg -i merged.mp4 -filter:v scale=480:-1 output_480.mp4");
projects.Add(project);
id--;
}
Room.Room room=Program.GetLibrary<Room.Room>();
if(room.LocalRooms.ContainsKey(parallel.RoomId))
{
ConsoleP.AppendLine("Local room found.");
foreach (Project p in projects)
Program.GetLibrary<TaskScheduler.TaskScheduler>().Scheduler.Add(new CaptureSchedulableTask()
{
Project = p,
RunAt=p.Capture.From
});
}
else if(room.RemoteRooms.ContainsKey(parallel.RoomId))
{
ConsoleP.AppendLine("Remote room found.");
foreach (Project p in projects)
Postman.SendToNode(room.RemoteRooms[parallel.RoomId].Item1.First(), new MsgTaskAdd()
{
Task = new CaptureSchedulableTask()
{
Project = p,
RunAt = p.Capture.From
}
});
}
else
{
ConsoleP.AppendLine("Room not found");
return;
}
}
}
}
......@@ -13,7 +13,7 @@ namespace KazetaNode.Libraries.KosApi
public override string Version => "1.0";
public override List<Command> Commands => new List<Command>() { new CmdKosApiCourseInfo(this),new CmdKosApiRoomInfo(this)};
public override List<Command> Commands => new List<Command>() { new CmdKosApiCourseInfo(this),new CmdKosApiRoomInfo(this),new CmdKosApiCaptureCourseEvent(this)};
public override List<Tuple<Type, Network.ReceiveMessage>> Messages => new List<Tuple<Type, Network.ReceiveMessage>>();
......
using System;
using System.Collections.Generic;
using System.Text;
using System;
using System.Collections.Generic;
using System.Text;
using KazetaNode.Coms;
using System.IO;
namespace KazetaNode.Libraries.LocalStorage
{
class LocalStorage : AbstractLibrary
namespace KazetaNode.Libraries.LocalStorage
{
class LocalStorage : AbstractLibrary
{
public override string Id => "localstorage";
......@@ -20,8 +20,8 @@ namespace KazetaNode.Libraries.LocalStorage
protected internal List<LocalStorageLocation> Locations = new List<LocalStorageLocation>();
public LocalStorage(dynamic config)
{
public LocalStorage(dynamic config)
{
foreach(dynamic loc in config)
{
Locations.Add(new LocalStorageLocation()
......@@ -31,18 +31,18 @@ namespace KazetaNode.Libraries.LocalStorage
MaxSize =Int32.Parse(loc["max_usage"]),
Primary=Boolean.Parse(loc["primary"])
});
}
}
}
public override AbstractLibraryInstance CreateCaptureInstance()
{
throw new NotImplementedException();
}
}
}
class LocalStorageLocation
{
public string FullPath { get; protected internal set; }
public string RelativePath { get; protected internal set; }
public int MaxSize { get; protected internal set; } = int.MaxValue;
public bool Primary { get; protected internal set; } = true;
}
}
}
}
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace KazetaNode.Libraries.Room
{
class CmdRoomInfo : Command
class CmdRoomInfo : Command<Room>
{
public override string[] Aliases => new string[] { "room-info" };
public CmdRoomInfo(Room library) : base(library)
{
}
public override string[] Aliases => new string[] { "room-local-detail" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
var room = library.LocalRooms[input.Arguments[0]];
ConsoleP.AppendDelimeter();
ConsoleP.AppendLine("Capability: ", "@darkgreen", String.Join(", ", room.Capability.Select(c => c.ToString())));
ConsoleP.AppendLine("Modes: ", "@darkgreen", String.Join(", ", room.Modes.Select(c => c.ToString())));
ConsoleP.AppendDelimeter();
if (input.Parameters.ContainsKey("a") || input.Parameters.ContainsKey("scripts"))
{
ConsoleP.AppendLine("Inicializate script:");
foreach (var terminate in room.Initialize)
{
ConsoleP.AppendLine("[ONLY= ", "@darkblue", String.Join(", ", terminate.Only.Select(c => c.ToString())), "@reset", " ]");
foreach (var line in terminate.Script)
ConsoleP.AppendLine(" - " + line);
}
ConsoleP.AppendDelimeter();
ConsoleP.AppendLine("Record script:");
foreach (var terminate in room.Capture)
{
ConsoleP.AppendLine("[ONLY= ", "@darkblue", String.Join(", ", terminate.Only.Select(c => c.ToString())), "@reset", " ]");
foreach (var line in terminate.Script)
ConsoleP.AppendLine(" - " + line);
}
ConsoleP.AppendDelimeter();
ConsoleP.AppendLine("Terminate script:");
foreach (var terminate in room.Terminate)
{
ConsoleP.AppendLine("[ONLY= ", "@darkblue", String.Join(", ", terminate.Only.Select(c => c.ToString())), "@reset", " ]");
foreach (var line in terminate.Script)
ConsoleP.AppendLine(" - " + line);
}
ConsoleP.AppendDelimeter();
}
if (input.Parameters.ContainsKey("a") || input.Parameters.ContainsKey("sources"))
{
ConsoleP.AppendLine("Sources:");
ConsoleP.AppendCols(new int[] { 20, 20, 20, 5, 5, 7 }, "IP", "ID", "Name", "Audio", "Video", "Priority");
foreach (var terminate in room.Sources)
{
ConsoleP.AppendCols(new int[] { 20, 20, 20, 5, 5, 7 }, "@green", terminate.Ip + ":" + terminate.Port, terminate.Id, terminate.DisplayName, terminate.AudioCapture ? "Yes" : "No", terminate.VideoCapture ? "Yes" : "No", terminate.Priority + "");
}
ConsoleP.AppendDelimeter();
}
}
}
class CmdLocalRoomInfo : Command<Room>
{
public CmdLocalRoomInfo(Room library) : base(library)
{
}
public override string[] Aliases => new string[] { "room-local" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
ConsoleP.AppendDelimeter();
ConsoleP.AppendCols(new int[] { 10,10 }, "Room","Capture sources");
ConsoleP.AppendDelimeter();
foreach (var room in library.LocalRooms)
{
ConsoleP.AppendCols(new int[] { 10,10 }, room.Key,room.Value.Sources.Count+"");
}
ConsoleP.AppendDelimeter();
}
}
class CmdRemoteRoomInfo : Command<Room>
{
public CmdRemoteRoomInfo(Room library) : base(library)
{
}
public override string[] Aliases => new string[] { "room-remote" };
public override void Execute(AbstractLibraryInstance instance, CommandInput input)
{
throw new NotImplementedException();
}
}
class CmdRoomCacheRefresh : Command<Room>
......
......@@ -10,7 +10,6 @@ namespace KazetaNode.Libraries.Room
}
class MsgRoomSynchronizeResponse : IMessage
{
public List<RoomModelBasic> Rooms { get; protected internal set; } = new List<RoomModelBasic>();
}
}
using KazetaNode.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace KazetaNode.Libraries.Room
{
class RoomsModel
{
public List<RoomModel> rooms { get; set; } = new List<RoomModel>();
}