more audio fixes and improvements
cover more audio fixes and improvements
The first two patches "audio: fix audio_generic_write" and "audio: fix audio_generic_read" are only compile tested. The code is only reachable from the DirectSound backend with the mixing-engine off. I don't know if it is reachable at all. I can't test because I don't have a Windows computer.
Volker Rümelin (9):
audio: fix audio_generic_write
audio: fix audio_generic_read
paaudio: remove unused variables
audio: prevent SIGSEGV in AUD_get_buffer_size_out
audio: fix bug 1858488
ossaudio: prevent SIGSEGV in oss_enable_out
ossaudio: prevent SIGPFE in oss_write
ossaudio: disable poll mode can't be reached
audio: audio_generic_get_buffer_in should honor *size
audio/alsaaudio.c | 1 + audio/audio.c | 77 ++++++++++++++++++++++++++----------------------------- audio/audio_int.h | 4 +-- audio/coreaudio.c | 7 +++-- audio/noaudio.c | 1 + audio/ossaudio.c | 28 ++++++++++++-------- audio/paaudio.c | 6 ++--- audio/sdlaudio.c | 7 +++-- audio/wavaudio.c | 1 + 9 files changed, 71 insertions(+), 61 deletions(-)
Signature · 1 line
2.16.4
PATCH 1/9 audio: fix audio_generic_write
The pcm_ops function put_buffer_out expects the returned pointer of function get_buffer_out as argument. Fix this.
--- audio/audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
audio/audio.c +1 -1
@@ -1475,7 +1475,7 @@ size_t audio_generic_write(HWVoiceOut *hw, void *buf, size_t size) copy_size =MIN (size, dst_size);memcpy (dst, buf, copy_size); -return hw->pcm_ops->put_buffer_out (hw, buf, copy_size); +return hw->pcm_ops->put_buffer_out (hw, dst, copy_size); }size_t audio_generic_read (HWVoiceIn *hw,void *buf,size_t size)
Signature · 1 line
2.16.4
PATCH 2/9 audio: fix audio_generic_read
In reply to Volker RümelinIt seems the function audio_generic_read started as a copy of function audio_generic_write and some necessary changes were forgotten. Fix the mixed up source and destination pointers and rename misnamed variables.
--- audio/audio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
audio/audio.c +5 -5
@@ -1480,12 +1480,12 @@ size_t audio_generic_write(HWVoiceOut *hw, void *buf, size_t size)size_t audio_generic_read (HWVoiceIn *hw,void *buf,size_t size) { -size_t dst_size, copy_size; -void *dst = hw->pcm_ops->get_buffer_in (hw, &dst_size); - copy_size =MIN (size, dst_size); +size_t src_size, copy_size; +void *src = hw->pcm_ops->get_buffer_in (hw, &src_size); + copy_size =MIN (size, src_size); -memcpy (dst, buf, copy_size); - hw->pcm_ops->put_buffer_in (hw, buf, copy_size); +memcpy (buf, src, copy_size); + hw->pcm_ops->put_buffer_in (hw, src, copy_size);return copy_size; }
Signature · 1 line
2.16.4
PATCH 3/9 paaudio: remove unused variables
In reply to Volker RümelinThe unused variables were last used before commit 49ddd7e122 "paaudio: port to the new audio backend api".
--- audio/paaudio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
audio/paaudio.c +2 -4
@@ -32,7 +32,6 @@ typedef struct {HWVoiceOut hw;pa_stream *stream;paaudio *g; -size_t samples; } PAVoiceOut; typedef struct {
@@ -41,7 +40,6 @@ typedef struct {const void *read_data;size_t read_length;paaudio *g; -size_t samples; } PAVoiceIn;static void qpa_conn_fini (PAConnection *c);
@@ -488,7 +486,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as, }audio_pcm_init_info (&hw->info, &obt_as); - hw->samples = pa->samples =audio_buffer_samples ( + hw->samples =audio_buffer_samples (qapi_AudiodevPaPerDirectionOptions_base (ppdo), &obt_as, ppdo->buffer_length);
@@ -536,7 +534,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) }audio_pcm_init_info (&hw->info, &obt_as); - hw->samples = pa->samples =audio_buffer_samples ( + hw->samples =audio_buffer_samples (qapi_AudiodevPaPerDirectionOptions_base (ppdo), &obt_as, ppdo->buffer_length);
Signature · 1 line
2.16.4
PATCH 4/9 audio: prevent SIGSEGV in AUD_get_buffer_size_out
In reply to Volker RümelinWith audiodev parameter out.mixing-engine=off hw->mix_buf is NULL. This leads to a segmentation fault in AUD_get_buffer_size_out. This patch reverts a small part of dc88e38fa7 "audio: unify input and output mixeng buffer management".
To reproduce the problem start qemu with
-soundhw adlib -audiodev pa,id=audio0,out.mixing-engine=off
--- audio/audio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
audio/audio.c +2 -2
@@ -878,9 +878,9 @@ size_t AUD_read(SWVoiceIn *sw, void *buf, size_t size) } } -int AUD_get_buffer_size_out (SWVoiceOut *sw) +int AUD_get_buffer_size_out (SWVoiceOut *sw) { -return sw->hw->mix_buf->size * sw->hw->info.bytes_per_frame; +return sw->hw->samples * sw->hw->info.bytes_per_frame; }void AUD_set_active_out (SWVoiceOut *sw,int on)
Signature · 1 line
2.16.4
PATCH 5/9 audio: fix bug 1858488
In reply to Volker RümelinThe combined generic buffer management code and buffer run out code in function audio_generic_put_buffer_out has a problematic behaviour. A few hundred milliseconds after playback starts the mixing buffer and the generic buffer are nearly full and the following pattern can be seen.
On first call of audio_pcm_hw_run_out the buffer run code in audio_generic_put_buffer_out writes some data to the audio hardware but the generic buffer will fill faster and is full when audio_pcm_hw_run_out returns. This is because emulated audio devices can produce playback data at a higher rate than the audio backend hardware consumes this data.
On next call of audio_pcm_hw_run_out the buffer run code in audio_generic_put_buffer_out writes some data to the audio hardware but no audio data is transferred to the generic buffer because the buffer is already full.
Then the pattern repeats. For the emulated audio device this looks like the audio timer period has doubled.
This patch splits the combined generic buffer management code and buffer run out code and calls the buffer run out code after buffer management code to break this pattern.
The bug report is for the wav audio backend. But the problem is not limited to this backend. All audio backends which use the audio_generic_put_buffer_out function show this problem.
--- audio/alsaaudio.c | 1 + audio/audio.c | 58 ++++++++++++++++++++++++++----------------------------- audio/audio_int.h | 4 ++-- audio/coreaudio.c | 7 +++++-- audio/noaudio.c | 1 + audio/ossaudio.c | 10 ++++++++++ audio/sdlaudio.c | 7 +++++-- audio/wavaudio.c | 1 + 8 files changed, 52 insertions(+), 37 deletions(-)
audio/alsaaudio.c +1 -0
@@ -906,6 +906,7 @@ static struct audio_pcm_ops alsa_pcm_ops = { .init_out = alsa_init_out, .fini_out = alsa_fini_out, .write = alsa_write, + .run_buffer_out = audio_generic_run_buffer_out, .enable_out = alsa_enable_out, .init_in = alsa_init_in,
audio/audio.c +27 -31
82 lines not on this page · raw message
audio/audio_int.h +2 -2
@@ -152,6 +152,7 @@ struct audio_pcm_ops {int (*init_out)(HWVoiceOut *hw,audsettings *as,void *drv_opaque);void (*fini_out)(HWVoiceOut *hw);size_t (*write) (HWVoiceOut *hw,void *buf,size_t size); +void (*run_buffer_out)(HWVoiceOut *hw);/* * get a buffer that after later can be passed to put_buffer_out; optional * returns the buffer, and writes it's size to size (in bytes)
@@ -178,10 +179,9 @@ struct audio_pcm_ops {void *audio_generic_get_buffer_in (HWVoiceIn *hw,size_t *size);void audio_generic_put_buffer_in (HWVoiceIn *hw,void *buf,size_t size); +void audio_generic_run_buffer_out (HWVoiceOut *hw);void *audio_generic_get_buffer_out (HWVoiceOut *hw,size_t *size);size_t audio_generic_put_buffer_out (HWVoiceOut *hw,void *buf,size_t size); -size_t audio_generic_put_buffer_out_nowrite (HWVoiceOut *hw,void *buf, -size_t size);size_t audio_generic_write (HWVoiceOut *hw,void *buf,size_t size);size_t audio_generic_read (HWVoiceIn *hw,void *buf,size_t size);
audio/coreaudio.c +5 -2
@@ -411,7 +411,7 @@ static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name) } COREAUDIO_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size), (hw, size)) -COREAUDIO_WRAPPER_FUNC (put_buffer_out_nowrite, size_t, +COREAUDIO_WRAPPER_FUNC (put_buffer_out, size_t, (HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size)) COREAUDIO_WRAPPER_FUNC(write, size_t, (HWVoiceOut *hw, void *buf, size_t size),
@@ -687,9 +687,12 @@ static void coreaudio_audio_fini (void *opaque)static struct audio_pcm_ops coreaudio_pcm_ops = { .init_out = coreaudio_init_out, .fini_out = coreaudio_fini_out, +/* wrapper for audio_generic_write */ .write = coreaudio_write, +/* wrapper for audio_generic_get_buffer_out */ .get_buffer_out = coreaudio_get_buffer_out, - .put_buffer_out = coreaudio_put_buffer_out_nowrite, +/* wrapper for audio_generic_put_buffer_out */ + .put_buffer_out = coreaudio_put_buffer_out, .enable_out = coreaudio_enable_out };
audio/noaudio.c +1 -0
@@ -118,6 +118,7 @@ static struct audio_pcm_ops no_pcm_ops = { .init_out = no_init_out, .fini_out = no_fini_out, .write = no_write, + .run_buffer_out = audio_generic_run_buffer_out, .enable_out = no_enable_out, .init_in = no_init_in,
audio/ossaudio.c +10 -0
@@ -382,6 +382,15 @@ static size_t oss_get_available_bytes(OSSVoiceOut *oss)return audio_ring_dist (cntinfo.ptr, oss->hw.pos_emul, oss->hw.size_emul); } +static void oss_run_buffer_out (HWVoiceOut *hw) +{ +OSSVoiceOut *oss = (OSSVoiceOut *)hw; + +if (!oss->mmapped) { +audio_generic_run_buffer_out (hw); + } +} +static void *oss_get_buffer_out (HWVoiceOut *hw,size_t *size) {OSSVoiceOut *oss = (OSSVoiceOut *) hw;
@@ -748,6 +757,7 @@ static struct audio_pcm_ops oss_pcm_ops = { .init_out = oss_init_out, .fini_out = oss_fini_out, .write = oss_write, + .run_buffer_out = oss_run_buffer_out, .get_buffer_out = oss_get_buffer_out, .put_buffer_out = oss_put_buffer_out, .enable_out = oss_enable_out,
audio/sdlaudio.c +5 -2
@@ -227,7 +227,7 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len) SDL_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size), (hw, size), *size = 0, sdl_unlock) -SDL_WRAPPER_FUNC (put_buffer_out_nowrite, size_t, +SDL_WRAPPER_FUNC (put_buffer_out, size_t, (HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size), /*nothing*/, sdl_unlock_and_post) SDL_WRAPPER_FUNC(write, size_t,
@@ -320,9 +320,12 @@ static void sdl_audio_fini (void *opaque)static struct audio_pcm_ops sdl_pcm_ops = { .init_out = sdl_init_out, .fini_out = sdl_fini_out, +/* wrapper for audio_generic_write */ .write = sdl_write, +/* wrapper for audio_generic_get_buffer_out */ .get_buffer_out = sdl_get_buffer_out, - .put_buffer_out = sdl_put_buffer_out_nowrite, +/* wrapper for audio_generic_put_buffer_out */ + .put_buffer_out = sdl_put_buffer_out, .enable_out = sdl_enable_out, };
audio/wavaudio.c +1 -0
@@ -197,6 +197,7 @@ static struct audio_pcm_ops wav_pcm_ops = { .init_out = wav_init_out, .fini_out = wav_fini_out, .write = wav_write_out, + .run_buffer_out = audio_generic_run_buffer_out, .enable_out = wav_enable_out, };
Signature · 1 line
2.16.4
PATCH 6/9 ossaudio: prevent SIGSEGV in oss_enable_out
In reply to Volker RümelinWith audiodev parameter out.mixing-engine=off hw->mix_buf is NULL. This patch reverts a small part of dc88e38fa7 "audio:
unify input and output mixeng buffer management".
To reproduce the problem start qemu with -audiodev oss,id=audio0,try-mmap=on,out.mixing-engine=off
--- audio/ossaudio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
audio/ossaudio.c +1 -1
@@ -592,7 +592,7 @@ static void oss_enable_out(HWVoiceOut *hw, bool enable)return ; } -audio_pcm_info_clear_buf (&hw->info, hw->buf_emul, hw->mix_buf->size); +audio_pcm_info_clear_buf (&hw->info, hw->buf_emul, hw->samples); trig =PCM_ENABLE_OUTPUT ;if (ioctl (oss->fd,SNDCTL_DSP_SETTRIGGER , &trig) <0 ) { oss_logerr(errno,
Signature · 1 line
2.16.4
PATCH 7/9 ossaudio: prevent SIGPFE in oss_write
In reply to Volker RümelinThe new buffer write position is modulo the buffer size.
To reproduce start qemu with:
-audiodev oss,id=audio0,try-mmap=on,out.mixing-engine=off
--- audio/ossaudio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
audio/ossaudio.c +1 -1
@@ -429,7 +429,7 @@ static size_t oss_write(HWVoiceOut *hw, void *buf, size_t len)size_t to_copy =MIN (len, hw->size_emul - hw->pos_emul);memcpy (hw->buf_emul + hw->pos_emul, buf, to_copy); - hw->pos_emul = (hw->pos_emul + to_copy) % hw->pos_emul; + hw->pos_emul = (hw->pos_emul + to_copy) % hw->size_emul; buf += to_copy; len -= to_copy; }
Signature · 1 line
2.16.4
PATCH 8/9 ossaudio: disable poll mode can't be reached
In reply to Volker RümelinCurrently there is no way to disable poll mode in oss_enable_out and oss_enable_in when it was enabled before. The enable code path always resets the poll mode state variable.
qemu_set_fd_handler"
--- audio/ossaudio.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
audio/ossaudio.c +5 -9
@@ -579,14 +579,12 @@ static void oss_enable_out(HWVoiceOut *hw, bool enable)AudiodevOssPerDirectionOptions *opdo = oss->dev->u.oss.out;if (enable) { -bool poll_mode = opdo->try_poll; + hw->poll_mode = opdo->try_poll;ldebug ("enabling voice\n" ); -if (poll_mode) { +if (hw->poll_mode) {oss_poll_out (hw); - poll_mode =0 ; } - hw->poll_mode = poll_mode;if (!oss->mmapped) {return ;
@@ -708,17 +706,15 @@ static void oss_enable_in(HWVoiceIn *hw, bool enable)AudiodevOssPerDirectionOptions *opdo = oss->dev->u.oss.out;if (enable) { -bool poll_mode = opdo->try_poll; + hw->poll_mode = opdo->try_poll; -if (poll_mode) { +if (hw->poll_mode) {oss_poll_in (hw); - poll_mode =0 ; } - hw->poll_mode = poll_mode; }else {if (hw->poll_mode) { - hw->poll_mode =0 ;qemu_set_fd_handler (oss->fd,NULL ,NULL ,NULL ); + hw->poll_mode =0 ; } } }
Signature · 1 line
2.16.4
PATCH 9/9 audio: audio_generic_get_buffer_in should honor *size
In reply to Volker RümelinThe function generic_get_buffer_in currently ignores the *size parameter and may return a buffer larger than *size.
As a result the variable samples in function audio_pcm_hw_run_in may underflow. The while loop then most likely will never termiate.
This bug was reported at http://bugs.debian.org/948658.
--- audio/audio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
audio/audio.c +2 -1
@@ -1406,7 +1406,8 @@ void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size) }assert (start >=0 && start < hw->size_emul); - *size =MIN (hw->pending_emul, hw->size_emul - start); + *size =MIN (*size, hw->pending_emul); + *size =MIN (*size, hw->size_emul - start);return hw->buf_emul + start; }
Signature · 1 line
2.16.4
Quoted 17 lines · Volker Rümelin
The first two patches "audio: fix
audio_generic_write" and "audio: fixaudio_generic_read" are only compile tested. The code is only reachable from the DirectSound backend with the mixing-engine off. I don't know if it is reachable at all. I can't test because I don't have a Windows computer.Volker Rümelin (9):
audio: fixaudio_generic_write
audio: fixaudio_generic_read
paaudio: remove unused variables
audio: prevent SIGSEGV inAUD_get_buffer_size_out
audio: fix bug 1858488
ossaudio: prevent SIGSEGV inoss_enable_out
ossaudio: prevent SIGPFE inoss_write
ossaudio: disable poll mode can't be reached
audio:audio_generic_get_buffer_inshould honor *size
Quoted 10 lines
audio/alsaaudio.c | 1 + audio/audio.c | 77 ++++++++++++++++++++++++++----------------------------- audio/audio_int.h | 4 +-- audio/coreaudio.c | 7 +++-- audio/noaudio.c | 1 + audio/ossaudio.c | 28 ++++++++++++-------- audio/paaudio.c | 6 ++--- audio/sdlaudio.c | 7 +++-- audio/wavaudio.c | 1 + 9 files changed, 71 insertions(+), 61 deletions(-)
Thanks for your patches! I've had reports from some of the PPC emulation guys that the switch to the new audio API broke the coreaudio backend on Macs (see
https://bugs.launchpad.net/qemu/+bug/1859916) and I've pointed them towards this patchset, but sadly it still doesn't appear to fix the issue.
Have you seen any issues with the coreaudio backend during your testing?
ATB,
Mark.
Quoted 29 lines · Volker Rümelin
Quoted 18 lines
The first two patches "audio: fix
audio_generic_write" and "audio: fixaudio_generic_read" are only compile tested. The code is only reachable from the DirectSound backend with the mixing-engine off. I don't know if it is reachable at all. I can't test because I don't have a Windows computer.Volker Rümelin (9):
audio: fixaudio_generic_write
audio: fixaudio_generic_read
paaudio: remove unused variables
audio: prevent SIGSEGV inAUD_get_buffer_size_out
audio: fix bug 1858488
ossaudio: prevent SIGSEGV inoss_enable_out
ossaudio: prevent SIGPFE inoss_write
ossaudio: disable poll mode can't be reached
audio:audio_generic_get_buffer_inshould honor *sizeQuoted 10 lines
audio/alsaaudio.c | 1 + audio/audio.c | 77 ++++++++++++++++++++++++++----------------------------- audio/audio_int.h | 4 +-- audio/coreaudio.c | 7 +++-- audio/noaudio.c | 1 + audio/ossaudio.c | 28 ++++++++++++-------- audio/paaudio.c | 6 ++--- audio/sdlaudio.c | 7 +++-- audio/wavaudio.c | 1 + 9 files changed, 71 insertions(+), 61 deletions(-)
Quoted 6 lines
Thanks for your patches! I've had reports from some of the PPC emulation guys that the switch to the new audio API broke the coreaudio backend on Macs (see
https://bugs.launchpad.net/qemu/+bug/1859916) and I've pointed them towards this patchset, but sadly it still doesn't appear to fix the issue.Have you seen any issues with the coreaudio backend during your testing?
Hi Mark,
I didn't test coreaudio. I don't have a Mac. One of my patches changes coreaudio.c because I renamed a function.
With best regards,
Volker
Quoted 3 lines
ATB,
Mark.