From 806ac3b27605d90f02dc43a46456befe302dcaf1 Mon Sep 17 00:00:00 2001 From: saraff-9EB1047A4BEB4cef8506B29BA325BD5A Date: Sat, 26 Sep 2020 10:23:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B2=D0=B8=D0=B7=D0=B8=D1=8F:=207?= =?UTF-8?q?17=20=D0=90=D0=B2=D1=82=D0=BE=D1=80:=20saraff=20=D0=94=D0=B0?= =?UTF-8?q?=D1=82=D0=B0:=2022=20=D1=81=D0=B5=D0=BD=D1=82=D1=8F=D0=B1=D1=80?= =?UTF-8?q?=D1=8F=202020=20=D0=B3.=2020:53:01=20=D0=A1=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B5:=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B1=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=20=D1=80=D0=B0=D0=B7=D1=80=D0=B5=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D0=B8=D0=B4=D0=B5?= =?UTF-8?q?=D0=BE.=20----=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20:=20/C#/Saraff.Twain.DS.DirectX/Saraff.Twa?= =?UTF-8?q?in.DS.DirectX/ComponentModel/IPersistent.cs=20=D0=98=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=91=D0=BD=D0=BD=D1=8B=D0=B5=20:=20/C#/Sara?= =?UTF-8?q?ff.Twain.DS.DirectX/Saraff.Twain.DS.DirectX/ComponentModel/IVid?= =?UTF-8?q?eoDevices.cs=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20:=20/C#/Saraff.Twain.DS.DirectX/Saraff.Twain.DS.?= =?UTF-8?q?DirectX/Core/=5FPersistentService.cs=20=D0=98=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=91=D0=BD=D0=BD=D1=8B=D0=B5=20:=20/C#/Saraff.Twain.DS.?= =?UTF-8?q?DirectX/Saraff.Twain.DS.DirectX/Core/=5FVideoDevices.cs=20?= =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD=D0=BD=D1=8B=D0=B5=20?= =?UTF-8?q?:=20/C#/Saraff.Twain.DS.DirectX/Saraff.Twain.DS.DirectX/UI/Data?= =?UTF-8?q?SourceForm.Designer.cs=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B5=20:=20/C#/Saraff.Twain.DS.DirectX/Sara?= =?UTF-8?q?ff.Twain.DS.DirectX/UI/DataSourceForm.cs=20=D0=98=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=91=D0=BD=D0=BD=D1=8B=D0=B5=20:=20/C#/Saraff.Twa?= =?UTF-8?q?in.DS.DirectX/Saraff.Twain.DS.DirectX/UI/DataSourceForm.resx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComponentModel/IPersistent.cs | 2 + .../ComponentModel/IVideoDevices.cs | 4 + .../Core/_PersistentService.cs | 17 +++++ Saraff.Twain.DS.DirectX/Core/_VideoDevices.cs | 7 ++ .../Properties/AssemblyInfo.cs | 4 +- .../UI/DataSourceForm.Designer.cs | 59 ++++++++++++--- Saraff.Twain.DS.DirectX/UI/DataSourceForm.cs | 74 ++++++++++++++++--- .../UI/DataSourceForm.resx | 5 +- 8 files changed, 147 insertions(+), 25 deletions(-) diff --git a/Saraff.Twain.DS.DirectX/ComponentModel/IPersistent.cs b/Saraff.Twain.DS.DirectX/ComponentModel/IPersistent.cs index 8d16612..9188372 100644 --- a/Saraff.Twain.DS.DirectX/ComponentModel/IPersistent.cs +++ b/Saraff.Twain.DS.DirectX/ComponentModel/IPersistent.cs @@ -45,6 +45,8 @@ public interface IPersistent { Size SourceSnapshotResolution { get; set; } + Size SourceVideoResolution { get; set; } + RotateFlipType RotateFlipType { get; set; } } } diff --git a/Saraff.Twain.DS.DirectX/ComponentModel/IVideoDevices.cs b/Saraff.Twain.DS.DirectX/ComponentModel/IVideoDevices.cs index 38097ea..e362c5b 100644 --- a/Saraff.Twain.DS.DirectX/ComponentModel/IVideoDevices.cs +++ b/Saraff.Twain.DS.DirectX/ComponentModel/IVideoDevices.cs @@ -52,6 +52,10 @@ public interface IVideoDevices { VideoCapabilities[] SnapshotCapabilities { get; } + VideoCapabilities VideoResolution { get; set; } + + VideoCapabilities[] VideoCapabilities { get; } + event EventHandler NewFrame; event EventHandler SnapshotFrame; diff --git a/Saraff.Twain.DS.DirectX/Core/_PersistentService.cs b/Saraff.Twain.DS.DirectX/Core/_PersistentService.cs index c03f6f4..ae44952 100644 --- a/Saraff.Twain.DS.DirectX/Core/_PersistentService.cs +++ b/Saraff.Twain.DS.DirectX/Core/_PersistentService.cs @@ -75,6 +75,23 @@ public Size SourceSnapshotResolution { } } + public Size SourceVideoResolution { + get { + using(var _stream = new MemoryStream(this.RegistryKey.GetValue(nameof(_PersistentService.SourceVideoResolution), new byte[0]) as byte[])) { + if(_stream.Length == 0) { + return Size.Empty; + } + return (Size)new SoapFormatter().Deserialize(_stream); + } + } + set { + using(var _stream = new MemoryStream()) { + new SoapFormatter().Serialize(_stream, value); + this.RegistryKey.SetValue(nameof(_PersistentService.SourceVideoResolution), _stream.ToArray(), RegistryValueKind.Binary); + } + } + } + public RotateFlipType RotateFlipType { get => (RotateFlipType)(int)this.RegistryKey.GetValue(nameof(_PersistentService.RotateFlipType), RotateFlipType.RotateNoneFlipNone); set => this.RegistryKey.SetValue(nameof(_PersistentService.RotateFlipType), (int)value, RegistryValueKind.DWord); diff --git a/Saraff.Twain.DS.DirectX/Core/_VideoDevices.cs b/Saraff.Twain.DS.DirectX/Core/_VideoDevices.cs index 8d9b0d6..2bfcf55 100644 --- a/Saraff.Twain.DS.DirectX/Core/_VideoDevices.cs +++ b/Saraff.Twain.DS.DirectX/Core/_VideoDevices.cs @@ -117,6 +117,13 @@ public VideoCapabilities SnapshotResolution { public VideoCapabilities[] SnapshotCapabilities => this.IsSnapshotSupported ? this.Current.SnapshotCapabilities : this.Current.VideoCapabilities; + public VideoCapabilities VideoResolution { + get => this.Current.VideoResolution; + set => this.Current.VideoResolution = value; + } + + public VideoCapabilities[] VideoCapabilities => this.Current.VideoCapabilities; + public event EventHandler NewFrame; public event EventHandler SnapshotFrame; diff --git a/Saraff.Twain.DS.DirectX/Properties/AssemblyInfo.cs b/Saraff.Twain.DS.DirectX/Properties/AssemblyInfo.cs index 4f937e3..6ad7925 100644 --- a/Saraff.Twain.DS.DirectX/Properties/AssemblyInfo.cs +++ b/Saraff.Twain.DS.DirectX/Properties/AssemblyInfo.cs @@ -68,8 +68,8 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.3.702")] -[assembly: AssemblyFileVersion("1.0.3.702")] +[assembly: AssemblyVersion("1.0.4.717")] +[assembly: AssemblyFileVersion("1.0.4.717")] [assembly: DataSource(typeof(MediaDataSource), MaxConnectionCount = 1)] [assembly: IoC.BindService(typeof(Extensions.ILog), typeof(Saraff.Twain.DS.DirectX.Core._LogService))] diff --git a/Saraff.Twain.DS.DirectX/UI/DataSourceForm.Designer.cs b/Saraff.Twain.DS.DirectX/UI/DataSourceForm.Designer.cs index 5a86e1f..0498269 100644 --- a/Saraff.Twain.DS.DirectX/UI/DataSourceForm.Designer.cs +++ b/Saraff.Twain.DS.DirectX/UI/DataSourceForm.Designer.cs @@ -64,9 +64,12 @@ private void InitializeComponent() { this.comboBox1 = new System.Windows.Forms.ComboBox(); this.filterInfoViewBindingSource = new System.Windows.Forms.BindingSource(this.components); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.comboBox4 = new System.Windows.Forms.ComboBox(); + this.videoBindingSource = new System.Windows.Forms.BindingSource(this.components); + this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.comboBox2 = new System.Windows.Forms.ComboBox(); - this.capabilityViewBindingSource = new System.Windows.Forms.BindingSource(this.components); + this.snapshotBindingSource = new System.Windows.Forms.BindingSource(this.components); this.transferImmediatelyCheckBox = new System.Windows.Forms.CheckBox(); this.comboBox3 = new System.Windows.Forms.ComboBox(); this.rotateFlipTypeViewBindingSource = new System.Windows.Forms.BindingSource(this.components); @@ -76,7 +79,8 @@ private void InitializeComponent() { this.splitContainer1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.filterInfoViewBindingSource)).BeginInit(); this.groupBox1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.capabilityViewBindingSource)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.videoBindingSource)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.snapshotBindingSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.rotateFlipTypeViewBindingSource)).BeginInit(); this.SuspendLayout(); // @@ -154,7 +158,7 @@ private void InitializeComponent() { this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(6, 19); this.comboBox1.Name = "comboBox1"; - this.comboBox1.Size = new System.Drawing.Size(444, 21); + this.comboBox1.Size = new System.Drawing.Size(294, 21); this.comboBox1.TabIndex = 1; // // filterInfoViewBindingSource @@ -165,6 +169,8 @@ private void InitializeComponent() { // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.comboBox4); + this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.comboBox2); this.groupBox1.Controls.Add(this.comboBox1); @@ -175,20 +181,47 @@ private void InitializeComponent() { this.groupBox1.TabStop = false; this.groupBox1.Text = "Device"; // + // comboBox4 + // + this.comboBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.comboBox4.DataSource = this.videoBindingSource; + this.comboBox4.DisplayMember = "Name"; + this.comboBox4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox4.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.comboBox4.FormattingEnabled = true; + this.comboBox4.Location = new System.Drawing.Point(346, 19); + this.comboBox4.Name = "comboBox4"; + this.comboBox4.Size = new System.Drawing.Size(121, 21); + this.comboBox4.TabIndex = 4; + // + // videoBindingSource + // + this.videoBindingSource.DataSource = typeof(Saraff.Twain.DS.DirectX.UI.DataSourceForm.CapabilityView); + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(306, 22); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(34, 13); + this.label2.TabIndex = 3; + this.label2.Text = "Video"; + // // label1 // this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(468, 22); + this.label1.Location = new System.Drawing.Point(473, 22); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(57, 13); + this.label1.Size = new System.Drawing.Size(52, 13); this.label1.TabIndex = 2; - this.label1.Text = "Resolution"; + this.label1.Text = "Snapshot"; // // comboBox2 // this.comboBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.comboBox2.DataSource = this.capabilityViewBindingSource; + this.comboBox2.DataSource = this.snapshotBindingSource; this.comboBox2.DisplayMember = "Name"; this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; @@ -198,9 +231,9 @@ private void InitializeComponent() { this.comboBox2.Size = new System.Drawing.Size(121, 21); this.comboBox2.TabIndex = 0; // - // capabilityViewBindingSource + // snapshotBindingSource // - this.capabilityViewBindingSource.DataSource = typeof(Saraff.Twain.DS.DirectX.UI.DataSourceForm.CapabilityView); + this.snapshotBindingSource.DataSource = typeof(Saraff.Twain.DS.DirectX.UI.DataSourceForm.CapabilityView); // // transferImmediatelyCheckBox // @@ -253,7 +286,8 @@ private void InitializeComponent() { ((System.ComponentModel.ISupportInitialize)(this.filterInfoViewBindingSource)).EndInit(); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.capabilityViewBindingSource)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.videoBindingSource)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.snapshotBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.rotateFlipTypeViewBindingSource)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -273,8 +307,11 @@ private void InitializeComponent() { private System.Windows.Forms.CheckBox transferImmediatelyCheckBox; private System.Windows.Forms.BindingSource filterInfoViewBindingSource; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; - private System.Windows.Forms.BindingSource capabilityViewBindingSource; + private System.Windows.Forms.BindingSource snapshotBindingSource; private System.Windows.Forms.ComboBox comboBox3; private System.Windows.Forms.BindingSource rotateFlipTypeViewBindingSource; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox comboBox4; + private System.Windows.Forms.BindingSource videoBindingSource; } } \ No newline at end of file diff --git a/Saraff.Twain.DS.DirectX/UI/DataSourceForm.cs b/Saraff.Twain.DS.DirectX/UI/DataSourceForm.cs index 80335e3..7986e06 100644 --- a/Saraff.Twain.DS.DirectX/UI/DataSourceForm.cs +++ b/Saraff.Twain.DS.DirectX/UI/DataSourceForm.cs @@ -92,7 +92,7 @@ protected override void OnClosed(EventArgs e) { if(this.PersistentService != null) { this.PersistentService.IsTransferImmediately = this._IsTransferImmediately; - this.PersistentService.SourceSnapshotResolution = this._CurrentCapabilityView?.Value.FrameSize ?? Size.Empty; + this.PersistentService.SourceSnapshotResolution = this._CurrentShapshotView?.Value.FrameSize ?? Size.Empty; this.PersistentService.RotateFlipType = this._CurrentRotateFlipTypeView.RotateFlipType; } } catch(Exception ex) { @@ -134,7 +134,10 @@ private void _AddThumbnail(Guid guid) { private void _Connect() { var _device = this._CurrentFilterInfoView?.VideoDevice; if(_device != null) { - this.capabilityViewBindingSource.DataSource = this.VideoDevices().SnapshotCapabilities + + #region Snapshot + + this.snapshotBindingSource.DataSource = this.VideoDevices().SnapshotCapabilities .Select(x => this.Factory.CreateInstance(i => i("value", x))) .ToList(); @@ -142,11 +145,31 @@ private void _Connect() { var _size = this.PersistentService?.SourceSnapshotResolution; this.VideoDevices().SnapshotResolution = this.VideoDevices().SnapshotCapabilities.FirstOrDefault(x => x.FrameSize == _size) ?? this.VideoDevices().SnapshotCapabilities.FirstOrDefault(); } - this.capabilityViewBindingSource.Position = this.VideoDevices().SnapshotCapabilities + this.snapshotBindingSource.Position = this.VideoDevices().SnapshotCapabilities .Select((x, i) => new { Element = x, Index = i }) .FirstOrDefault(x => x.Element.FrameSize == this.VideoDevices().SnapshotResolution.FrameSize && x.Element.BitCount == this.VideoDevices().SnapshotResolution.BitCount)?.Index ?? 0; - this.capabilityViewBindingSource.CurrentChanged += this._CapabilityViewBindingSourceCurrentChanged; + this.snapshotBindingSource.CurrentChanged += this._SnapshotBindingSourceCurrentChanged; + + #endregion + + #region Video + + this.videoBindingSource.DataSource = this.VideoDevices().VideoCapabilities + .Select(x => this.Factory.CreateInstance(i => i("value", x))) + .ToList(); + + if(this.VideoDevices().VideoResolution == null) { + var _size = this.PersistentService?.SourceVideoResolution; + this.VideoDevices().VideoResolution = this.VideoDevices().VideoCapabilities.FirstOrDefault(x => x.FrameSize == _size) ?? this.VideoDevices().VideoCapabilities.FirstOrDefault(); + } + this.videoBindingSource.Position = this.VideoDevices().VideoCapabilities + .Select((x, i) => new { Element = x, Index = i }) + .FirstOrDefault(x => x.Element.FrameSize == this.VideoDevices().VideoResolution.FrameSize && x.Element.BitCount == this.VideoDevices().VideoResolution.BitCount)?.Index ?? 0; + + this.videoBindingSource.CurrentChanged += this._VideoBindingSourceCurrentChanged; + + #endregion this._Resize(); @@ -156,7 +179,7 @@ private void _Connect() { } private void _Disconnect() { - this.capabilityViewBindingSource.CurrentChanged -= this._CapabilityViewBindingSourceCurrentChanged; + this.snapshotBindingSource.CurrentChanged -= this._SnapshotBindingSourceCurrentChanged; if(this.player.VideoSource != null) { this.player.SignalToStop(); this.player.WaitForStop(); @@ -165,9 +188,20 @@ private void _Disconnect() { } private void _Resize() { - var _frame = this._CurrentCapabilityView.Value.FrameSize; - this.Width -= this.player.Width - (this._CurrentRotateFlipTypeView.IsToSide ? _frame.Height : _frame.Width); - this.Height -= this.player.Height - (this._CurrentRotateFlipTypeView.IsToSide ? _frame.Width : _frame.Height); + var _frame = this._CurrentVideoView.Value.FrameSize; + + var _area = Screen.PrimaryScreen.WorkingArea.Size; + var _width = this.Width - this.player.Width + (this._CurrentRotateFlipTypeView.IsToSide ? _frame.Height : _frame.Width); + var _height = this.Height - this.player.Height + (this._CurrentRotateFlipTypeView.IsToSide ? _frame.Width : _frame.Height); + + if(_width < _area.Width && _height < _area.Height) { + this.Width = _width; + this.Height = _height; + } else { + this.Location = Point.Empty; + this.Width = _width * Math.Min(_area.Height, _height * Math.Min(_area.Width, _width) / _width) / _height; + this.Height = _height * Math.Min(_area.Width, _width * Math.Min(_area.Height, _height) / _height) / _width; + } } #region Properties @@ -179,7 +213,9 @@ private bool _IsTransferImmediately { private FilterInfoView _CurrentFilterInfoView => this.filterInfoViewBindingSource.Current as FilterInfoView; - private CapabilityView _CurrentCapabilityView => this.capabilityViewBindingSource.Current as CapabilityView; + private CapabilityView _CurrentShapshotView => this.snapshotBindingSource.Current as CapabilityView; + + private CapabilityView _CurrentVideoView => this.videoBindingSource.Current as CapabilityView; private RotateFlipTypeView _CurrentRotateFlipTypeView => this.rotateFlipTypeViewBindingSource.Current as RotateFlipTypeView; @@ -212,15 +248,31 @@ private void _FilterInfoViewBindingSourceCurrentChanged(object sender, EventArgs } } - private void _CapabilityViewBindingSourceCurrentChanged(object sender, EventArgs e) { + private void _SnapshotBindingSourceCurrentChanged(object sender, EventArgs e) { try { - var _cap = this._CurrentCapabilityView?.Value; + var _cap = this._CurrentShapshotView?.Value; var _device = this._CurrentFilterInfoView?.VideoDevice; if(_device != null && _cap != null) { _device.SignalToStop(); _device.WaitForStop(); _device.SnapshotResolution = _cap; + _device.Start(); + } + } catch(Exception ex) { + this.Log?.Write(ex); + } + } + + private void _VideoBindingSourceCurrentChanged(object sender, EventArgs e) { + try { + var _cap = this._CurrentVideoView?.Value; + var _device = this._CurrentFilterInfoView?.VideoDevice; + if(_device != null && _cap != null) { + _device.SignalToStop(); + _device.WaitForStop(); + _device.VideoResolution = _cap; + this._Resize(); _device.Start(); diff --git a/Saraff.Twain.DS.DirectX/UI/DataSourceForm.resx b/Saraff.Twain.DS.DirectX/UI/DataSourceForm.resx index 2279f7a..a6e5723 100644 --- a/Saraff.Twain.DS.DirectX/UI/DataSourceForm.resx +++ b/Saraff.Twain.DS.DirectX/UI/DataSourceForm.resx @@ -120,7 +120,10 @@ 17, 17 - + + 663, 17 + + 220, 17