default: esd is obsolete, hence don't load it anymore by default
[pulseaudio-mirror.git] / src / pulsecore / memblock.h
blobca108ccd21a8901c3ef97758c1bae55fd54b3794
1 #ifndef foopulsememblockhfoo
2 #define foopulsememblockhfoo
4 /***
5 This file is part of PulseAudio.
7 Copyright 2004-2006 Lennart Poettering
8 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
10 PulseAudio is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as
12 published by the Free Software Foundation; either version 2.1 of the
13 License, or (at your option) any later version.
15 PulseAudio is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with PulseAudio; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 USA.
24 ***/
26 #include <sys/types.h>
27 #include <inttypes.h>
29 #include <pulse/def.h>
30 #include <pulsecore/atomic.h>
32 /* A pa_memblock is a reference counted memory block. PulseAudio
33 * passed references to pa_memblocks around instead of copying
34 * data. See pa_memchunk for a structure that describes parts of
35 * memory blocks. */
37 /* The type of memory this block points to */
38 typedef enum pa_memblock_type {
39 PA_MEMBLOCK_POOL, /* Memory is part of the memory pool */
40 PA_MEMBLOCK_POOL_EXTERNAL, /* Data memory is part of the memory pool but the pa_memblock structure itself not */
41 PA_MEMBLOCK_APPENDED, /* the data is appended to the memory block */
42 PA_MEMBLOCK_USER, /* User supplied memory, to be freed with free_cb */
43 PA_MEMBLOCK_FIXED, /* data is a pointer to fixed memory that needs not to be freed */
44 PA_MEMBLOCK_IMPORTED, /* Memory is imported from another process via shm */
45 PA_MEMBLOCK_TYPE_MAX
46 } pa_memblock_type_t;
48 typedef struct pa_memblock pa_memblock;
49 typedef struct pa_mempool pa_mempool;
50 typedef struct pa_mempool_stat pa_mempool_stat;
51 typedef struct pa_memimport_segment pa_memimport_segment;
52 typedef struct pa_memimport pa_memimport;
53 typedef struct pa_memexport pa_memexport;
55 typedef void (*pa_memimport_release_cb_t)(pa_memimport *i, uint32_t block_id, void *userdata);
56 typedef void (*pa_memexport_revoke_cb_t)(pa_memexport *e, uint32_t block_id, void *userdata);
58 /* Please note that updates to this structure are not locked,
59 * i.e. n_allocated might be updated at a point in time where
60 * n_accumulated is not yet. Take these values with a grain of salt,
61 * they are here for purely statistical reasons.*/
62 struct pa_mempool_stat {
63 pa_atomic_t n_allocated;
64 pa_atomic_t n_accumulated;
65 pa_atomic_t n_imported;
66 pa_atomic_t n_exported;
67 pa_atomic_t allocated_size;
68 pa_atomic_t accumulated_size;
69 pa_atomic_t imported_size;
70 pa_atomic_t exported_size;
72 pa_atomic_t n_too_large_for_pool;
73 pa_atomic_t n_pool_full;
75 pa_atomic_t n_allocated_by_type[PA_MEMBLOCK_TYPE_MAX];
76 pa_atomic_t n_accumulated_by_type[PA_MEMBLOCK_TYPE_MAX];
79 /* Allocate a new memory block of type PA_MEMBLOCK_MEMPOOL or PA_MEMBLOCK_APPENDED, depending on the size */
80 pa_memblock *pa_memblock_new(pa_mempool *, size_t length);
82 /* Allocate a new memory block of type PA_MEMBLOCK_MEMPOOL. If the requested size is too large, return NULL */
83 pa_memblock *pa_memblock_new_pool(pa_mempool *, size_t length);
85 /* Allocate a new memory block of type PA_MEMBLOCK_USER */
86 pa_memblock *pa_memblock_new_user(pa_mempool *, void *data, size_t length, pa_free_cb_t free_cb, pa_bool_t read_only);
88 /* A special case of pa_memblock_new_user: take a memory buffer previously allocated with pa_xmalloc() */
89 #define pa_memblock_new_malloced(p,data,length) pa_memblock_new_user(p, data, length, pa_xfree, 0)
91 /* Allocate a new memory block of type PA_MEMBLOCK_FIXED */
92 pa_memblock *pa_memblock_new_fixed(pa_mempool *, void *data, size_t length, pa_bool_t read_only);
94 void pa_memblock_unref(pa_memblock*b);
95 pa_memblock* pa_memblock_ref(pa_memblock*b);
97 /* This special unref function has to be called by the owner of the
98 memory of a static memory block when he wants to release all
99 references to the memory. This causes the memory to be copied and
100 converted into a pool or malloc'ed memory block. Please note that this
101 function is not multiple caller safe, i.e. needs to be locked
102 manually if called from more than one thread at the same time. */
103 void pa_memblock_unref_fixed(pa_memblock*b);
105 pa_bool_t pa_memblock_is_read_only(pa_memblock *b);
106 pa_bool_t pa_memblock_is_silence(pa_memblock *b);
107 pa_bool_t pa_memblock_ref_is_one(pa_memblock *b);
108 void pa_memblock_set_is_silence(pa_memblock *b, pa_bool_t v);
110 void* pa_memblock_acquire(pa_memblock *b);
111 void pa_memblock_release(pa_memblock *b);
112 size_t pa_memblock_get_length(pa_memblock *b);
113 pa_mempool * pa_memblock_get_pool(pa_memblock *b);
115 pa_memblock *pa_memblock_will_need(pa_memblock *b);
117 /* The memory block manager */
118 pa_mempool* pa_mempool_new(pa_bool_t shared, size_t size);
119 void pa_mempool_free(pa_mempool *p);
120 const pa_mempool_stat* pa_mempool_get_stat(pa_mempool *p);
121 void pa_mempool_vacuum(pa_mempool *p);
122 int pa_mempool_get_shm_id(pa_mempool *p, uint32_t *id);
123 pa_bool_t pa_mempool_is_shared(pa_mempool *p);
124 size_t pa_mempool_block_size_max(pa_mempool *p);
126 /* For recieving blocks from other nodes */
127 pa_memimport* pa_memimport_new(pa_mempool *p, pa_memimport_release_cb_t cb, void *userdata);
128 void pa_memimport_free(pa_memimport *i);
129 pa_memblock* pa_memimport_get(pa_memimport *i, uint32_t block_id, uint32_t shm_id, size_t offset, size_t size);
130 int pa_memimport_process_revoke(pa_memimport *i, uint32_t block_id);
132 /* For sending blocks to other nodes */
133 pa_memexport* pa_memexport_new(pa_mempool *p, pa_memexport_revoke_cb_t cb, void *userdata);
134 void pa_memexport_free(pa_memexport *e);
135 int pa_memexport_put(pa_memexport *e, pa_memblock *b, uint32_t *block_id, uint32_t *shm_id, size_t *offset, size_t *size);
136 int pa_memexport_process_release(pa_memexport *e, uint32_t id);
138 #endif