Skip to content

Commit

Permalink
多种参数预设可选
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSAN committed Jan 1, 2021
1 parent dc7ae46 commit d6a982d
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 46 deletions.
79 changes: 55 additions & 24 deletions MirrorCaster/MainForm.Designer.cs

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

106 changes: 86 additions & 20 deletions MirrorCaster/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.VisualBasic;
using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO.Pipes;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -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
{
Expand All @@ -68,6 +90,8 @@ private bool isCasting
volUpKeyButton.Enabled = value;
volDownKeyButton.Enabled = value;

profileComboBox.Enabled = !value;
hwdecEnableCheckBox.Enabled = !value;
vsyncEnableCheckBox.Enabled = !value;
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -158,26 +192,34 @@ 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)
{
Console.WriteLine("无法关闭StdOUT," + ex.Message);
}
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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
4 changes: 2 additions & 2 deletions MirrorCaster/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit d6a982d

Please sign in to comment.