mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	v4l2: fix buffer amount check
When we get buffers from the driver, check if we have at least as many as we requested. If we have more, that's ok, we will simply not queue them. Previously we would ignore the input number of buffers and use the allocated amount to fill up the buffer array, which might be too small and then we crash.
This commit is contained in:
		
							parent
							
								
									ec5f2d7337
								
							
						
					
					
						commit
						ccf2891070
					
				
					 1 changed files with 5 additions and 5 deletions
				
			
		| 
						 | 
					@ -891,8 +891,9 @@ static int spa_v4l2_set_format(struct impl *this, struct spa_video_info *format,
 | 
				
			||||||
	bool match;
 | 
						bool match;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_zero(fmt);
 | 
						spa_zero(fmt);
 | 
				
			||||||
	spa_zero(streamparm);
 | 
					 | 
				
			||||||
	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 | 
						fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spa_zero(streamparm);
 | 
				
			||||||
	streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 | 
						streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (format->media_subtype) {
 | 
						switch (format->media_subtype) {
 | 
				
			||||||
| 
						 | 
					@ -1506,11 +1507,10 @@ mmap_init(struct impl *this,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_log_debug(this->log, "got %d buffers", reqbuf.count);
 | 
						spa_log_debug(this->log, "got %d buffers", reqbuf.count);
 | 
				
			||||||
	n_buffers = reqbuf.count;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (n_buffers < 2) {
 | 
						if (reqbuf.count < n_buffers) {
 | 
				
			||||||
		spa_log_error(this->log, "'%s' can't allocate enough buffers (%d)",
 | 
							spa_log_error(this->log, "'%s' can't allocate enough buffers (%d < %d)",
 | 
				
			||||||
				this->props.device, n_buffers);
 | 
									this->props.device, reqbuf.count, n_buffers);
 | 
				
			||||||
		return -ENOMEM;
 | 
							return -ENOMEM;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue