2004-07-16 19:56:36 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***
|
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
|
|
|
|
|
|
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-07-16 19:16:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-07-03 00:19:40 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <errno.h>
|
2004-07-03 00:19:40 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/macro.h>
|
|
|
|
|
#include <pulsecore/core-util.h>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2004-07-03 00:19:40 +00:00
|
|
|
#include "memchunk.h"
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_memchunk* pa_memchunk_make_writable(pa_memchunk *c, size_t min) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_memblock *n;
|
2004-11-17 00:05:25 +00:00
|
|
|
size_t l;
|
2007-10-28 19:13:50 +00:00
|
|
|
void *tdata, *sdata;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(c->memblock);
|
2004-07-03 00:19:40 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (pa_memblock_ref_is_one(c->memblock) &&
|
|
|
|
|
!pa_memblock_is_read_only(c->memblock) &&
|
|
|
|
|
pa_memblock_get_length(c->memblock) >= c->index+min)
|
|
|
|
|
return c;
|
2004-11-17 00:05:25 +00:00
|
|
|
|
|
|
|
|
l = c->length;
|
|
|
|
|
if (l < min)
|
|
|
|
|
l = min;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
n = pa_memblock_new(pa_memblock_get_pool(c->memblock), l);
|
|
|
|
|
tdata = pa_memblock_acquire(n);
|
|
|
|
|
sdata = pa_memblock_acquire(c->memblock);
|
|
|
|
|
memcpy(tdata, (uint8_t*) sdata + c->index, c->length);
|
|
|
|
|
pa_memblock_release(n);
|
|
|
|
|
pa_memblock_release(c->memblock);
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_memblock_unref(c->memblock);
|
2004-07-03 00:19:40 +00:00
|
|
|
c->memblock = n;
|
|
|
|
|
c->index = 0;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
return c;
|
2004-07-03 00:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_memchunk* pa_memchunk_reset(pa_memchunk *c) {
|
|
|
|
|
pa_assert(c);
|
2004-07-03 00:19:40 +00:00
|
|
|
|
2008-06-13 21:06:31 +00:00
|
|
|
memset(c, 0, sizeof(*c));
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_memchunk *pa_memchunk_will_need(const pa_memchunk *c) {
|
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(c->memblock);
|
|
|
|
|
|
|
|
|
|
/* A version of pa_memblock_will_need() that works on memchunks
|
|
|
|
|
* instead of memblocks */
|
|
|
|
|
|
|
|
|
|
p = (uint8_t*) pa_memblock_acquire(c->memblock) + c->index;
|
|
|
|
|
pa_will_need(p, c->length);
|
|
|
|
|
pa_memblock_release(c->memblock);
|
|
|
|
|
|
|
|
|
|
return (pa_memchunk*) c;
|
2004-07-03 00:19:40 +00:00
|
|
|
}
|
2008-05-15 23:34:41 +00:00
|
|
|
|
|
|
|
|
pa_memchunk* pa_memchunk_memcpy(pa_memchunk *dst, pa_memchunk *src) {
|
|
|
|
|
void *p, *q;
|
|
|
|
|
|
|
|
|
|
pa_assert(dst);
|
|
|
|
|
pa_assert(src);
|
|
|
|
|
pa_assert(dst->length == src->length);
|
|
|
|
|
|
|
|
|
|
p = pa_memblock_acquire(dst->memblock);
|
|
|
|
|
q = pa_memblock_acquire(src->memblock);
|
|
|
|
|
|
|
|
|
|
memmove((uint8_t*) p + dst->index,
|
|
|
|
|
(uint8_t*) q + src->index,
|
|
|
|
|
dst->length);
|
|
|
|
|
|
|
|
|
|
pa_memblock_release(dst->memblock);
|
|
|
|
|
pa_memblock_release(src->memblock);
|
|
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
|
}
|