mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	alsa: limit the size we copy to min_avail
This commit is contained in:
		
							parent
							
								
									f4ab376a08
								
							
						
					
					
						commit
						4270e867ed
					
				
					 1 changed files with 10 additions and 8 deletions
				
			
		| 
						 | 
					@ -204,12 +204,13 @@ snd_pcm_pipewire_process(snd_pcm_pipewire_t *pw, struct buffer *b)
 | 
				
			||||||
	const snd_pcm_channel_area_t *areas;
 | 
						const snd_pcm_channel_area_t *areas;
 | 
				
			||||||
	snd_pcm_channel_area_t *pwareas;
 | 
						snd_pcm_channel_area_t *pwareas;
 | 
				
			||||||
	snd_pcm_uframes_t xfer = 0;
 | 
						snd_pcm_uframes_t xfer = 0;
 | 
				
			||||||
	unsigned int channel, bps;
 | 
						unsigned int channel, bps, bpf;
 | 
				
			||||||
	snd_pcm_uframes_t nframes;
 | 
						snd_pcm_uframes_t nframes;
 | 
				
			||||||
	uint32_t index = 0, nbytes, maxsize, avail;
 | 
						uint32_t index = 0, nbytes, maxsize, avail;
 | 
				
			||||||
	void *ptr;
 | 
						void *ptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bps = io->channels * pw->sample_bits;
 | 
						bps = io->channels * pw->sample_bits;
 | 
				
			||||||
 | 
						bpf = bps / 8;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pwareas = alloca(io->channels * sizeof(snd_pcm_channel_area_t));
 | 
						pwareas = alloca(io->channels * sizeof(snd_pcm_channel_area_t));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -222,20 +223,21 @@ snd_pcm_pipewire_process(snd_pcm_pipewire_t *pw, struct buffer *b)
 | 
				
			||||||
		filled = spa_ringbuffer_get_write_index(&b->rb->ringbuffer, &index);
 | 
							filled = spa_ringbuffer_get_write_index(&b->rb->ringbuffer, &index);
 | 
				
			||||||
		avail = b->rb->ringbuffer.size - filled;
 | 
							avail = b->rb->ringbuffer.size - filled;
 | 
				
			||||||
		offset = index % b->rb->ringbuffer.size;
 | 
							offset = index % b->rb->ringbuffer.size;
 | 
				
			||||||
                nbytes = SPA_MIN(avail, b->rb->ringbuffer.size - offset);
 | 
							avail = SPA_MIN(avail, b->rb->ringbuffer.size - offset);
 | 
				
			||||||
                nbytes = SPA_MIN(nbytes, pw->min_avail);
 | 
							avail = SPA_MIN(avail, pw->min_avail * bpf);
 | 
				
			||||||
 | 
							nbytes = avail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ptr = SPA_MEMBER(b->ptr, offset, void);
 | 
							ptr = SPA_MEMBER(b->ptr, offset, void);
 | 
				
			||||||
		pw_log_trace("%d %d %d %d %p", nbytes, avail, filled, offset, ptr);
 | 
							pw_log_trace("%d %d %d %d %p", nbytes, avail, filled, offset, ptr);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else {
 | 
						else {
 | 
				
			||||||
		avail = b->buffer->datas[0].chunk->size;
 | 
							avail = b->buffer->datas[0].chunk->size;
 | 
				
			||||||
 | 
							avail = SPA_MIN(avail, pw->min_avail * bpf);
 | 
				
			||||||
		maxsize = b->buffer->datas[0].maxsize;
 | 
							maxsize = b->buffer->datas[0].maxsize;
 | 
				
			||||||
		nbytes = SPA_MIN(avail, maxsize);
 | 
							nbytes = SPA_MIN(avail, maxsize);
 | 
				
			||||||
		ptr = b->ptr;
 | 
							ptr = b->ptr;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	nframes = nbytes / (bps / 8);
 | 
						nframes = nbytes / bpf;
 | 
				
			||||||
	nframes = SPA_MIN(nframes, pw->min_avail);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (channel = 0; channel < io->channels; channel++) {
 | 
						for (channel = 0; channel < io->channels; channel++) {
 | 
				
			||||||
		pwareas[channel].addr = ptr;
 | 
							pwareas[channel].addr = ptr;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue