CasparCG / server

CasparCG Server is a Windows and Linux software used to play out professional graphics, audio and video to multiple outputs. It has been in 24/7 broadcast production since 2006. Ready-to-use downloads are available under the Releases tab https://casparcg.com.
GNU General Public License v3.0
902 stars 269 forks source link

Server not responsive after back dating system time #1233

Open PeterAkakpo opened 5 years ago

PeterAkakpo commented 5 years ago

Expected behaviour

Server should continue to run irrespective of what the system date and time is.

Current behaviour

Server stops responding (frozen) when the system date or time is set to a value less than the current time. The server starts responding again when the system time gets to the point at which it was when you first changed it, but plays the video at a faster rate before becoming normal.


Steps to reproduce

  1. Start the server
  2. Add a screen consumer (eg ADD 1-99 SCREEN 0)
  3. Play any video (eg PLAY 1-0 amb)
  4. Back date the system time.

Environment


Screenshots

If applicable, add screenshots as complementary information.

grahamspr86 commented 4 years ago

I'm assuming an NTP update could cause issues here?

premultiply commented 4 years ago

A correct NTP implementation (ntp.org, chrony, meinberg, ...) adjusts the clock speed and does not make the clock jump.

Julusian commented 4 years ago

I think this is down to the channel tick clock in your setup being done based on the system clock, so I can understand changing it to cause that (it would be waiting until it passed the original time to produce the next frame). It should be possible to do something here though, to make this at most be a couple of frames of glitch instead

scriptorian commented 4 years ago

This problem is caused by a known Microsoft Visual Studio bug: https://developercommunity.visualstudio.com/content/problem/61684/stdthis-threadsleep-for-depends-on-system-time.html.

I've tried some different approaches and they have all ended up in the same place. I imagine spinning a CPU reading the current time could be made to work with care but that's not a great plan.

dotarmin commented 4 years ago

@scriptorian, can you just sum what you have found so far regarding this issue? Thanks Simon.

scriptorian commented 4 years ago

Further information: Any consumer which reports that it doesn't have a synchronization clock relies on core/consumer/output.cpp executing a once per frame sleep until the next frame is due to be processed. This sleep is done using the C++ std::this_thread::sleep_until function, with the 'until' time calculated to be one frame time later than the last call. If the system time is changed backwards then the wait will increase by the amount the time has been adjusted. The Microsoft standard library team have apparently fixed this but it cannot be released because it is a change that breaks binary compatibility. Please see the link above for more details. As I note there I haven't so far found a way around this problem. I assume that this problem will not arise with a linux build but I currently can't test that.

dotarmin commented 4 years ago

Based on the information we have on this we'll drop it from the milestone because it is dependent on a bug in Visual Studio.

gizahNL commented 2 years ago

I'd also say there is a problem in using high_resolution_clock instead of steady_clock, since high_resolution_clock is not guaranteed to be either steady or monotonously increasing, both of these aspects being absolutely critical to correct functioning of frame timing.