[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 51/51] usbaudio: change playback counters to 64 bit
From: |
Kővágó, Zoltán |
Subject: |
[Qemu-devel] [PATCH 51/51] usbaudio: change playback counters to 64 bit |
Date: |
Thu, 14 Jan 2016 14:46:04 +0100 |
With stereo playback, they need about 375 minutes of continuous audio
playback to overflow, which is usually not a problem (as stopping and
later resuming playback resets the counters). But with 7.1 audio, they
only need about 95 minutes to overflow.
After the overflow, the buf->prod % USBAUDIO_PACKET_SIZE(channels)
assertion no longer holds true, which will result in overflowing the
buffer. With 64 bit variables, it would take some 762000 years to
overflow.
Signed-off-by: Kővágó, Zoltán <address@hidden>
---
hw/usb/dev-audio.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index 7f28996..63f3c4e 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -576,9 +576,9 @@ static const USBDesc desc_audio_multi = {
struct streambuf {
uint8_t *data;
- uint32_t size;
- uint32_t prod;
- uint32_t cons;
+ size_t size;
+ uint64_t prod;
+ uint64_t cons;
};
static void streambuf_init(struct streambuf *buf, uint32_t size,
@@ -599,12 +599,14 @@ static void streambuf_fini(struct streambuf *buf)
static int streambuf_put(struct streambuf *buf, USBPacket *p, uint32_t
channels)
{
- uint32_t free = buf->size - (buf->prod - buf->cons);
+ uint64_t free = buf->size - (buf->prod - buf->cons);
if (free < USBAUDIO_PACKET_SIZE(channels)) {
return 0;
}
+ /* can happen if prod overflows */
+ assert(buf->prod % USBAUDIO_PACKET_SIZE(channels) == 0);
usb_packet_copy(p, buf->data + (buf->prod % buf->size),
USBAUDIO_PACKET_SIZE(channels));
buf->prod += USBAUDIO_PACKET_SIZE(channels);
@@ -613,7 +615,7 @@ static int streambuf_put(struct streambuf *buf, USBPacket
*p, uint32_t channels)
static uint8_t *streambuf_get(struct streambuf *buf, size_t *len)
{
- uint32_t used = buf->prod - buf->cons;
+ uint64_t used = buf->prod - buf->cons;
uint8_t *data;
if (!used) {
--
2.7.0
- [Qemu-devel] [PATCH 37/51] audio: remove remains of the old backend api, (continued)
- [Qemu-devel] [PATCH 37/51] audio: remove remains of the old backend api, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 20/51] audio: audiodev= parameters no longer optional when -audiodev present, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 32/51] ossaudio: port to the new audio backend api, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 42/51] audio: add mixeng option (documentation), Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 43/51] audio: make mixeng optional, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 47/51] audio: basic support for multichannel audio, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 39/51] audio: remove hw->samples, buffer_size_in/out pcm_ops, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 41/51] audio: split ctl_* functions into enable_* and volume_*, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 49/51] usb-audio: do not count on avail bytes actually available, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 40/51] audio: common rate control code for timer based outputs, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 51/51] usbaudio: change playback counters to 64 bit,
Kővágó, Zoltán <=
- [Qemu-devel] [PATCH 24/51] audio: do not run each backend in audio_run, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 23/51] audio: remove audio_MIN, audio_MAX, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 48/51] paaudio: channel-map option, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 46/51] audio: replace shift in audio_pcm_info with bytes_per_frame, Kővágó, Zoltán, 2016/01/14
- [Qemu-devel] [PATCH 38/51] audio: unify input and output mixeng buffer management, Kővágó, Zoltán, 2016/01/14
- Re: [Qemu-devel] [PATCH 00/51] audio 5.1 patches, Victor Toso, 2016/01/14
- Re: [Qemu-devel] [PATCH 00/51] audio 5.1 patches, Gerd Hoffmann, 2016/01/15