diff options
author | Sairamreddy Bojja <quic_sbojja@quicinc.com> | 2023-03-13 12:26:57 +0530 |
---|---|---|
committer | Sairamreddy Bojja <quic_sbojja@quicinc.com> | 2023-03-13 12:28:25 +0530 |
commit | 592347b1b3b9fd1c69877a29cc250c78c4b9b6fc (patch) | |
tree | 8ff84f79bb871c15761516f097bf466700255858 | |
parent | 08e9750b96a8e51918ff7896bafff606b6d3d3c9 (diff) |
tinycompress: do not loop in the compress read
Return the compress read immediately when it is
successful. client can recall for the remaining bytes.
Also, In case of capture, move the plugin state
to prepared when set params is successful.
Earlier in case of playback this plug state is moved
to prepare only when first write is successful.
Change-Id: I9a6a365d78ede8ff04e4d99bcdaca05a71831d6c
CRs-Fixed: 3424064
-rw-r--r-- | compress.c | 76 | ||||
-rw-r--r-- | compress_plugin.c | 6 | ||||
-rw-r--r-- | include/tinycompress/tinycompress.h | 2 |
3 files changed, 44 insertions, 40 deletions
@@ -397,51 +397,49 @@ int compress_read(struct compress *compress, void *buf, unsigned int size) return oops(compress, ENODEV, "device not ready"); fds.events = POLLIN; - while (size) { - if (compress->ops->ioctl(compress->data, SNDRV_COMPRESS_AVAIL, &avail)) - return oops(compress, errno, "cannot get avail"); + if (compress->ops->ioctl(compress->data, 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 total; - ret = compress->ops->poll(compress->data, &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 = compress->ops->poll(compress->data, &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 = compress->ops->read(compress->data, 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)) + return 0; + if (ret < 0) + return oops(compress, errno, "poll error"); + if (fds.revents & POLLIN) { + return 0; } - - 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 = compress->ops->read(compress->data, cbuf, to_read); + if (num_read < 0) { + /* If play was paused the read returns -EBADFD */ + if (errno == EBADFD) + return 0; + return oops(compress, errno, "read failed!"); } - return total; + size -= num_read; + cbuf += num_read; + total += num_read; + + return num_read; } int compress_start(struct compress *compress) diff --git a/compress_plugin.c b/compress_plugin.c index 0e536cc..22f8f11 100644 --- a/compress_plugin.c +++ b/compress_plugin.c @@ -43,6 +43,7 @@ #include <linux/ioctl.h> #include <sound/asound.h> #include "tinycompress/compress_plugin.h" +#include "tinycompress/tinycompress.h" #include "sound/compress_offload.h" #include "compress_ops.h" #include "snd_utils.h" @@ -96,8 +97,11 @@ static int compress_plug_set_params(struct compress_plug_data *plug_data, return -EINVAL; rc = plugin->ops->set_params(plugin, params); - if (!rc) + if (!rc) { plugin->state = COMPRESS_PLUG_STATE_SETUP; + if (plug_data->flags & COMPRESS_OUT) + plugin->state = COMPRESS_PLUG_STATE_PREPARED; + } return rc; } diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h index 97b305f..83c8f9e 100644 --- a/include/tinycompress/tinycompress.h +++ b/include/tinycompress/tinycompress.h @@ -53,6 +53,8 @@ #ifndef __TINYCOMPRESS_H #define __TINYCOMPRESS_H +#include <stdbool.h> + #if defined(__cplusplus) extern "C" { #endif |