Skip to content

Instantly share code, notes, and snippets.

@Themaister
Created June 16, 2011 23:14
Show Gist options
  • Select an option

  • Save Themaister/1030541 to your computer and use it in GitHub Desktop.

Select an option

Save Themaister/1030541 to your computer and use it in GitHub Desktop.
roar_mus_t roar_vs_latency2(roar_vs_t * vss, int * error) {
check_async_latency(vss);
ssize_t pos = vss->writec - vss->last_server_pos;
ssize_t bps;
size_t lpos;
size_t lag;
bps = roar_info2samplesize(&(vss->info));
lioc = vss->writec;
lpos = (lioc*8) / bps;
lag = (signed long long int)lpos - (signed long long int)pos;
lag /= vss->info.channels;
lag *= 1000000;
lag /= vss->info.rate;
#ifdef _HAVE_SOCKOPT
if (vss->latc.target > vss->latc.minlag) {
roar_vs_latency_managed(vss, lag);
}
#endif
struct timeval time_now;
gettimeofday(&time_now, NULL);
roar_mus_t drift = (time_now.tv_sec - vss->latinfo.last_time.tv_sec) * 1000000 + (time_now.tv_usec - vss->latinfo.last_time.tv_usec);
if (drift > lag) {
lag = 0;
} else {
lag -= drift;
}
return lag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment