@@ -578,9 +578,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,
@@ -601,7 +601,7 @@ 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);
+ int64_t free = buf->size - (buf->prod - buf->cons);
if (free < USBAUDIO_PACKET_SIZE(channels)) {
return 0;
@@ -610,6 +610,8 @@ static int streambuf_put(struct streambuf *buf, USBPacket *p, uint32_t 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);
@@ -618,10 +620,10 @@ 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;
+ int64_t used = buf->prod - buf->cons;
uint8_t *data;
- if (!used) {
+ if (used <= 0) {
*len = 0;
return NULL;
}