diff options
author | hselasky <hselasky@FreeBSD.org> | 2016-11-12 17:27:28 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2016-11-12 17:27:28 +0000 |
commit | 027e40d02e2b55de73161e0fc65ccbf92fe7d063 (patch) | |
tree | a8de2c78a00fb401bb7c0d38227eb7cb180f4ec5 | |
parent | 9182987ec694666c49c220c7c01d8cbe8bcbf2c8 (diff) | |
download | FreeBSD-src-027e40d02e2b55de73161e0fc65ccbf92fe7d063.zip FreeBSD-src-027e40d02e2b55de73161e0fc65ccbf92fe7d063.tar.gz |
MFC r308437 and r308461:
Range check the jitter values to avoid bogus sample rate adjustments.
The expected deviation should not be more than 1Hz per second. The USB
v2.0 specification also mandates this requirement. Refer to chapter
5.12.4.2 about feedback.
Allow higher sample rates to have more jitter than lower ones.
PR: 208791
-rw-r--r-- | sys/dev/sound/usb/uaudio.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/sys/dev/sound/usb/uaudio.c b/sys/dev/sound/usb/uaudio.c index 7e32b70..fcffbe5 100644 --- a/sys/dev/sound/usb/uaudio.c +++ b/sys/dev/sound/usb/uaudio.c @@ -2078,9 +2078,23 @@ uaudio_chan_play_sync_callback(struct usb_xfer *xfer, usb_error_t error) * Use feedback value as fallback when there is no * recording channel: */ - if (ch->priv_sc->sc_rec_chan.num_alt == 0) - ch->jitter_curr = temp - sample_rate; + if (ch->priv_sc->sc_rec_chan.num_alt == 0) { + int32_t jitter_max = howmany(sample_rate, 16000); + /* + * Range check the jitter values to avoid + * bogus sample rate adjustments. The expected + * deviation should not be more than 1Hz per + * second. The USB v2.0 specification also + * mandates this requirement. Refer to chapter + * 5.12.4.2 about feedback. + */ + ch->jitter_curr = temp - sample_rate; + if (ch->jitter_curr > jitter_max) + ch->jitter_curr = jitter_max; + else if (ch->jitter_curr < -jitter_max) + ch->jitter_curr = -jitter_max; + } ch->feedback_rate = temp; break; |