-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayerDX11TextureNode.cs
185 lines (150 loc) · 5.84 KB
/
PlayerDX11TextureNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#region usings
using System;
using System.ComponentModel.Composition;
using VVVV.PluginInterfaces.V1;
using VVVV.PluginInterfaces.V2;
using VVVV.Core.Logging;
using FeralTic.DX11;
using FeralTic.DX11.Resources;
using VVVV.DX11.ImagePlayer;
#endregion usings
namespace VVVV.DX11
{
#region PluginInfo
[PluginInfo(Name = "Player",
Category = "DX11.Texture",
Version = "2d",
Help = "Optimized playback of image stacks",
Tags = "",
Credits = "sponsored by http://meso.net",
Author = "woei")]
#endregion PluginInfo
public class PlayerDX11Node : IPluginEvaluate, IPartImportsSatisfiedNotification, IDX11ResourceHost, IDisposable
{
#region fields & pins
[Input("Directory", StringType = StringType.Directory)]
public ISpread<string> FDirectory;
[Input("Filemask", DefaultString = "*.*")]
public ISpread<string> FFileMask;
[Input("Reload", IsBang = true)]
public ISpread<bool> FReload;
[Input("Decoder", Visibility = PinVisibility.OnlyInspector)]
public ISpread<DecoderChoice> FDecoderChoice;
[Input("Wait for Frame", DefaultBoolean = true, Visibility = PinVisibility.OnlyInspector)]
public ISpread<bool> FWaitFrame;
[Input("Preload Frames")]
public ISpread<ISpread<int>> FPreloadFrames;
[Input("Visible Frame Indices", BinSize = 1)]
public ISpread<ISpread<int>> FVisibleFrameId;
[Output("Texture Out")]
public ISpread<DX11Resource<DX11ResourceTexture2D>> FTextureOutput;
[Output("Width")]
public ISpread<int> FWidth;
[Output("Height")]
public ISpread<int> FHeight;
[Output("Frame Loaded")]
public ISpread<bool> FLoaded;
[Output("Duration Load")]
public ISpread<double> FLoadTime;
[Output("Duration Swap")]
public ISpread<double> FSwapTime;
[Output("Frame Count")]
public ISpread<int> FFrameCount;
[Output("Loaded")]
public ISpread<ISpread<bool>> FPreloaded;
[Import()]
public ILogger FLogger;
private Spread<Player> FPlayers = new Spread<Player>(0);
private readonly MemoryPool FMemoryPool = new MemoryPool();
private int FSpreadMax;
#endregion fields & pins
public void OnImportsSatisfied()
{
FTextureOutput.SliceCount = 0;
FPreloaded.SliceCount = 0;
}
public void Dispose()
{
foreach (var p in FPlayers)
p.Dispose();
FMemoryPool.Dispose();
}
//called when data for any output pin is requested
public void Evaluate(int _)
{
FSpreadMax = FDirectory.SliceCount
.CombineWith(FFileMask)
.CombineWith(FReload)
.CombineWith(FDecoderChoice)
.CombineWith(FWaitFrame)
.CombineSpreads(FPreloadFrames.SliceCount)
.CombineSpreads(FVisibleFrameId.SliceCount);
FPlayers.ResizeAndDispose(FSpreadMax, (int slice) => new Player(FDirectory[slice], FFileMask[slice], FMemoryPool, FLogger));
FFrameCount.SliceCount = FSpreadMax;
FPreloaded.SliceCount = FSpreadMax;
int texSliceCount = FSpreadMax.CombineSpreads(SpreadUtils.SpreadMax(FVisibleFrameId as System.Collections.Generic.IEnumerable<ISpread<int>>));
FTextureOutput.Resize(texSliceCount, () => new DX11Resource<DX11ResourceTexture2D>(), (t) => t.Dispose());
FWidth.SliceCount = texSliceCount;
FHeight.SliceCount = texSliceCount;
FLoaded.SliceCount = texSliceCount;
FLoadTime.SliceCount = texSliceCount;
FSwapTime.SliceCount = texSliceCount;
for (int i=0; i< FSpreadMax; i++)
{
if (FPlayers[i].DirectoryName != FDirectory[i] || FPlayers[i].FileMask != FFileMask[i] || FReload[i])
{
FPlayers[i].Dispose();
FPlayers[i] = new Player(FDirectory[i], FFileMask[i], FMemoryPool, FLogger);
}
if (FPlayers[i].FrameCount > 0)
{
FPlayers[i].Preload(FPreloadFrames[i], FDecoderChoice[i]);
}
FFrameCount[i] = FPlayers[i].FrameCount;
FPreloaded[i].AssignFrom(FPlayers[i].Loaded);
}
}
public void Update(DX11RenderContext context)
{
int i = 0;
for (int b = 0; b < FSpreadMax; b++)
{
for (int s = 0; s < FVisibleFrameId[b].SliceCount; s++)
{
if (FPlayers[b].FrameCount > 0)
{
try
{
var frame = FPlayers[b][FVisibleFrameId[b][s]];
frame.WaitForFrame = FWaitFrame[b];
FTextureOutput[i][context] = frame.SetSRV(FTextureOutput[i][context], context);
FWidth[i] = frame.Description.Width;
FHeight[i] = frame.Description.Height;
FLoaded[i] = frame.Loaded;
FLoadTime[i] = frame.LoadTime;
FSwapTime[i] = frame.SwapTime;
}
catch (Exception e)
{
FLogger.Log(e);
}
}
else
{
FWidth[i] = 0;
FHeight[i] = 0;
FLoaded[i] = false;
FLoadTime[i] = 0;
FSwapTime[i] = 0;
}
i++;
}
}
}
public void Destroy(DX11RenderContext context, bool force)
{
foreach (var t in FTextureOutput)
t.Dispose(context);
}
}
}