Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/tinycompress/tinycompress.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
* compress_read: read data from the compress stream
* return bytes read on success, negative on error
* By default this is a blocking call and will block until
* size bytes have been written or there was a read error.
* some bytes have been read or there was a read error.
* If non-blocking mode was enabled using compress_nonblock()
* the behaviour will change to read only as many bytes as
* are currently available (if no bytes are available it
Expand Down
72 changes: 33 additions & 39 deletions src/lib/compress_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static int compress_hw_read(void *data, void *buf, size_t size)
struct snd_compr_avail avail;
struct pollfd fds;
int to_read = 0;
int num_read, total = 0, ret;
int num_read = 0, ret;
char* cbuf = buf;
const unsigned int frag_size = compress->config->fragment_size;

Expand All @@ -344,50 +344,44 @@ static int compress_hw_read(void *data, void *buf, size_t size)
fds.fd = compress->fd;
fds.events = POLLIN;

while (size) {
if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail))
return oops(compress, errno, "cannot get avail");
if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail))
return oops(compress, errno, "cannot get avail");

if ( (avail.avail < frag_size) && (avail.avail < size) ) {
/* Less than one fragment available and not at the
* end of the read, so poll
*/
if (compress->nonblocking)
return total;
if ( (avail.avail < frag_size) && (avail.avail < size) ) {
/* Less than one fragment available and not at the
* end of the read, so poll
*/
if (compress->nonblocking)
return num_read;

ret = poll(&fds, 1, compress->max_poll_wait_ms);
if (fds.revents & POLLERR) {
return oops(compress, EIO, "poll returned error!");
}
/* A pause will cause -EBADFD or zero.
* This is not an error, just stop reading */
if ((ret == 0) || (ret < 0 && errno == EBADFD))
break;
if (ret < 0)
return oops(compress, errno, "poll error");
if (fds.revents & POLLIN) {
continue;
}
ret = poll(&fds, 1, compress->max_poll_wait_ms);
if (fds.revents & POLLERR) {
return oops(compress, EIO, "poll returned error!");
}
/* read avail bytes */
if (size > avail.avail)
to_read = avail.avail;
else
to_read = size;
num_read = read(compress->fd, cbuf, to_read);
if (num_read < 0) {
/* If play was paused the read returns -EBADFD */
if (errno == EBADFD)
break;
return oops(compress, errno, "read failed!");
/* A pause will cause -EBADFD or zero.
* This is not an error, just stop reading */
if ((ret == 0) || (ret < 0 && errno == EBADFD))
break;
if (ret < 0)
return oops(compress, errno, "poll error");
if (fds.revents & POLLIN) {
continue;
}

size -= num_read;
cbuf += num_read;
total += num_read;
}
/* read avail bytes */
if (size > avail.avail)
to_read = avail.avail;
else
to_read = size;
num_read = read(compress->fd, cbuf, to_read);
if (num_read < 0) {
/* If play was paused the read returns -EBADFD */
if (errno == EBADFD)
break;
return oops(compress, errno, "read failed!");
}

return total;
return num_read;
}

static int compress_hw_start(void *data)
Expand Down