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

@ -600,6 +600,8 @@ parse_control (PinosStream *stream,
priv->format = g_bytes_new_static (str, strlen (str)+1); priv->format = g_bytes_new_static (str, strlen (str)+1);
g_object_notify (G_OBJECT (stream), "format"); g_object_notify (G_OBJECT (stream), "format");
spa_format_unref (p.format);
/* FIXME send update port status */ /* FIXME send update port status */
/* send state-change */ /* send state-change */

View file

@ -138,6 +138,8 @@ struct _SpaBuffer {
#define SPA_BUFFER_METAS(b) (SPA_MEMBER ((b), (b)->metas, SpaMeta)) #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_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 #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View file

@ -28,6 +28,7 @@ typedef struct _SpaFormat SpaFormat;
#include <spa/defs.h> #include <spa/defs.h>
#include <spa/props.h> #include <spa/props.h>
#include <spa/memory.h>
typedef enum { typedef enum {
SPA_MEDIA_TYPE_INVALID = 0, SPA_MEDIA_TYPE_INVALID = 0,
@ -55,12 +56,23 @@ typedef enum {
SPA_MEDIA_SUBTYPE_BAYER = 15, SPA_MEDIA_SUBTYPE_BAYER = 15,
} SpaMediaSubType; } SpaMediaSubType;
/**
* SpaFormat:
* @props: properties
* @media_type: media type
* @media_subtype: subtype
* @mem: memory reference
*/
struct _SpaFormat { struct _SpaFormat {
SpaProps props; SpaProps props;
SpaMediaType media_type; SpaMediaType media_type;
SpaMediaSubType media_subtype; 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 { typedef enum {
SPA_PROP_ID_INVALID = 0, SPA_PROP_ID_INVALID = 0,
SPA_PROP_ID_MEDIA_CUSTOM_START = 200, SPA_PROP_ID_MEDIA_CUSTOM_START = 200,

View file

@ -58,6 +58,7 @@ struct _SpaMemoryRef {
* SpaMemory: * SpaMemory:
* @refcount: a refcount * @refcount: a refcount
* @notify: notify when refcount is 0 * @notify: notify when refcount is 0
* @user_data: owner specific used data
* @pool_id: the id of the pool * @pool_id: the id of the pool
* @id: the memory id * @id: the memory id
* @flags: extra memory flags * @flags: extra memory flags
@ -69,6 +70,7 @@ struct _SpaMemoryRef {
struct _SpaMemory { struct _SpaMemory {
int refcount; int refcount;
SpaNotify notify; SpaNotify notify;
void *user_data;
SpaMemoryRef mem; SpaMemoryRef mem;
SpaMemoryFlags flags; SpaMemoryFlags flags;
const char *type; const char *type;
@ -77,6 +79,9 @@ struct _SpaMemory {
size_t size; size_t size;
}; };
#define SPA_MEMORY_POOL_SHARED 0
#define SPA_MEMORY_POOL_LOCAL 1
void spa_memory_init (void); void spa_memory_init (void);
uint32_t spa_memory_pool_get (uint32_t type); 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); void spa_memory_pool_free (uint32_t);
SpaMemory * spa_memory_alloc (uint32_t pool_id); 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); 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_import (SpaMemoryRef *ref);
SpaMemory * spa_memory_find (SpaMemoryRef *ref); SpaMemory * spa_memory_find (SpaMemoryRef *ref);

View file

@ -157,63 +157,17 @@ typedef struct {
/** /**
* SpaProps: * 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. * Generic propertiers.
*/ */
struct _SpaProps { struct _SpaProps {
/**
* SpaProps::n_prop_info:
*
* The number of items in @prop_info.
*/
unsigned int n_prop_info; unsigned int n_prop_info;
/**
* SpaProps::prop_info:
*
* Info about the properties. Can be %NULL when unspecified.
*/
const SpaPropInfo *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 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)
{ {
@ -239,10 +193,36 @@ spa_props_index_for_name (const SpaProps *props, const char *name)
} }
SpaResult spa_props_generic_set_prop (SpaProps *props, /**
* 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, unsigned int index,
const SpaPropValue *value); const SpaPropValue *value);
SpaResult spa_props_generic_get_prop (const SpaProps *props, /**
* 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, unsigned int index,
SpaPropValue *value); SpaPropValue *value);

View file

@ -209,8 +209,6 @@ spa_audio_raw_format_init (SpaAudioRawFormat *format)
format->format.media_subtype = SPA_MEDIA_SUBTYPE_RAW; format->format.media_subtype = SPA_MEDIA_SUBTYPE_RAW;
format->format.props.n_prop_info = SPA_N_ELEMENTS (raw_format_prop_info); format->format.props.n_prop_info = SPA_N_ELEMENTS (raw_format_prop_info);
format->format.props.prop_info = raw_format_prop_info; format->format.props.prop_info = raw_format_prop_info;
format->format.props.set_prop = spa_props_generic_set_prop;
format->format.props.get_prop = spa_props_generic_get_prop;
format->unset_mask = (1 << 0) | (1 << 2) | (1 << 3) | (1 << 4); format->unset_mask = (1 << 0) | (1 << 2) | (1 << 3) | (1 << 4);
format->info = default_info; format->info = default_info;
@ -235,7 +233,7 @@ spa_audio_raw_format_parse (const SpaFormat *format,
spa_audio_raw_format_init (rawformat); spa_audio_raw_format_init (rawformat);
props = &format->props; props = &format->props;
if ((res = props->get_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_RAW_INFO), &value)) < 0) if ((res = spa_props_get_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_RAW_INFO), &value)) < 0)
goto fallback; goto fallback;
if (value.type != SPA_PROP_TYPE_POINTER || value.size != sizeof (SpaAudioRawInfo)) if (value.type != SPA_PROP_TYPE_POINTER || value.size != sizeof (SpaAudioRawInfo))

View file

@ -348,16 +348,15 @@ iter_parse_set_format (struct stack_iter *si, SpaControlCmdSetFormat *cmd)
unsigned int i, j; unsigned int i, j;
SpaPropInfo *pi; SpaPropInfo *pi;
SpaPropRangeInfo *ri; SpaPropRangeInfo *ri;
SpaMemory *mem;
cmd->port_id = *p++; cmd->port_id = *p++;
cmd->format = malloc (si->size - 4); mem = spa_memory_alloc_size (SPA_MEMORY_POOL_LOCAL, p, si->size - 4);
memcpy (cmd->format, p, si->size - 4); cmd->format = spa_memory_ensure_ptr (mem);
cmd->format->mem = mem->mem;
tp = (SpaProps *) &cmd->format->props; tp = (SpaProps *) &cmd->format->props;
tp->prop_info = SPA_MEMBER (tp, SPA_PTR_TO_INT (tp->prop_info), SpaPropInfo); tp->prop_info = SPA_MEMBER (tp, SPA_PTR_TO_INT (tp->prop_info), SpaPropInfo);
tp->set_prop = spa_props_generic_set_prop;
tp->get_prop = spa_props_generic_get_prop;
tp->priv = NULL;
/* now fix all the pointers */ /* now fix all the pointers */
for (i = 0; i < tp->n_prop_info; i++) { for (i = 0; i < tp->n_prop_info; i++) {
@ -764,13 +763,10 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf)
tp = SPA_MEMBER (tf, offsetof (SpaFormat, props), SpaProps); tp = SPA_MEMBER (tf, offsetof (SpaFormat, props), SpaProps);
tp->n_prop_info = sp->n_prop_info; tp->n_prop_info = sp->n_prop_info;
tp->prop_info = SPA_INT_TO_PTR (sizeof (SpaFormat) + sizeof (uint32_t)); tp->prop_info = SPA_INT_TO_PTR (sizeof (SpaProps) + sizeof (uint32_t));
tp->set_prop = NULL;
tp->get_prop = NULL;
tp->priv = NULL;
/* write propinfo array, adjust offset of mask */ /* write propinfo array, adjust offset of mask */
bpi = pi = (SpaPropInfo *) ((uint8_t *)tp + sizeof (SpaFormat) + sizeof (uint32_t)); bpi = pi = (SpaPropInfo *) ((uint8_t *)tp + sizeof (SpaProps) + sizeof (uint32_t));
for (i = 0; i < tp->n_prop_info; i++) { for (i = 0; i < tp->n_prop_info; i++) {
memcpy (pi, &sp->prop_info[i], sizeof (SpaPropInfo)); memcpy (pi, &sp->prop_info[i], sizeof (SpaPropInfo));
pi->mask_offset = sizeof (SpaFormat); pi->mask_offset = sizeof (SpaFormat);
@ -781,7 +777,7 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf)
pi = bpi; pi = bpi;
/* write range info arrays, adjust offset to it */ /* write range info arrays, adjust offset to it */
for (i = 0; i < tp->n_prop_info; i++) { for (i = 0; i < tp->n_prop_info; i++) {
pi->range_values = SPA_INT_TO_PTR (SPA_PTRDIFF (ri, tf)); pi->range_values = SPA_INT_TO_PTR (SPA_PTRDIFF (ri, tp));
for (j = 0; j < pi->n_range_values; j++) { for (j = 0; j < pi->n_range_values; j++) {
memcpy (ri, &sp->prop_info[i].range_values[j], sizeof (SpaPropRangeInfo)); memcpy (ri, &sp->prop_info[i].range_values[j], sizeof (SpaPropRangeInfo));
ri++; ri++;
@ -796,7 +792,7 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf)
if (pi->name) { if (pi->name) {
slen = strlen (pi->name) + 1; slen = strlen (pi->name) + 1;
memcpy (p, pi->name, slen); memcpy (p, pi->name, slen);
pi->name = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tf)); pi->name = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
p += slen; p += slen;
} else { } else {
pi->name = 0; pi->name = 0;
@ -804,14 +800,14 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf)
if (pi->description) { if (pi->description) {
slen = strlen (pi->description) + 1; slen = strlen (pi->description) + 1;
memcpy (p, pi->description, slen); memcpy (p, pi->description, slen);
pi->description = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tf)); pi->description = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
p += slen; p += slen;
} else { } else {
pi->description = 0; pi->description = 0;
} }
if (pi->default_value) { if (pi->default_value) {
memcpy (p, pi->default_value, pi->default_size); memcpy (p, pi->default_value, pi->default_size);
pi->default_value = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tf)); pi->default_value = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
p += pi->default_size; p += pi->default_size;
} else { } else {
pi->default_value = 0; pi->default_value = 0;
@ -820,7 +816,7 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf)
if (ri->name) { if (ri->name) {
slen = strlen (ri->name) + 1; slen = strlen (ri->name) + 1;
memcpy (p, ri->name, slen); memcpy (p, ri->name, slen);
ri->name = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tf)); ri->name = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
p += slen; p += slen;
} else { } else {
ri->name = 0; ri->name = 0;
@ -828,14 +824,14 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf)
if (ri->description) { if (ri->description) {
slen = strlen (ri->description) + 1; slen = strlen (ri->description) + 1;
memcpy (p, ri->description, slen); memcpy (p, ri->description, slen);
ri->description = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tf)); ri->description = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
p += slen; p += slen;
} else { } else {
ri->description = 0; ri->description = 0;
} }
if (ri->size) { if (ri->size) {
memcpy (p, ri->value, ri->size); memcpy (p, ri->value, ri->size);
ri->value = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tf)); ri->value = SPA_INT_TO_PTR (SPA_PTRDIFF (p, tp));
p += ri->size; p += ri->size;
} else { } else {
ri->value = 0; ri->value = 0;
@ -849,7 +845,7 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf)
for (i = 0; i < tp->n_prop_info; i++) { for (i = 0; i < tp->n_prop_info; i++) {
if (pi->offset) { if (pi->offset) {
memcpy (p, SPA_MEMBER (sp, pi->offset, void), pi->maxsize); memcpy (p, SPA_MEMBER (sp, pi->offset, void), pi->maxsize);
pi->offset = SPA_PTRDIFF (p, tf); pi->offset = SPA_PTRDIFF (p, tp);
p += pi->maxsize; p += pi->maxsize;
} else { } else {
pi->offset = 0; pi->offset = 0;

View file

@ -335,7 +335,7 @@ spa_debug_props (const SpaProps *props, bool print_ranges)
else else
fprintf (stderr, "None"); fprintf (stderr, "None");
res = props->get_prop (props, i, &value); res = spa_props_get_prop (props, i, &value);
fprintf (stderr, ". Current: "); fprintf (stderr, ". Current: ");
if (res == SPA_RESULT_OK) if (res == SPA_RESULT_OK)
@ -407,7 +407,7 @@ spa_debug_format (const SpaFormat *format)
SpaPropValue value; SpaPropValue value;
SpaResult res; SpaResult res;
res = props->get_prop (props, i, &value); res = spa_props_get_prop (props, i, &value);
if (res == SPA_RESULT_PROPERTY_UNSET && info->flags & SPA_PROP_FLAG_OPTIONAL) if (res == SPA_RESULT_PROPERTY_UNSET && info->flags & SPA_PROP_FLAG_OPTIONAL)
continue; continue;

View file

@ -62,7 +62,8 @@ spa_memory_init (void)
static bool initialized = false; static bool initialized = false;
if (!initialized) { if (!initialized) {
spa_memory_pool_init (&pools[0], 0); spa_memory_pool_init (&pools[0], SPA_MEMORY_POOL_SHARED);
spa_memory_pool_init (&pools[1], SPA_MEMORY_POOL_LOCAL);
initialized = true; initialized = true;
} }
} }
@ -114,12 +115,31 @@ spa_memory_alloc (uint32_t pool_id)
mem = &pool->memories[id]; mem = &pool->memories[id];
mem->refcount = 1; mem->refcount = 1;
mem->notify = NULL; mem->notify = NULL;
mem->fd = -1;
mem->ptr = NULL;
mem->mem.pool_id = pool_id; mem->mem.pool_id = pool_id;
mem->mem.id = id; mem->mem.id = id;
return mem; return mem;
} }
SpaMemory *
spa_memory_alloc_size (uint32_t pool_id, void *data, size_t size)
{
SpaMemory *mem;
if (!(mem = spa_memory_alloc (pool_id)))
return NULL;
mem->flags = SPA_MEMORY_FLAG_READWRITE;
mem->ptr = malloc (size);
mem->size = size;
if (data)
memcpy (mem->ptr, data, size);
return mem;
}
SpaMemory * SpaMemory *
spa_memory_alloc_with_fd (uint32_t pool_id, void *data, size_t size) spa_memory_alloc_with_fd (uint32_t pool_id, void *data, size_t size)
{ {
@ -151,13 +171,11 @@ spa_memory_alloc_with_fd (uint32_t pool_id, void *data, size_t size)
} }
mem->flags = SPA_MEMORY_FLAG_READWRITE; mem->flags = SPA_MEMORY_FLAG_READWRITE;
mem->ptr = NULL;
mem->size = size; mem->size = size;
return mem; return mem;
} }
SpaMemory * SpaMemory *
spa_memory_import (SpaMemoryRef *ref) spa_memory_import (SpaMemoryRef *ref)
{ {
@ -189,22 +207,56 @@ spa_memory_import (SpaMemoryRef *ref)
mem->refcount = 1; mem->refcount = 1;
mem->notify = NULL; mem->notify = NULL;
mem->mem = *ref; mem->mem = *ref;
mem->ptr = NULL;
mem->fd = -1;
} }
return mem; return mem;
} }
SpaResult SpaResult
spa_memory_free (SpaMemoryRef *ref) spa_memory_ref (SpaMemoryRef *ref)
{
SpaMemory *mem;
if (!(mem = spa_memory_find (ref)))
return SPA_RESULT_ERROR;
mem->refcount++;
return SPA_RESULT_OK;
}
static void
spa_memory_free (SpaMemory *mem)
{ {
SpaMemoryPool *pool; SpaMemoryPool *pool;
if (ref == NULL || ref->pool_id >= MAX_POOLS || !pools[ref->pool_id].valid) if (mem->fd != -1) {
return SPA_RESULT_INVALID_ARGUMENTS; if (mem->ptr)
munmap (mem->ptr, mem->size);
pool = &pools[ref->pool_id]; close (mem->fd);
pool->free_mem[pool->n_free] = ref->id; }
pool = &pools[mem->mem.pool_id];
pool->free_mem[pool->n_free] = mem->mem.id;
pool->n_free++; pool->n_free++;
}
SpaResult
spa_memory_unref (SpaMemoryRef *ref)
{
SpaMemory *mem;
if (!(mem = spa_memory_find (ref)))
return SPA_RESULT_ERROR;
if (--mem->refcount == 0) {
if (mem->notify)
mem->notify (mem);
if (mem->refcount == 0)
spa_memory_free (mem);
}
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }

View file

@ -25,7 +25,7 @@
#include <spa/props.h> #include <spa/props.h>
SpaResult SpaResult
spa_props_generic_set_prop (SpaProps *props, spa_props_set_prop (SpaProps *props,
unsigned int index, unsigned int index,
const SpaPropValue *value) const SpaPropValue *value)
{ {
@ -56,7 +56,7 @@ spa_props_generic_set_prop (SpaProps *props,
SpaResult SpaResult
spa_props_generic_get_prop (const SpaProps *props, spa_props_get_prop (const SpaProps *props,
unsigned int index, unsigned int index,
SpaPropValue *value) SpaPropValue *value)
{ {
@ -100,7 +100,7 @@ spa_props_copy (const SpaProps *src,
if (!(info->flags & SPA_PROP_FLAG_WRITABLE)) if (!(info->flags & SPA_PROP_FLAG_WRITABLE))
continue; continue;
if ((res = src->get_prop (src, spa_props_index_for_id (src, info->id), &value)) < 0) if ((res = spa_props_get_prop (src, spa_props_index_for_id (src, info->id), &value)) < 0)
continue; continue;
if (value.type != info->type) if (value.type != info->type)
return SPA_RESULT_WRONG_PROPERTY_TYPE; return SPA_RESULT_WRONG_PROPERTY_TYPE;

View file

@ -483,8 +483,6 @@ spa_video_raw_format_init (SpaVideoRawFormat *format)
format->format.media_subtype = SPA_MEDIA_SUBTYPE_RAW; format->format.media_subtype = SPA_MEDIA_SUBTYPE_RAW;
format->format.props.n_prop_info = SPA_N_ELEMENTS (raw_format_prop_info); format->format.props.n_prop_info = SPA_N_ELEMENTS (raw_format_prop_info);
format->format.props.prop_info = raw_format_prop_info; format->format.props.prop_info = raw_format_prop_info;
format->format.props.set_prop = spa_props_generic_set_prop;
format->format.props.get_prop = spa_props_generic_get_prop;
format->unset_mask = (1 << 14)-1; format->unset_mask = (1 << 14)-1;
format->info = default_info; format->info = default_info;
@ -509,7 +507,7 @@ spa_video_raw_format_parse (const SpaFormat *format,
spa_video_raw_format_init (rawformat); spa_video_raw_format_init (rawformat);
props = &format->props; props = &format->props;
if ((res = props->get_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_VIDEO_RAW_INFO), &value)) < 0) if ((res = spa_props_get_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_VIDEO_RAW_INFO), &value)) < 0)
goto fallback; goto fallback;
if (value.type != SPA_PROP_TYPE_POINTER || value.size != sizeof (SpaVideoRawInfo)) if (value.type != SPA_PROP_TYPE_POINTER || value.size != sizeof (SpaVideoRawInfo))

View file

@ -633,8 +633,6 @@ alsa_sink_init (const SpaHandleFactory *factory,
this->node.handle = handle; this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST; this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info; this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_alsa_sink_props (&this->props[1]); reset_alsa_sink_props (&this->props[1]);
this->info.flags = SPA_PORT_INFO_FLAG_NONE; this->info.flags = SPA_PORT_INFO_FLAG_NONE;

View file

@ -795,8 +795,6 @@ spa_audiomixer_init (const SpaHandleFactory *factory,
this->node.handle = handle; this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST; this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info; this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_audiomixer_props (&this->props[1]); reset_audiomixer_props (&this->props[1]);
this->ports[0].valid = true; this->ports[0].valid = true;

View file

@ -583,8 +583,6 @@ audiotestsrc_init (const SpaHandleFactory *factory,
this->node.handle = handle; this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST; this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info; this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_audiotestsrc_props (&this->props[1]); reset_audiotestsrc_props (&this->props[1]);
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFER | this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFER |

View file

@ -574,8 +574,6 @@ spa_ffmpeg_dec_init (SpaHandle *handle)
this->node.handle = handle; this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST; this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info; this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_ffmpeg_dec_props (&this->props[1]); reset_ffmpeg_dec_props (&this->props[1]);
this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE; this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;

View file

@ -574,8 +574,6 @@ spa_ffmpeg_enc_init (SpaHandle *handle)
this->node.handle = handle; this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST; this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info; this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_ffmpeg_enc_props (&this->props[1]); reset_ffmpeg_enc_props (&this->props[1]);
this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE; this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE;

View file

@ -565,7 +565,7 @@ add_buffer (SpaProxy *this, uint32_t port_id, SpaBuffer *buffer)
if (buffer->mem.id == SPA_ID_INVALID) { if (buffer->mem.id == SPA_ID_INVALID) {
fprintf (stderr, "proxy %p: alloc buffer space\n", this); fprintf (stderr, "proxy %p: alloc buffer space\n", this);
bmem = spa_memory_alloc_with_fd (0, buffer, buffer->size); bmem = spa_memory_alloc_with_fd (SPA_MEMORY_POOL_SHARED, buffer, buffer->size);
b = spa_memory_ensure_ptr (bmem); b = spa_memory_ensure_ptr (bmem);
b->mem = bmem->mem; b->mem = bmem->mem;
b->offset = 0; b->offset = 0;
@ -1021,8 +1021,6 @@ proxy_instantiate (const SpaHandleFactory *factory,
this->node.handle = handle; this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST; this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info; this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_proxy_props (&this->props[1]); reset_proxy_props (&this->props[1]);
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1])); memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));

View file

@ -343,8 +343,6 @@ spa_v4l2_format_init (V4l2Format *f)
{ {
f->fmt.props.n_prop_info = 3; f->fmt.props.n_prop_info = 3;
f->fmt.props.prop_info = f->infos; f->fmt.props.prop_info = f->infos;
f->fmt.props.set_prop = spa_props_generic_set_prop;
f->fmt.props.get_prop = spa_props_generic_get_prop;
spa_video_raw_fill_prop_info (&f->infos[0], spa_video_raw_fill_prop_info (&f->infos[0],
SPA_PROP_ID_VIDEO_FORMAT, SPA_PROP_ID_VIDEO_FORMAT,
@ -716,8 +714,6 @@ v4l2_source_init (const SpaHandleFactory *factory,
this->node.handle = handle; this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST; this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info; this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_v4l2_source_props (&this->props[1]); reset_v4l2_source_props (&this->props[1]);
this->state[0].info.flags = SPA_PORT_INFO_FLAG_NONE; this->state[0].info.flags = SPA_PORT_INFO_FLAG_NONE;

View file

@ -279,8 +279,6 @@ again:
fmt->fmt.media_subtype = info->media_subtype; fmt->fmt.media_subtype = info->media_subtype;
fmt->fmt.props.prop_info = fmt->infos; fmt->fmt.props.prop_info = fmt->infos;
fmt->fmt.props.n_prop_info = pi = 0; fmt->fmt.props.n_prop_info = pi = 0;
fmt->fmt.props.set_prop = spa_props_generic_set_prop;
fmt->fmt.props.get_prop = spa_props_generic_get_prop;
fmt->unset_mask = 0; fmt->unset_mask = 0;
if (info->media_subtype == SPA_MEDIA_SUBTYPE_RAW) { if (info->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
@ -526,8 +524,10 @@ spa_v4l2_import_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_bu
state->reqbuf = reqbuf; state->reqbuf = reqbuf;
if (state->alloc_mem) if (state->alloc_mem)
spa_memory_free (&state->alloc_mem->mem); spa_memory_unref (&state->alloc_mem->mem);
state->alloc_mem = spa_memory_alloc_with_fd (0, NULL, sizeof (V4l2Buffer) * reqbuf.count); state->alloc_mem = spa_memory_alloc_with_fd (SPA_MEMORY_POOL_SHARED,
NULL,
sizeof (V4l2Buffer) * reqbuf.count);
state->alloc_buffers = spa_memory_ensure_ptr (state->alloc_mem); state->alloc_buffers = spa_memory_ensure_ptr (state->alloc_mem);
for (i = 0; i < reqbuf.count; i++) { for (i = 0; i < reqbuf.count; i++) {
@ -602,8 +602,10 @@ mmap_init (SpaV4l2Source *this,
state->reqbuf = reqbuf; state->reqbuf = reqbuf;
if (state->alloc_mem) if (state->alloc_mem)
spa_memory_free (&state->alloc_mem->mem); spa_memory_unref (&state->alloc_mem->mem);
state->alloc_mem = spa_memory_alloc_with_fd (0, NULL, sizeof (V4l2Buffer) * reqbuf.count); state->alloc_mem = spa_memory_alloc_with_fd (SPA_MEMORY_POOL_SHARED,
NULL,
sizeof (V4l2Buffer) * reqbuf.count);
state->alloc_buffers = spa_memory_ensure_ptr (state->alloc_mem); state->alloc_buffers = spa_memory_ensure_ptr (state->alloc_mem);
for (i = 0; i < reqbuf.count; i++) { for (i = 0; i < reqbuf.count; i++) {
@ -643,7 +645,7 @@ mmap_init (SpaV4l2Source *this,
b->metas[0].offset = offsetof (V4l2Buffer, header); b->metas[0].offset = offsetof (V4l2Buffer, header);
b->metas[0].size = sizeof (b->header); b->metas[0].size = sizeof (b->header);
mem = spa_memory_alloc (0); mem = spa_memory_alloc (SPA_MEMORY_POOL_SHARED);
mem->flags = SPA_MEMORY_FLAG_READABLE; mem->flags = SPA_MEMORY_FLAG_READABLE;
mem->size = buf.length; mem->size = buf.length;
b->datas[0].mem = mem->mem; b->datas[0].mem = mem->mem;
@ -801,7 +803,7 @@ spa_v4l2_stop (SpaV4l2Source *this)
} else { } else {
munmap (mem->ptr, mem->size); munmap (mem->ptr, mem->size);
} }
spa_memory_free (&mem->mem); spa_memory_unref (&mem->mem);
} }
state->have_buffers = false; state->have_buffers = false;

View file

@ -693,8 +693,6 @@ volume_instantiate (const SpaHandleFactory *factory,
this->node.handle = handle; this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST; this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info; this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_volume_props (&this->props[1]); reset_volume_props (&this->props[1]);
this->ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFER | this->ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFER |

View file

@ -573,8 +573,6 @@ xv_sink_init (const SpaHandleFactory *factory,
this->node.handle = handle; this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST; this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info; this->props[1].props.prop_info = prop_info;
this->props[1].props.set_prop = spa_props_generic_set_prop;
this->props[1].props.get_prop = spa_props_generic_get_prop;
reset_xv_sink_props (&this->props[1]); reset_xv_sink_props (&this->props[1]);
this->info.flags = SPA_PORT_INFO_FLAG_NONE; this->info.flags = SPA_PORT_INFO_FLAG_NONE;

View file

@ -199,7 +199,7 @@ make_nodes (AppData *data)
value.type = SPA_PROP_TYPE_STRING; value.type = SPA_PROP_TYPE_STRING;
value.value = "hw:0"; value.value = "hw:0";
value.size = strlen (value.value)+1; value.size = strlen (value.value)+1;
props->set_prop (props, spa_props_index_for_name (props, "device"), &value); spa_props_set_prop (props, spa_props_index_for_name (props, "device"), &value);
if ((res = spa_node_set_props (data->sink, props)) < 0) if ((res = spa_node_set_props (data->sink, props)) < 0)
printf ("got set_props error %d\n", res); printf ("got set_props error %d\n", res);
@ -242,16 +242,16 @@ negotiate_formats (AppData *data)
value.value = &val; value.value = &val;
val = SPA_AUDIO_FORMAT_S16LE; val = SPA_AUDIO_FORMAT_S16LE;
if ((res = props->set_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_FORMAT), &value)) < 0) if ((res = spa_props_set_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_FORMAT), &value)) < 0)
return res; return res;
val = 1; val = 1;
if ((res = props->set_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_LAYOUT), &value)) < 0) if ((res = spa_props_set_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_LAYOUT), &value)) < 0)
return res; return res;
val = 44100; val = 44100;
if ((res = props->set_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_RATE), &value)) < 0) if ((res = spa_props_set_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_RATE), &value)) < 0)
return res; return res;
val = 2; val = 2;
if ((res = props->set_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_CHANNELS), &value)) < 0) if ((res = spa_props_set_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_AUDIO_CHANNELS), &value)) < 0)
return res; return res;
if ((res = spa_node_port_set_format (data->sink, 0, false, format)) < 0) if ((res = spa_node_port_set_format (data->sink, 0, false, format)) < 0)

View file

@ -275,7 +275,7 @@ alloc_buffers (AppData *data)
b->metas[1].offset = offsetof (SDLBuffer, ptr); b->metas[1].offset = offsetof (SDLBuffer, ptr);
b->metas[1].size = sizeof (b->ptr); b->metas[1].size = sizeof (b->ptr);
mem = spa_memory_alloc (0); mem = spa_memory_alloc (SPA_MEMORY_POOL_LOCAL);
mem->flags = SPA_MEMORY_FLAG_READWRITE; mem->flags = SPA_MEMORY_FLAG_READWRITE;
mem->type = "sysmem"; mem->type = "sysmem";
mem->fd = -1; mem->fd = -1;
@ -317,8 +317,6 @@ negotiate_formats (AppData *data)
f.fmt.media_subtype = SPA_MEDIA_SUBTYPE_RAW; f.fmt.media_subtype = SPA_MEDIA_SUBTYPE_RAW;
f.fmt.props.n_prop_info = 3; f.fmt.props.n_prop_info = 3;
f.fmt.props.prop_info = f.infos; f.fmt.props.prop_info = f.infos;
f.fmt.props.set_prop = spa_props_generic_set_prop;
f.fmt.props.get_prop = spa_props_generic_get_prop;
spa_video_raw_fill_prop_info (&f.infos[0], spa_video_raw_fill_prop_info (&f.infos[0],
SPA_PROP_ID_VIDEO_FORMAT, SPA_PROP_ID_VIDEO_FORMAT,