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
|
|
|
|
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 <assert.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2004-07-03 00:19:40 +00:00
|
|
|
#include "memchunk.h"
|
|
|
|
|
|
2006-08-18 19:55:18 +00:00
|
|
|
void 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-01-04 13:43:45 +00:00
|
|
|
|
2006-08-18 19:55:18 +00:00
|
|
|
assert(c);
|
|
|
|
|
assert(c->memblock);
|
2006-11-06 13:06:01 +00:00
|
|
|
assert(PA_REFCNT_VALUE(c->memblock) > 0);
|
2004-07-03 00:19:40 +00:00
|
|
|
|
2006-11-06 13:06:01 +00:00
|
|
|
if (PA_REFCNT_VALUE(c->memblock) == 1 &&
|
|
|
|
|
!c->memblock->read_only &&
|
|
|
|
|
c->memblock->length >= c->index+min)
|
2004-07-03 00:19:40 +00:00
|
|
|
return;
|
2004-11-17 00:05:25 +00:00
|
|
|
|
|
|
|
|
l = c->length;
|
|
|
|
|
if (l < min)
|
|
|
|
|
l = min;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-11-06 13:06:01 +00:00
|
|
|
n = pa_memblock_new(c->memblock->pool, l);
|
|
|
|
|
memcpy(n->data, (uint8_t*) c->memblock->data + c->index, c->length);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_memchunk_reset(pa_memchunk *c) {
|
2004-11-17 00:05:25 +00:00
|
|
|
assert(c);
|
2004-07-03 00:19:40 +00:00
|
|
|
|
2004-11-17 00:05:25 +00:00
|
|
|
c->memblock = NULL;
|
|
|
|
|
c->length = c->index = 0;
|
2004-07-03 00:19:40 +00:00
|
|
|
}
|