diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-22 16:21:16 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-22 16:21:16 +0200 |
| commit | 3de0d44f88b713e7b018f470c7bd318a775345b7 (patch) | |
| tree | 7b5b2a1b50e4a9ab9e2f55269dd666133fd97e5e /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture | |
| parent | e4498de8bf54d586d5af7d119b7c33ad4c0031b5 (diff) | |
| download | Tango-3de0d44f88b713e7b018f470c7bd318a775345b7.tar.gz Tango-3de0d44f88b713e7b018f470c7bd318a775345b7.zip | |
Implemented video recording on Data Capture Module!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture')
5 files changed, 99 insertions, 5 deletions
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 @@ <Reference Include="GalaSoft.MvvmLight.Platform, Version=5.3.0.19032, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL"> <HintPath>..\..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath> </Reference> + <Reference Include="Google.Protobuf, Version=3.4.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> + <HintPath>..\..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll</HintPath> + </Reference> <Reference Include="MahApps.Metro, Version=1.5.0.23, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL"> <HintPath>..\..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll</HintPath> </Reference> 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 /// </summary> public IMachineOperator MachineOperator { get; set; } + private List<CaptureDevice> _captureDevices; + /// <summary> + /// Gets or sets the capture devices. + /// </summary> + public List<CaptureDevice> 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<double>(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 @@ <UserControl.Resources> <converters:StringEllipsisConverter x:Key="StringEllipsisConverter" /> <converters:BooleanToVisibilityInverseConverter x:Key="BooleanToVisibilityInverseConverter" /> + <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> <converters:NumberToFileSizeConverter x:Key="NumberToFileSizeConverter"/> <converters:BooleanInverseConverter x:Key="BooleanInverseConverter" /> </UserControl.Resources> @@ -81,10 +82,10 @@ <Image Source="../Images/capture-device.png" Width="42"></Image> <TextBlock VerticalAlignment="Center" Margin="10 10 0 0" Foreground="DimGray" FontSize="16" FontWeight="SemiBold">CAPTURE DEVICES</TextBlock> </StackPanel> - <ItemsControl Margin="0 20 0 0" ItemsSource="{Binding VideoCaptureProvider.AvailableCaptureDevices}"> + <ItemsControl Margin="0 20 0 0" ItemsSource="{Binding CaptureDevices}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> - <UniformGrid Rows="1" Columns="{Binding VideoCaptureProvider.AvailableCaptureDevices.Count}" /> + <UniformGrid Rows="1" Columns="{Binding CaptureDevices.Count}" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> @@ -101,9 +102,26 @@ <TextBlock FontSize="11" Text="{Binding Device.Name,Converter={StaticResource StringEllipsisConverter},ConverterParameter=30,FallbackValue='No Camera',TargetNullValue='No Camera'}"></TextBlock> </Border> - <Image Source="{Binding VideoSource,Mode=OneWay,IsAsync=True}" Stretch="Fill" Visibility="{Binding IsStarted,Converter={StaticResource BooleanToVisibilityConverter}}"></Image> + <Image Source="{Binding VideoSource,Mode=OneWay,IsAsync=True}" Stretch="Fill"> + <Image.Style> + <Style TargetType="Image"> + <Setter Property="Visibility" Value="Hidden"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsStarted}" Value="True"> + <Setter Property="Visibility" Value="Visible"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding IsStarted}" Value="False"> + <Setter Property="Visibility" Value="Hidden"></Setter> + </DataTrigger> + <DataTrigger Binding="{Binding EmulatedMode}" Value="True"> + <Setter Property="Visibility" Value="Visible"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </Image.Style> + </Image> - <Grid Background="#83000000" Cursor="Hand"> + <Grid Background="#83000000" Cursor="Hand" Visibility="{Binding EmulatedMode,Converter={StaticResource BooleanToVisibilityInverseConverter}}"> <Grid.Style> <Style TargetType="Grid"> <Setter Property="Opacity" Value="0"></Setter> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config index cacd4cd77..5d794b958 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config @@ -6,6 +6,46 @@ <assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" /> </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-1.2.2.0" newVersion="1.2.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-1.4.2.0" newVersion="1.4.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> + </dependentAssembly> </assemblyBinding> </runtime> </configuration>
\ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/packages.config index 4fd672b32..9f69ed86f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/packages.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/packages.config @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <packages> <package id="CommonServiceLocator" version="1.3" targetFramework="net46" /> + <package id="Google.Protobuf" version="3.4.1" targetFramework="net46" /> <package id="MahApps.Metro" version="1.5.0" targetFramework="net46" /> <package id="MaterialDesignColors" version="1.1.2" targetFramework="net46" /> <package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net46" /> |
