@@ -33,15 +33,23 @@ namespace winrt::StyleTransferEffectCpp::implementation
3333 outputTransformed.Close ();
3434 }
3535
36+
3637 void StyleTransferEffect::ProcessFrame (ProcessVideoFrameContext context) {
37- // Play around with dropping frames so as to not overwhelm when processing slowly
38- if ((frameNum + 1 ) % 5 == 0 ) {
39- frameNum = 0 ;
40- OutputDebugString (L" Drop" );
41- return ;
38+ auto now = std::chrono::high_resolution_clock::now ();
39+ std::chrono::milliseconds timePassed;
40+ // If the first time calling ProcessFrame, just start the timer
41+ if (firstProcessFrameCall) {
42+ m_StartTime = now;
43+ firstProcessFrameCall = false ;
4244 }
45+ // On the second and any proceding process,
46+ else {
47+ timePassed = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_StartTime);
48+ m_StartTime = now;
49+ Notifier.SetFrameRate (1000 .f / timePassed.count ()); // Convert to FPS: milli to seconds, invert
50+ }
51+
4352 OutputDebugString (L" PF Start | " );
44- auto startSync = std::chrono::high_resolution_clock::now ();
4553
4654 VideoFrame inputFrame = context.InputFrame ();
4755 VideoFrame outputFrame = context.OutputFrame ();
@@ -55,10 +63,7 @@ namespace winrt::StyleTransferEffectCpp::implementation
5563 Session.Evaluate (Binding, L" test" );
5664 outputTransformed.CopyToAsync (outputFrame).get ();
5765
58- auto syncTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now () - startSync);
59- Notifier.SetFrameRate (1000 .f / syncTime.count ()); // Convert to FPS: milli to seconds, invert
6066 OutputDebugString (L" PF End\n " );
61- frameNum++;
6267 }
6368
6469 void StyleTransferEffect::SetEncodingProperties (VideoEncodingProperties props, IDirect3DDevice device) {
0 commit comments