diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2020-01-06 16:48:35 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2020-01-06 16:48:35 +0000 |
commit | 5d112176457c070baa954fb6860df5ed1e55ad5c (patch) | |
tree | 71e25c3741cff1f17a92d22ca85049095f1b5c43 | |
parent | 81e6a7345a1299c8d0ce879e6abfe928a24df62b (diff) | |
parent | 40ad46d3cc463fab5a23db466f77e37aff23f927 (diff) |
Merge remote-tracking branch 'remotes/kraxel/tags/audio-20200106-pull-request' into staging
audio: bugfixes.
# gpg: Signature made Mon 06 Jan 2020 12:51:15 GMT
# gpg: using RSA key 4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" [full]
# gpg: aka "Gerd Hoffmann <gerd@kraxel.org>" [full]
# gpg: aka "Gerd Hoffmann (private) <kraxel@gmail.com>" [full]
# Primary key fingerprint: A032 8CFF B93A 17A7 9901 FE7D 4CB6 D8EE D3E8 7138
* remotes/kraxel/tags/audio-20200106-pull-request:
audio: fix integer overflow
paaudio: wait until the recording stream is ready
paaudio: try to drain the recording stream
paaudio: drop recording stream in qpa_fini_in
hda-codec: fix recording rate control
hda-codec: fix playback rate control
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r-- | audio/audio.c | 2 | ||||
-rw-r--r-- | audio/paaudio.c | 70 | ||||
-rw-r--r-- | hw/audio/hda-codec.c | 8 |
3 files changed, 54 insertions, 26 deletions
diff --git a/audio/audio.c b/audio/audio.c index 56fae55047..abea027fdf 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1738,7 +1738,7 @@ static AudioState *audio_init(Audiodev *dev, const char *name) if (dev->timer_period <= 0) { s->period_ticks = 1; } else { - s->period_ticks = dev->timer_period * SCALE_US; + s->period_ticks = dev->timer_period * (int64_t)SCALE_US; } e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s); diff --git a/audio/paaudio.c b/audio/paaudio.c index 55a91f8980..dbfe48c03a 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -156,34 +156,48 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length) { PAVoiceIn *p = (PAVoiceIn *) hw; PAConnection *c = p->g->conn; - size_t l; - int r; + size_t total = 0; pa_threaded_mainloop_lock(c->mainloop); CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, "pa_threaded_mainloop_lock failed\n"); + if (pa_stream_get_state(p->stream) != PA_STREAM_READY) { + /* wait for stream to become ready */ + goto unlock; + } + + while (total < length) { + size_t l; + int r; + + if (!p->read_length) { + r = pa_stream_peek(p->stream, &p->read_data, &p->read_length); + CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, + "pa_stream_peek failed\n"); + if (!p->read_length) { + /* buffer is empty */ + break; + } + } - if (!p->read_length) { - r = pa_stream_peek(p->stream, &p->read_data, &p->read_length); - CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, - "pa_stream_peek failed\n"); - } - - l = MIN(p->read_length, length); - memcpy(data, p->read_data, l); + l = MIN(p->read_length, length - total); + memcpy((char *)data + total, p->read_data, l); - p->read_data += l; - p->read_length -= l; + p->read_data += l; + p->read_length -= l; + total += l; - if (!p->read_length) { - r = pa_stream_drop(p->stream); - CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, - "pa_stream_drop failed\n"); + if (!p->read_length) { + r = pa_stream_drop(p->stream); + CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, + "pa_stream_drop failed\n"); + } } +unlock: pa_threaded_mainloop_unlock(c->mainloop); - return l; + return total; unlock_and_fail: pa_threaded_mainloop_unlock(c->mainloop); @@ -536,7 +550,6 @@ static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream) { int err; - pa_threaded_mainloop_lock(c->mainloop); /* * wait until actually connects. workaround pa bug #247 * https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/247 @@ -550,7 +563,6 @@ static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream) dolog("Failed to disconnect! err=%d\n", err); } pa_stream_unref(stream); - pa_threaded_mainloop_unlock(c->mainloop); } static void qpa_fini_out (HWVoiceOut *hw) @@ -558,8 +570,12 @@ static void qpa_fini_out (HWVoiceOut *hw) PAVoiceOut *pa = (PAVoiceOut *) hw; if (pa->stream) { - qpa_simple_disconnect(pa->g->conn, pa->stream); + PAConnection *c = pa->g->conn; + + pa_threaded_mainloop_lock(c->mainloop); + qpa_simple_disconnect(c, pa->stream); pa->stream = NULL; + pa_threaded_mainloop_unlock(c->mainloop); } } @@ -568,8 +584,20 @@ static void qpa_fini_in (HWVoiceIn *hw) PAVoiceIn *pa = (PAVoiceIn *) hw; if (pa->stream) { - qpa_simple_disconnect(pa->g->conn, pa->stream); + PAConnection *c = pa->g->conn; + + pa_threaded_mainloop_lock(c->mainloop); + if (pa->read_length) { + int r = pa_stream_drop(pa->stream); + if (r) { + qpa_logerr(pa_context_errno(c->context), + "pa_stream_drop failed\n"); + } + pa->read_length = 0; + } + qpa_simple_disconnect(c, pa->stream); pa->stream = NULL; + pa_threaded_mainloop_unlock(c->mainloop); } } diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c index f17e8d8dce..e711a99a41 100644 --- a/hw/audio/hda-codec.c +++ b/hw/audio/hda-codec.c @@ -265,8 +265,6 @@ static void hda_audio_input_cb(void *opaque, int avail) int64_t to_transfer = MIN(B_SIZE - (wpos - rpos), avail); - hda_timer_sync_adjust(st, -((wpos - rpos) + to_transfer - (B_SIZE >> 1))); - while (to_transfer) { uint32_t start = (uint32_t) (wpos & B_MASK); uint32_t chunk = (uint32_t) MIN(B_SIZE - start, to_transfer); @@ -278,6 +276,8 @@ static void hda_audio_input_cb(void *opaque, int avail) break; } } + + hda_timer_sync_adjust(st, -((wpos - rpos) - (B_SIZE >> 1))); } static void hda_audio_output_timer(void *opaque) @@ -338,8 +338,6 @@ static void hda_audio_output_cb(void *opaque, int avail) return; } - hda_timer_sync_adjust(st, (wpos - rpos) - to_transfer - (B_SIZE >> 1)); - while (to_transfer) { uint32_t start = (uint32_t) (rpos & B_MASK); uint32_t chunk = (uint32_t) MIN(B_SIZE - start, to_transfer); @@ -351,6 +349,8 @@ static void hda_audio_output_cb(void *opaque, int avail) break; } } + + hda_timer_sync_adjust(st, (wpos - rpos) - (B_SIZE >> 1)); } static void hda_audio_compat_input_cb(void *opaque, int avail) |