From d6a982db41c07e15c2ff9dc14c1a07079762a09c Mon Sep 17 00:00:00 2001 From: TGSAN Date: Sat, 2 Jan 2021 06:16:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=A7=8D=E5=8F=82=E6=95=B0=E9=A2=84?= =?UTF-8?q?=E8=AE=BE=E5=8F=AF=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MirrorCaster/MainForm.Designer.cs | 79 ++++++++++++------ MirrorCaster/MainForm.cs | 106 +++++++++++++++++++----- MirrorCaster/Properties/AssemblyInfo.cs | 4 +- 3 files changed, 143 insertions(+), 46 deletions(-) diff --git a/MirrorCaster/MainForm.Designer.cs b/MirrorCaster/MainForm.Designer.cs index 90c6c2d..b22020c 100644 --- a/MirrorCaster/MainForm.Designer.cs +++ b/MirrorCaster/MainForm.Designer.cs @@ -39,20 +39,22 @@ private void InitializeComponent() this.backKeyButton = new System.Windows.Forms.Button(); this.homeKeyButton = new System.Windows.Forms.Button(); this.controlPanel = new System.Windows.Forms.FlowLayoutPanel(); + this.vsyncEnableCheckBox = new System.Windows.Forms.CheckBox(); + this.hwdecEnableCheckBox = new System.Windows.Forms.CheckBox(); + this.profileComboBox = new System.Windows.Forms.ComboBox(); this.startCastSingleButton = new System.Windows.Forms.Button(); this.testButton = new System.Windows.Forms.Button(); this.mutiKeyButton = new System.Windows.Forms.Button(); this.menuKeyButton = new System.Windows.Forms.Button(); this.volUpKeyButton = new System.Windows.Forms.Button(); this.volDownKeyButton = new System.Windows.Forms.Button(); - this.vsyncEnableCheckBox = new System.Windows.Forms.CheckBox(); this.screenBox.SuspendLayout(); this.controlPanel.SuspendLayout(); this.SuspendLayout(); // // startCastButton // - this.startCastButton.Location = new System.Drawing.Point(93, 4); + this.startCastButton.Location = new System.Drawing.Point(301, 4); this.startCastButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.startCastButton.Name = "startCastButton"; this.startCastButton.Size = new System.Drawing.Size(87, 33); @@ -64,7 +66,7 @@ private void InitializeComponent() // stopCastButton // this.stopCastButton.Enabled = false; - this.stopCastButton.Location = new System.Drawing.Point(549, 4); + this.stopCastButton.Location = new System.Drawing.Point(757, 4); this.stopCastButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.stopCastButton.Name = "stopCastButton"; this.stopCastButton.Size = new System.Drawing.Size(87, 33); @@ -106,7 +108,7 @@ private void InitializeComponent() // powerKeyButton // this.powerKeyButton.Enabled = false; - this.powerKeyButton.Location = new System.Drawing.Point(642, 4); + this.powerKeyButton.Location = new System.Drawing.Point(850, 4); this.powerKeyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.powerKeyButton.Name = "powerKeyButton"; this.powerKeyButton.Size = new System.Drawing.Size(87, 33); @@ -118,7 +120,7 @@ private void InitializeComponent() // backKeyButton // this.backKeyButton.Enabled = false; - this.backKeyButton.Location = new System.Drawing.Point(735, 4); + this.backKeyButton.Location = new System.Drawing.Point(943, 4); this.backKeyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.backKeyButton.Name = "backKeyButton"; this.backKeyButton.Size = new System.Drawing.Size(87, 33); @@ -130,7 +132,7 @@ private void InitializeComponent() // homeKeyButton // this.homeKeyButton.Enabled = false; - this.homeKeyButton.Location = new System.Drawing.Point(828, 4); + this.homeKeyButton.Location = new System.Drawing.Point(1036, 4); this.homeKeyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.homeKeyButton.Name = "homeKeyButton"; this.homeKeyButton.Size = new System.Drawing.Size(87, 33); @@ -145,6 +147,8 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Right))); this.controlPanel.AutoScroll = true; this.controlPanel.Controls.Add(this.vsyncEnableCheckBox); + this.controlPanel.Controls.Add(this.hwdecEnableCheckBox); + this.controlPanel.Controls.Add(this.profileComboBox); this.controlPanel.Controls.Add(this.startCastButton); this.controlPanel.Controls.Add(this.startCastSingleButton); this.controlPanel.Controls.Add(this.testButton); @@ -162,9 +166,46 @@ private void InitializeComponent() this.controlPanel.TabIndex = 6; this.controlPanel.WrapContents = false; // + // vsyncEnableCheckBox + // + this.vsyncEnableCheckBox.AutoSize = true; + this.vsyncEnableCheckBox.Location = new System.Drawing.Point(12, 11); + this.vsyncEnableCheckBox.Margin = new System.Windows.Forms.Padding(12, 11, 0, 3); + this.vsyncEnableCheckBox.Name = "vsyncEnableCheckBox"; + this.vsyncEnableCheckBox.Size = new System.Drawing.Size(75, 21); + this.vsyncEnableCheckBox.TabIndex = 17; + this.vsyncEnableCheckBox.Text = "垂直同步"; + this.vsyncEnableCheckBox.UseVisualStyleBackColor = true; + this.vsyncEnableCheckBox.CheckedChanged += new System.EventHandler(this.vsyncEnableCheckBox_CheckedChanged); + // + // hwdecEnableCheckBox + // + this.hwdecEnableCheckBox.AutoSize = true; + this.hwdecEnableCheckBox.Checked = true; + this.hwdecEnableCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; + this.hwdecEnableCheckBox.Location = new System.Drawing.Point(87, 11); + this.hwdecEnableCheckBox.Margin = new System.Windows.Forms.Padding(0, 11, 0, 3); + this.hwdecEnableCheckBox.Name = "hwdecEnableCheckBox"; + this.hwdecEnableCheckBox.Size = new System.Drawing.Size(75, 21); + this.hwdecEnableCheckBox.TabIndex = 19; + this.hwdecEnableCheckBox.Text = "硬件加速"; + this.hwdecEnableCheckBox.UseVisualStyleBackColor = true; + this.hwdecEnableCheckBox.CheckedChanged += new System.EventHandler(this.hwdecEnableCheckBox_CheckedChanged); + // + // profileComboBox + // + this.profileComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.profileComboBox.FormattingEnabled = true; + this.profileComboBox.Location = new System.Drawing.Point(165, 8); + this.profileComboBox.Margin = new System.Windows.Forms.Padding(3, 8, 3, 3); + this.profileComboBox.Name = "profileComboBox"; + this.profileComboBox.Size = new System.Drawing.Size(130, 25); + this.profileComboBox.TabIndex = 18; + this.profileComboBox.SelectedIndexChanged += new System.EventHandler(this.profileComboBox_SelectedIndexChanged); + // // startCastSingleButton // - this.startCastSingleButton.Location = new System.Drawing.Point(186, 4); + this.startCastSingleButton.Location = new System.Drawing.Point(394, 4); this.startCastSingleButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.startCastSingleButton.Name = "startCastSingleButton"; this.startCastSingleButton.Size = new System.Drawing.Size(264, 33); @@ -176,7 +217,7 @@ private void InitializeComponent() // // testButton // - this.testButton.Location = new System.Drawing.Point(456, 4); + this.testButton.Location = new System.Drawing.Point(664, 4); this.testButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.testButton.Name = "testButton"; this.testButton.Size = new System.Drawing.Size(87, 33); @@ -189,7 +230,7 @@ private void InitializeComponent() // mutiKeyButton // this.mutiKeyButton.Enabled = false; - this.mutiKeyButton.Location = new System.Drawing.Point(921, 4); + this.mutiKeyButton.Location = new System.Drawing.Point(1129, 4); this.mutiKeyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.mutiKeyButton.Name = "mutiKeyButton"; this.mutiKeyButton.Size = new System.Drawing.Size(87, 33); @@ -201,7 +242,7 @@ private void InitializeComponent() // menuKeyButton // this.menuKeyButton.Enabled = false; - this.menuKeyButton.Location = new System.Drawing.Point(1014, 4); + this.menuKeyButton.Location = new System.Drawing.Point(1222, 4); this.menuKeyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.menuKeyButton.Name = "menuKeyButton"; this.menuKeyButton.Size = new System.Drawing.Size(87, 33); @@ -213,7 +254,7 @@ private void InitializeComponent() // volUpKeyButton // this.volUpKeyButton.Enabled = false; - this.volUpKeyButton.Location = new System.Drawing.Point(1107, 4); + this.volUpKeyButton.Location = new System.Drawing.Point(1315, 4); this.volUpKeyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.volUpKeyButton.Name = "volUpKeyButton"; this.volUpKeyButton.Size = new System.Drawing.Size(87, 33); @@ -225,7 +266,7 @@ private void InitializeComponent() // volDownKeyButton // this.volDownKeyButton.Enabled = false; - this.volDownKeyButton.Location = new System.Drawing.Point(1200, 4); + this.volDownKeyButton.Location = new System.Drawing.Point(1408, 4); this.volDownKeyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.volDownKeyButton.Name = "volDownKeyButton"; this.volDownKeyButton.Size = new System.Drawing.Size(87, 33); @@ -234,18 +275,6 @@ private void InitializeComponent() this.volDownKeyButton.UseVisualStyleBackColor = true; this.volDownKeyButton.Click += new System.EventHandler(this.VolDownKeyButton_Click); // - // vsyncEnableCheckBox - // - this.vsyncEnableCheckBox.AutoSize = true; - this.vsyncEnableCheckBox.Location = new System.Drawing.Point(12, 11); - this.vsyncEnableCheckBox.Margin = new System.Windows.Forms.Padding(12, 11, 3, 3); - this.vsyncEnableCheckBox.Name = "vsyncEnableCheckBox"; - this.vsyncEnableCheckBox.Size = new System.Drawing.Size(75, 21); - this.vsyncEnableCheckBox.TabIndex = 17; - this.vsyncEnableCheckBox.Text = "垂直同步"; - this.vsyncEnableCheckBox.UseVisualStyleBackColor = true; - this.vsyncEnableCheckBox.CheckedChanged += new System.EventHandler(this.vsyncEnableCheckBox_CheckedChanged); - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); @@ -285,6 +314,8 @@ private void InitializeComponent() private System.Windows.Forms.Button testButton; private System.Windows.Forms.Button startCastSingleButton; private System.Windows.Forms.CheckBox vsyncEnableCheckBox; + private System.Windows.Forms.ComboBox profileComboBox; + private System.Windows.Forms.CheckBox hwdecEnableCheckBox; } } diff --git a/MirrorCaster/MainForm.cs b/MirrorCaster/MainForm.cs index 98965b7..7029aae 100644 --- a/MirrorCaster/MainForm.cs +++ b/MirrorCaster/MainForm.cs @@ -1,5 +1,6 @@ using Microsoft.VisualBasic; using System; +using System.Collections.Specialized; using System.Diagnostics; using System.IO.Pipes; using System.Runtime.InteropServices; @@ -45,12 +46,33 @@ int dwFlags [DllImport("user32.dll")] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); - private readonly Process stdoutProcess = new Process(); - private readonly Process stdinProcess = new Process(); - private StreamPipe RePipe; + private Process stdoutProcess = null; + private Process stdinProcess = null; + private StreamPipe rePipe; private CastType castType = CastType.Internal; private bool isCastingValue = false; private bool isEnableVSync = false; + private bool isEnableHWDec = true; + private UserMPVArg profileArgs; + + private OrderedDictionary profileList = new OrderedDictionary() { + { + "超低延迟模式", + new UserMPVArg("", false) + }, + { + "均衡(偏向低延迟)", + new UserMPVArg("--speed=10", true) + }, + { + "均衡(偏向稳定)", + new UserMPVArg( "--speed=1.01", true) + }, + { + "稳定模式", + new UserMPVArg("", true) + }, + }; private bool isCasting { @@ -68,6 +90,8 @@ private bool isCasting volUpKeyButton.Enabled = value; volDownKeyButton.Enabled = value; + profileComboBox.Enabled = !value; + hwdecEnableCheckBox.Enabled = !value; vsyncEnableCheckBox.Enabled = !value; } } @@ -88,6 +112,14 @@ private enum CastType public MainForm() { InitializeComponent(); + + profileComboBox.Items.Clear(); + foreach (string item in profileList.Keys) + { + profileComboBox.Items.Add(item); + } + profileComboBox.SelectedIndex = 0; + profileArgs = profileList[profileComboBox.Text] as UserMPVArg; #if DEBUG testButton.Visible = true; #endif @@ -142,10 +174,12 @@ private void StartCastAction() private void StartCast() { + stdoutProcess = new Process(); + stdinProcess = new Process(); StdOut(); StdIn(); - RePipe = new StreamPipe(stdoutProcess.StandardOutput.BaseStream, stdinProcess.StandardInput.BaseStream); - RePipe.Connect(); + rePipe = new StreamPipe(stdoutProcess.StandardOutput.BaseStream, stdinProcess.StandardInput.BaseStream); + rePipe.Connect(); instartDeviceInfoData.deviceVmode = deviceInfoData.deviceVmode; // 记录播放时的横竖屏状态(是否竖屏) isCasting = true; heartTimer.Enabled = true; @@ -158,9 +192,13 @@ private void StopCast() { try { - stdoutProcess.Exited -= StdIOProcess_Exited; - // stdoutProcess.OutputDataReceived -= new DataReceivedEventHandler(StdOutProcessOutDataReceived); - stdoutProcess.Kill(); + if (stdoutProcess != null) + { + stdoutProcess.Exited -= StdIOProcess_Exited; + // stdoutProcess.OutputDataReceived -= new DataReceivedEventHandler(StdOutProcessOutDataReceived); + stdoutProcess.Kill(); + stdoutProcess = null; + } } catch (Exception ex) { @@ -168,16 +206,20 @@ private void StopCast() } try { - stdinProcess.Exited -= StdIOProcess_Exited; - // stdinProcess.OutputDataReceived -= new DataReceivedEventHandler(StdInProcessOutDataReceived); - stdinProcess.Kill(); + if (stdinProcess != null) + { + stdinProcess.Exited -= StdIOProcess_Exited; + // stdinProcess.OutputDataReceived -= new DataReceivedEventHandler(StdInProcessOutDataReceived); + stdinProcess.Kill(); + stdoutProcess = null; + } } catch (Exception ex) { Console.WriteLine("无法关闭StdIN," + ex.Message); } - if (RePipe != null) { - RePipe.Disconnect(); + if (rePipe != null) { + rePipe.Disconnect(); } } catch (Exception ex) @@ -282,15 +324,17 @@ private void StdIn() widArg = default; break; } - string vsync_args = "--d3d11-sync-interval=" + (isEnableVSync ? "1" : "0"); - string release_args = "--input-default-bindings=no --osd-level=0"; + string vsyncArgs = "--d3d11-sync-interval=" + (isEnableVSync ? "1" : "0"); + string releaseArgs = "--input-default-bindings=no --osd-level=0"; + string fpsControlArgs = profileArgs.useDeviceFPS ? $"--no-correct-pts --fps={deviceInfoData.deviceRefreshRate}" : "--untimed"; + string hwdecArgs = isEnableHWDec ? "--hwdec=yes" : "--hwdec=no"; #if DEBUG - release_args = default; + releaseArgs = default; #endif - string mpv_full_args = $"--title=\"Mirror Caster Source\" --cache=no --no-cache --profile=low-latency --untimed --no-correct-pts --video-latency-hacks=yes --speed=1.2 { vsync_args } --framedrop=decoder --hwdec=auto --no-audio --no-config --no-border -no-osc --no-taskbar-progress { release_args } { widArg } -"; - Console.WriteLine("MPV ARGS:\r\n" + mpv_full_args); + string mpvFullArgs = $"--title=\"Mirror Caster Source\" --cache=no --no-cache --profile=low-latency --framedrop=decoder { vsyncArgs } --scale=spline36 --cscale=spline36 --dscale=mitchell --correct-downscaling=yes --linear-downscaling=yes --sigmoid-upscaling=yes { fpsControlArgs } --video-latency-hacks=yes { profileArgs.argsStr } --vo=gpu { hwdecArgs } --no-audio --no-config --no-border -no-osc --no-taskbar-progress { releaseArgs } { widArg } -"; + Console.WriteLine("MPV ARGS:\r\n" + mpvFullArgs); stdinProcess.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + @"lib\mpv\mpv.exe"; - stdinProcess.StartInfo.Arguments = mpv_full_args; + stdinProcess.StartInfo.Arguments = mpvFullArgs; //stdinProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; stdinProcess.StartInfo.UseShellExecute = false; stdinProcess.StartInfo.RedirectStandardOutput = true; @@ -453,7 +497,29 @@ private void testButton_Click(object sender, EventArgs e) private void vsyncEnableCheckBox_CheckedChanged(object sender, EventArgs e) { - isEnableVSync = vsyncEnableCheckBox.Checked; + isEnableVSync = (sender as CheckBox).Checked; + } + + private void hwdecEnableCheckBox_CheckedChanged(object sender, EventArgs e) + { + isEnableHWDec = (sender as CheckBox).Checked; + } + + private void profileComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + profileArgs = profileList[(sender as ComboBox).Text] as UserMPVArg; + } + } + + public class UserMPVArg + { + public string argsStr; + public bool useDeviceFPS; + + public UserMPVArg(string argsStr, bool useDeviceFPS) + { + this.argsStr = argsStr; + this.useDeviceFPS = useDeviceFPS; } } } diff --git a/MirrorCaster/Properties/AssemblyInfo.cs b/MirrorCaster/Properties/AssemblyInfo.cs index 53c3632..bf6f684 100644 --- a/MirrorCaster/Properties/AssemblyInfo.cs +++ b/MirrorCaster/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")]