mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	filter: return the newly filtered object
Always take the state of the builder to get the newly filtered object, even in the case there is no filter. Handle the case where we can't copy the pod in the case of a NULL filter by reverting the state of the builder. Rework the function a bit to make it possible to pass a NULL result (to calculate the required size, for example) Fixes #226
This commit is contained in:
		
							parent
							
								
									74665de68e
								
							
						
					
					
						commit
						de22ca68da
					
				
					 1 changed files with 10 additions and 12 deletions
				
			
		| 
						 | 
				
			
			@ -378,20 +378,18 @@ spa_pod_filter(struct spa_pod_builder *b,
 | 
			
		|||
        spa_return_val_if_fail(pod != NULL, -EINVAL);
 | 
			
		||||
        spa_return_val_if_fail(b != NULL, -EINVAL);
 | 
			
		||||
 | 
			
		||||
	if (filter == NULL) {
 | 
			
		||||
		spa_pod_builder_raw_padded(b, pod, SPA_POD_SIZE(pod));
 | 
			
		||||
		*result = (struct spa_pod*)b->data;
 | 
			
		||||
		if (!*result)
 | 
			
		||||
			return -EINVAL;
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	spa_pod_builder_get_state(b, &state);
 | 
			
		||||
	if ((res = spa_pod_filter_part(b, pod, SPA_POD_SIZE(pod), filter, SPA_POD_SIZE(filter))) < 0) {
 | 
			
		||||
		spa_pod_builder_reset(b, &state);
 | 
			
		||||
	}
 | 
			
		||||
	if (filter == NULL)
 | 
			
		||||
		res = spa_pod_builder_raw_padded(b, pod, SPA_POD_SIZE(pod));
 | 
			
		||||
	else
 | 
			
		||||
		*result = (struct spa_pod*)spa_pod_builder_deref(b, state.offset);
 | 
			
		||||
		res = spa_pod_filter_part(b, pod, SPA_POD_SIZE(pod), filter, SPA_POD_SIZE(filter));
 | 
			
		||||
 | 
			
		||||
	if (res < 0) {
 | 
			
		||||
		spa_pod_builder_reset(b, &state);
 | 
			
		||||
	} else if (result) {
 | 
			
		||||
		*result = (struct spa_pod*)spa_pod_builder_deref(b, state.offset);
 | 
			
		||||
		if (*result == NULL)
 | 
			
		||||
			res = -EINVAL;
 | 
			
		||||
	}
 | 
			
		||||
	return res;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue