From dd1fbef28f64b426b81382607082555d3ccf0451 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 4 Aug 2016 19:24:16 +0200 Subject: [PATCH] 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. --- pinos/client/stream.c | 2 + spa/include/spa/buffer.h | 2 + spa/include/spa/format.h | 12 ++++ spa/include/spa/memory.h | 10 ++- spa/include/spa/props.h | 96 ++++++++++--------------- spa/lib/audio-raw.c | 4 +- spa/lib/control.c | 32 ++++----- spa/lib/debug.c | 4 +- spa/lib/memory.c | 70 +++++++++++++++--- spa/lib/props.c | 14 ++-- spa/lib/video-raw.c | 4 +- spa/plugins/alsa/alsa-sink.c | 2 - spa/plugins/audiomixer/audiomixer.c | 2 - spa/plugins/audiotestsrc/audiotestsrc.c | 2 - spa/plugins/ffmpeg/ffmpeg-dec.c | 2 - spa/plugins/ffmpeg/ffmpeg-enc.c | 2 - spa/plugins/remote/proxy.c | 4 +- spa/plugins/v4l2/v4l2-source.c | 4 -- spa/plugins/v4l2/v4l2-utils.c | 18 ++--- spa/plugins/volume/volume.c | 2 - spa/plugins/xv/xv-sink.c | 2 - spa/tests/test-mixer.c | 10 +-- spa/tests/test-v4l2.c | 4 +- 23 files changed, 166 insertions(+), 138 deletions(-) diff --git a/pinos/client/stream.c b/pinos/client/stream.c index e80d9f26f..649489881 100644 --- a/pinos/client/stream.c +++ b/pinos/client/stream.c @@ -600,6 +600,8 @@ parse_control (PinosStream *stream, priv->format = g_bytes_new_static (str, strlen (str)+1); g_object_notify (G_OBJECT (stream), "format"); + spa_format_unref (p.format); + /* FIXME send update port status */ /* send state-change */ diff --git a/spa/include/spa/buffer.h b/spa/include/spa/buffer.h index a5609fd11..f8bc70b5f 100644 --- a/spa/include/spa/buffer.h +++ b/spa/include/spa/buffer.h @@ -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" */ diff --git a/spa/include/spa/format.h b/spa/include/spa/format.h index 3f88ad94d..8f8a44a47 100644 --- a/spa/include/spa/format.h +++ b/spa/include/spa/format.h @@ -28,6 +28,7 @@ typedef struct _SpaFormat SpaFormat; #include #include +#include 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, diff --git a/spa/include/spa/memory.h b/spa/include/spa/memory.h index d1e2c1423..13f1e32e7 100644 --- a/spa/include/spa/memory.h +++ b/spa/include/spa/memory.h @@ -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); diff --git a/spa/include/spa/props.h b/spa/include/spa/props.h index 5c81aeb03..41e303b0e 100644 --- a/spa/include/spa/props.h +++ b/spa/include/spa/props.h @@ -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 diff --git a/spa/lib/audio-raw.c b/spa/lib/audio-raw.c index e75672314..0dbef8633 100644 --- a/spa/lib/audio-raw.c +++ b/spa/lib/audio-raw.c @@ -209,8 +209,6 @@ spa_audio_raw_format_init (SpaAudioRawFormat *format) format->format.media_subtype = SPA_MEDIA_SUBTYPE_RAW; 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.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->info = default_info; @@ -235,7 +233,7 @@ spa_audio_raw_format_parse (const SpaFormat *format, spa_audio_raw_format_init (rawformat); 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; if (value.type != SPA_PROP_TYPE_POINTER || value.size != sizeof (SpaAudioRawInfo)) diff --git a/spa/lib/control.c b/spa/lib/control.c index 27d48542b..e0399c2fa 100644 --- a/spa/lib/control.c +++ b/spa/lib/control.c @@ -348,16 +348,15 @@ iter_parse_set_format (struct stack_iter *si, SpaControlCmdSetFormat *cmd) unsigned int i, j; SpaPropInfo *pi; SpaPropRangeInfo *ri; + SpaMemory *mem; cmd->port_id = *p++; - cmd->format = malloc (si->size - 4); - memcpy (cmd->format, p, si->size - 4); + mem = spa_memory_alloc_size (SPA_MEMORY_POOL_LOCAL, p, si->size - 4); + cmd->format = spa_memory_ensure_ptr (mem); + cmd->format->mem = mem->mem; tp = (SpaProps *) &cmd->format->props; 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 */ 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->n_prop_info = sp->n_prop_info; - tp->prop_info = SPA_INT_TO_PTR (sizeof (SpaFormat) + sizeof (uint32_t)); - tp->set_prop = NULL; - tp->get_prop = NULL; - tp->priv = NULL; + tp->prop_info = SPA_INT_TO_PTR (sizeof (SpaProps) + sizeof (uint32_t)); /* 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++) { memcpy (pi, &sp->prop_info[i], sizeof (SpaPropInfo)); pi->mask_offset = sizeof (SpaFormat); @@ -781,7 +777,7 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf) pi = bpi; /* write range info arrays, adjust offset to it */ 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++) { memcpy (ri, &sp->prop_info[i].range_values[j], sizeof (SpaPropRangeInfo)); ri++; @@ -796,7 +792,7 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf) if (pi->name) { slen = strlen (pi->name) + 1; 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; } else { pi->name = 0; @@ -804,14 +800,14 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf) if (pi->description) { slen = strlen (pi->description) + 1; 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; } else { pi->description = 0; } if (pi->default_value) { 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; } else { pi->default_value = 0; @@ -820,7 +816,7 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf) if (ri->name) { slen = strlen (ri->name) + 1; 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; } else { ri->name = 0; @@ -828,14 +824,14 @@ builder_add_set_format (struct stack_builder *sb, SpaControlCmdSetFormat *sf) if (ri->description) { slen = strlen (ri->description) + 1; 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; } else { ri->description = 0; } if (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; } else { 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++) { if (pi->offset) { 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; } else { pi->offset = 0; diff --git a/spa/lib/debug.c b/spa/lib/debug.c index c412e1f77..e96d875ab 100644 --- a/spa/lib/debug.c +++ b/spa/lib/debug.c @@ -335,7 +335,7 @@ spa_debug_props (const SpaProps *props, bool print_ranges) else fprintf (stderr, "None"); - res = props->get_prop (props, i, &value); + res = spa_props_get_prop (props, i, &value); fprintf (stderr, ". Current: "); if (res == SPA_RESULT_OK) @@ -407,7 +407,7 @@ spa_debug_format (const SpaFormat *format) SpaPropValue value; 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) continue; diff --git a/spa/lib/memory.c b/spa/lib/memory.c index 60d6152fd..a9de29a62 100644 --- a/spa/lib/memory.c +++ b/spa/lib/memory.c @@ -62,7 +62,8 @@ spa_memory_init (void) static bool initialized = false; 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; } } @@ -114,12 +115,31 @@ spa_memory_alloc (uint32_t pool_id) mem = &pool->memories[id]; mem->refcount = 1; mem->notify = NULL; + mem->fd = -1; + mem->ptr = NULL; mem->mem.pool_id = pool_id; mem->mem.id = id; 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 * 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->ptr = NULL; mem->size = size; return mem; } - SpaMemory * spa_memory_import (SpaMemoryRef *ref) { @@ -189,22 +207,56 @@ spa_memory_import (SpaMemoryRef *ref) mem->refcount = 1; mem->notify = NULL; mem->mem = *ref; + mem->ptr = NULL; + mem->fd = -1; } return mem; } 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; - if (ref == NULL || ref->pool_id >= MAX_POOLS || !pools[ref->pool_id].valid) - return SPA_RESULT_INVALID_ARGUMENTS; - - pool = &pools[ref->pool_id]; - pool->free_mem[pool->n_free] = ref->id; + if (mem->fd != -1) { + if (mem->ptr) + munmap (mem->ptr, mem->size); + close (mem->fd); + } + pool = &pools[mem->mem.pool_id]; + pool->free_mem[pool->n_free] = mem->mem.id; 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; } diff --git a/spa/lib/props.c b/spa/lib/props.c index c72980a11..3e18f6e08 100644 --- a/spa/lib/props.c +++ b/spa/lib/props.c @@ -25,9 +25,9 @@ #include SpaResult -spa_props_generic_set_prop (SpaProps *props, - unsigned int index, - const SpaPropValue *value) +spa_props_set_prop (SpaProps *props, + unsigned int index, + const SpaPropValue *value) { const SpaPropInfo *info; @@ -56,9 +56,9 @@ spa_props_generic_set_prop (SpaProps *props, SpaResult -spa_props_generic_get_prop (const SpaProps *props, - unsigned int index, - SpaPropValue *value) +spa_props_get_prop (const SpaProps *props, + unsigned int index, + SpaPropValue *value) { const SpaPropInfo *info; @@ -100,7 +100,7 @@ spa_props_copy (const SpaProps *src, if (!(info->flags & SPA_PROP_FLAG_WRITABLE)) 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; if (value.type != info->type) return SPA_RESULT_WRONG_PROPERTY_TYPE; diff --git a/spa/lib/video-raw.c b/spa/lib/video-raw.c index 8ccfd9a60..9788fba3f 100644 --- a/spa/lib/video-raw.c +++ b/spa/lib/video-raw.c @@ -483,8 +483,6 @@ spa_video_raw_format_init (SpaVideoRawFormat *format) format->format.media_subtype = SPA_MEDIA_SUBTYPE_RAW; 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.set_prop = spa_props_generic_set_prop; - format->format.props.get_prop = spa_props_generic_get_prop; format->unset_mask = (1 << 14)-1; format->info = default_info; @@ -509,7 +507,7 @@ spa_video_raw_format_parse (const SpaFormat *format, spa_video_raw_format_init (rawformat); 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; if (value.type != SPA_PROP_TYPE_POINTER || value.size != sizeof (SpaVideoRawInfo)) diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index 0492b2053..8ad8f0ad4 100644 --- a/spa/plugins/alsa/alsa-sink.c +++ b/spa/plugins/alsa/alsa-sink.c @@ -633,8 +633,6 @@ alsa_sink_init (const SpaHandleFactory *factory, this->node.handle = handle; this->props[1].props.n_prop_info = PROP_ID_LAST; 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]); this->info.flags = SPA_PORT_INFO_FLAG_NONE; diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index b7ffb8357..40a9fc77c 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -795,8 +795,6 @@ spa_audiomixer_init (const SpaHandleFactory *factory, this->node.handle = handle; this->props[1].props.n_prop_info = PROP_ID_LAST; 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]); this->ports[0].valid = true; diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index 401a48493..1dd2f747f 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -583,8 +583,6 @@ audiotestsrc_init (const SpaHandleFactory *factory, this->node.handle = handle; this->props[1].props.n_prop_info = PROP_ID_LAST; 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]); this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFER | diff --git a/spa/plugins/ffmpeg/ffmpeg-dec.c b/spa/plugins/ffmpeg/ffmpeg-dec.c index 9fe05a353..94cfe0d9f 100644 --- a/spa/plugins/ffmpeg/ffmpeg-dec.c +++ b/spa/plugins/ffmpeg/ffmpeg-dec.c @@ -574,8 +574,6 @@ spa_ffmpeg_dec_init (SpaHandle *handle) this->node.handle = handle; this->props[1].props.n_prop_info = PROP_ID_LAST; 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]); this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE; diff --git a/spa/plugins/ffmpeg/ffmpeg-enc.c b/spa/plugins/ffmpeg/ffmpeg-enc.c index 0a153a585..9721209f1 100644 --- a/spa/plugins/ffmpeg/ffmpeg-enc.c +++ b/spa/plugins/ffmpeg/ffmpeg-enc.c @@ -574,8 +574,6 @@ spa_ffmpeg_enc_init (SpaHandle *handle) this->node.handle = handle; this->props[1].props.n_prop_info = PROP_ID_LAST; 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]); this->state[INPUT_PORT_ID].info.flags = SPA_PORT_INFO_FLAG_NONE; diff --git a/spa/plugins/remote/proxy.c b/spa/plugins/remote/proxy.c index db5196d04..527bb147c 100644 --- a/spa/plugins/remote/proxy.c +++ b/spa/plugins/remote/proxy.c @@ -565,7 +565,7 @@ add_buffer (SpaProxy *this, uint32_t port_id, SpaBuffer *buffer) if (buffer->mem.id == SPA_ID_INVALID) { 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->mem = bmem->mem; b->offset = 0; @@ -1021,8 +1021,6 @@ proxy_instantiate (const SpaHandleFactory *factory, this->node.handle = handle; this->props[1].props.n_prop_info = PROP_ID_LAST; 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]); memcpy (&this->props[0], &this->props[1], sizeof (this->props[1])); diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index bc0319294..71dc74ecb 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -343,8 +343,6 @@ spa_v4l2_format_init (V4l2Format *f) { f->fmt.props.n_prop_info = 3; 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_PROP_ID_VIDEO_FORMAT, @@ -716,8 +714,6 @@ v4l2_source_init (const SpaHandleFactory *factory, this->node.handle = handle; this->props[1].props.n_prop_info = PROP_ID_LAST; 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]); this->state[0].info.flags = SPA_PORT_INFO_FLAG_NONE; diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index 935a8cf4e..ca476bebe 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -279,8 +279,6 @@ again: fmt->fmt.media_subtype = info->media_subtype; fmt->fmt.props.prop_info = fmt->infos; 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; 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; if (state->alloc_mem) - spa_memory_free (&state->alloc_mem->mem); - state->alloc_mem = spa_memory_alloc_with_fd (0, NULL, sizeof (V4l2Buffer) * reqbuf.count); + spa_memory_unref (&state->alloc_mem->mem); + 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); for (i = 0; i < reqbuf.count; i++) { @@ -602,8 +602,10 @@ mmap_init (SpaV4l2Source *this, state->reqbuf = reqbuf; if (state->alloc_mem) - spa_memory_free (&state->alloc_mem->mem); - state->alloc_mem = spa_memory_alloc_with_fd (0, NULL, sizeof (V4l2Buffer) * reqbuf.count); + spa_memory_unref (&state->alloc_mem->mem); + 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); 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].size = sizeof (b->header); - mem = spa_memory_alloc (0); + mem = spa_memory_alloc (SPA_MEMORY_POOL_SHARED); mem->flags = SPA_MEMORY_FLAG_READABLE; mem->size = buf.length; b->datas[0].mem = mem->mem; @@ -801,7 +803,7 @@ spa_v4l2_stop (SpaV4l2Source *this) } else { munmap (mem->ptr, mem->size); } - spa_memory_free (&mem->mem); + spa_memory_unref (&mem->mem); } state->have_buffers = false; diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index 33468bb14..9dec16fcc 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -693,8 +693,6 @@ volume_instantiate (const SpaHandleFactory *factory, this->node.handle = handle; this->props[1].props.n_prop_info = PROP_ID_LAST; 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]); this->ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFER | diff --git a/spa/plugins/xv/xv-sink.c b/spa/plugins/xv/xv-sink.c index 4cbca631c..64030e636 100644 --- a/spa/plugins/xv/xv-sink.c +++ b/spa/plugins/xv/xv-sink.c @@ -573,8 +573,6 @@ xv_sink_init (const SpaHandleFactory *factory, this->node.handle = handle; this->props[1].props.n_prop_info = PROP_ID_LAST; 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]); this->info.flags = SPA_PORT_INFO_FLAG_NONE; diff --git a/spa/tests/test-mixer.c b/spa/tests/test-mixer.c index bfdeb2461..dec44a2e5 100644 --- a/spa/tests/test-mixer.c +++ b/spa/tests/test-mixer.c @@ -199,7 +199,7 @@ make_nodes (AppData *data) value.type = SPA_PROP_TYPE_STRING; value.value = "hw:0"; 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) printf ("got set_props error %d\n", res); @@ -242,16 +242,16 @@ negotiate_formats (AppData *data) value.value = &val; 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; 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; 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; 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; if ((res = spa_node_port_set_format (data->sink, 0, false, format)) < 0) diff --git a/spa/tests/test-v4l2.c b/spa/tests/test-v4l2.c index d9d49b8c3..da83a9208 100644 --- a/spa/tests/test-v4l2.c +++ b/spa/tests/test-v4l2.c @@ -275,7 +275,7 @@ alloc_buffers (AppData *data) b->metas[1].offset = offsetof (SDLBuffer, 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->type = "sysmem"; mem->fd = -1; @@ -317,8 +317,6 @@ negotiate_formats (AppData *data) f.fmt.media_subtype = SPA_MEDIA_SUBTYPE_RAW; f.fmt.props.n_prop_info = 3; 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_PROP_ID_VIDEO_FORMAT,