mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	spa: libcamera: source: simplify format lookup
Use range based for loops instead of indices.
This commit is contained in:
		
							parent
							
								
									0ea7dc9f19
								
							
						
					
					
						commit
						489cc49937
					
				
					 1 changed files with 16 additions and 18 deletions
				
			
		| 
						 | 
					@ -414,28 +414,26 @@ static const struct format_info format_info[] = {
 | 
				
			||||||
#undef MAKE_FMT
 | 
					#undef MAKE_FMT
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct format_info *video_format_to_info(const PixelFormat &pix) {
 | 
					static const struct format_info *video_format_to_info(const PixelFormat &pix)
 | 
				
			||||||
	size_t i;
 | 
					{
 | 
				
			||||||
 | 
						for (const auto& f : format_info) {
 | 
				
			||||||
	for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) {
 | 
							if (f.pix == pix)
 | 
				
			||||||
		if (format_info[i].pix == pix)
 | 
								return &f;
 | 
				
			||||||
			return &format_info[i];
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return NULL;
 | 
					
 | 
				
			||||||
 | 
						return nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct format_info *find_format_info_by_media_type(uint32_t type,
 | 
					static const struct format_info *find_format_info_by_media_type(
 | 
				
			||||||
		uint32_t subtype, uint32_t format, int startidx)
 | 
						uint32_t type, uint32_t subtype, uint32_t format)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	size_t i;
 | 
						for (const auto& f : format_info) {
 | 
				
			||||||
 | 
							if (f.media_type == type && f.media_subtype == subtype
 | 
				
			||||||
	for (i = startidx; i < SPA_N_ELEMENTS(format_info); i++) {
 | 
							    && (f.format == SPA_VIDEO_FORMAT_UNKNOWN || f.format == format))
 | 
				
			||||||
		if ((format_info[i].media_type == type) &&
 | 
								return &f;
 | 
				
			||||||
		    (format_info[i].media_subtype == subtype) &&
 | 
					 | 
				
			||||||
		    (format == SPA_VIDEO_FORMAT_UNKNOWN || format_info[i].format == format))
 | 
					 | 
				
			||||||
			return &format_info[i];
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return NULL;
 | 
					
 | 
				
			||||||
 | 
						return nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int score_size(Size &a, Size &b)
 | 
					static int score_size(Size &a, Size &b)
 | 
				
			||||||
| 
						 | 
					@ -681,7 +679,7 @@ static int spa_libcamera_set_format(struct impl *impl, struct port *port,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	info = find_format_info_by_media_type(format->media_type,
 | 
						info = find_format_info_by_media_type(format->media_type,
 | 
				
			||||||
					      format->media_subtype, video_format, 0);
 | 
										      format->media_subtype, video_format);
 | 
				
			||||||
	if (info == NULL || size == NULL || framerate == NULL) {
 | 
						if (info == NULL || size == NULL || framerate == NULL) {
 | 
				
			||||||
		spa_log_error(impl->log, "unknown media type %d %d %d", format->media_type,
 | 
							spa_log_error(impl->log, "unknown media type %d %d %d", format->media_type,
 | 
				
			||||||
			      format->media_subtype, video_format);
 | 
								      format->media_subtype, video_format);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue