[PULL 3/9] audio: fix size calculation in AUD_get_buffer_size_out()

marcandre.lureau@redhat.com posted 9 patches 5 months, 3 weeks ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, Christian Schoenebeck <qemu_oss@crudebyte.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>
There is a newer version of this series
[PULL 3/9] audio: fix size calculation in AUD_get_buffer_size_out()
Posted by marcandre.lureau@redhat.com 5 months, 3 weeks ago
From: Volker Rümelin <vr_qemu@t-online.de>

The buffer size calculated by AUD_get_buffer_size_out() is often
incorrect. sw->hw->samples * sw->hw->info.bytes_per_frame is the
size of the mixing engine buffer in audio frames multiplied by
the size of one frame of the audio backend. Due to resampling or
format conversion, the size of the frontend buffer can differ
significantly.

Return the correct buffer size when the mixing engine is used.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20250515054429.7385-3-vr_qemu@t-online.de>
---
 audio/audio.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/audio/audio.c b/audio/audio.c
index 70ef22b1a4..3f5baf0cc6 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -909,6 +909,10 @@ int AUD_get_buffer_size_out(SWVoiceOut *sw)
         return 0;
     }
 
+    if (audio_get_pdo_out(sw->s->dev)->mixing_engine) {
+        return sw->resample_buf.size * sw->info.bytes_per_frame;
+    }
+
     return sw->hw->samples * sw->hw->info.bytes_per_frame;
 }
 
-- 
2.49.0


Re: [PULL 3/9] audio: fix size calculation in AUD_get_buffer_size_out()
Posted by Michael Tokarev 4 months, 1 week ago
On 25.05.2025 16:27, marcandre.lureau@redhat.com wrote:
> From: Volker Rümelin <vr_qemu@t-online.de>
> 
> The buffer size calculated by AUD_get_buffer_size_out() is often
> incorrect. sw->hw->samples * sw->hw->info.bytes_per_frame is the
> size of the mixing engine buffer in audio frames multiplied by
> the size of one frame of the audio backend. Due to resampling or
> format conversion, the size of the frontend buffer can differ
> significantly.
> 
> Return the correct buffer size when the mixing engine is used.
> 
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
> Message-Id: <20250515054429.7385-3-vr_qemu@t-online.de>
> ---
>   audio/audio.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/audio/audio.c b/audio/audio.c
> index 70ef22b1a4..3f5baf0cc6 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -909,6 +909,10 @@ int AUD_get_buffer_size_out(SWVoiceOut *sw)
>           return 0;
>       }
>   
> +    if (audio_get_pdo_out(sw->s->dev)->mixing_engine) {
> +        return sw->resample_buf.size * sw->info.bytes_per_frame;
> +    }
> +
>       return sw->hw->samples * sw->hw->info.bytes_per_frame;
>   }
>   

Hi!

Is this relevant for 7.2.x qemu-stable series?

Commit v7.2.0-2160-g2c3f9a0a92 "audio: change type and name of the
resample buffer" introduced sw->resample_buf, before that commit
there was sw->buf, of different type.

Maybe whole this series should not be picked up for stable-7.2,
after all?

Thanks,

/mjt

Re: [PULL 3/9] audio: fix size calculation in AUD_get_buffer_size_out()
Posted by Volker Rümelin 4 months, 1 week ago
Am 09.07.25 um 04:24 schrieb Michael Tokarev:
> On 25.05.2025 16:27, marcandre.lureau@redhat.com wrote:
>> From: Volker Rümelin <vr_qemu@t-online.de>
>>
>> The buffer size calculated by AUD_get_buffer_size_out() is often
>> incorrect. sw->hw->samples * sw->hw->info.bytes_per_frame is the
>> size of the mixing engine buffer in audio frames multiplied by
>> the size of one frame of the audio backend. Due to resampling or
>> format conversion, the size of the frontend buffer can differ
>> significantly.
>>
>> Return the correct buffer size when the mixing engine is used.
>>
>> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
>> Message-Id: <20250515054429.7385-3-vr_qemu@t-online.de>
>> ---
>>   audio/audio.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/audio/audio.c b/audio/audio.c
>> index 70ef22b1a4..3f5baf0cc6 100644
>> --- a/audio/audio.c
>> +++ b/audio/audio.c
>> @@ -909,6 +909,10 @@ int AUD_get_buffer_size_out(SWVoiceOut *sw)
>>           return 0;
>>       }
>>   +    if (audio_get_pdo_out(sw->s->dev)->mixing_engine) {
>> +        return sw->resample_buf.size * sw->info.bytes_per_frame;
>> +    }
>> +
>>       return sw->hw->samples * sw->hw->info.bytes_per_frame;
>>   }
>>   
>
> Hi!
>
> Is this relevant for 7.2.x qemu-stable series?
>
> Commit v7.2.0-2160-g2c3f9a0a92 "audio: change type and name of the
> resample buffer" introduced sw->resample_buf, before that commit
> there was sw->buf, of different type.
>
> Maybe whole this series should not be picked up for stable-7.2,
> after all?
>

Hi,

I would drop this patch in staging-7.2. This issue exists since end of
2004 and it hasn't really been a big problem since then. You can keep
the patch "audio: fix SIGSEGV in AUD_get_buffer_size_out()".

With best regards,
Volker

> Thanks,
>
> /mjt
>
>