pcm: ioplug: Transfer all available data
The snd_pcm_mmap_begin() call returns the amount of contiguous data,
which is less than the total available if it wraps around the buffer
boundary.
If we don't handle this split we leave stale data in the buffer that
should have been overwritten, as well as unread data in the io_plugin
that gets transferred on a subsequent call at the wrong offset.
Signed-off-by: Rob Duncan <rduncan@teslamotors.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Rob Duncan authored 5 years ago
Takashi Iwai committed 5 years ago
715 | 715 | snd_pcm_ioplug_hw_ptr_update(pcm); |
716 | 716 | if (io->data->state == SND_PCM_STATE_XRUN) |
717 | 717 | return -EPIPE; |
718 | ||
719 | avail = snd_pcm_mmap_avail(pcm); | |
718 | 720 | if (pcm->stream == SND_PCM_STREAM_CAPTURE && |
719 | 721 | pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED && |
720 | 722 | pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) { |
727 | 729 | result = io->data->callback->transfer(io->data, areas, offset, size); |
728 | 730 | if (result < 0) |
729 | 731 | return result; |
732 | ||
733 | /* If the available data doesn't fit in the | |
734 | contiguous area at the end of the mmap we | |
735 | must transfer the remaining data to the | |
736 | beginning of the mmap. */ | |
737 | if (size < avail) { | |
738 | result = io->data->callback->transfer(io->data, areas, | |
739 | 0, avail - size); | |
740 | if (result < 0) | |
741 | return result; | |
742 | } | |
730 | 743 | } |
731 | 744 | } |
732 | avail = snd_pcm_mmap_avail(pcm); | |
733 | 745 | if (avail > io->avail_max) |
734 | 746 | io->avail_max = avail; |
735 | 747 | return (snd_pcm_sframes_t)avail; |