mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	pulsecore: Transform pa_mempool_new() into a factory method
Soon we're going to have three types of memory pools: POSIX shm_open() pools, memfd memfd_create() ones, and privately malloc()-ed pools. Thus introduce annotations for the memory types supported and change pa_mempool_new() into a factory method based on required memory. Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
This commit is contained in:
		
							parent
							
								
									211a520543
								
							
						
					
					
						commit
						b88acd0266
					
				
					 18 changed files with 97 additions and 37 deletions
				
			
		| 
						 | 
					@ -700,6 +700,7 @@ libpulsecommon_@PA_MAJORMINOR@_la_SOURCES = \
 | 
				
			||||||
		pulsecore/refcnt.h \
 | 
							pulsecore/refcnt.h \
 | 
				
			||||||
		pulsecore/srbchannel.c pulsecore/srbchannel.h \
 | 
							pulsecore/srbchannel.c pulsecore/srbchannel.h \
 | 
				
			||||||
		pulsecore/sample-util.c pulsecore/sample-util.h \
 | 
							pulsecore/sample-util.c pulsecore/sample-util.h \
 | 
				
			||||||
 | 
							pulsecore/mem.h \
 | 
				
			||||||
		pulsecore/shm.c pulsecore/shm.h \
 | 
							pulsecore/shm.c pulsecore/shm.h \
 | 
				
			||||||
		pulsecore/bitset.c pulsecore/bitset.h \
 | 
							pulsecore/bitset.c pulsecore/bitset.h \
 | 
				
			||||||
		pulsecore/socket-client.c pulsecore/socket-client.h \
 | 
							pulsecore/socket-client.c pulsecore/socket-client.h \
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -125,6 +125,7 @@ static void reset_callbacks(pa_context *c) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *p) {
 | 
					pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *p) {
 | 
				
			||||||
    pa_context *c;
 | 
					    pa_context *c;
 | 
				
			||||||
 | 
					    pa_mem_type_t type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(mainloop);
 | 
					    pa_assert(mainloop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -170,10 +171,13 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *
 | 
				
			||||||
    c->srb_template.readfd = -1;
 | 
					    c->srb_template.readfd = -1;
 | 
				
			||||||
    c->srb_template.writefd = -1;
 | 
					    c->srb_template.writefd = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) {
 | 
					    type = !c->conf->disable_shm ? PA_MEM_TYPE_SHARED_POSIX : PA_MEM_TYPE_PRIVATE;
 | 
				
			||||||
 | 
					    if (!(c->mempool = pa_mempool_new(type, c->conf->shm_size))) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!c->conf->disable_shm)
 | 
					        if (!c->conf->disable_shm) {
 | 
				
			||||||
            c->mempool = pa_mempool_new(false, c->conf->shm_size);
 | 
					            pa_log_warn("Failed to allocate shared memory pool. Falling back to a normal private one.");
 | 
				
			||||||
 | 
					            c->mempool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, c->conf->shm_size);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!c->mempool) {
 | 
					        if (!c->mempool) {
 | 
				
			||||||
            context_free(c);
 | 
					            context_free(c);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -69,14 +69,14 @@ pa_core* pa_core_new(pa_mainloop_api *m, bool shared, size_t shm_size) {
 | 
				
			||||||
    pa_assert(m);
 | 
					    pa_assert(m);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (shared) {
 | 
					    if (shared) {
 | 
				
			||||||
        if (!(pool = pa_mempool_new(shared, shm_size))) {
 | 
					        if (!(pool = pa_mempool_new(PA_MEM_TYPE_SHARED_POSIX, shm_size))) {
 | 
				
			||||||
            pa_log_warn("Failed to allocate shared memory pool. Falling back to a normal memory pool.");
 | 
					            pa_log_warn("Failed to allocate shared memory pool. Falling back to a normal memory pool.");
 | 
				
			||||||
            shared = false;
 | 
					            shared = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!shared) {
 | 
					    if (!shared) {
 | 
				
			||||||
        if (!(pool = pa_mempool_new(shared, shm_size))) {
 | 
					        if (!(pool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, shm_size))) {
 | 
				
			||||||
            pa_log("pa_mempool_new() failed.");
 | 
					            pa_log("pa_mempool_new() failed.");
 | 
				
			||||||
            return NULL;
 | 
					            return NULL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										51
									
								
								src/pulsecore/mem.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/pulsecore/mem.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,51 @@
 | 
				
			||||||
 | 
					#ifndef foopulsememhfoo
 | 
				
			||||||
 | 
					#define foopulsememhfoo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/***
 | 
				
			||||||
 | 
					  This file is part of PulseAudio.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Copyright 2016 Ahmed S. Darwish <darwish.07@gmail.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  PulseAudio is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					  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.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  PulseAudio 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
 | 
				
			||||||
 | 
					  Lesser General Public License for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  You should have received a copy of the GNU Lesser General Public
 | 
				
			||||||
 | 
					  License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					***/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdbool.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <pulsecore/macro.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef enum pa_mem_type {
 | 
				
			||||||
 | 
					    PA_MEM_TYPE_SHARED_POSIX,         /* Data is shared and created using POSIX shm_open() */
 | 
				
			||||||
 | 
					    PA_MEM_TYPE_SHARED_MEMFD,         /* Data is shared and created using Linux memfd_create() */
 | 
				
			||||||
 | 
					    PA_MEM_TYPE_PRIVATE,              /* Data is private and created using classic memory allocation
 | 
				
			||||||
 | 
					                                         (posix_memalign(), malloc() or anonymous mmap()) */
 | 
				
			||||||
 | 
					} pa_mem_type_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline const char *pa_mem_type_to_string(pa_mem_type_t type) {
 | 
				
			||||||
 | 
					    switch (type) {
 | 
				
			||||||
 | 
					    case PA_MEM_TYPE_SHARED_POSIX:
 | 
				
			||||||
 | 
					        return "shared posix-shm";
 | 
				
			||||||
 | 
					    case PA_MEM_TYPE_SHARED_MEMFD:
 | 
				
			||||||
 | 
					        return "shared memfd";
 | 
				
			||||||
 | 
					    case PA_MEM_TYPE_PRIVATE:
 | 
				
			||||||
 | 
					        return "private";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pa_assert_not_reached();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline bool pa_mem_type_is_shared(pa_mem_type_t t) {
 | 
				
			||||||
 | 
					    return (t == PA_MEM_TYPE_SHARED_POSIX) || (t == PA_MEM_TYPE_SHARED_MEMFD);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -773,7 +773,7 @@ static void memblock_replace_import(pa_memblock *b) {
 | 
				
			||||||
    pa_mutex_unlock(import->mutex);
 | 
					    pa_mutex_unlock(import->mutex);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pa_mempool* pa_mempool_new(bool shared, size_t size) {
 | 
					pa_mempool *pa_mempool_new(pa_mem_type_t type, size_t size) {
 | 
				
			||||||
    pa_mempool *p;
 | 
					    pa_mempool *p;
 | 
				
			||||||
    char t1[PA_BYTES_SNPRINT_MAX], t2[PA_BYTES_SNPRINT_MAX];
 | 
					    char t1[PA_BYTES_SNPRINT_MAX], t2[PA_BYTES_SNPRINT_MAX];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -793,13 +793,13 @@ pa_mempool* pa_mempool_new(bool shared, size_t size) {
 | 
				
			||||||
            p->n_blocks = 2;
 | 
					            p->n_blocks = 2;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pa_shm_create_rw(&p->memory, p->n_blocks * p->block_size, shared, 0700) < 0) {
 | 
					    if (pa_shm_create_rw(&p->memory, type, p->n_blocks * p->block_size, 0700) < 0) {
 | 
				
			||||||
        pa_xfree(p);
 | 
					        pa_xfree(p);
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_log_debug("Using %s memory pool with %u slots of size %s each, total size is %s, maximum usable slot size is %lu",
 | 
					    pa_log_debug("Using %s memory pool with %u slots of size %s each, total size is %s, maximum usable slot size is %lu",
 | 
				
			||||||
                 p->memory.shared ? "shared" : "private",
 | 
					                 pa_mem_type_to_string(type),
 | 
				
			||||||
                 p->n_blocks,
 | 
					                 p->n_blocks,
 | 
				
			||||||
                 pa_bytes_snprint(t1, sizeof(t1), (unsigned) p->block_size),
 | 
					                 pa_bytes_snprint(t1, sizeof(t1), (unsigned) p->block_size),
 | 
				
			||||||
                 pa_bytes_snprint(t2, sizeof(t2), (unsigned) (p->n_blocks * p->block_size)),
 | 
					                 pa_bytes_snprint(t2, sizeof(t2), (unsigned) (p->n_blocks * p->block_size)),
 | 
				
			||||||
| 
						 | 
					@ -922,11 +922,18 @@ void pa_mempool_vacuum(pa_mempool *p) {
 | 
				
			||||||
    pa_flist_free(list, NULL);
 | 
					    pa_flist_free(list, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* No lock necessary */
 | 
				
			||||||
 | 
					bool pa_mempool_is_shared(pa_mempool *p) {
 | 
				
			||||||
 | 
					    pa_assert(p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return pa_mem_type_is_shared(p->memory.type);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* No lock necessary */
 | 
					/* No lock necessary */
 | 
				
			||||||
int pa_mempool_get_shm_id(pa_mempool *p, uint32_t *id) {
 | 
					int pa_mempool_get_shm_id(pa_mempool *p, uint32_t *id) {
 | 
				
			||||||
    pa_assert(p);
 | 
					    pa_assert(p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!p->memory.shared)
 | 
					    if (!pa_mempool_is_shared(p))
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    *id = p->memory.id;
 | 
					    *id = p->memory.id;
 | 
				
			||||||
| 
						 | 
					@ -934,13 +941,6 @@ int pa_mempool_get_shm_id(pa_mempool *p, uint32_t *id) {
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* No lock necessary */
 | 
					 | 
				
			||||||
bool pa_mempool_is_shared(pa_mempool *p) {
 | 
					 | 
				
			||||||
    pa_assert(p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return p->memory.shared;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pa_mempool* pa_mempool_ref(pa_mempool *p) {
 | 
					pa_mempool* pa_mempool_ref(pa_mempool *p) {
 | 
				
			||||||
    pa_assert(p);
 | 
					    pa_assert(p);
 | 
				
			||||||
    pa_assert(PA_REFCNT_VALUE(p) > 0);
 | 
					    pa_assert(PA_REFCNT_VALUE(p) > 0);
 | 
				
			||||||
| 
						 | 
					@ -1139,7 +1139,7 @@ pa_memexport* pa_memexport_new(pa_mempool *p, pa_memexport_revoke_cb_t cb, void
 | 
				
			||||||
    pa_assert(p);
 | 
					    pa_assert(p);
 | 
				
			||||||
    pa_assert(cb);
 | 
					    pa_assert(cb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!p->memory.shared)
 | 
					    if (!pa_mempool_is_shared(p))
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    e = pa_xnew(pa_memexport, 1);
 | 
					    e = pa_xnew(pa_memexport, 1);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,7 @@ typedef struct pa_memblock pa_memblock;
 | 
				
			||||||
#include <pulse/xmalloc.h>
 | 
					#include <pulse/xmalloc.h>
 | 
				
			||||||
#include <pulsecore/atomic.h>
 | 
					#include <pulsecore/atomic.h>
 | 
				
			||||||
#include <pulsecore/memchunk.h>
 | 
					#include <pulsecore/memchunk.h>
 | 
				
			||||||
 | 
					#include <pulsecore/mem.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* A pa_memblock is a reference counted memory block. PulseAudio
 | 
					/* A pa_memblock is a reference counted memory block. PulseAudio
 | 
				
			||||||
 * passes references to pa_memblocks around instead of copying
 | 
					 * passes references to pa_memblocks around instead of copying
 | 
				
			||||||
| 
						 | 
					@ -123,7 +124,7 @@ pa_mempool * pa_memblock_get_pool(pa_memblock *b);
 | 
				
			||||||
pa_memblock *pa_memblock_will_need(pa_memblock *b);
 | 
					pa_memblock *pa_memblock_will_need(pa_memblock *b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* The memory block manager */
 | 
					/* The memory block manager */
 | 
				
			||||||
pa_mempool* pa_mempool_new(bool shared, size_t size);
 | 
					pa_mempool *pa_mempool_new(pa_mem_type_t type, size_t size);
 | 
				
			||||||
void pa_mempool_unref(pa_mempool *p);
 | 
					void pa_mempool_unref(pa_mempool *p);
 | 
				
			||||||
pa_mempool* pa_mempool_ref(pa_mempool *p);
 | 
					pa_mempool* pa_mempool_ref(pa_mempool *p);
 | 
				
			||||||
const pa_mempool_stat* pa_mempool_get_stat(pa_mempool *p);
 | 
					const pa_mempool_stat* pa_mempool_get_stat(pa_mempool *p);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,6 +55,7 @@
 | 
				
			||||||
#include <pulsecore/core-util.h>
 | 
					#include <pulsecore/core-util.h>
 | 
				
			||||||
#include <pulsecore/ipacl.h>
 | 
					#include <pulsecore/ipacl.h>
 | 
				
			||||||
#include <pulsecore/thread-mq.h>
 | 
					#include <pulsecore/thread-mq.h>
 | 
				
			||||||
 | 
					#include <pulsecore/mem.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "protocol-native.h"
 | 
					#include "protocol-native.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2621,7 +2622,7 @@ static void setup_srbchannel(pa_native_connection *c) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!(c->rw_mempool = pa_mempool_new(true, c->protocol->core->shm_size))) {
 | 
					    if (!(c->rw_mempool = pa_mempool_new(PA_MEM_TYPE_SHARED_POSIX, c->protocol->core->shm_size))) {
 | 
				
			||||||
        pa_log_warn("Disabling srbchannel, reason: Failed to allocate shared "
 | 
					        pa_log_warn("Disabling srbchannel, reason: Failed to allocate shared "
 | 
				
			||||||
                    "writable memory pool.");
 | 
					                    "writable memory pool.");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +51,7 @@
 | 
				
			||||||
#include <pulsecore/core-util.h>
 | 
					#include <pulsecore/core-util.h>
 | 
				
			||||||
#include <pulsecore/macro.h>
 | 
					#include <pulsecore/macro.h>
 | 
				
			||||||
#include <pulsecore/atomic.h>
 | 
					#include <pulsecore/atomic.h>
 | 
				
			||||||
 | 
					#include <pulsecore/mem.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "shm.h"
 | 
					#include "shm.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -100,7 +101,7 @@ static char *segment_name(char *fn, size_t l, unsigned id) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int pa_shm_create_rw(pa_shm *m, size_t size, bool shared, mode_t mode) {
 | 
					int pa_shm_create_rw(pa_shm *m, pa_mem_type_t type, size_t size, mode_t mode) {
 | 
				
			||||||
#ifdef HAVE_SHM_OPEN
 | 
					#ifdef HAVE_SHM_OPEN
 | 
				
			||||||
    char fn[32];
 | 
					    char fn[32];
 | 
				
			||||||
    int fd = -1;
 | 
					    int fd = -1;
 | 
				
			||||||
| 
						 | 
					@ -119,7 +120,7 @@ int pa_shm_create_rw(pa_shm *m, size_t size, bool shared, mode_t mode) {
 | 
				
			||||||
    /* Round up to make it page aligned */
 | 
					    /* Round up to make it page aligned */
 | 
				
			||||||
    size = PA_PAGE_ALIGN(size);
 | 
					    size = PA_PAGE_ALIGN(size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!shared) {
 | 
					    if (!pa_mem_type_is_shared(type)) {
 | 
				
			||||||
        m->id = 0;
 | 
					        m->id = 0;
 | 
				
			||||||
        m->size = size;
 | 
					        m->size = size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -184,7 +185,7 @@ int pa_shm_create_rw(pa_shm *m, size_t size, bool shared, mode_t mode) {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m->shared = shared;
 | 
					    m->type = type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -209,7 +210,7 @@ void pa_shm_free(pa_shm *m) {
 | 
				
			||||||
    pa_assert(m->ptr != MAP_FAILED);
 | 
					    pa_assert(m->ptr != MAP_FAILED);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!m->shared) {
 | 
					    if (!pa_mem_type_is_shared(m->type)) {
 | 
				
			||||||
#ifdef MAP_ANONYMOUS
 | 
					#ifdef MAP_ANONYMOUS
 | 
				
			||||||
        if (munmap(m->ptr, m->size) < 0)
 | 
					        if (munmap(m->ptr, m->size) < 0)
 | 
				
			||||||
            pa_log("munmap() failed: %s", pa_cstrerror(errno));
 | 
					            pa_log("munmap() failed: %s", pa_cstrerror(errno));
 | 
				
			||||||
| 
						 | 
					@ -325,7 +326,7 @@ static int shm_attach(pa_shm *m, unsigned id, bool writable, bool for_cleanup) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m->do_unlink = false;
 | 
					    m->do_unlink = false;
 | 
				
			||||||
    m->shared = true;
 | 
					    m->type = PA_MEM_TYPE_SHARED_POSIX;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert_se(pa_close(fd) == 0);
 | 
					    pa_assert_se(pa_close(fd) == 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,16 +23,17 @@
 | 
				
			||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <pulsecore/macro.h>
 | 
					#include <pulsecore/macro.h>
 | 
				
			||||||
 | 
					#include <pulsecore/mem.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct pa_shm {
 | 
					typedef struct pa_shm {
 | 
				
			||||||
 | 
					    pa_mem_type_t type;
 | 
				
			||||||
    unsigned id;
 | 
					    unsigned id;
 | 
				
			||||||
    void *ptr;
 | 
					    void *ptr;
 | 
				
			||||||
    size_t size;
 | 
					    size_t size;
 | 
				
			||||||
    bool do_unlink:1;
 | 
					    bool do_unlink:1;
 | 
				
			||||||
    bool shared:1;
 | 
					 | 
				
			||||||
} pa_shm;
 | 
					} pa_shm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int pa_shm_create_rw(pa_shm *m, size_t size, bool shared, mode_t mode);
 | 
					int pa_shm_create_rw(pa_shm *m, pa_mem_type_t type, size_t size, mode_t mode);
 | 
				
			||||||
int pa_shm_attach(pa_shm *m, unsigned id, bool writable);
 | 
					int pa_shm_attach(pa_shm *m, unsigned id, bool writable);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pa_shm_punch(pa_shm *m, size_t offset, size_t size);
 | 
					void pa_shm_punch(pa_shm *m, size_t offset, size_t size);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -76,7 +76,7 @@ static void run_mix_test(
 | 
				
			||||||
    samples_ref = out_ref + (8 - align);
 | 
					    samples_ref = out_ref + (8 - align);
 | 
				
			||||||
    nsamples = channels * (SAMPLES - (8 - align));
 | 
					    nsamples = channels * (SAMPLES - (8 - align));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fail_unless((pool = pa_mempool_new(false, 0)) != NULL, NULL);
 | 
					    fail_unless((pool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0)) != NULL, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_random(samples0, nsamples * sizeof(int16_t));
 | 
					    pa_random(samples0, nsamples * sizeof(int16_t));
 | 
				
			||||||
    c0.memblock = pa_memblock_new_fixed(pool, samples0, nsamples * sizeof(int16_t), false);
 | 
					    c0.memblock = pa_memblock_new_fixed(pool, samples0, nsamples * sizeof(int16_t), false);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -136,7 +136,7 @@ START_TEST (lfe_filter_test) {
 | 
				
			||||||
    a.format = PA_SAMPLE_S16NE;
 | 
					    a.format = PA_SAMPLE_S16NE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lft.ss = &a;
 | 
					    lft.ss = &a;
 | 
				
			||||||
    pa_assert_se(lft.pool = pa_mempool_new(false, 0));
 | 
					    pa_assert_se(lft.pool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* We prepare pseudo-random input audio samples for lfe-filter rewind testing*/
 | 
					    /* We prepare pseudo-random input audio samples for lfe-filter rewind testing*/
 | 
				
			||||||
    ori_sample_ptr = pa_xmalloc(pa_frame_size(lft.ss) * TOTAL_SAMPLES);
 | 
					    ori_sample_ptr = pa_xmalloc(pa_frame_size(lft.ss) * TOTAL_SAMPLES);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,7 +36,7 @@ int main(int argc, char *argv[]) {
 | 
				
			||||||
    pa_mcalign *a;
 | 
					    pa_mcalign *a;
 | 
				
			||||||
    pa_memchunk c;
 | 
					    pa_memchunk c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    p = pa_mempool_new(false, 0);
 | 
					    p = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    a = pa_mcalign_new(11);
 | 
					    a = pa_mcalign_new(11);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,11 +80,11 @@ START_TEST (memblock_test) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const char txt[] = "This is a test!";
 | 
					    const char txt[] = "This is a test!";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pool_a = pa_mempool_new(true, 0);
 | 
					    pool_a = pa_mempool_new(PA_MEM_TYPE_SHARED_POSIX, 0);
 | 
				
			||||||
    fail_unless(pool_a != NULL);
 | 
					    fail_unless(pool_a != NULL);
 | 
				
			||||||
    pool_b = pa_mempool_new(true, 0);
 | 
					    pool_b = pa_mempool_new(PA_MEM_TYPE_SHARED_POSIX, 0);
 | 
				
			||||||
    fail_unless(pool_b != NULL);
 | 
					    fail_unless(pool_b != NULL);
 | 
				
			||||||
    pool_c = pa_mempool_new(true, 0);
 | 
					    pool_c = pa_mempool_new(PA_MEM_TYPE_SHARED_POSIX, 0);
 | 
				
			||||||
    fail_unless(pool_c != NULL);
 | 
					    fail_unless(pool_c != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_mempool_get_shm_id(pool_a, &id_a);
 | 
					    pa_mempool_get_shm_id(pool_a, &id_a);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -108,7 +108,7 @@ START_TEST (memblockq_test) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_log_set_level(PA_LOG_DEBUG);
 | 
					    pa_log_set_level(PA_LOG_DEBUG);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    p = pa_mempool_new(false, 0);
 | 
					    p = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    silence.memblock = pa_memblock_new_fixed(p, (char*) "__", 2, 1);
 | 
					    silence.memblock = pa_memblock_new_fixed(p, (char*) "__", 2, 1);
 | 
				
			||||||
    fail_unless(silence.memblock != NULL);
 | 
					    fail_unless(silence.memblock != NULL);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -286,7 +286,7 @@ START_TEST (mix_test) {
 | 
				
			||||||
    if (!getenv("MAKE_CHECK"))
 | 
					    if (!getenv("MAKE_CHECK"))
 | 
				
			||||||
        pa_log_set_level(PA_LOG_DEBUG);
 | 
					        pa_log_set_level(PA_LOG_DEBUG);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fail_unless((pool = pa_mempool_new(false, 0)) != NULL, NULL);
 | 
					    fail_unless((pool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0)) != NULL, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    a.channels = 1;
 | 
					    a.channels = 1;
 | 
				
			||||||
    a.rate = 44100;
 | 
					    a.rate = 44100;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,7 +51,7 @@ int main(int argc, char *argv[]) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_log_set_level(PA_LOG_DEBUG);
 | 
					    pa_log_set_level(PA_LOG_DEBUG);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert_se(pool = pa_mempool_new(false, 0));
 | 
					    pa_assert_se(pool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (i = 0; maps[i].channels > 0; i++)
 | 
					    for (i = 0; maps[i].channels > 0; i++)
 | 
				
			||||||
        for (j = 0; maps[j].channels > 0; j++) {
 | 
					        for (j = 0; maps[j].channels > 0; j++) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -404,7 +404,7 @@ int main(int argc, char *argv[]) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = 0;
 | 
					    ret = 0;
 | 
				
			||||||
    pa_assert_se(pool = pa_mempool_new(false, 0));
 | 
					    pa_assert_se(pool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!all_formats) {
 | 
					    if (!all_formats) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,7 +85,7 @@ START_TEST (srbchannel_test) {
 | 
				
			||||||
    int pipefd[4];
 | 
					    int pipefd[4];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_mainloop *ml = pa_mainloop_new();
 | 
					    pa_mainloop *ml = pa_mainloop_new();
 | 
				
			||||||
    pa_mempool *mp = pa_mempool_new(true, 0);
 | 
					    pa_mempool *mp = pa_mempool_new(PA_MEM_TYPE_SHARED_POSIX, 0);
 | 
				
			||||||
    pa_iochannel *io1, *io2;
 | 
					    pa_iochannel *io1, *io2;
 | 
				
			||||||
    pa_pstream *p1, *p2;
 | 
					    pa_pstream *p1, *p2;
 | 
				
			||||||
    pa_srbchannel *sr1, *sr2;
 | 
					    pa_srbchannel *sr1, *sr2;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue