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! --- .../ViewModels/MainViewVM.cs | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels') 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(); } -- cgit v1.3.1