From 3de0d44f88b713e7b018f470c7bd318a775345b7 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 22 Mar 2018 16:21:16 +0200 Subject: Implemented video recording on Data Capture Module! --- .../Tango.MachineStudio.DataCapture.csproj | 3 ++ .../ViewModels/MainViewVM.cs | 34 +++++++++++++++++- .../Views/MainView.xaml | 26 +++++++++++--- .../Tango.MachineStudio.DataCapture/app.config | 40 ++++++++++++++++++++++ .../packages.config | 1 + 5 files changed, 99 insertions(+), 5 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj index d4df08651..efa6d2ad7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj @@ -40,6 +40,9 @@ ..\..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Platform.dll + + ..\..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + ..\..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs index 9062da11a..b3d717263 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; +using System.Windows.Media.Imaging; using Tango.Core.Commands; using Tango.Integration.Diagnostics; using Tango.Integration.Operation; @@ -89,6 +90,16 @@ namespace Tango.MachineStudio.DataCapture.ViewModels /// public IMachineOperator MachineOperator { get; set; } + private List _captureDevices; + /// + /// Gets or sets the capture devices. + /// + public List CaptureDevices + { + get { return _captureDevices; } + set { _captureDevices = value; RaisePropertyChangedAuto(); } + } + #endregion #region Commands @@ -172,7 +183,7 @@ namespace Tango.MachineStudio.DataCapture.ViewModels MediaSeekForwardCommand = new RelayCommand(MediaSeekForward, () => !Recorder.IsRecording && Player.IsPlaying); MediaSeekBackwardCommand = new RelayCommand(MediaSeekBackward, () => !Recorder.IsRecording && Player.IsPlaying); MediaSeekCommand = new RelayCommand(MediaSeek, (x) => Player.IsPlaying); - MediaSeekHoldCommand = new RelayCommand(MediaSeekHold,() => Player.IsPlaying); + MediaSeekHoldCommand = new RelayCommand(MediaSeekHold, () => Player.IsPlaying); _recordingsFolder = Path.Combine(SettingsManager.DefaultFolder, "Recordings"); Directory.CreateDirectory(_recordingsFolder); @@ -184,6 +195,8 @@ namespace Tango.MachineStudio.DataCapture.ViewModels _recordingBarItem = new BarItem(_notification, new RecordingBarView() { DataContext = this }); _playerBarItem = new BarItem(_notification, new PlayingBarView() { DataContext = this }); + CaptureDevices = VideoCaptureProvider.AvailableCaptureDevices.ToList(); + LoadRecordings(); } @@ -204,6 +217,14 @@ namespace Tango.MachineStudio.DataCapture.ViewModels if (Recorder.IsRecording) { Recorder.Write(frame); + + Task.Factory.StartNew(() => + { + CaptureDevices.First().Invoke(() => + { + Recorder.Write(CaptureDevices.Where(x => x.VideoSource != null).Select(x => x.VideoSource.GetAsFrozen() as BitmapSource)); + }); + }); } } } @@ -289,6 +310,8 @@ namespace Tango.MachineStudio.DataCapture.ViewModels Player = player; Player.FrameReceived += Player_FrameReceived; } + + CaptureDevices.ForEach(x => x.DisableSourceUpdate()); } private void Player_FrameReceived(object sender, DataFileFrame frame) @@ -296,6 +319,14 @@ namespace Tango.MachineStudio.DataCapture.ViewModels if (_frameProvider.Disable) { _frameProvider.PushFrame(frame.PushDiagnosticsResponse); + + CaptureDevices.First().BeginInvoke(() => + { + for (int i = 0; i < frame.VideoFrames.Count; i++) + { + CaptureDevices[i].VideoSource = frame.VideoFrames[i].ToByteArray().ToBitmapSource(); + } + }); } } @@ -339,6 +370,7 @@ namespace Tango.MachineStudio.DataCapture.ViewModels else if (Player.IsPlaying) { await Player.Stop(); + CaptureDevices.ForEach(x => x.EnableSourceUpdate()); _frameProvider.Disable = false; _playerBarItem.Pop(); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/MainView.xaml index e3f9d380a..445d0d216 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/MainView.xaml @@ -17,6 +17,7 @@ + @@ -81,10 +82,10 @@ CAPTURE DEVICES - + - + @@ -101,9 +102,26 @@ - + + + + + - +