work on memory references

Add a memory reference helper struct that we can use to track the memory
in buffers and formats.
Remove custom property get and set, the default ones will work fine.
Custom ones are problematic when we want to serialize properties in
formats etc.
Deserialized Formats are now tracked in the memory pool and can be freed
if needed.
This commit is contained in:
Wim Taymans 2016-08-04 19:24:16 +02:00
parent 8f9222bf9e
commit dd1fbef28f
23 changed files with 166 additions and 138 deletions

View file

@ -138,6 +138,8 @@ struct _SpaBuffer {
#define SPA_BUFFER_METAS(b) (SPA_MEMBER ((b), (b)->metas, SpaMeta))
#define SPA_BUFFER_DATAS(b) (SPA_MEMBER ((b), (b)->datas, SpaData))
#define spa_buffer_ref(b) spa_memory_ref (&(b)->mem)
#define spa_buffer_unref(b) spa_memory_unref (&(b)->mem)
#ifdef __cplusplus
} /* extern "C" */

View file

@ -28,6 +28,7 @@ typedef struct _SpaFormat SpaFormat;
#include <spa/defs.h>
#include <spa/props.h>
#include <spa/memory.h>
typedef enum {
SPA_MEDIA_TYPE_INVALID = 0,
@ -55,12 +56,23 @@ typedef enum {
SPA_MEDIA_SUBTYPE_BAYER = 15,
} SpaMediaSubType;
/**
* SpaFormat:
* @props: properties
* @media_type: media type
* @media_subtype: subtype
* @mem: memory reference
*/
struct _SpaFormat {
SpaProps props;
SpaMediaType media_type;
SpaMediaSubType media_subtype;
SpaMemoryRef mem;
};
#define spa_format_ref(f) spa_memory_ref(&(f)->mem)
#define spa_format_unref(f) spa_memory_unref(&(f)->mem)
typedef enum {
SPA_PROP_ID_INVALID = 0,
SPA_PROP_ID_MEDIA_CUSTOM_START = 200,

View file

@ -58,6 +58,7 @@ struct _SpaMemoryRef {
* SpaMemory:
* @refcount: a refcount
* @notify: notify when refcount is 0
* @user_data: owner specific used data
* @pool_id: the id of the pool
* @id: the memory id
* @flags: extra memory flags
@ -69,6 +70,7 @@ struct _SpaMemoryRef {
struct _SpaMemory {
int refcount;
SpaNotify notify;
void *user_data;
SpaMemoryRef mem;
SpaMemoryFlags flags;
const char *type;
@ -77,6 +79,9 @@ struct _SpaMemory {
size_t size;
};
#define SPA_MEMORY_POOL_SHARED 0
#define SPA_MEMORY_POOL_LOCAL 1
void spa_memory_init (void);
uint32_t spa_memory_pool_get (uint32_t type);
@ -84,9 +89,12 @@ uint32_t spa_memory_pool_new (void);
void spa_memory_pool_free (uint32_t);
SpaMemory * spa_memory_alloc (uint32_t pool_id);
SpaMemory * spa_memory_alloc_size (uint32_t pool_id, void *data, size_t size);
SpaMemory * spa_memory_alloc_with_fd (uint32_t pool_id, void *data, size_t size);
SpaResult spa_memory_free (SpaMemoryRef *ref);
SpaResult spa_memory_ref (SpaMemoryRef *ref);
SpaResult spa_memory_unref (SpaMemoryRef *ref);
SpaMemory * spa_memory_import (SpaMemoryRef *ref);
SpaMemory * spa_memory_find (SpaMemoryRef *ref);

View file

@ -157,63 +157,17 @@ typedef struct {
/**
* SpaProps:
* @n_prop_info: number of elements in @prop_info
* @prop_info: array of #SpaPropInfo. Contains info about the
* properties. Can be %NULL when unspecified.
*
* Generic propertiers.
*/
struct _SpaProps {
/**
* SpaProps::n_prop_info:
*
* The number of items in @prop_info.
*/
unsigned int n_prop_info;
/**
* SpaProps::prop_info:
*
* Info about the properties. Can be %NULL when unspecified.
*/
unsigned int n_prop_info;
const SpaPropInfo *prop_info;
/**
* SpaProps::set_prop
* @props: a #SpaProps
* @index: the index of the property in the prop_info array
* @value: the value to set
*
* Sets @value in @prop. type should match the type specified
* in the #SpaPropInfo at @index or else #SPA_RESULT_WRONG_PROPERTY_TYPE
* is returned.
*
* Returns: #SPA_RESULT_OK on success.
* #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid
* #SPA_RESULT_WRONG_PROPERTY_TYPE when type is not correct
*/
SpaResult (*set_prop) (SpaProps *props,
unsigned int index,
const SpaPropValue *value);
/**
* SpaProps::get_prop
* @props: a #SpaProps
* @index: the property index in the prop_info array
* @value: a location for the type, size and value
*
* Get the type, size and value of the property at @index.
*
* Returns: #SPA_RESULT_OK on success.
* #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid
* #SPA_RESULT_PROPERTY_UNSET when no value has been set yet
*/
SpaResult (*get_prop) (const SpaProps *props,
unsigned int index,
SpaPropValue *value);
void *priv;
};
#define spa_props_set_prop(p,...) (p)->set_prop((p),__VA_ARGS__)
#define spa_props_get_prop(p,...) (p)->get_prop((p),__VA_ARGS__)
static inline unsigned int
spa_props_index_for_id (const SpaProps *props, uint32_t id)
{
@ -239,15 +193,41 @@ spa_props_index_for_name (const SpaProps *props, const char *name)
}
SpaResult spa_props_generic_set_prop (SpaProps *props,
unsigned int index,
const SpaPropValue *value);
SpaResult spa_props_generic_get_prop (const SpaProps *props,
unsigned int index,
SpaPropValue *value);
/**
* spa_props_set_prop:
* @props: a #SpaProps
* @index: the index of the property in the prop_info array
* @value: the value to set
*
* Sets @value in @prop. type should match the type specified
* in the #SpaPropInfo at @index or else #SPA_RESULT_WRONG_PROPERTY_TYPE
* is returned.
*
* Returns: #SPA_RESULT_OK on success.
* #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid
* #SPA_RESULT_WRONG_PROPERTY_TYPE when type is not correct
*/
SpaResult spa_props_set_prop (SpaProps *props,
unsigned int index,
const SpaPropValue *value);
/**
* spa_props_get_prop:
* @props: a #SpaProps
* @index: the property index in the prop_info array
* @value: a location for the type, size and value
*
* Get the type, size and value of the property at @index.
*
* Returns: #SPA_RESULT_OK on success.
* #SPA_RESULT_INVALID_PROPERTY_INDEX when @index is not valid
* #SPA_RESULT_PROPERTY_UNSET when no value has been set yet
*/
SpaResult spa_props_get_prop (const SpaProps *props,
unsigned int index,
SpaPropValue *value);
SpaResult spa_props_copy (const SpaProps *src,
SpaProps *dest);
SpaResult spa_props_copy (const SpaProps *src,
SpaProps *dest);
#ifdef __cplusplus