[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 23/25] usb-audio: do not count on avail bytes actual
From: |
Kővágó, Zoltán |
Subject: |
[Qemu-devel] [PATCH 23/25] usb-audio: do not count on avail bytes actually available |
Date: |
Sun, 25 Aug 2019 20:46:25 +0200 |
This assumption is no longer true when mixeng is turned off.
Signed-off-by: Kővágó, Zoltán <address@hidden>
---
hw/usb/dev-audio.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index ae42e5a2f1..74c99b1f12 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -319,30 +319,31 @@ static int streambuf_put(struct streambuf *buf, USBPacket
*p)
{
uint32_t free = buf->size - (buf->prod - buf->cons);
- if (!free) {
+ if (free < USBAUDIO_PACKET_SIZE) {
return 0;
}
if (p->iov.size != USBAUDIO_PACKET_SIZE) {
return 0;
}
- assert(free >= USBAUDIO_PACKET_SIZE);
+
usb_packet_copy(p, buf->data + (buf->prod % buf->size),
USBAUDIO_PACKET_SIZE);
buf->prod += USBAUDIO_PACKET_SIZE;
return USBAUDIO_PACKET_SIZE;
}
-static uint8_t *streambuf_get(struct streambuf *buf)
+static uint8_t *streambuf_get(struct streambuf *buf, size_t *len)
{
uint32_t used = buf->prod - buf->cons;
uint8_t *data;
if (!used) {
+ *len = 0;
return NULL;
}
- assert(used >= USBAUDIO_PACKET_SIZE);
data = buf->data + (buf->cons % buf->size);
- buf->cons += USBAUDIO_PACKET_SIZE;
+ *len = MIN(buf->prod - buf->cons,
+ buf->size - (buf->cons % buf->size));
return data;
}
@@ -374,16 +375,21 @@ static void output_callback(void *opaque, int avail)
USBAudioState *s = opaque;
uint8_t *data;
- for (;;) {
- if (avail < USBAUDIO_PACKET_SIZE) {
- return;
- }
- data = streambuf_get(&s->out.buf);
+ while (avail) {
+ size_t written, len;
+
+ data = streambuf_get(&s->out.buf, &len);
if (!data) {
return;
}
- AUD_write(s->out.voice, data, USBAUDIO_PACKET_SIZE);
- avail -= USBAUDIO_PACKET_SIZE;
+
+ written = AUD_write(s->out.voice, data, len);
+ avail -= written;
+ s->out.buf.cons += written;
+
+ if (written < len) {
+ return;
+ }
}
}
--
2.22.0
- Re: [Qemu-devel] [PATCH 13/25] audio: remove hw->samples, buffer_size_in/out pcm_ops, (continued)
- [Qemu-devel] [PATCH 16/25] audio: add mixeng option (documentation), Kővágó, Zoltán, 2019/08/25
- [Qemu-devel] [PATCH 17/25] audio: make mixeng optional, Kővágó, Zoltán, 2019/08/25
- [Qemu-devel] [PATCH 12/25] audio: unify input and output mixeng buffer management, Kővágó, Zoltán, 2019/08/25
- [Qemu-devel] [PATCH 14/25] audio: common rate control code for timer based outputs, Kővágó, Zoltán, 2019/08/25
- [Qemu-devel] [PATCH 15/25] audio: split ctl_* functions into enable_* and volume_*, Kővágó, Zoltán, 2019/08/25
- [Qemu-devel] [PATCH 19/25] audio: support more than two channels in volume setting, Kővágó, Zoltán, 2019/08/25
- [Qemu-devel] [PATCH 21/25] audio: basic support for multichannel audio, Kővágó, Zoltán, 2019/08/25
- [Qemu-devel] [PATCH 23/25] usb-audio: do not count on avail bytes actually available,
Kővágó, Zoltán <=
- [Qemu-devel] [PATCH 20/25] audio: replace shift in audio_pcm_info with bytes_per_frame, Kővágó, Zoltán, 2019/08/25
- [Qemu-devel] [PATCH 25/25] usbaudio: change playback counters to 64 bit, Kővágó, Zoltán, 2019/08/25
- [Qemu-devel] [PATCH 22/25] paaudio: channel-map option, Kővágó, Zoltán, 2019/08/25