Re: AW: Video and sound syncronisation
Nice to see a new directshow developer in the team
At least MS decoder does throttling when CPU / GPU limit is reached and it will change those on the fly - not sure if it affects current code but at least for the audio renderer & A/V sync we need the real fps and not the one that decoder provides (MP1's renderer in audio renderer bnrach has a workaround, it uses the value provided by the source filter).
StretchRect shouldn't be used - at least in the long run. It has some severe issues with ATI have (latest only) - https://forum.team-mediaportal.com/development-mp-1-1-0-526/possibility-revert-ati-hack-78263/
Here's what to use instead in the future (texture based) - https://forum.team-mediaportal.com/591332-post157.html
Not sure if we want to have that parameter, since it seems to cause D3DPRESENT_INTERVAL_IMMEDIATE to be used (which causes tearing).
See previous comment
Idea is good, I hope it will give a bit more time for the video rendering (1 ms maybe ).
Glitch recovery should be also implemented at some point - based on those stats. There is also some sample code how to do it - Direct3D9Ex Flip Mode Present and Present Statistics Sample - Home
today I spent some more hours in testing, here are some facts about current situtation:
Nice to see a new directshow developer in the team
1) Scheduling
The evr presenter schedules frames, present them if they are in due time (<1/4 of frame duration).
Here I found one issue: the "Kate Bush..." sample clip has a 29.97 frame rate, but on startup it's detected falsly as 25 fps. I have now fixed this inside scheduler byto read the sample's duration. This divided by 4 is the new limit to callback.Code:hr = pSample->GetSampleDuration(&hnsSampleDuration);
At least MS decoder does throttling when CPU / GPU limit is reached and it will change those on the fly - not sure if it affects current code but at least for the audio renderer & A/V sync we need the real fps and not the one that decoder provides (MP1's renderer in audio renderer bnrach has a workaround, it uses the value provided by the source filter).
Code:using (Surface surf = Surface.FromPointer(new IntPtr(dwSurface))) { GraphicsDevice.Device.StretchRectangle(surf, cropRect, _surface, new Rectangle(Point.Empty, _croppedVideoSize), TextureFilter.None); }
StretchRect shouldn't be used - at least in the long run. It has some severe issues with ATI have (latest only) - https://forum.team-mediaportal.com/development-mp-1-1-0-526/possibility-revert-ati-hack-78263/
Here's what to use instead in the future (texture based) - https://forum.team-mediaportal.com/591332-post157.html
Code:_device.PresentEx(Present.ForceImmediate);
Not sure if we want to have that parameter, since it seems to cause D3DPRESENT_INTERVAL_IMMEDIATE to be used (which causes tearing).
Windowed mode supports D3DPRESENT_INTERVAL_DEFAULT, D3DPRESENT_INTERVAL_IMMEDIATE, and D3DPRESENT_INTERVAL_ONE. D3DPRESENT_INTERVAL_DEFAULT and the D3DPRESENT_INTERVAL_ONE are nearly equivalent (see the information regarding timer resolution below). They perform similarly to COPY_VSYNC in that there is only one present per frame, and they prevent tearing with beam-following. In contrast, D3DPRESENT_INTERVAL_IMMEDIATE will attempt to provide an unlimited presentation rate.
This means, we use the ForceImmediate call that is not bound to vsync (see D3DPRESENT (Windows))
See previous comment
Not sure if it improves the situation, but my idea was to have to GUI already rendered and then we can immediatly PresentEx()...
Idea is good, I hope it will give a bit more time for the video rendering (1 ms maybe ).
3) Available statistics
The frame scheduling part can use collected statistics about PresentCount, PresentRefreshCount, SyncRefreshCount, SyncQPCTime, SyncGPUTime (IDirect3DSwapChain9Ex::GetPresentStatistics Method (Windows), D3DPRESENTSTATS Structure (Windows))
This can be used to improve the scheduling quality more.
Glitch recovery should be also implemented at some point - based on those stats. There is also some sample code how to do it - Direct3D9Ex Flip Mode Present and Present Statistics Sample - Home