Commit 159c81ea authored by Simon Morlat's avatar Simon Morlat

The ticker synchronizer must update the average clock skew only when new samples are read.

Otherwise there is no information to provide to the ticker.
parent 94892b66
Pipeline #284 failed with stage
in 0 seconds
......@@ -114,6 +114,7 @@ struct _MSTickerSynchronizer
uint64_t offset; /**<the default offset of ticker*/
double av_skew; /**< mean skew */
unsigned int external_time_count; /**< number of times ms_ticker_synchronizer_set_external_time() is called */
uint64_t current_nsamples; /**< The last number of samples read notified with ms_ticker_synchronizer_update*/
};
/**
......
......@@ -641,6 +641,7 @@ static void au_read_preprocess(MSFilter *f){
static void au_read_process(MSFilter *f){
AURead *d = (AURead *) f->data;
mblk_t *m;
while((m=au_read_get(d))!=NULL){
d->read_frames += (msgdsize(m) / 2) / d->common.nchannels;
ms_queue_put(f->outputs[0],m);
......
......@@ -564,7 +564,7 @@ static void au_read_postprocess(MSFilter *f){
static void au_read_process(MSFilter *f){
au_filter_read_data_t *d=(au_filter_read_data_t*)f->data;
mblk_t *m;
bool_t read_something = FALSE;
if (!(d->base.card->read_started=d->base.card->io_unit_started)) {
//make sure audio unit is started
start_audio_unit((au_filter_base_t*)d,f->ticker->time);
......@@ -577,7 +577,7 @@ static void au_read_process(MSFilter *f){
}
ms_mutex_unlock(&d->mutex);
if (read_something) ms_ticker_synchronizer_update(d->ticker_synchronizer, d->read_samples, d->base.card->rate);
ms_ticker_synchronizer_update(d->ticker_synchronizer, d->read_samples, d->base.card->rate);
}
/***********************************write function********************/
......
......@@ -606,11 +606,20 @@ double ms_ticker_synchronizer_set_external_time(MSTickerSynchronizer* ts, const
}
double ms_ticker_synchronizer_update(MSTickerSynchronizer *ts, uint64_t nb_samples, unsigned int sample_rate) {
uint64_t ms = ((1000 * nb_samples) / (uint64_t)sample_rate);
MSTimeSpec timespec;
timespec.tv_nsec = (ms % 1000) * 1000000LL;
timespec.tv_sec = ms / 1000LL;
return ms_ticker_synchronizer_set_external_time(ts, &timespec);
/* It is important that the average clock skew is updated ONLY if the user notifies that nb_samples has changed.
Indeed, the fact that the soundcard didn't delivered samples during a period of time doesn't mean that the time has stopped or slowed.
What we need is that each time we get new samples, we correlate them with system time to make a correction on the msticker timer.
Imagine that the soundcard stops for some reason: without this check the msticker would stop as well.
*/
if (nb_samples > ts->current_nsamples || ts->offset == 0){
ts->current_nsamples = nb_samples;
uint64_t ms = ((1000 * nb_samples) / (uint64_t)sample_rate);
MSTimeSpec timespec;
timespec.tv_nsec = (ms % 1000) * 1000000LL;
timespec.tv_sec = ms / 1000LL;
return ms_ticker_synchronizer_set_external_time(ts, &timespec);
}
return ts->av_skew;
}
uint64_t ms_ticker_round(uint64_t ms) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment