Skip to content

Commit 5faf4a8

Browse files
committed
Added extra check for the Watcher to make sure the file has finished transferring before it is sent for encoding.
The "stability check" interval can be configured in Global Options -> Advanced.
1 parent 6fb14ca commit 5faf4a8

18 files changed

Lines changed: 428 additions & 127 deletions

VidCoder/Extensions/WatchedFileStatusExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public static WatchedFileStatusLive ToLive(this WatchedFileStatus status)
1414
{
1515
switch (status)
1616
{
17+
case WatchedFileStatus.Found:
18+
return WatchedFileStatusLive.Found;
1719
case WatchedFileStatus.Planned:
1820
return WatchedFileStatusLive.Planned;
1921
case WatchedFileStatus.Canceled:

VidCoder/Model/Config/Config.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private static void Initialize(SQLiteConnection connection)
9191
cache.Add("EnableDirectXDecoding", DatabaseConfig.Get("EnableDirectXDecoding", true, connection));
9292
cache.Add("WatcherMode", DatabaseConfig.Get("WatcherMode", "FileSystemWatcher", connection));
9393
cache.Add("WatcherPollIntervalSeconds", DatabaseConfig.Get("WatcherPollIntervalSeconds", 5, connection));
94+
cache.Add("WatcherStabilityCheckIntervalSeconds", DatabaseConfig.Get("WatcherStabilityCheckIntervalSeconds", 1.0, connection));
9495
cache.Add("WorkerProcessPriority", DatabaseConfig.Get("WorkerProcessPriority", "BelowNormal", connection));
9596
cache.Add("LogVerbosity", DatabaseConfig.Get("LogVerbosity", 1, connection));
9697
cache.Add("CopyLogToOutputFolder", DatabaseConfig.Get("CopyLogToOutputFolder", false, connection));
@@ -482,6 +483,11 @@ public static int WatcherPollIntervalSeconds
482483
get { return (int)cache["WatcherPollIntervalSeconds"]; }
483484
set { Set("WatcherPollIntervalSeconds", value); }
484485
}
486+
public static double WatcherStabilityCheckIntervalSeconds
487+
{
488+
get { return (double)cache["WatcherStabilityCheckIntervalSeconds"]; }
489+
set { Set("WatcherStabilityCheckIntervalSeconds", value); }
490+
}
485491
public static string WorkerProcessPriority
486492
{
487493
get { return (string)cache["WorkerProcessPriority"]; }
@@ -810,6 +816,7 @@ public static class Observables
810816
public static IObservable<bool> EnableDirectXDecoding => GetObservable<bool>("EnableDirectXDecoding");
811817
public static IObservable<string> WatcherMode => GetObservable<string>("WatcherMode");
812818
public static IObservable<int> WatcherPollIntervalSeconds => GetObservable<int>("WatcherPollIntervalSeconds");
819+
public static IObservable<double> WatcherStabilityCheckIntervalSeconds => GetObservable<double>("WatcherStabilityCheckIntervalSeconds");
813820
public static IObservable<string> WorkerProcessPriority => GetObservable<string>("WorkerProcessPriority");
814821
public static IObservable<int> LogVerbosity => GetObservable<int>("LogVerbosity");
815822
public static IObservable<bool> CopyLogToOutputFolder => GetObservable<bool>("CopyLogToOutputFolder");

VidCoder/Model/Config/Config.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ EnableDirectXDecoding|bool|true
7474

7575
WatcherMode|string|"FileSystemWatcher"
7676
WatcherPollIntervalSeconds|int|5
77+
WatcherStabilityCheckIntervalSeconds|double|1.0
7778
WorkerProcessPriority|string|"BelowNormal"
7879
LogVerbosity|int|1
7980
CopyLogToOutputFolder|bool|false

VidCoder/Model/WatchedFileStatusLive.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ namespace VidCoder.Model;
1111
/// </summary>
1212
public enum WatchedFileStatusLive
1313
{
14+
/// <summary>
15+
/// VidCoder has found the file, but is waiting for it to be fully written before trying to encode it.
16+
/// </summary>
17+
Found,
18+
1419
/// <summary>
1520
/// VidCoder has planned to encode this file but it has not yet been added to the queue. It should only be in this state as long as it takes to scan the item.
1621
/// </summary>

VidCoder/Resources/EnumsRes.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VidCoder/Resources/EnumsRes.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,7 @@
408408
<data name="WhenFileExists_Skip" xml:space="preserve">
409409
<value>Skip</value>
410410
</data>
411+
<data name="WatchedFileStatusLive_Found" xml:space="preserve">
412+
<value>Found</value>
413+
</data>
411414
</root>

VidCoder/Resources/OptionsRes.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VidCoder/Resources/OptionsRes.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,7 @@ Polling: Periodically checks the contents of the folders. Uses significant CPU a
478478
<data name="EnableQuickSyncHyperEncodeToolTip" xml:space="preserve">
479479
<value>Use multiple media engines to speed up a single encode where supported. Disable to allow load balancing multiple parallel encodes across media engines.</value>
480480
</data>
481+
<data name="WatcherStabilityIntervalLabel" xml:space="preserve">
482+
<value>File stability wait interval (seconds):</value>
483+
</data>
481484
</root>

VidCoder/Services/WatchedFileStatusTracker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void Start()
3737
SQLiteConnection connection = Database.Connection;
3838

3939
// Queue up anything that hasn't been encoded yet
40-
Dictionary<string, WatchedFile> plannedFiles = WatcherStorage.GetPlannedFiles(connection);
40+
Dictionary<string, WatchedFile> plannedFiles = WatcherStorage.GetFilesWithStatus(connection, WatchedFileStatus.Planned);
4141
this.logger.LogDebug($"Starting WatchedFileStatusTracker. Found {plannedFiles.Count} planned files.");
4242

4343
foreach (var job in this.processingService.EncodeQueue.Items)

VidCoder/View/OptionsDialog.xaml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,29 @@
632632
ItemsSource="{Binding WatcherModeChoices}"
633633
SelectedValue="{Binding WatcherMode}"
634634
SelectedValuePath="Value" />
635+
</StackPanel>
636+
637+
<StackPanel Margin="12 6 0 0" Orientation="Vertical">
638+
639+
640+
<StackPanel Margin="0 0 0 0" Orientation="Horizontal">
641+
<TextBlock
642+
Name="watcherStabilityIntervalLabel"
643+
VerticalAlignment="Center"
644+
Text="{x:Static res:OptionsRes.WatcherStabilityIntervalLabel}" />
645+
646+
<controls:NumberBox
647+
Width="45"
648+
Height="20"
649+
Margin="6 0 0 0"
650+
AllowEmpty="False"
651+
Maximum="3600"
652+
Minimum="0.5"
653+
Number="{Binding WatcherStabilityIntervalSeconds, Mode=TwoWay}" />
654+
</StackPanel>
635655

636656
<StackPanel
637-
Margin="10 0 0 0"
657+
Margin="0 6 0 0"
638658
Orientation="Horizontal"
639659
Visibility="{Binding WatcherMode, Converter={StaticResource EnumVisibilityConverter}, ConverterParameter={x:Static commonModel:WatcherMode.Polling}}">
640660
<TextBlock
@@ -650,9 +670,9 @@
650670
Minimum="1"
651671
Number="{Binding WatcherPollIntervalSeconds, Mode=TwoWay}" />
652672
</StackPanel>
653-
654673
</StackPanel>
655674

675+
656676
<!-- Part file naming -->
657677
<StackPanel Margin="0 6 0 0" Orientation="Horizontal">
658678
<TextBlock

0 commit comments

Comments
 (0)