mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									b0fc685115
								
							
						
					
					
						commit
						1714332719
					
				
					 1 changed files with 13 additions and 1 deletions
				
			
		| 
						 | 
					@ -716,6 +716,8 @@ static snd_pcm_sframes_t snd_pcm_ioplug_avail_update(snd_pcm_t *pcm)
 | 
				
			||||||
	snd_pcm_ioplug_hw_ptr_update(pcm);
 | 
						snd_pcm_ioplug_hw_ptr_update(pcm);
 | 
				
			||||||
	if (io->data->state == SND_PCM_STATE_XRUN)
 | 
						if (io->data->state == SND_PCM_STATE_XRUN)
 | 
				
			||||||
		return -EPIPE;
 | 
							return -EPIPE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						avail = snd_pcm_mmap_avail(pcm);
 | 
				
			||||||
	if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
 | 
						if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
 | 
				
			||||||
	    pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED &&
 | 
						    pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED &&
 | 
				
			||||||
	    pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
 | 
						    pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
 | 
				
			||||||
| 
						 | 
					@ -728,9 +730,19 @@ static snd_pcm_sframes_t snd_pcm_ioplug_avail_update(snd_pcm_t *pcm)
 | 
				
			||||||
			result = io->data->callback->transfer(io->data, areas, offset, size);
 | 
								result = io->data->callback->transfer(io->data, areas, offset, size);
 | 
				
			||||||
			if (result < 0)
 | 
								if (result < 0)
 | 
				
			||||||
				return result;
 | 
									return result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* If the available data doesn't fit in the
 | 
				
			||||||
 | 
								   contiguous area at the end of the mmap we
 | 
				
			||||||
 | 
								   must transfer the remaining data to the
 | 
				
			||||||
 | 
								   beginning of the mmap. */
 | 
				
			||||||
 | 
								if (size < avail) {
 | 
				
			||||||
 | 
									result = io->data->callback->transfer(io->data, areas,
 | 
				
			||||||
 | 
													      0, avail - size);
 | 
				
			||||||
 | 
									if (result < 0)
 | 
				
			||||||
 | 
										return result;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	avail = snd_pcm_mmap_avail(pcm);
 | 
					 | 
				
			||||||
	if (avail > io->avail_max)
 | 
						if (avail > io->avail_max)
 | 
				
			||||||
		io->avail_max = avail;
 | 
							io->avail_max = avail;
 | 
				
			||||||
	return (snd_pcm_sframes_t)avail;
 | 
						return (snd_pcm_sframes_t)avail;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue