mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-09 13:29:59 -05:00
memblock: Add pa_memblock_acquire_chunk().
Besides making the code a bit cleaner, this also gets rid of a few "cast increases required alignment of target type" warnings.
This commit is contained in:
parent
33e5802df2
commit
3d6092bb0f
16 changed files with 52 additions and 40 deletions
|
|
@ -459,6 +459,13 @@ void* pa_memblock_acquire(pa_memblock *b) {
|
|||
return pa_atomic_ptr_load(&b->data);
|
||||
}
|
||||
|
||||
/* No lock necessary */
|
||||
void *pa_memblock_acquire_chunk(const pa_memchunk *c) {
|
||||
pa_assert(c);
|
||||
|
||||
return (uint8_t *) pa_memblock_acquire(c->memblock) + c->index;
|
||||
}
|
||||
|
||||
/* No lock necessary, in corner cases locks by its own */
|
||||
void pa_memblock_release(pa_memblock *b) {
|
||||
int r;
|
||||
|
|
|
|||
|
|
@ -23,11 +23,14 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
typedef struct pa_memblock pa_memblock;
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <pulse/def.h>
|
||||
#include <pulsecore/atomic.h>
|
||||
#include <pulsecore/memchunk.h>
|
||||
|
||||
/* A pa_memblock is a reference counted memory block. PulseAudio
|
||||
* passes references to pa_memblocks around instead of copying
|
||||
|
|
@ -45,7 +48,6 @@ typedef enum pa_memblock_type {
|
|||
PA_MEMBLOCK_TYPE_MAX
|
||||
} pa_memblock_type_t;
|
||||
|
||||
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;
|
||||
|
|
@ -108,7 +110,9 @@ pa_bool_t pa_memblock_ref_is_one(pa_memblock *b);
|
|||
void pa_memblock_set_is_silence(pa_memblock *b, pa_bool_t v);
|
||||
|
||||
void* pa_memblock_acquire(pa_memblock *b);
|
||||
void *pa_memblock_acquire_chunk(const pa_memchunk *c);
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ pa_memchunk *pa_memchunk_will_need(const pa_memchunk *c) {
|
|||
/* A version of pa_memblock_will_need() that works on memchunks
|
||||
* instead of memblocks */
|
||||
|
||||
p = (uint8_t*) pa_memblock_acquire(c->memblock) + c->index;
|
||||
p = pa_memblock_acquire_chunk(c);
|
||||
pa_will_need(p, c->length);
|
||||
pa_memblock_release(c->memblock);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,16 +22,18 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
typedef struct pa_memchunk pa_memchunk;
|
||||
|
||||
#include <pulsecore/memblock.h>
|
||||
|
||||
/* A memchunk describes a part of a memblock. In contrast to the memblock, a
|
||||
* memchunk is not allocated dynamically or reference counted, instead
|
||||
* it is usually stored on the stack and copied around */
|
||||
|
||||
typedef struct pa_memchunk {
|
||||
struct pa_memchunk {
|
||||
pa_memblock *memblock;
|
||||
size_t index, length;
|
||||
} pa_memchunk;
|
||||
};
|
||||
|
||||
/* Make a memchunk writable, i.e. make sure that the caller may have
|
||||
* exclusive access to the memblock and it is not read-only. If needed
|
||||
|
|
|
|||
|
|
@ -577,7 +577,7 @@ static int do_write(pa_pstream *p) {
|
|||
if (p->write.data)
|
||||
d = p->write.data;
|
||||
else {
|
||||
d = (uint8_t*) pa_memblock_acquire(p->write.memchunk.memblock) + p->write.memchunk.index;
|
||||
d = pa_memblock_acquire_chunk(&p->write.memchunk);
|
||||
release_memblock = p->write.memchunk.memblock;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1119,8 +1119,8 @@ static pa_memchunk* convert_to_work_format(pa_resampler *r, pa_memchunk *input)
|
|||
r->to_work_format_buf.memblock = pa_memblock_new(r->mempool, r->to_work_format_buf.length);
|
||||
}
|
||||
|
||||
src = (uint8_t*) pa_memblock_acquire(input->memblock) + input->index;
|
||||
dst = (uint8_t*) pa_memblock_acquire(r->to_work_format_buf.memblock);
|
||||
src = pa_memblock_acquire_chunk(input);
|
||||
dst = pa_memblock_acquire(r->to_work_format_buf.memblock);
|
||||
|
||||
r->to_work_format_func(n_samples, src, dst);
|
||||
|
||||
|
|
@ -1188,7 +1188,7 @@ static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) {
|
|||
}
|
||||
}
|
||||
|
||||
src = (uint8_t *) pa_memblock_acquire(input->memblock) + input->index;
|
||||
src = pa_memblock_acquire_chunk(input);
|
||||
dst = (uint8_t *) pa_memblock_acquire(r->remap_buf.memblock) + leftover_length;
|
||||
|
||||
if (r->map_required) {
|
||||
|
|
@ -1268,7 +1268,7 @@ static pa_memchunk *convert_from_work_format(pa_resampler *r, pa_memchunk *input
|
|||
r->from_work_format_buf.memblock = pa_memblock_new(r->mempool, r->from_work_format_buf.length);
|
||||
}
|
||||
|
||||
src = (uint8_t*) pa_memblock_acquire(input->memblock) + input->index;
|
||||
src = pa_memblock_acquire_chunk(input);
|
||||
dst = pa_memblock_acquire(r->from_work_format_buf.memblock);
|
||||
r->from_work_format_func(n_samples, src, dst);
|
||||
pa_memblock_release(input->memblock);
|
||||
|
|
@ -1345,10 +1345,10 @@ static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, un
|
|||
|
||||
memset(&data, 0, sizeof(data));
|
||||
|
||||
data.data_in = (float*) ((uint8_t*) pa_memblock_acquire(input->memblock) + input->index);
|
||||
data.data_in = pa_memblock_acquire_chunk(input);
|
||||
data.input_frames = (long int) in_n_frames;
|
||||
|
||||
data.data_out = (float*) ((uint8_t*) pa_memblock_acquire(output->memblock) + output->index);
|
||||
data.data_out = pa_memblock_acquire_chunk(output);
|
||||
data.output_frames = (long int) *out_n_frames;
|
||||
|
||||
data.src_ratio = (double) r->o_ss.rate / r->i_ss.rate;
|
||||
|
|
@ -1417,8 +1417,8 @@ static void speex_resample_float(pa_resampler *r, const pa_memchunk *input, unsi
|
|||
pa_assert(output);
|
||||
pa_assert(out_n_frames);
|
||||
|
||||
in = (float*) ((uint8_t*) pa_memblock_acquire(input->memblock) + input->index);
|
||||
out = (float*) ((uint8_t*) pa_memblock_acquire(output->memblock) + output->index);
|
||||
in = pa_memblock_acquire_chunk(input);
|
||||
out = pa_memblock_acquire_chunk(output);
|
||||
|
||||
pa_assert_se(speex_resampler_process_interleaved_float(r->speex.state, in, &inf, out, &outf) == 0);
|
||||
|
||||
|
|
@ -1438,8 +1438,8 @@ static void speex_resample_int(pa_resampler *r, const pa_memchunk *input, unsign
|
|||
pa_assert(output);
|
||||
pa_assert(out_n_frames);
|
||||
|
||||
in = (int16_t*) ((uint8_t*) pa_memblock_acquire(input->memblock) + input->index);
|
||||
out = (int16_t*) ((uint8_t*) pa_memblock_acquire(output->memblock) + output->index);
|
||||
in = pa_memblock_acquire_chunk(input);
|
||||
out = pa_memblock_acquire_chunk(output);
|
||||
|
||||
pa_assert_se(speex_resampler_process_interleaved_int(r->speex.state, in, &inf, out, &outf) == 0);
|
||||
|
||||
|
|
@ -1515,8 +1515,8 @@ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned
|
|||
|
||||
fz = r->w_sz * r->o_ss.channels;
|
||||
|
||||
src = (uint8_t*) pa_memblock_acquire(input->memblock) + input->index;
|
||||
dst = (uint8_t*) pa_memblock_acquire(output->memblock) + output->index;
|
||||
src = pa_memblock_acquire_chunk(input);
|
||||
dst = pa_memblock_acquire_chunk(output);
|
||||
|
||||
for (o_index = 0;; o_index++, r->trivial.o_counter++) {
|
||||
i_index = (r->trivial.o_counter * r->i_ss.rate) / r->o_ss.rate;
|
||||
|
|
@ -1577,8 +1577,8 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i
|
|||
pa_assert(output);
|
||||
pa_assert(out_n_frames);
|
||||
|
||||
src = (uint8_t*) pa_memblock_acquire(input->memblock) + input->index;
|
||||
dst = (uint8_t*) pa_memblock_acquire(output->memblock) + output->index;
|
||||
src = pa_memblock_acquire_chunk(input);
|
||||
dst = pa_memblock_acquire_chunk(output);
|
||||
|
||||
i = (r->peaks.o_counter * r->i_ss.rate) / r->o_ss.rate;
|
||||
i = i > r->peaks.i_counter ? i - r->peaks.i_counter : 0;
|
||||
|
|
@ -1708,8 +1708,8 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned
|
|||
p = pa_memblock_acquire(b);
|
||||
|
||||
/* Now copy the input data, splitting up channels */
|
||||
t = ((int16_t*) ((uint8_t*) pa_memblock_acquire(input->memblock) + input->index)) + c;
|
||||
k = (int16_t*) ((uint8_t*) p);
|
||||
t = (int16_t*) pa_memblock_acquire_chunk(input) + c;
|
||||
k = p;
|
||||
for (u = 0; u < in_n_frames; u++) {
|
||||
*k = *t;
|
||||
t += r->o_ss.channels;
|
||||
|
|
@ -1736,7 +1736,7 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned
|
|||
previous_consumed_frames = consumed_frames;
|
||||
|
||||
/* And place the results in the output buffer */
|
||||
s = (short*) ((uint8_t*) pa_memblock_acquire(output->memblock) + output->index) + c;
|
||||
s = (int16_t *) pa_memblock_acquire_chunk(output) + c;
|
||||
for (u = 0; u < used_frames; u++) {
|
||||
*s = *q;
|
||||
q++;
|
||||
|
|
@ -1748,7 +1748,7 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned
|
|||
}
|
||||
|
||||
if (previous_consumed_frames < (int) in_n_frames) {
|
||||
void *leftover_data = (int16_t *) ((uint8_t *) pa_memblock_acquire(input->memblock) + output->index) + previous_consumed_frames * r->o_ss.channels;
|
||||
void *leftover_data = (int16_t *) pa_memblock_acquire_chunk(input) + previous_consumed_frames * r->o_ss.channels;
|
||||
size_t leftover_length = (in_n_frames - previous_consumed_frames) * r->o_ss.channels * sizeof(int16_t);
|
||||
|
||||
save_leftover(r, leftover_data, leftover_length);
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ size_t pa_mix(
|
|||
}
|
||||
|
||||
for (k = 0; k < nstreams; k++)
|
||||
streams[k].ptr = (uint8_t*) pa_memblock_acquire(streams[k].chunk.memblock) + streams[k].chunk.index;
|
||||
streams[k].ptr = pa_memblock_acquire_chunk(&streams[k].chunk);
|
||||
|
||||
for (z = 0; z < nstreams; z++)
|
||||
if (length > streams[z].chunk.length)
|
||||
|
|
@ -741,7 +741,7 @@ void pa_volume_memchunk(
|
|||
|
||||
calc_volume_table[spec->format] ((void *)linear, volume);
|
||||
|
||||
ptr = (uint8_t*) pa_memblock_acquire(c->memblock) + c->index;
|
||||
ptr = pa_memblock_acquire_chunk(c);
|
||||
|
||||
do_volume (ptr, (void *)linear, spec->channels, c->length);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue