mirror of
https://github.com/qemu/qemu.git
synced 2025-08-09 01:50:43 +00:00
usb-audio: do not count on avail bytes actually available
This assumption is no longer true when mixeng is turned off. Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Message-id: d63f4d39a0ee7a2e4e7e4a2eb005ba79120eaf1d.1570996490.git.DirtY.iCE.hu@gmail.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
b5c7db3eef
commit
2c6a740f6b
@ -319,30 +319,31 @@ static int streambuf_put(struct streambuf *buf, USBPacket *p)
|
|||||||
{
|
{
|
||||||
uint32_t free = buf->size - (buf->prod - buf->cons);
|
uint32_t free = buf->size - (buf->prod - buf->cons);
|
||||||
|
|
||||||
if (!free) {
|
if (free < USBAUDIO_PACKET_SIZE) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (p->iov.size != USBAUDIO_PACKET_SIZE) {
|
if (p->iov.size != USBAUDIO_PACKET_SIZE) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert(free >= USBAUDIO_PACKET_SIZE);
|
|
||||||
usb_packet_copy(p, buf->data + (buf->prod % buf->size),
|
usb_packet_copy(p, buf->data + (buf->prod % buf->size),
|
||||||
USBAUDIO_PACKET_SIZE);
|
USBAUDIO_PACKET_SIZE);
|
||||||
buf->prod += USBAUDIO_PACKET_SIZE;
|
buf->prod += USBAUDIO_PACKET_SIZE;
|
||||||
return 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;
|
uint32_t used = buf->prod - buf->cons;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
|
|
||||||
if (!used) {
|
if (!used) {
|
||||||
|
*len = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
assert(used >= USBAUDIO_PACKET_SIZE);
|
|
||||||
data = buf->data + (buf->cons % buf->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;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,16 +375,21 @@ static void output_callback(void *opaque, int avail)
|
|||||||
USBAudioState *s = opaque;
|
USBAudioState *s = opaque;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
|
|
||||||
for (;;) {
|
while (avail) {
|
||||||
if (avail < USBAUDIO_PACKET_SIZE) {
|
size_t written, len;
|
||||||
return;
|
|
||||||
}
|
data = streambuf_get(&s->out.buf, &len);
|
||||||
data = streambuf_get(&s->out.buf);
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user