mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
mem: remove memory stuff
Remove the memory stuff from the spa API, we can do thing more simple and efficiently if we always allocate buffers outside of the plugins and only implement an alloc function on the node when it can do something clever. Move serialize code to the props/format/buffer code Make it possible to copy a format and properties.
This commit is contained in:
parent
fe37e2bc1b
commit
24108e01c1
46 changed files with 901 additions and 1546 deletions
|
|
@ -25,7 +25,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
typedef struct _SpaBuffer SpaBuffer;
|
||||
typedef struct _SpaBufferGroup SpaBufferGroup;
|
||||
|
||||
/**
|
||||
* SpaMetaType:
|
||||
|
|
@ -41,7 +40,6 @@ typedef enum {
|
|||
} SpaMetaType;
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/memory.h>
|
||||
#include <spa/port.h>
|
||||
|
||||
/**
|
||||
|
|
@ -106,29 +104,48 @@ typedef struct {
|
|||
/**
|
||||
* SpaMeta:
|
||||
* @type: metadata type
|
||||
* @offset: offset of metadata in the buffer structure
|
||||
* @data: pointer to metadata
|
||||
* @size: size of metadata
|
||||
*/
|
||||
typedef struct {
|
||||
SpaMetaType type;
|
||||
off_t offset;
|
||||
void *data;
|
||||
size_t size;
|
||||
} SpaMeta;
|
||||
|
||||
/**
|
||||
* SpaDataType:
|
||||
* @SPA_DATA_TYPE_INVALID: invalid data, should be ignored
|
||||
* @SPA_DATA_TYPE_MEMPTR: data points to CPU accessible memory
|
||||
* @SPA_DATA_TYPE_FD: data is an int file descriptor, use SPA_PTR_TO_INT
|
||||
* @SPA_DATA_TYPE_ID: data is an id use SPA_PTR_TO_INT32
|
||||
*/
|
||||
typedef enum {
|
||||
SPA_DATA_TYPE_INVALID = 0,
|
||||
SPA_DATA_TYPE_MEMPTR,
|
||||
SPA_DATA_TYPE_FD,
|
||||
SPA_DATA_TYPE_ID,
|
||||
} SpaDataType;
|
||||
|
||||
/**
|
||||
* SpaData:
|
||||
* @mem: reference to the memory to use
|
||||
* @stride: stride of memory if applicable
|
||||
* @type: memory type
|
||||
* @data: pointer to memory
|
||||
* @offset: offset in @data
|
||||
* @size: size of @data
|
||||
* @stride: stride of data if applicable
|
||||
*/
|
||||
typedef struct {
|
||||
SpaMemoryChunk mem;
|
||||
SpaDataType type;
|
||||
void *data;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
ssize_t stride;
|
||||
} SpaData;
|
||||
|
||||
/**
|
||||
* SpaBuffer:
|
||||
* @id: buffer id
|
||||
* @mem: reference to the memory for this buffer
|
||||
* @n_metas: number of metadata
|
||||
* @metas: offset of array of @n_metas metadata
|
||||
* @n_datas: number of data pointers
|
||||
|
|
@ -136,23 +153,32 @@ typedef struct {
|
|||
*/
|
||||
struct _SpaBuffer {
|
||||
uint32_t id;
|
||||
SpaMemoryChunk mem;
|
||||
unsigned int n_metas;
|
||||
off_t metas;
|
||||
SpaMeta *metas;
|
||||
unsigned int n_datas;
|
||||
off_t datas;
|
||||
SpaData *datas;
|
||||
};
|
||||
|
||||
#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)
|
||||
size_t spa_buffer_get_size (const SpaBuffer *buffer);
|
||||
size_t spa_buffer_serialize (void *dest, const SpaBuffer *buffer);
|
||||
SpaBuffer * spa_buffer_deserialize (void *src, off_t offset);
|
||||
|
||||
SpaResult spa_buffer_alloc (SpaAllocParam **params,
|
||||
unsigned int n_params,
|
||||
SpaBuffer **buffers,
|
||||
unsigned int *n_buffers);
|
||||
/**
|
||||
* SpaBufferAllocFlags:
|
||||
* @SPA_BUFFER_ALLOC_FLAG_NONE: no flags
|
||||
* @SPA_BUFFER_ALLOC_FLAG_NO_MEM: don't allocate memory
|
||||
*/
|
||||
typedef enum {
|
||||
SPA_BUFFER_ALLOC_FLAG_NONE = 0,
|
||||
SPA_BUFFER_ALLOC_FLAG_NO_MEM,
|
||||
} SpaBufferAllocFlags;
|
||||
|
||||
SpaResult spa_buffer_alloc (SpaBufferAllocFlags flags,
|
||||
SpaAllocParam **params,
|
||||
unsigned int n_params,
|
||||
SpaBuffer **buffers,
|
||||
unsigned int *n_buffers);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ typedef struct _SpaControlBuilder SpaControlBuilder;
|
|||
#include <spa/format.h>
|
||||
#include <spa/port.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/memory.h>
|
||||
|
||||
struct _SpaControl {
|
||||
size_t x[16];
|
||||
|
|
@ -153,28 +152,32 @@ typedef struct {
|
|||
|
||||
/* SPA_CONTROL_CMD_ADD_MEM */
|
||||
typedef struct {
|
||||
uint32_t seq;
|
||||
uint32_t port_id;
|
||||
SpaMemoryRef mem;
|
||||
uint32_t mem_type;
|
||||
uint32_t mem_id;
|
||||
unsigned int fd_index;
|
||||
uint32_t flags;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
} SpaControlCmdAddMem;
|
||||
|
||||
/* SPA_CONTROL_CMD_REMOVE_MEM */
|
||||
typedef struct {
|
||||
uint32_t seq;
|
||||
uint32_t port_id;
|
||||
SpaMemoryRef mem;
|
||||
uint32_t mem_id;
|
||||
} SpaControlCmdRemoveMem;
|
||||
|
||||
typedef struct {
|
||||
uint32_t mem_id;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
} SpaControlMemRef;
|
||||
|
||||
/* SPA_CONTROL_CMD_USE_BUFFERS */
|
||||
typedef struct {
|
||||
uint32_t seq;
|
||||
uint32_t port_id;
|
||||
unsigned int n_buffers;
|
||||
SpaBuffer **buffers;
|
||||
uint32_t seq;
|
||||
uint32_t port_id;
|
||||
unsigned int n_buffers;
|
||||
SpaControlMemRef *buffers;
|
||||
} SpaControlCmdUseBuffers;
|
||||
|
||||
/* SPA_CONTROL_CMD_PROCESS_BUFFER */
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ typedef struct _SpaFormat SpaFormat;
|
|||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/props.h>
|
||||
#include <spa/memory.h>
|
||||
|
||||
typedef enum {
|
||||
SPA_MEDIA_TYPE_INVALID = 0,
|
||||
|
|
@ -83,38 +82,30 @@ typedef enum {
|
|||
|
||||
/**
|
||||
* SpaFormat:
|
||||
* @props: properties
|
||||
* @media_type: media type
|
||||
* @media_subtype: subtype
|
||||
* @mem: memory reference
|
||||
* @offset: offset in memory
|
||||
* @size: size in memory
|
||||
* @props: properties
|
||||
*/
|
||||
struct _SpaFormat {
|
||||
SpaProps props;
|
||||
SpaMediaType media_type;
|
||||
SpaMediaSubType media_subtype;
|
||||
SpaMemoryChunk mem;
|
||||
SpaProps props;
|
||||
};
|
||||
|
||||
static inline void
|
||||
spa_format_ref (SpaFormat *format)
|
||||
{
|
||||
spa_memory_ref (&format->mem.mem);
|
||||
}
|
||||
|
||||
static inline void
|
||||
spa_format_unref (SpaFormat *format)
|
||||
{
|
||||
spa_memory_unref (&format->mem.mem);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
SPA_PROP_ID_INVALID = 0,
|
||||
SPA_PROP_ID_MEDIA_CUSTOM_START = 200,
|
||||
} SpaFormatProps;
|
||||
|
||||
SpaResult spa_format_fixate (SpaFormat *format);
|
||||
|
||||
SpaResult spa_format_fixate (SpaFormat *format);
|
||||
|
||||
size_t spa_format_get_size (const SpaFormat *format);
|
||||
size_t spa_format_serialize (void *dest, const SpaFormat *format);
|
||||
SpaFormat * spa_format_deserialize (void *src, off_t offset);
|
||||
|
||||
SpaFormat * spa_format_copy_into (void *dest, const SpaFormat *format);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
|
|
@ -1,123 +0,0 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_MEMORY_H__
|
||||
#define __SPA_MEMORY_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _SpaMemory SpaMemory;
|
||||
typedef struct _SpaMemoryRef SpaMemoryRef;
|
||||
typedef struct _SpaMemoryChunk SpaMemoryChunk;
|
||||
typedef struct _SpaMemoryPool SpaMemoryPool;
|
||||
|
||||
#include <spa/defs.h>
|
||||
|
||||
/**
|
||||
* SpaMemoryFlags:
|
||||
* @SPA_MEMORY_FLAG_NONE: no flag
|
||||
* @SPA_MEMORY_FLAG_READABLE: memory is writable
|
||||
* @SPA_MEMORY_FLAG_WRITABLE: memory is readable
|
||||
*/
|
||||
typedef enum {
|
||||
SPA_MEMORY_FLAG_NONE = 0,
|
||||
SPA_MEMORY_FLAG_READABLE = (1 << 0),
|
||||
SPA_MEMORY_FLAG_WRITABLE = (1 << 1),
|
||||
} SpaMemoryFlags;
|
||||
|
||||
#define SPA_MEMORY_FLAG_READWRITE (SPA_MEMORY_FLAG_READABLE|SPA_MEMORY_FLAG_WRITABLE)
|
||||
|
||||
/**
|
||||
* SpaMemoryRef:
|
||||
* @pool_id: the pool id
|
||||
* @id: mem_id
|
||||
*
|
||||
* A reference to a block of memory
|
||||
*/
|
||||
struct _SpaMemoryRef {
|
||||
uint32_t pool_id;
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
/**
|
||||
* SpaMemoryChunk:
|
||||
* @mem: the memory
|
||||
* @offset: the offset in the memory
|
||||
* @size: the size in the memory
|
||||
*
|
||||
* A reference to a part of memory
|
||||
*/
|
||||
struct _SpaMemoryChunk {
|
||||
SpaMemoryRef mem;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
};
|
||||
/**
|
||||
* SpaMemory:
|
||||
* @refcount: a refcount
|
||||
* @notify: notify when refcount is 0
|
||||
* @user_data: owner specific user data
|
||||
* @pool_id: the id of the pool
|
||||
* @id: the memory id
|
||||
* @flags: extra memory flags
|
||||
* @type: memory type
|
||||
* @fd: fd of memory of -1 if not known
|
||||
* @ptr: ptr to memory accessible with CPU
|
||||
* @size: size of memory
|
||||
*/
|
||||
struct _SpaMemory {
|
||||
int refcount;
|
||||
SpaNotify notify;
|
||||
void *user_data;
|
||||
SpaMemoryRef mem;
|
||||
SpaMemoryFlags flags;
|
||||
const char *type;
|
||||
int fd;
|
||||
void *ptr;
|
||||
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);
|
||||
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_ref (SpaMemoryRef *ref);
|
||||
SpaResult spa_memory_unref (SpaMemoryRef *ref);
|
||||
|
||||
SpaMemory * spa_memory_import (SpaMemoryRef *ref);
|
||||
SpaMemory * spa_memory_find (SpaMemoryRef *ref);
|
||||
|
||||
void * spa_memory_ensure_ptr (SpaMemory *mem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_MEMORY_H__ */
|
||||
|
|
@ -430,7 +430,7 @@ struct _SpaNode {
|
|||
* @buffers: an array of buffer pointers
|
||||
* @n_buffers: number of elements in @buffers
|
||||
*
|
||||
* Tell the port to allocate buffers.
|
||||
* Tell the port to allocate memory for @buffers.
|
||||
*
|
||||
* For input ports, the buffers will be dequeued and ready to be filled
|
||||
* and pushed into the port. A notify should be configured so that you can
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ spa_props_index_for_name (const SpaProps *props, const char *name)
|
|||
|
||||
|
||||
/**
|
||||
* spa_props_set_prop:
|
||||
* spa_props_set_value:
|
||||
* @props: a #SpaProps
|
||||
* @index: the index of the property in the prop_info array
|
||||
* @value: the value to set
|
||||
|
|
@ -212,29 +212,36 @@ spa_props_index_for_name (const SpaProps *props, const char *name)
|
|||
* #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,
|
||||
SpaResult spa_props_set_value (SpaProps *props,
|
||||
unsigned int index,
|
||||
const SpaPropValue *value);
|
||||
/**
|
||||
* spa_props_get_prop:
|
||||
* spa_props_get_value:
|
||||
* @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.
|
||||
* Get the 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,
|
||||
SpaResult spa_props_get_value (const SpaProps *props,
|
||||
unsigned int index,
|
||||
SpaPropValue *value);
|
||||
|
||||
SpaResult spa_props_copy (const SpaProps *src,
|
||||
SpaResult spa_props_copy_values (const SpaProps *src,
|
||||
SpaProps *dest);
|
||||
|
||||
|
||||
size_t spa_props_get_size (const SpaProps *props);
|
||||
size_t spa_props_serialize (void *dest, const SpaProps *props);
|
||||
SpaProps * spa_props_deserialize (void *src, off_t offset);
|
||||
|
||||
SpaProps * spa_props_copy_into (void *dest, const SpaProps *props);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue