Fixes for write loop logic
cover Fixes for write loop logic
Two small patches which correct the logic of compress_write() so that it will work correctly if asked to write a buffer shorter than the fragment length. The first patch is needed to ensure that if the client requests auto-configuration of fragment size the internal copy of the config contains the configured fragment size. The second patch contains the actual fix to the write loop logic.
Richard Fitzgerald (2):
compress: copy final version of config struct
compress: do not poll if enough space to write remaining data
compress.c | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.2.5
PATCH 1/2 compress: copy final version of config struct
compress_open() should delay taking a copy of the
config struct until we've finished modifying it.
--- compress.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
compress.c +2 -1
@@ -235,7 +235,6 @@ struct compress *compress_open(unsigned int card, unsigned int device, compress->config =calloc (1 ,sizeof (*config));if (!compress->config) goto input_fail; -memcpy (compress->config, config,sizeof (*compress->config));snprintf (fn,sizeof (fn),"/dev/snd/comprC%uD%u" , card, device);
@@ -277,6 +276,8 @@ struct compress *compress_open(unsigned int card, unsigned int device, goto codec_fail; }#endif + +memcpy (compress->config, config,sizeof (*compress->config));fill_compress_params (config, ¶ms);if (ioctl (compress->fd,SNDRV_COMPRESS_SET_PARAMS , ¶ms)) {
Signature · 1 line
1.7.2.5
PATCH 2/2 compress: do not poll if enough space to write remaining data
In reply to Richard FitzgeraldChanges the poll logic in compress_write() to prevent it polling if there is enough available space to write all remaining data. Previously the logic always polled for an entire fragment to become available before starting the first write.
This change allows short writes of < frag_size, which is likely at the end of a stream.
--- compress.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)
compress.c +4 -6
@@ -368,12 +368,10 @@ int compress_write(struct compress *compress, const void *buf, unsigned int sizeif (ioctl (compress->fd,SNDRV_COMPRESS_AVAIL , &avail))return oops (compress, errno,"cannot get avail" ); -if ( (avail.avail < frag_size) - || ((to_write !=0 ) && (avail.avail < size)) ) { -/* not enough space for one fragment, or we have done -* a short write and there isn't enough space for all -* the remaining data -*/ +/* We can write if we have at least one fragment available +* or there is enough space for all remaining data +*/ +if ((avail.avail < frag_size) && (avail.avail < size)) { ret =poll (&fds,1 , compress->max_poll_wait_ms);/* A pause will cause -EBADFD or zero. * This is not an error, just stop writing */
Signature · 1 line
1.7.2.5
Quoted 11 lines · Richard Fitzgerald
Two small patches which correct the logic of
compress_write()so that it will work correctly if asked to write a buffer shorter than the fragment length. The first patch is needed to ensure that if the client requests auto-configuration of fragment size the internal copy of the config contains the configured fragment size. The second patch contains the actual fix to the write loop logic.Richard Fitzgerald (2):
compress: copy final version of config struct
compress: do not poll if enough space to write remaining data
Applied thanks
--
~Vinod
Quoted 11 lines
compress.c | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-)Signature · 6 lines
1.7.2.5 _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel