Skip to content

Commit 5d83acf

Browse files
committed
Fix clear video race condition
1 parent c58a967 commit 5d83acf

File tree

12 files changed

+101
-24
lines changed

12 files changed

+101
-24
lines changed

Examples/TensorStack.Example.Extractors/Services/ExtractorService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class ExtractorService : ServiceBase, IExtractorService
1818
{
1919
private readonly Settings _settings;
2020
private readonly IMediaService _mediaService;
21+
private ExtractorModel _currentModel;
2122
private IPipeline _currentPipeline;
2223
private CancellationTokenSource _cancellationTokenSource;
2324
private bool _isLoaded;
@@ -35,6 +36,10 @@ public ExtractorService(Settings settings, IMediaService mediaService)
3536
_mediaService = mediaService;
3637
}
3738

39+
/// <summary>
40+
/// Gets the model.
41+
public ExtractorModel Model => _currentModel;
42+
3843
/// <summary>
3944
/// Gets a value indicating whether this instance is loaded.
4045
/// </summary>
@@ -89,6 +94,7 @@ public async Task LoadAsync(ExtractorModel model, Device device)
8994
await _currentPipeline.UnloadAsync(cancellationToken);
9095
}
9196

97+
_currentModel = model;
9298
_currentConfig = new ExtractorConfig
9399
{
94100
Path = model.Path,
@@ -115,6 +121,7 @@ public async Task LoadAsync(ExtractorModel model, Device device)
115121
_currentPipeline?.Dispose();
116122
_currentPipeline = null;
117123
_currentConfig = null;
124+
_currentModel = null;
118125
throw;
119126
}
120127
finally
@@ -373,6 +380,7 @@ public async Task UnloadAsync()
373380
_currentPipeline.Dispose();
374381
_currentPipeline = null;
375382
_currentConfig = null;
383+
_currentModel = null;
376384
}
377385

378386
IsLoaded = false;
@@ -384,6 +392,7 @@ public async Task UnloadAsync()
384392

385393
public interface IExtractorService
386394
{
395+
ExtractorModel Model { get; }
387396
bool IsLoaded { get; }
388397
bool IsLoading { get; }
389398
bool IsExecuting { get; }

Examples/TensorStack.Example.Extractors/Views/ImageExtractorView.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using TensorStack.Extractors.Common;
1010
using TensorStack.Image;
1111
using TensorStack.WPF;
12+
using TensorStack.WPF.Controls;
1213
using TensorStack.WPF.Services;
1314

1415
namespace TensorStack.Example.Views
@@ -173,6 +174,16 @@ public bool IsTransparent
173174
}
174175

175176

177+
public override Task OpenAsync(OpenViewArgs args = null)
178+
{
179+
if (ExtractorService.IsLoaded)
180+
{
181+
SelectedModel = ExtractorService.Model;
182+
}
183+
return base.OpenAsync(args);
184+
}
185+
186+
176187
private async Task LoadAsync()
177188
{
178189
var timestamp = Stopwatch.GetTimestamp();

Examples/TensorStack.Example.Extractors/Views/VideoExtractorView.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
<Border Margin="4">
167167
<Grid Margin="20" >
168168
<CommonControls:VideoStreamElement
169+
x:Name="ResultControl"
169170
SplitterVisibility="Auto"
170171
SplitterPosition="Source"
171172
SplitterDirection="LeftToRight"

Examples/TensorStack.Example.Extractors/Views/VideoExtractorView.xaml.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using TensorStack.Extractors.Common;
1111
using TensorStack.Video;
1212
using TensorStack.WPF;
13+
using TensorStack.WPF.Controls;
1314
using TensorStack.WPF.Services;
1415

1516
namespace TensorStack.Example.Views
@@ -176,6 +177,16 @@ public bool IsTransparent
176177
}
177178

178179

180+
public override Task OpenAsync(OpenViewArgs args = null)
181+
{
182+
if (ExtractorService.IsLoaded)
183+
{
184+
SelectedModel = ExtractorService.Model;
185+
}
186+
return base.OpenAsync(args);
187+
}
188+
189+
179190
private async Task LoadAsync()
180191
{
181192
var timestamp = Stopwatch.GetTimestamp();
@@ -215,10 +226,8 @@ private bool CanUnload()
215226

216227
private async Task ExecuteAsync()
217228
{
229+
await ResultControl.ClearAsync();
218230
var timestamp = Stopwatch.GetTimestamp();
219-
Progress.Clear();
220-
ResultVideo = default;
221-
CompareVideo = default;
222231

223232
// Run Extractor
224233
var resultVideo = _selectedModel.Type switch

Examples/TensorStack.Example.Upscaler/Services/UpscaleService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class UpscaleService : ServiceBase, IUpscaleService
1717
{
1818
private readonly Settings _settings;
1919
private readonly IMediaService _mediaService;
20+
private UpscaleModel _currentModel;
2021
private UpscalePipeline _currentPipeline;
2122
private CancellationTokenSource _cancellationTokenSource;
2223
private bool _isLoaded;
@@ -34,6 +35,11 @@ public UpscaleService(Settings settings, IMediaService mediaService)
3435
_mediaService = mediaService;
3536
}
3637

38+
/// <summary>
39+
/// Gets the model.
40+
/// </summary>
41+
public UpscaleModel Model => _currentModel;
42+
3743
/// <summary>
3844
/// Gets a value indicating whether this instance is loaded.
3945
/// </summary>
@@ -88,6 +94,7 @@ public async Task LoadAsync(UpscaleModel model, Device device)
8894
await _currentPipeline.UnloadAsync(cancellationToken);
8995
}
9096

97+
_currentModel = model;
9198
_currentConfig = new UpscalerConfig
9299
{
93100
Channels = model.Channels,
@@ -107,6 +114,7 @@ public async Task LoadAsync(UpscaleModel model, Device device)
107114
_currentPipeline?.Dispose();
108115
_currentPipeline = null;
109116
_currentConfig = null;
117+
_currentModel = null;
110118
throw;
111119
}
112120
finally
@@ -209,6 +217,7 @@ public async Task UnloadAsync()
209217
_currentPipeline.Dispose();
210218
_currentPipeline = null;
211219
_currentConfig = null;
220+
_currentModel = null;
212221
}
213222

214223
IsLoaded = false;
@@ -220,6 +229,7 @@ public async Task UnloadAsync()
220229

221230
public interface IUpscaleService
222231
{
232+
UpscaleModel Model { get; }
223233
bool IsLoaded { get; }
224234
bool IsLoading { get; }
225235
bool IsExecuting { get; }

Examples/TensorStack.Example.Upscaler/Views/ImageUpscaleView.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ public int TileOverlap
9797
}
9898

9999

100+
public override Task OpenAsync(OpenViewArgs args = null)
101+
{
102+
if (UpscaleService.IsLoaded)
103+
{
104+
SelectedModel = UpscaleService.Model;
105+
}
106+
return base.OpenAsync(args);
107+
}
108+
109+
100110
private async Task LoadAsync()
101111
{
102112
var timestamp = Stopwatch.GetTimestamp();

Examples/TensorStack.Example.Upscaler/Views/InterpolationView.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<Border Margin="4">
110110
<Grid Margin="20" >
111111
<CommonControls:VideoStreamElement
112+
x:Name="ResultControl"
112113
SplitterVisibility="Auto"
113114
SplitterPosition="Source"
114115
SplitterDirection="LeftToRight"

Examples/TensorStack.Example.Upscaler/Views/InterpolationView.xaml.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ private bool CanUnload()
112112

113113
private async Task ExecuteAsync()
114114
{
115+
await ResultControl.ClearAsync();
115116
var timestamp = Stopwatch.GetTimestamp();
116-
Progress.Clear();
117-
ResultVideo = default;
118-
CompareVideo = default;
119117

120118
// Run Interpolation
121119
var resultVideo = await InterpolationService.ExecuteAsync(new InterpolationRequest

Examples/TensorStack.Example.Upscaler/Views/VideoUpscaleView.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<Border Margin="4">
118118
<Grid Margin="20" >
119119
<CommonControls:VideoStreamElement
120+
x:Name="ResultControl"
120121
SplitterVisibility="Auto"
121122
SplitterPosition="Source"
122123
SplitterDirection="LeftToRight"

Examples/TensorStack.Example.Upscaler/Views/VideoUpscaleView.xaml.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ public int TileOverlap
103103
}
104104

105105

106+
public override Task OpenAsync(OpenViewArgs args = null)
107+
{
108+
if (UpscaleService.IsLoaded)
109+
{
110+
SelectedModel = UpscaleService.Model;
111+
}
112+
return base.OpenAsync(args);
113+
}
114+
115+
106116
private async Task LoadAsync()
107117
{
108118
var timestamp = Stopwatch.GetTimestamp();
@@ -142,10 +152,8 @@ private bool CanUnload()
142152

143153
private async Task ExecuteAsync()
144154
{
155+
await ResultControl.ClearAsync();
145156
var timestamp = Stopwatch.GetTimestamp();
146-
Progress.Clear();
147-
ResultVideo = default;
148-
CompareVideo = default;
149157

150158
// Run Upscaler
151159
var upscaledVideo = await UpscaleService.ExecuteAsync(new UpscaleVideoRequest

0 commit comments

Comments
 (0)