@@ -12,11 +12,7 @@ using namespace concurrency;
1212namespace winrt ::StyleTransferEffectCpp::implementation
1313{
1414 StyleTransferEffect::StyleTransferEffect () :
15- cachedOutput (nullptr ),
16- cachedOutputCopy (VideoFrame(Windows::Graphics::Imaging::BitmapPixelFormat::Bgra8, 640 , 360 )),
17- outputTransformed (VideoFrame(Windows::Graphics::Imaging::BitmapPixelFormat::Bgra8, 720 , 720 )),
18- Session (nullptr ),
19- Binding (nullptr )
15+ Session (nullptr )
2016 {
2117 for (int i = 0 ; i < swapChainEntryCount; i++)
2218 {
@@ -25,38 +21,37 @@ namespace winrt::StyleTransferEffectCpp::implementation
2521 }
2622
2723 IVectorView<VideoEncodingProperties> StyleTransferEffect::SupportedEncodingProperties () {
28- VideoEncodingProperties encodingProperties = VideoEncodingProperties ();
29- encodingProperties .Subtype (L" ARGB32" );
30- return single_threaded_vector (std::vector<VideoEncodingProperties>{encodingProperties }).GetView ();
24+ VideoEncodingProperties props = VideoEncodingProperties ();
25+ props .Subtype (L" ARGB32" );
26+ return single_threaded_vector (std::vector<VideoEncodingProperties>{props }).GetView ();
3127 }
3228
3329 bool StyleTransferEffect::TimeIndependent () { return true ; }
3430 MediaMemoryTypes StyleTransferEffect::SupportedMemoryTypes () { return MediaMemoryTypes::GpuAndCpu; }
3531 bool StyleTransferEffect::IsReadOnly () { return false ; }
3632 void StyleTransferEffect::DiscardQueuedFrames () {}
3733
38- void StyleTransferEffect::Close (MediaEffectClosedReason m ) {
34+ void StyleTransferEffect::Close (MediaEffectClosedReason) {
3935 OutputDebugString (L" Close Begin | " );
4036 std::lock_guard<mutex> guard{ Processing };
41- OutputDebugString (L" Close\n " );
42- if (Binding != nullptr ) Binding.Clear ();
43- if (Session != nullptr ) Session.Close ();
4437 // Make sure evalAsyncs are done before clearing resources
4538 for (int i = 0 ; i < swapChainEntryCount; i++) {
4639 if (bindings[i]->activetask != nullptr &&
4740 bindings[i]->binding != nullptr )
4841 {
42+ std::wostringstream ss;
43+ ss << i;
44+ OutputDebugString (ss.str ().c_str ());
4945 bindings[i]->activetask .get ();
5046 bindings[i]->binding .Clear ();
5147 }
5248 }
49+ if (Session != nullptr ) Session.Close ();
50+ OutputDebugString (L" Close\n " );
5351 }
5452
5553 void StyleTransferEffect::SubmitEval (VideoFrame input, VideoFrame output) {
5654 auto currentBinding = bindings[0 ].get ();
57- // VideoFrame outputTransformed = cachedOutput;
58- // Different way of waiting for a swapchain index to finish?
59- // Or would it be just setting the output to be a cached frame?
6055 if (currentBinding->activetask == nullptr
6156 || currentBinding->activetask .Status () != Windows::Foundation::AsyncStatus::Started)
6257 {
@@ -67,16 +62,15 @@ namespace winrt::StyleTransferEffectCpp::implementation
6762 OutputDebugString (ss.str ().c_str ());
6863 OutputDebugString (L" | " );
6964
70- // bind the input and the output buffers by name
7165 currentBinding->binding .Bind (InputImageDescription, input);
7266 // submit an eval and wait for it to finish submitting work
7367 {
7468 std::lock_guard<mutex> guard{ Processing };
7569 std::rotate (bindings.begin (), bindings.begin () + 1 , bindings.end ());
7670 finishedIdx = (finishedIdx - 1 + swapChainEntryCount) % swapChainEntryCount;
71+ currentBinding->activetask = Session.EvaluateAsync (currentBinding->binding , ss.str ().c_str ());
7772 }
78- currentBinding->activetask = Session.EvaluateAsync (currentBinding->binding , ss.str ().c_str ());
79- currentBinding->activetask .Completed ([&, currentBinding, now](auto && asyncInfo, winrt::Windows::Foundation::AsyncStatus const args) {
73+ currentBinding->activetask .Completed ([&, currentBinding, now](auto && asyncInfo, winrt::Windows::Foundation::AsyncStatus const ) {
8074 OutputDebugString (L" PF Eval completed |" );
8175 VideoFrame evalOutput = asyncInfo.GetResults ().Outputs ().Lookup (OutputImageDescription).try_as <VideoFrame>();
8276 int bindingIdx;
@@ -103,7 +97,6 @@ namespace winrt::StyleTransferEffectCpp::implementation
10397 if (bindings[finishedIdx]->outputCache != nullptr ) {
10498 std::wostringstream ss;
10599 ss << finishedIdx;
106- // std::lock_guard<mutex> guard{ Copy };
107100 OutputDebugString (L" \n Start CopyAsync " );
108101 OutputDebugString (ss.str ().c_str ());
109102 bindings[finishedIdx]->outputCache .CopyToAsync (output).get ();
@@ -114,7 +107,6 @@ namespace winrt::StyleTransferEffectCpp::implementation
114107
115108 void StyleTransferEffect::ProcessFrame (ProcessVideoFrameContext context) {
116109 OutputDebugString (L" PF Start | " );
117- auto now = std::chrono::high_resolution_clock::now ();
118110 VideoFrame inputFrame = context.InputFrame ();
119111 VideoFrame outputFrame = context.OutputFrame ();
120112
@@ -145,7 +137,6 @@ namespace winrt::StyleTransferEffectCpp::implementation
145137 LearningModel m_model = LearningModel::LoadFromFilePath (modelName);
146138 LearningModelDeviceKind m_device = useGpu ? LearningModelDeviceKind::DirectX : LearningModelDeviceKind::Cpu;
147139 Session = LearningModelSession{ m_model, LearningModelDevice (m_device) };
148- Binding = LearningModelBinding{ Session };
149140
150141 InputImageDescription = L" inputImage" ;
151142 OutputImageDescription = L" outputImage" ;
0 commit comments