summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2019-11-25 21:00:14 +0530
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>2019-11-28 08:59:41 +0000
commit6d27c0ac08a4071353e95f8fdc2ff97603f39bce (patch)
tree88be022dda6cc9e1c9cccfa4bb907efe0792d5b4
parentd8a51c60973872fb8b1f2af7bbe0f5e457218cd9 (diff)
downloadgstreamer-plugins-bad-6d27c0ac08a4071353e95f8fdc2ff97603f39bce.tar.gz
wasapisrc: Fix glitching and clock skew issues
We were miscalculating the device period, i.e. the number of frames we'll get from WASAPI in each IAudioClient::GetBuffer call, due to a calculation mistake (truncate instead of round). For example, on my machine when the aux input is set to 44.1KHz, the reported device period is 101587, which comes out to 447.998 frames per ::GetBuffer call. In reality we will, of course, get 448 frames per call, but we were truncating, so we expected 447 and were discarding one frame every time. This led to glitching, and skew over time. Interestingly, I can only see this with 44.1Khz. 48Khz/96Khz are fine, because the device period is a more 'even' number. Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/806
-rw-r--r--sys/wasapi/gstwasapiutil.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/sys/wasapi/gstwasapiutil.c b/sys/wasapi/gstwasapiutil.c
index 81df8d838..1651bdf80 100644
--- a/sys/wasapi/gstwasapiutil.c
+++ b/sys/wasapi/gstwasapiutil.c
@@ -919,7 +919,9 @@ gst_wasapi_util_initialize_audioclient (GstElement * self,
*ret_devicep_frames = n_frames;
} else {
- *ret_devicep_frames = (rate * device_period * 100) / GST_SECOND;
+ /* device_period can be a non-power-of-10 value so round while converting */
+ *ret_devicep_frames =
+ gst_util_uint64_scale_round (device_period, rate * 100, GST_SECOND);
}
return TRUE;