mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Make buffer structure sharable
Use stucture offsets instead of pointers so that we can share the buffer structure between client and server. We can then pass an fd wrapping the memory of the buffer to the client. Add beginnings of a memory pool
This commit is contained in:
parent
3ace7e9648
commit
98993c680b
23 changed files with 456 additions and 583 deletions
|
|
@ -89,12 +89,12 @@ typedef struct {
|
|||
/**
|
||||
* SpaMeta:
|
||||
* @type: metadata type
|
||||
* @data: pointer to metadata
|
||||
* @offset: offset of metadata
|
||||
* @size: size of metadata
|
||||
*/
|
||||
typedef struct {
|
||||
SpaMetaType type;
|
||||
void *data;
|
||||
off_t offset;
|
||||
size_t size;
|
||||
} SpaMeta;
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ typedef enum {
|
|||
* SpaData:
|
||||
* @id: user id
|
||||
* @type: the type of data
|
||||
* @ptr_type: more info abouut the type of @ptr
|
||||
* @ptr_type: more info about the type of @ptr
|
||||
* @ptr: pointer to data or fd
|
||||
* @offset: offset of data
|
||||
* @size: size of data
|
||||
|
|
@ -139,21 +139,25 @@ typedef struct {
|
|||
/**
|
||||
* SpaBuffer:
|
||||
* @id: buffer id
|
||||
* @size: total size of the buffer data
|
||||
* @size: total size of the buffer structure
|
||||
* @n_metas: number of metadata
|
||||
* @metas: array of @n_metas metadata
|
||||
* @metas: offset of array of @n_metas metadata
|
||||
* @n_datas: number of data pointers
|
||||
* @datas: array of @n_datas data pointers
|
||||
* @datas: offset of array of @n_datas data pointers
|
||||
*/
|
||||
struct _SpaBuffer {
|
||||
uint32_t id;
|
||||
size_t size;
|
||||
unsigned int n_metas;
|
||||
SpaMeta *metas;
|
||||
off_t metas;
|
||||
unsigned int n_datas;
|
||||
SpaData *datas;
|
||||
off_t datas;
|
||||
};
|
||||
|
||||
#define SPA_BUFFER_METAS(b) (SPA_MEMBER ((b), (b)->metas, SpaMeta))
|
||||
#define SPA_BUFFER_DATAS(b) (SPA_MEMBER ((b), (b)->datas, SpaData))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -178,7 +178,10 @@ typedef struct {
|
|||
/* SPA_CONTROL_CMD_ADD_BUFFER */
|
||||
typedef struct {
|
||||
uint32_t port_id;
|
||||
SpaBuffer *buffer;
|
||||
uint32_t buffer_id;
|
||||
int fd_index;
|
||||
uint64_t offset;
|
||||
uint64_t size;
|
||||
} SpaControlCmdAddBuffer;
|
||||
|
||||
/* SPA_CONTROL_CMD_REMOVE_BUFFER */
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ extern "C" {
|
|||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/port.h>
|
||||
#include <spa/buffer.h>
|
||||
|
||||
SpaResult spa_debug_port_info (const SpaPortInfo *info);
|
||||
SpaResult spa_debug_buffer (const SpaBuffer *buffer);
|
||||
SpaResult spa_debug_dump_mem (void *data, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ extern "C" {
|
|||
#endif
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum {
|
||||
SPA_RESULT_OK = 0,
|
||||
|
|
@ -71,6 +72,14 @@ typedef void (*SpaNotify) (void *data);
|
|||
#define SPA_MIN(a,b) ((a)<(b) ? (a) : (b))
|
||||
#define SPA_MAX(a,b) ((a)>(b) ? (a) : (b))
|
||||
|
||||
#define SPA_MEMBER(b,o,t) ((t*)((uint8_t*)(b) + (o)))
|
||||
|
||||
#define SPA_PTR_TO_INT(p) ((int) ((intptr_t) (p)))
|
||||
#define SPA_INT_TO_PTR(u) ((void*) ((intptr_t) (u)))
|
||||
|
||||
#define SPA_PTR_TO_UINT32(p) ((uint32_t) ((uintptr_t) (p)))
|
||||
#define SPA_UINT32_TO_PTR(u) ((void*) ((uintptr_t) (u)))
|
||||
|
||||
#define SPA_ID_INVALID ((uint32_t)0xffffffff)
|
||||
|
||||
|
||||
|
|
|
|||
81
spa/include/spa/memory.h
Normal file
81
spa/include/spa/memory.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* 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 _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;
|
||||
|
||||
/**
|
||||
* SpaMemory:
|
||||
* @refcount: a refcount
|
||||
* @notify: notify when refcount is 0
|
||||
* @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;
|
||||
uint32_t pool_id;
|
||||
uint32_t id;
|
||||
SpaMemoryFlags flags;
|
||||
const char *type;
|
||||
int fd;
|
||||
void *ptr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
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);
|
||||
SpaResult spa_memory_free (uint32_t pool_id, uint32_t id);
|
||||
|
||||
SpaMemory * spa_memory_find (uint32_t pool_id, uint32_t id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_MEMORY_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue