mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	compare: add size to compare
This commit is contained in:
		
							parent
							
								
									982fa0c80b
								
							
						
					
					
						commit
						be1725c67b
					
				
					 2 changed files with 18 additions and 12 deletions
				
			
		| 
						 | 
					@ -40,7 +40,7 @@ extern "C" {
 | 
				
			||||||
#include <spa/pod/iter.h>
 | 
					#include <spa/pod/iter.h>
 | 
				
			||||||
#include <spa/pod/builder.h>
 | 
					#include <spa/pod/builder.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline int spa_pod_compare_value(uint32_t type, const void *r1, const void *r2)
 | 
					static inline int spa_pod_compare_value(uint32_t type, const void *r1, const void *r2, uint32_t size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	switch (type) {
 | 
						switch (type) {
 | 
				
			||||||
	case SPA_TYPE_None:
 | 
						case SPA_TYPE_None:
 | 
				
			||||||
| 
						 | 
					@ -58,6 +58,8 @@ static inline int spa_pod_compare_value(uint32_t type, const void *r1, const voi
 | 
				
			||||||
		return *(double *) r1 - *(double *) r2;
 | 
							return *(double *) r1 - *(double *) r2;
 | 
				
			||||||
	case SPA_TYPE_String:
 | 
						case SPA_TYPE_String:
 | 
				
			||||||
		return strcmp((char *)r1, (char *)r2);
 | 
							return strcmp((char *)r1, (char *)r2);
 | 
				
			||||||
 | 
						case SPA_TYPE_Bytes:
 | 
				
			||||||
 | 
							return memcmp((char *)r1, (char *)r2, size);
 | 
				
			||||||
	case SPA_TYPE_Rectangle:
 | 
						case SPA_TYPE_Rectangle:
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		const struct spa_rectangle *rec1 = (struct spa_rectangle *) r1,
 | 
							const struct spa_rectangle *rec1 = (struct spa_rectangle *) r1,
 | 
				
			||||||
| 
						 | 
					@ -156,7 +158,11 @@ static inline int spa_pod_compare(const struct spa_pod *pod1,
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		res = spa_pod_compare_value(SPA_POD_TYPE(pod1), SPA_POD_BODY(pod1), SPA_POD_BODY(pod2));
 | 
							if (SPA_POD_BODY_SIZE(pod1) != SPA_POD_BODY_SIZE(pod2))
 | 
				
			||||||
 | 
								return -EINVAL;
 | 
				
			||||||
 | 
							res = spa_pod_compare_value(SPA_POD_TYPE(pod1),
 | 
				
			||||||
 | 
									SPA_POD_BODY(pod1), SPA_POD_BODY(pod2),
 | 
				
			||||||
 | 
									SPA_POD_BODY_SIZE(pod1));
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return res;
 | 
						return res;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,12 +51,12 @@ static inline int spa_pod_choice_fix_default(struct spa_pod_choice *choice)
 | 
				
			||||||
	case SPA_CHOICE_Step:
 | 
						case SPA_CHOICE_Step:
 | 
				
			||||||
		if (nvals > 1) {
 | 
							if (nvals > 1) {
 | 
				
			||||||
			alt = SPA_MEMBER(alt, size, void);
 | 
								alt = SPA_MEMBER(alt, size, void);
 | 
				
			||||||
			if (spa_pod_compare_value(type, val, alt) < 0)
 | 
								if (spa_pod_compare_value(type, val, alt, size) < 0)
 | 
				
			||||||
				memcpy(val, alt, size);
 | 
									memcpy(val, alt, size);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (nvals > 2) {
 | 
							if (nvals > 2) {
 | 
				
			||||||
			alt = SPA_MEMBER(alt, size, void);
 | 
								alt = SPA_MEMBER(alt, size, void);
 | 
				
			||||||
			if (spa_pod_compare_value(type, val, alt) > 0)
 | 
								if (spa_pod_compare_value(type, val, alt, size) > 0)
 | 
				
			||||||
				memcpy(val, alt, size);
 | 
									memcpy(val, alt, size);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ static inline int spa_pod_choice_fix_default(struct spa_pod_choice *choice)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (i = 1; i < nvals; i++) {
 | 
							for (i = 1; i < nvals; i++) {
 | 
				
			||||||
			alt = SPA_MEMBER(alt, size, void);
 | 
								alt = SPA_MEMBER(alt, size, void);
 | 
				
			||||||
			if (spa_pod_compare_value(type, val, alt) == 0) {
 | 
								if (spa_pod_compare_value(type, val, alt, size) == 0) {
 | 
				
			||||||
				best = alt;
 | 
									best = alt;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -138,7 +138,7 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
 | 
				
			||||||
		/* copy all equal values but don't copy the default value again */
 | 
							/* copy all equal values but don't copy the default value again */
 | 
				
			||||||
		for (j = 0, a1 = alt1; j < nalt1; j++, a1 = SPA_MEMBER(a1, size, void)) {
 | 
							for (j = 0, a1 = alt1; j < nalt1; j++, a1 = SPA_MEMBER(a1, size, void)) {
 | 
				
			||||||
			for (k = 0, a2 = alt2; k < nalt2; k++, a2 = SPA_MEMBER(a2,size,void)) {
 | 
								for (k = 0, a2 = alt2; k < nalt2; k++, a2 = SPA_MEMBER(a2,size,void)) {
 | 
				
			||||||
				if (spa_pod_compare_value(type, a1, a2) == 0) {
 | 
									if (spa_pod_compare_value(type, a1, a2, size) == 0) {
 | 
				
			||||||
					if (p1c == SPA_CHOICE_Enum || j > 0)
 | 
										if (p1c == SPA_CHOICE_Enum || j > 0)
 | 
				
			||||||
						spa_pod_builder_raw(b, a1, size);
 | 
											spa_pod_builder_raw(b, a1, size);
 | 
				
			||||||
					n_copied++;
 | 
										n_copied++;
 | 
				
			||||||
| 
						 | 
					@ -155,9 +155,9 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
 | 
				
			||||||
		int n_copied = 0;
 | 
							int n_copied = 0;
 | 
				
			||||||
		/* copy all values inside the range */
 | 
							/* copy all values inside the range */
 | 
				
			||||||
		for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 = SPA_MEMBER(a1,size,void)) {
 | 
							for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 = SPA_MEMBER(a1,size,void)) {
 | 
				
			||||||
			if (spa_pod_compare_value(type, a1, a2) < 0)
 | 
								if (spa_pod_compare_value(type, a1, a2, size) < 0)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			if (spa_pod_compare_value(type, a1, SPA_MEMBER(a2,size,void)) > 0)
 | 
								if (spa_pod_compare_value(type, a1, SPA_MEMBER(a2,size,void), size) > 0)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			spa_pod_builder_raw(b, a1, size);
 | 
								spa_pod_builder_raw(b, a1, size);
 | 
				
			||||||
			n_copied++;
 | 
								n_copied++;
 | 
				
			||||||
| 
						 | 
					@ -177,9 +177,9 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
 | 
				
			||||||
		int n_copied = 0;
 | 
							int n_copied = 0;
 | 
				
			||||||
		/* copy all values inside the range */
 | 
							/* copy all values inside the range */
 | 
				
			||||||
		for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 = SPA_MEMBER(a2,size,void)) {
 | 
							for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 = SPA_MEMBER(a2,size,void)) {
 | 
				
			||||||
			if (spa_pod_compare_value(type, a2, a1) < 0)
 | 
								if (spa_pod_compare_value(type, a2, a1, size) < 0)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			if (spa_pod_compare_value(type, a2, SPA_MEMBER(a1,size,void)) > 0)
 | 
								if (spa_pod_compare_value(type, a2, SPA_MEMBER(a1,size,void), size) > 0)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			spa_pod_builder_raw(b, a2, size);
 | 
								spa_pod_builder_raw(b, a2, size);
 | 
				
			||||||
			n_copied++;
 | 
								n_copied++;
 | 
				
			||||||
| 
						 | 
					@ -190,7 +190,7 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_Range) {
 | 
						if (p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_Range) {
 | 
				
			||||||
		if (spa_pod_compare_value(type, alt1, alt2) < 0)
 | 
							if (spa_pod_compare_value(type, alt1, alt2, size) < 0)
 | 
				
			||||||
			spa_pod_builder_raw(b, alt2, size);
 | 
								spa_pod_builder_raw(b, alt2, size);
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			spa_pod_builder_raw(b, alt1, size);
 | 
								spa_pod_builder_raw(b, alt1, size);
 | 
				
			||||||
| 
						 | 
					@ -198,7 +198,7 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
 | 
				
			||||||
		alt1 = SPA_MEMBER(alt1,size,void);
 | 
							alt1 = SPA_MEMBER(alt1,size,void);
 | 
				
			||||||
		alt2 = SPA_MEMBER(alt2,size,void);
 | 
							alt2 = SPA_MEMBER(alt2,size,void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (spa_pod_compare_value(type, alt1, alt2) < 0)
 | 
							if (spa_pod_compare_value(type, alt1, alt2, size) < 0)
 | 
				
			||||||
			spa_pod_builder_raw(b, alt1, size);
 | 
								spa_pod_builder_raw(b, alt1, size);
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			spa_pod_builder_raw(b, alt2, size);
 | 
								spa_pod_builder_raw(b, alt2, size);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue