From 93f013579832dc82ad10c354ff68360af92acd62 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Sat, 17 Feb 2024 00:11:32 +0900 Subject: [PATCH] wasapi2: Fix choppy rendering This reverts questionable commit 009bc15f3397252e9e3954ae4af15ffcdbdeac69 which looks completely wrong. The GstWasapi2RingBuffer:buffer_size variable is used to calculate available buffer size we can write (i.e., available size = buffer_size - padding_size). But the commit makes the size to be exactly same as buffer period. Then, it can confuse this element as if the endpoint buffer is full on I/O event callback (if padding size is equal to buffer period) but it's not true. Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2870 Part-of: --- .../sys/wasapi2/gstwasapi2ringbuffer.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/wasapi2/gstwasapi2ringbuffer.cpp b/subprojects/gst-plugins-bad/sys/wasapi2/gstwasapi2ringbuffer.cpp index ebf23d31b9..aa8aa6cd2e 100644 --- a/subprojects/gst-plugins-bad/sys/wasapi2/gstwasapi2ringbuffer.cpp +++ b/subprojects/gst-plugins-bad/sys/wasapi2/gstwasapi2ringbuffer.cpp @@ -1045,6 +1045,7 @@ gst_wasapi2_ring_buffer_acquire (GstAudioRingBuffer * buf, ComPtr < IAudioStreamVolume > audio_volume; GstAudioChannelPosition *position = nullptr; guint period = 0; + gint segtotal = 2; GST_DEBUG_OBJECT (buf, "Acquire"); @@ -1139,18 +1140,13 @@ gst_wasapi2_ring_buffer_acquire (GstAudioRingBuffer * buf, g_assert (period > 0); - if (self->buffer_size > period) { - GST_INFO_OBJECT (self, "Updating buffer size %d -> %d", self->buffer_size, - period); - self->buffer_size = period; - } - spec->segsize = period * GST_AUDIO_INFO_BPF (&buf->spec.info); - spec->segtotal = 2; + segtotal = (self->buffer_size / period); + spec->segtotal = MAX (segtotal, 2); GST_INFO_OBJECT (self, - "Buffer size: %d frames, period: %d frames, segsize: %d bytes", - self->buffer_size, period, spec->segsize); + "Buffer size: %d frames, period: %d frames, segsize: %d bytes, " + "segtotal: %d", self->buffer_size, period, spec->segsize, spec->segtotal); if (self->device_class == GST_WASAPI2_CLIENT_DEVICE_CLASS_RENDER) { ComPtr < IAudioRenderClient > render_client;