Skip to content

Commit

Permalink
Ревизия: 717
Browse files Browse the repository at this point in the history
Автор: saraff
Дата: 22 сентября 2020 г. 20:53:01
Сообщение:
Добавлена возможность выбора разрешения для видео.
----
Изменённые : /C#/Saraff.Twain.DS.DirectX/Saraff.Twain.DS.DirectX/ComponentModel/IPersistent.cs
Изменённые : /C#/Saraff.Twain.DS.DirectX/Saraff.Twain.DS.DirectX/ComponentModel/IVideoDevices.cs
Изменённые : /C#/Saraff.Twain.DS.DirectX/Saraff.Twain.DS.DirectX/Core/_PersistentService.cs
Изменённые : /C#/Saraff.Twain.DS.DirectX/Saraff.Twain.DS.DirectX/Core/_VideoDevices.cs
Изменённые : /C#/Saraff.Twain.DS.DirectX/Saraff.Twain.DS.DirectX/UI/DataSourceForm.Designer.cs
Изменённые : /C#/Saraff.Twain.DS.DirectX/Saraff.Twain.DS.DirectX/UI/DataSourceForm.cs
Изменённые : /C#/Saraff.Twain.DS.DirectX/Saraff.Twain.DS.DirectX/UI/DataSourceForm.resx
  • Loading branch information
saraff-9EB1047A4BEB4cef8506B29BA325BD5A committed Sep 26, 2020
1 parent e419db5 commit 806ac3b
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Saraff.Twain.DS.DirectX/ComponentModel/IPersistent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public interface IPersistent {

Size SourceSnapshotResolution { get; set; }

Size SourceVideoResolution { get; set; }

RotateFlipType RotateFlipType { get; set; }
}
}
4 changes: 4 additions & 0 deletions Saraff.Twain.DS.DirectX/ComponentModel/IVideoDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public interface IVideoDevices {

VideoCapabilities[] SnapshotCapabilities { get; }

VideoCapabilities VideoResolution { get; set; }

VideoCapabilities[] VideoCapabilities { get; }

event EventHandler<NewFrameEventArgs> NewFrame;

event EventHandler<NewFrameEventArgs> SnapshotFrame;
Expand Down
17 changes: 17 additions & 0 deletions Saraff.Twain.DS.DirectX/Core/_PersistentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions Saraff.Twain.DS.DirectX/Core/_VideoDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NewFrameEventArgs> NewFrame;

public event EventHandler<NewFrameEventArgs> SnapshotFrame;
Expand Down
4 changes: 2 additions & 2 deletions Saraff.Twain.DS.DirectX/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
59 changes: 48 additions & 11 deletions Saraff.Twain.DS.DirectX/UI/DataSourceForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 63 additions & 11 deletions Saraff.Twain.DS.DirectX/UI/DataSourceForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -134,19 +134,42 @@ 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<CapabilityView>(i => i("value", x)))
.ToList();

if(this.VideoDevices().SnapshotResolution == null) {
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<CapabilityView>(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();

Expand All @@ -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();
Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion Saraff.Twain.DS.DirectX/UI/DataSourceForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@
<metadata name="filterInfoViewBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="capabilityViewBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="videoBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>663, 17</value>
</metadata>
<metadata name="snapshotBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>220, 17</value>
</metadata>
<metadata name="rotateFlipTypeViewBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Expand Down

0 comments on commit 806ac3b

Please sign in to comment.