2006-08-18 19:55:18 +00:00
|
|
|
#ifndef foopulsememblockhfoo
|
|
|
|
|
#define foopulsememblockhfoo
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-16 19:56:36 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
License, or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2004-11-14 14:58:54 +00:00
|
|
|
Lesser General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2006-06-19 21:53:48 +00:00
|
|
|
License along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#include <sys/types.h>
|
2004-06-15 15:18:33 +00:00
|
|
|
#include <inttypes.h>
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulse/def.h>
|
2007-05-27 20:38:14 +00:00
|
|
|
#include <pulsecore/atomic.h>
|
2006-08-18 19:55:18 +00:00
|
|
|
|
2006-06-19 22:11:49 +00:00
|
|
|
/* A pa_memblock is a reference counted memory block. PulseAudio
|
2012-02-22 13:07:17 +01:00
|
|
|
* passes references to pa_memblocks around instead of copying
|
2004-11-21 21:31:28 +00:00
|
|
|
* data. See pa_memchunk for a structure that describes parts of
|
|
|
|
|
* memory blocks. */
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* The type of memory this block points to */
|
2006-01-27 16:25:31 +00:00
|
|
|
typedef enum pa_memblock_type {
|
2006-08-18 19:55:18 +00:00
|
|
|
PA_MEMBLOCK_POOL, /* Memory is part of the memory pool */
|
2012-02-22 13:07:17 +01:00
|
|
|
PA_MEMBLOCK_POOL_EXTERNAL, /* Data memory is part of the memory pool but the pa_memblock structure itself is not */
|
|
|
|
|
PA_MEMBLOCK_APPENDED, /* The data is appended to the memory block */
|
2006-08-18 19:55:18 +00:00
|
|
|
PA_MEMBLOCK_USER, /* User supplied memory, to be freed with free_cb */
|
2012-02-22 13:07:17 +01:00
|
|
|
PA_MEMBLOCK_FIXED, /* Data is a pointer to fixed memory that needs not to be freed */
|
2006-08-18 19:55:18 +00:00
|
|
|
PA_MEMBLOCK_IMPORTED, /* Memory is imported from another process via shm */
|
2006-08-19 16:25:15 +00:00
|
|
|
PA_MEMBLOCK_TYPE_MAX
|
2006-01-27 16:25:31 +00:00
|
|
|
} pa_memblock_type_t;
|
2004-11-21 21:31:28 +00:00
|
|
|
|
2006-08-18 19:55:18 +00:00
|
|
|
typedef struct pa_memblock pa_memblock;
|
|
|
|
|
typedef struct pa_mempool pa_mempool;
|
|
|
|
|
typedef struct pa_mempool_stat pa_mempool_stat;
|
|
|
|
|
typedef struct pa_memimport_segment pa_memimport_segment;
|
|
|
|
|
typedef struct pa_memimport pa_memimport;
|
|
|
|
|
typedef struct pa_memexport pa_memexport;
|
|
|
|
|
|
|
|
|
|
typedef void (*pa_memimport_release_cb_t)(pa_memimport *i, uint32_t block_id, void *userdata);
|
|
|
|
|
typedef void (*pa_memexport_revoke_cb_t)(pa_memexport *e, uint32_t block_id, void *userdata);
|
|
|
|
|
|
2006-08-29 02:01:39 +00:00
|
|
|
/* Please note that updates to this structure are not locked,
|
|
|
|
|
* i.e. n_allocated might be updated at a point in time where
|
|
|
|
|
* n_accumulated is not yet. Take these values with a grain of salt,
|
2007-10-28 19:13:50 +00:00
|
|
|
* they are here for purely statistical reasons.*/
|
2006-08-18 19:55:18 +00:00
|
|
|
struct pa_mempool_stat {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_atomic_t n_allocated;
|
|
|
|
|
pa_atomic_t n_accumulated;
|
|
|
|
|
pa_atomic_t n_imported;
|
|
|
|
|
pa_atomic_t n_exported;
|
|
|
|
|
pa_atomic_t allocated_size;
|
|
|
|
|
pa_atomic_t accumulated_size;
|
|
|
|
|
pa_atomic_t imported_size;
|
|
|
|
|
pa_atomic_t exported_size;
|
|
|
|
|
|
|
|
|
|
pa_atomic_t n_too_large_for_pool;
|
|
|
|
|
pa_atomic_t n_pool_full;
|
|
|
|
|
|
|
|
|
|
pa_atomic_t n_allocated_by_type[PA_MEMBLOCK_TYPE_MAX];
|
|
|
|
|
pa_atomic_t n_accumulated_by_type[PA_MEMBLOCK_TYPE_MAX];
|
2006-08-18 19:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Allocate a new memory block of type PA_MEMBLOCK_MEMPOOL or PA_MEMBLOCK_APPENDED, depending on the size */
|
|
|
|
|
pa_memblock *pa_memblock_new(pa_mempool *, size_t length);
|
|
|
|
|
|
|
|
|
|
/* Allocate a new memory block of type PA_MEMBLOCK_MEMPOOL. If the requested size is too large, return NULL */
|
|
|
|
|
pa_memblock *pa_memblock_new_pool(pa_mempool *, size_t length);
|
2004-11-21 21:31:28 +00:00
|
|
|
|
|
|
|
|
/* Allocate a new memory block of type PA_MEMBLOCK_USER */
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memblock *pa_memblock_new_user(pa_mempool *, void *data, size_t length, pa_free_cb_t free_cb, pa_bool_t read_only);
|
2006-08-18 19:55:18 +00:00
|
|
|
|
|
|
|
|
/* A special case of pa_memblock_new_user: take a memory buffer previously allocated with pa_xmalloc() */
|
|
|
|
|
#define pa_memblock_new_malloced(p,data,length) pa_memblock_new_user(p, data, length, pa_xfree, 0)
|
|
|
|
|
|
|
|
|
|
/* Allocate a new memory block of type PA_MEMBLOCK_FIXED */
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_memblock *pa_memblock_new_fixed(pa_mempool *, void *data, size_t length, pa_bool_t read_only);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_memblock_unref(pa_memblock*b);
|
|
|
|
|
pa_memblock* pa_memblock_ref(pa_memblock*b);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* This special unref function has to be called by the owner of the
|
|
|
|
|
memory of a static memory block when he wants to release all
|
|
|
|
|
references to the memory. This causes the memory to be copied and
|
2007-10-28 19:13:50 +00:00
|
|
|
converted into a pool or malloc'ed memory block. Please note that this
|
|
|
|
|
function is not multiple caller safe, i.e. needs to be locked
|
|
|
|
|
manually if called from more than one thread at the same time. */
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_memblock_unref_fixed(pa_memblock*b);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_bool_t pa_memblock_is_read_only(pa_memblock *b);
|
|
|
|
|
pa_bool_t pa_memblock_is_silence(pa_memblock *b);
|
|
|
|
|
pa_bool_t pa_memblock_ref_is_one(pa_memblock *b);
|
|
|
|
|
void pa_memblock_set_is_silence(pa_memblock *b, pa_bool_t v);
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
void* pa_memblock_acquire(pa_memblock *b);
|
|
|
|
|
void pa_memblock_release(pa_memblock *b);
|
|
|
|
|
size_t pa_memblock_get_length(pa_memblock *b);
|
|
|
|
|
pa_mempool * pa_memblock_get_pool(pa_memblock *b);
|
|
|
|
|
|
|
|
|
|
pa_memblock *pa_memblock_will_need(pa_memblock *b);
|
|
|
|
|
|
2006-08-18 19:55:18 +00:00
|
|
|
/* The memory block manager */
|
2008-10-01 01:14:36 +02:00
|
|
|
pa_mempool* pa_mempool_new(pa_bool_t shared, size_t size);
|
2006-08-18 19:55:18 +00:00
|
|
|
void pa_mempool_free(pa_mempool *p);
|
|
|
|
|
const pa_mempool_stat* pa_mempool_get_stat(pa_mempool *p);
|
|
|
|
|
void pa_mempool_vacuum(pa_mempool *p);
|
|
|
|
|
int pa_mempool_get_shm_id(pa_mempool *p, uint32_t *id);
|
2008-05-15 23:34:41 +00:00
|
|
|
pa_bool_t pa_mempool_is_shared(pa_mempool *p);
|
2007-10-28 19:13:50 +00:00
|
|
|
size_t pa_mempool_block_size_max(pa_mempool *p);
|
2006-08-18 19:55:18 +00:00
|
|
|
|
2011-08-24 18:24:46 +02:00
|
|
|
/* For receiving blocks from other nodes */
|
2006-08-18 19:55:18 +00:00
|
|
|
pa_memimport* pa_memimport_new(pa_mempool *p, pa_memimport_release_cb_t cb, void *userdata);
|
|
|
|
|
void pa_memimport_free(pa_memimport *i);
|
|
|
|
|
pa_memblock* pa_memimport_get(pa_memimport *i, uint32_t block_id, uint32_t shm_id, size_t offset, size_t size);
|
|
|
|
|
int pa_memimport_process_revoke(pa_memimport *i, uint32_t block_id);
|
|
|
|
|
|
|
|
|
|
/* For sending blocks to other nodes */
|
|
|
|
|
pa_memexport* pa_memexport_new(pa_mempool *p, pa_memexport_revoke_cb_t cb, void *userdata);
|
|
|
|
|
void pa_memexport_free(pa_memexport *e);
|
|
|
|
|
int pa_memexport_put(pa_memexport *e, pa_memblock *b, uint32_t *block_id, uint32_t *shm_id, size_t *offset, size_t *size);
|
|
|
|
|
int pa_memexport_process_release(pa_memexport *e, uint32_t id);
|
2004-06-15 15:18:33 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#endif
|