mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -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
|
|
@ -532,7 +532,7 @@ static int hsp_process_render(struct userdata *u) {
|
|||
* SEQPACKET, and we generated the data of the MTU size, so this
|
||||
* should just work. */
|
||||
|
||||
p = (const uint8_t*) pa_memblock_acquire(u->write_memchunk.memblock) + u->write_memchunk.index;
|
||||
p = (const uint8_t *) pa_memblock_acquire_chunk(&u->write_memchunk);
|
||||
l = pa_write(u->stream_fd, p, u->write_memchunk.length, &u->stream_write_type);
|
||||
pa_memblock_release(u->write_memchunk.memblock);
|
||||
|
||||
|
|
@ -706,7 +706,7 @@ static int a2dp_process_render(struct userdata *u) {
|
|||
|
||||
/* Try to create a packet of the full MTU */
|
||||
|
||||
p = (const uint8_t*) pa_memblock_acquire(u->write_memchunk.memblock) + u->write_memchunk.index;
|
||||
p = (const uint8_t *) pa_memblock_acquire_chunk(&u->write_memchunk);
|
||||
to_encode = u->write_memchunk.length;
|
||||
|
||||
d = (uint8_t*) a2dp->buffer + sizeof(*header) + sizeof(*payload);
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
|
|||
|
||||
pa_sink_render_full(u->sink, nbytes, &chunk);
|
||||
|
||||
p = (uint8_t*) pa_memblock_acquire(chunk.memblock) + chunk.index;
|
||||
p = pa_memblock_acquire_chunk(&chunk);
|
||||
pa_deinterleave(p, u->buffer, u->channels, sizeof(float), (unsigned) offset);
|
||||
pa_memblock_release(chunk.memblock);
|
||||
|
||||
|
|
|
|||
|
|
@ -575,7 +575,7 @@ static void process_samples(struct userdata *u){
|
|||
static void input_buffer(struct userdata *u, pa_memchunk *in){
|
||||
size_t fs = pa_frame_size(&(u->sink->sample_spec));
|
||||
size_t samples = in->length/fs;
|
||||
float *src = (float*) ((uint8_t*) pa_memblock_acquire(in->memblock) + in->index);
|
||||
float *src = pa_memblock_acquire_chunk(in);
|
||||
pa_assert(u->samples_gathered + samples <= u->input_buffer_max);
|
||||
for(size_t c = 0; c < u->channels; c++) {
|
||||
//buffer with an offset after the overlap from previous
|
||||
|
|
|
|||
|
|
@ -488,8 +488,8 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
|
|||
|
||||
pa_memblockq_drop(u->memblockq, chunk->length);
|
||||
|
||||
src = (float*) ((uint8_t*) pa_memblock_acquire(tchunk.memblock) + tchunk.index);
|
||||
dst = (float*) pa_memblock_acquire(chunk->memblock);
|
||||
src = pa_memblock_acquire_chunk(&tchunk);
|
||||
dst = pa_memblock_acquire(chunk->memblock);
|
||||
|
||||
for (h = 0; h < (u->channels / u->max_ladspaport_count); h++) {
|
||||
for (c = 0; c < u->input_count; c++)
|
||||
|
|
|
|||
|
|
@ -238,8 +238,8 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
|
|||
|
||||
pa_memblockq_drop(u->memblockq, chunk->length);
|
||||
|
||||
src = (float*) ((uint8_t*) pa_memblock_acquire(tchunk.memblock) + tchunk.index);
|
||||
dst = (float*) pa_memblock_acquire(chunk->memblock);
|
||||
src = pa_memblock_acquire_chunk(&tchunk);
|
||||
dst = pa_memblock_acquire(chunk->memblock);
|
||||
|
||||
/* (3) PUT YOUR CODE HERE TO DO SOMETHING WITH THE DATA */
|
||||
|
||||
|
|
|
|||
|
|
@ -311,8 +311,7 @@ static void source_output_push_cb(pa_source_output *o, const pa_memchunk *chunk)
|
|||
pa_assert( target_chunk.memblock );
|
||||
|
||||
/* get target pointer */
|
||||
target = (void*)((uint8_t*)pa_memblock_acquire(target_chunk.memblock)
|
||||
+ target_chunk.index);
|
||||
target = pa_memblock_acquire_chunk(&target_chunk);
|
||||
|
||||
/* set-up mixing structure
|
||||
volume was taken care of in sink and source already */
|
||||
|
|
|
|||
|
|
@ -252,8 +252,8 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
|
|||
|
||||
pa_memblockq_drop(u->memblockq, n * u->sink_fs);
|
||||
|
||||
src = (float*) ((uint8_t*) pa_memblock_acquire(tchunk.memblock) + tchunk.index);
|
||||
dst = (float*) pa_memblock_acquire(chunk->memblock);
|
||||
src = pa_memblock_acquire_chunk(&tchunk);
|
||||
dst = pa_memblock_acquire(chunk->memblock);
|
||||
|
||||
for (l = 0; l < n; l++) {
|
||||
memcpy(((char*) u->input_buffer) + u->input_buffer_offset * u->sink_fs, ((char *) src) + l * u->sink_fs, u->sink_fs);
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q) {
|
|||
|
||||
pa_assert(chunk.memblock);
|
||||
|
||||
iov[iov_idx].iov_base = ((uint8_t*) pa_memblock_acquire(chunk.memblock) + chunk.index);
|
||||
iov[iov_idx].iov_base = pa_memblock_acquire_chunk(&chunk);
|
||||
iov[iov_idx].iov_len = k;
|
||||
mb[iov_idx] = chunk.memblock;
|
||||
iov_idx ++;
|
||||
|
|
@ -203,7 +203,7 @@ int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_mempool *pool, struct
|
|||
chunk->memblock = pa_memblock_ref(c->memchunk.memblock);
|
||||
chunk->index = c->memchunk.index;
|
||||
|
||||
iov.iov_base = (uint8_t*) pa_memblock_acquire(chunk->memblock) + chunk->index;
|
||||
iov.iov_base = pa_memblock_acquire_chunk(chunk);
|
||||
iov.iov_len = (size_t) size;
|
||||
|
||||
m.msg_name = NULL;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -450,7 +450,7 @@ START_TEST (mix_test) {
|
|||
k.length = i.length;
|
||||
k.index = 0;
|
||||
|
||||
ptr = (uint8_t*) pa_memblock_acquire(k.memblock) + k.index;
|
||||
ptr = pa_memblock_acquire_chunk(&k);
|
||||
pa_mix(m, 2, ptr, k.length, &a, NULL, FALSE);
|
||||
pa_memblock_release(k.memblock);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue