Copied synching algorithm from ffplay.