mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	props: improve unset mask
Add support for more than 32 properties
This commit is contained in:
		
							parent
							
								
									c8830adaa3
								
							
						
					
					
						commit
						80ed927885
					
				
					 2 changed files with 19 additions and 4 deletions
				
			
		| 
						 | 
					@ -139,6 +139,14 @@ typedef struct {
 | 
				
			||||||
  const char              **tags;
 | 
					  const char              **tags;
 | 
				
			||||||
} SpaPropInfo;
 | 
					} SpaPropInfo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * SpaPropValue:
 | 
				
			||||||
 | 
					 * @type: a property type
 | 
				
			||||||
 | 
					 * @size: the property size
 | 
				
			||||||
 | 
					 * @value: the property value.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The structure to set and get properties.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
  SpaPropType  type;
 | 
					  SpaPropType  type;
 | 
				
			||||||
  size_t       size;
 | 
					  size_t       size;
 | 
				
			||||||
| 
						 | 
					@ -150,7 +158,10 @@ typedef struct {
 | 
				
			||||||
 * @n_prop_info: number of elements in @prop_info
 | 
					 * @n_prop_info: number of elements in @prop_info
 | 
				
			||||||
 * @prop_info: array of #SpaPropInfo. Contains info about the
 | 
					 * @prop_info: array of #SpaPropInfo. Contains info about the
 | 
				
			||||||
 *             properties. Can be %NULL when unspecified.
 | 
					 *             properties. Can be %NULL when unspecified.
 | 
				
			||||||
 * @unset_mask: mask of unset properties
 | 
					 * @unset_mask: mask of unset properties. For each property in @prop_info there
 | 
				
			||||||
 | 
					 *              is a corresponding bit that specifies if the property is currently
 | 
				
			||||||
 | 
					 *              unset. When more that 32 properties are present, more uint32_t
 | 
				
			||||||
 | 
					 *              fields follow this one.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Generic propertiers.
 | 
					 * Generic propertiers.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					@ -160,6 +171,10 @@ struct _SpaProps {
 | 
				
			||||||
  uint32_t           unset_mask;
 | 
					  uint32_t           unset_mask;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define SPA_PROPS_INDEX_IS_UNSET(p,idx) ((&(p)->unset_mask)[(idx) >> 5] & (1U << ((idx) & 31)))
 | 
				
			||||||
 | 
					#define SPA_PROPS_INDEX_UNSET(p,idx)    ((&(p)->unset_mask)[(idx) >> 5] |= (1U << ((idx) & 31)))
 | 
				
			||||||
 | 
					#define SPA_PROPS_INDEX_SET(p,idx)      ((&(p)->unset_mask)[(idx) >> 5] &= ~(1U << ((idx) & 31)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline unsigned int
 | 
					static inline unsigned int
 | 
				
			||||||
spa_props_index_for_id (const SpaProps *props, uint32_t id)
 | 
					spa_props_index_for_id (const SpaProps *props, uint32_t id)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ spa_props_set_prop (SpaProps           *props,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  memcpy (SPA_MEMBER (props, info->offset, void), value->value, value->size);
 | 
					  memcpy (SPA_MEMBER (props, info->offset, void), value->value, value->size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  props->unset_mask &= ~(1u << index);
 | 
					  SPA_PROPS_INDEX_SET (props, index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return SPA_RESULT_OK;
 | 
					  return SPA_RESULT_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -68,7 +68,7 @@ spa_props_get_prop (const SpaProps *props,
 | 
				
			||||||
  if ((info->flags & SPA_PROP_FLAG_READABLE) == 0)
 | 
					  if ((info->flags & SPA_PROP_FLAG_READABLE) == 0)
 | 
				
			||||||
    return SPA_RESULT_INVALID_PROPERTY_ACCESS;
 | 
					    return SPA_RESULT_INVALID_PROPERTY_ACCESS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (props->unset_mask & (1u << index))
 | 
					  if (SPA_PROPS_INDEX_IS_UNSET (props, index))
 | 
				
			||||||
    return SPA_RESULT_PROPERTY_UNSET;
 | 
					    return SPA_RESULT_PROPERTY_UNSET;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  value->type = info->type;
 | 
					  value->type = info->type;
 | 
				
			||||||
| 
						 | 
					@ -103,7 +103,7 @@ spa_props_copy (const SpaProps *src,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memcpy (SPA_MEMBER (dest, info->offset, void), value.value, value.size);
 | 
					    memcpy (SPA_MEMBER (dest, info->offset, void), value.value, value.size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dest->unset_mask &= ~(1u << i);
 | 
					    SPA_PROPS_INDEX_SET (dest, i);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return SPA_RESULT_OK;
 | 
					  return SPA_RESULT_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue