mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	libcamera: Handle missing control info default values
Libcamera does not always provide default values for all control infos, see https://git.libcamera.org/libcamera/libcamera.git/tree/src/ipa/rkisp1/rkisp1.cpp?h=v0.0.2#n98 Sanitize those values, avoiding crashes.
This commit is contained in:
		
							parent
							
								
									0da1a3ba82
								
							
						
					
					
						commit
						b952d52b59
					
				
					 1 changed files with 35 additions and 15 deletions
				
			
		| 
						 | 
					@ -500,28 +500,48 @@ next:
 | 
				
			||||||
			0);
 | 
								0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (ctrl_id->type()) {
 | 
						switch (ctrl_id->type()) {
 | 
				
			||||||
	case ControlTypeBool:
 | 
						case ControlTypeBool: {
 | 
				
			||||||
 | 
							bool def;
 | 
				
			||||||
 | 
							if (ctrl_info.def().isNone())
 | 
				
			||||||
 | 
								def = ctrl_info.min().get<bool>();
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								def = ctrl_info.def().get<bool>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		spa_pod_builder_add(&b,
 | 
							spa_pod_builder_add(&b,
 | 
				
			||||||
					SPA_PROP_INFO_type, SPA_POD_CHOICE_Bool(
 | 
										SPA_PROP_INFO_type, SPA_POD_CHOICE_Bool(
 | 
				
			||||||
						(bool)ctrl_info.def().get<bool>()),
 | 
												def),
 | 
				
			||||||
					0);
 | 
										0);
 | 
				
			||||||
		break;
 | 
						} break;
 | 
				
			||||||
	case ControlTypeFloat:
 | 
						case ControlTypeFloat: {
 | 
				
			||||||
 | 
							float min = ctrl_info.min().get<float>();
 | 
				
			||||||
 | 
							float max = ctrl_info.max().get<float>();
 | 
				
			||||||
 | 
							float def;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (ctrl_info.def().isNone())
 | 
				
			||||||
 | 
								def = (min + max) / 2;
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								def = ctrl_info.def().get<float>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		spa_pod_builder_add(&b,
 | 
							spa_pod_builder_add(&b,
 | 
				
			||||||
				SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Float(
 | 
									SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Float(
 | 
				
			||||||
						(float)ctrl_info.def().get<float>(),
 | 
											def, min, max),
 | 
				
			||||||
						(float)ctrl_info.min().get<float>(),
 | 
					 | 
				
			||||||
						(float)ctrl_info.max().get<float>()),
 | 
					 | 
				
			||||||
				0);
 | 
									0);
 | 
				
			||||||
		break;
 | 
						} break;
 | 
				
			||||||
	case ControlTypeInteger32:
 | 
						case ControlTypeInteger32: {
 | 
				
			||||||
 | 
							int32_t min = ctrl_info.min().get<int32_t>();
 | 
				
			||||||
 | 
							int32_t max = ctrl_info.max().get<int32_t>();
 | 
				
			||||||
 | 
							int32_t def;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (ctrl_info.def().isNone())
 | 
				
			||||||
 | 
								def = (min + max) / 2;
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								def = ctrl_info.def().get<int32_t>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		spa_pod_builder_add(&b,
 | 
							spa_pod_builder_add(&b,
 | 
				
			||||||
				SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Int(
 | 
									SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Int(
 | 
				
			||||||
						(int32_t)ctrl_info.def().get<int32_t>(),
 | 
											def, min, max),
 | 
				
			||||||
						(int32_t)ctrl_info.min().get<int32_t>(),
 | 
					 | 
				
			||||||
						(int32_t)ctrl_info.max().get<int32_t>()),
 | 
					 | 
				
			||||||
				0);
 | 
									0);
 | 
				
			||||||
		break;
 | 
						} break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		goto next;
 | 
							goto next;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue