Added compute device selection

Added a call to butterflow to get compute devices, as well as a user setting that lets them set which device they want to use. I only have a single GPU, so I am unable to test this.
This commit is contained in:
Jordan Wages 2018-09-12 21:35:06 -05:00
parent 77d409b4c7
commit d454d7a7f0
11 changed files with 127 additions and 14 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="butterflow-ui" Language="1033" Version="1.0.3" Manufacturer="butterflow-ui @ github" UpgradeCode="bba9d512-377a-467e-920a-cbcf36ffc072">
<Product Id="*" Name="butterflow-ui" Language="1033" Version="1.0.4" Manufacturer="butterflow-ui @ github" UpgradeCode="bba9d512-377a-467e-920a-cbcf36ffc072">
<Package Id="*" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

View File

@ -13,6 +13,9 @@
<setting name="Language" serializeAs="String">
<value>en-US</value>
</setting>
<setting name="Device" serializeAs="String">
<value>0</value>
</setting>
</butterflow_ui.Properties.Settings>
</userSettings>
</configuration>

View File

@ -24,6 +24,8 @@ namespace butterflow_ui
private const string REGEX_PROGRESS = @"To write\:\s*\w*\s*\w*\,*\w*\s*(?<Progress>\d+\.*\d*)%";
/// <summary> An alternative RegEx string for detecting progress made when rendering a video. </summary>
private const string REGEX_PROGRESS_ALT = @"\<Rendering progress\:\s*(?<Progress>\d+\.*\d*)%\>";
/// <summary> The RegEx string for determining available processing devices in butterflow.. </summary>
private const string REGEX_DEVICE = @"\*\s*Device\s*(?<DeviceID>\d+)\s*\:\s*(?<DeviceName>(\w*\s*)*)";
/// <summary> Full pathname of the butterflow executable file. </summary>
private Lazy<string> executablePath = new Lazy<string>(() => Path.Combine(Directory.GetCurrentDirectory(), "ThirdPartyCompiled", "butterflow.exe"));
@ -41,6 +43,8 @@ namespace butterflow_ui
private InputInterpreter interpreter = new InputInterpreter();
/// <summary> Event queue for all listeners interested in ParsedConsoleOutputRecieved events. </summary>
public event EventHandler<ButterflowOutputArgs> ParsedConsoleOutputRecieved;
/// <summary> Event queue for all listeners interested in ButterflowExited events. </summary>
public event EventHandler<ButterflowExitArgs> ButterflowExited;
#endregion
@ -91,6 +95,10 @@ namespace butterflow_ui
}
}
/// <summary> Gets or sets the list of devices available for butterflow processing. </summary>
/// <value> The devices available for butterflow processing. </value>
public Dictionary<int, string> Devices { get; private set; } = new Dictionary<int, string>();
#endregion
#region Methods
@ -99,7 +107,7 @@ namespace butterflow_ui
/// <param name="optionsConfiguration"> The options configuration. </param>
public void Run(OptionsConfiguration optionsConfiguration)
{
for(int i = 0; i < optionsConfiguration.VideoInput.Count(); i++)
for (int i = 0; i < optionsConfiguration.VideoInput.Count(); i++)
{
var arguments = optionsConfiguration.ToButterflowArguments(i);
this.runQueue.Enqueue(arguments);
@ -139,7 +147,7 @@ namespace butterflow_ui
/// <summary> Kills the running instance of butterflow, cancelling its current operation. </summary>
public void Cancel()
{
if(this.IsRunning && this.runningProcess != null)
if (this.IsRunning && this.runningProcess != null)
{
this.runningProcess.Kill();
}
@ -155,6 +163,13 @@ namespace butterflow_ui
Run(arguments);
}
/// <summary> Gets the devices available for butterflow processing. </summary>
public void GetDevices()
{
string arguments = "--show-devices";
Run(arguments);
}
/// <summary> Runs butterflow with the given <paramref name="arguments"/> by adding it to the queue. </summary>
/// <param name="arguments"> Options for controlling the operation. </param>
private void Run(string arguments)
@ -172,6 +187,8 @@ namespace butterflow_ui
this.IsRunning = false;
this.runningProcess = null;
OnButterflowExited();
ProcessQueue();
}
@ -201,7 +218,7 @@ namespace butterflow_ui
// Test for playback rate
regex = new Regex(REGEX_RATE);
foreach(Match match in regex.Matches(consoleOutput))
foreach (Match match in regex.Matches(consoleOutput))
{
var rate = match.Groups["Rate"].Value;
@ -210,7 +227,7 @@ namespace butterflow_ui
// Test for progress being made when rendering a video
regex = new Regex(REGEX_PROGRESS);
foreach(Match match in regex.Matches(consoleOutput))
foreach (Match match in regex.Matches(consoleOutput))
{
var progress = match.Groups["Progress"].Value;
@ -230,6 +247,23 @@ namespace butterflow_ui
OnParsedConsoleOutputRecieved(ButterflowOutputType.Progress, progress, consoleOutput);
}
regex = new Regex(REGEX_DEVICE);
foreach (Match match in regex.Matches(consoleOutput))
{
var deviceID = match.Groups["DeviceID"].Value;
var deviceName = match.Groups["DeviceName"].Value.Trim();
this.interpreter.Interpret(deviceID);
if (!this.Devices.ContainsKey(this.interpreter.Int))
{
this.Devices.Add(this.interpreter.Int, deviceName);
OnPropertyChanged("Devices");
}
OnParsedConsoleOutputRecieved(ButterflowOutputType.Device, deviceName, consoleOutput);
}
}
/// <summary> Executes the parsed console output recieved action. </summary>
@ -238,10 +272,13 @@ namespace butterflow_ui
/// <param name="consoleOutput"> The console output from butterflow. </param>
private void OnParsedConsoleOutputRecieved(ButterflowOutputType outputType, string value, string consoleOutput)
{
if (this.ParsedConsoleOutputRecieved != null)
{
this.ParsedConsoleOutputRecieved(this, new ButterflowOutputArgs(outputType, value, consoleOutput));
}
this.ParsedConsoleOutputRecieved?.Invoke(this, new ButterflowOutputArgs(outputType, value, consoleOutput));
}
/// <summary> Executes the butterflow exited action. </summary>
private void OnButterflowExited()
{
this.ButterflowExited?.Invoke(this, new ButterflowExitArgs());
}
/// <summary> Event handler. Called by Process for output data received events. </summary>
@ -308,6 +345,19 @@ namespace butterflow_ui
#endregion
}
/// <summary> Arguments for butterflow exiting. </summary>
public class ButterflowExitArgs : EventArgs
{
#region Constructors
public ButterflowExitArgs()
{
//
}
#endregion
}
/// <summary> Values that represent butterflow output types. </summary>
public enum ButterflowOutputType
{
@ -318,7 +368,9 @@ namespace butterflow_ui
/// <summary> Video playback rate. </summary>
Rate,
/// <summary> Video processing progress. </summary>
Progress
Progress,
/// <summary> An available processing device. </summary>
Device
}
#endregion

View File

@ -303,6 +303,15 @@ namespace butterflow_ui.Localization {
}
}
/// <summary>
/// Looks up a localized string similar to Computing Device.
/// </summary>
public static string DeviceLabel {
get {
return ResourceManager.GetString("DeviceLabel", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to _Edit.
/// </summary>

View File

@ -390,4 +390,7 @@
<data name="UpdateAvailableLabel" xml:space="preserve">
<value>A newer version of butterflow-ui is available.</value>
</data>
<data name="DeviceLabel" xml:space="preserve">
<value>Computing Device</value>
</data>
</root>

View File

@ -6,6 +6,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using butterflow_ui.Properties;
using csmic;
namespace butterflow_ui
@ -531,6 +532,11 @@ namespace butterflow_ui
stringBuilder.AppendFormat("-vs {0}:{1} ", this.Width, this.Height);
}
if(Settings.Default.Device != 0)
{
stringBuilder.AppendFormat("-device {0} ", Settings.Default.Device);
}
if (!string.IsNullOrWhiteSpace(this.PlaybackRate)) stringBuilder.AppendFormat("-r {0} ", this.PlaybackRate);
if (this.KeepAudio) stringBuilder.Append("-audio ");
if (this.LosslessQuality) stringBuilder.Append("-l ");

View File

@ -14,7 +14,11 @@
<Label Content="{x:Static loc:Localization.LanguageLabel}" />
<ComboBox DisplayMemberPath="DisplayName" ItemsSource="{Binding SupportedLanguages, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:OptionsWindow}}, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding Source={x:Static settings:Settings.Default}, Path=Language}" />
</WrapPanel>
<TextBlock Text="{x:Static loc:Localization.OptionsWindowLanguageChangeNotice}" />
<TextBlock Text="{x:Static loc:Localization.OptionsWindowLanguageChangeNotice}" Foreground="Gray" />
<WrapPanel>
<Label Content="{x:Static loc:Localization.DeviceLabel}" />
<ComboBox Name="comboDeviceList" DisplayMemberPath="Value" ItemsSource="{Binding ButterflowWrapper.Devices, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:OptionsWindow}}, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="{Binding Source={x:Static settings:Settings.Default}, Path=Device}" />
</WrapPanel>
<Separator Margin="0,10" />
<Button Name="btnSave" MaxWidth="45" Content="{x:Static loc:Localization.SaveLabel}" Click="btnSave_Click" />
</StackPanel>

View File

@ -1,4 +1,5 @@
using System;
using butterflow_ui.Properties;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@ -21,6 +22,9 @@ namespace butterflow_ui
{
#region Properties
/// <summary> The butterflow wrapper used to call butterflow. </summary>
public ButterflowWrapper ButterflowWrapper { get; set; } = new ButterflowWrapper();
/// <summary> Gets or sets the supported languages. </summary>
/// <value> The supported languages. </value>
public List<CultureInfo> SupportedLanguages { get; set; } = new List<CultureInfo>(new[]
@ -40,6 +44,8 @@ namespace butterflow_ui
/// <summary> Default constructor. </summary>
public OptionsWindow()
{
this.ButterflowWrapper.GetDevices();
this.ButterflowWrapper.ButterflowExited += ButterflowWrapper_ButterflowExited;
InitializeComponent();
}
@ -57,6 +63,21 @@ namespace butterflow_ui
this.Close();
}
/// <summary> Butterflow wrapper butterflow exited. </summary>
/// <param name="sender"> Source of the event. </param>
/// <param name="e"> The ButterflowExitArgs to process. </param>
private void ButterflowWrapper_ButterflowExited(object sender, ButterflowWrapper.ButterflowExitArgs e)
{
if (Settings.Default.Device >= 0)
{
this.comboDeviceList.Dispatcher.Invoke(() => this.comboDeviceList.SelectedIndex = Settings.Default.Device);
}
else
{
this.comboDeviceList.Dispatcher.Invoke(() => this.comboDeviceList.SelectedIndex = 0);
}
}
#endregion
}
}

View File

@ -51,5 +51,5 @@ using System.Windows;
// 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.*")]
[assembly: AssemblyVersion("1.0.4.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -12,7 +12,7 @@ namespace butterflow_ui.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.7.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.8.0.0")]
public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@ -34,5 +34,17 @@ namespace butterflow_ui.Properties {
this["Language"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public int Device {
get {
return ((int)(this["Device"]));
}
set {
this["Device"] = value;
}
}
}
}

View File

@ -5,5 +5,8 @@
<Setting Name="Language" Type="System.Globalization.CultureInfo" Scope="User">
<Value Profile="(Default)">en-US</Value>
</Setting>
<Setting Name="Device" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>