mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-07 13:30:03 -05:00
Rework memory management to allow shared memory data transfer. The central idea
is to allocate all audio memory blocks from a per-process memory pool which is available as read-only SHM segment to other local processes. Then, instead of writing the actual audio data to the socket just write references to this shared memory pool. To work optimally all memory blocks should now be of type PA_MEMBLOCK_POOL or PA_MEMBLOCK_POOL_EXTERNAL. The function pa_memblock_new() now generates memory blocks of this type by default. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1266 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
ff48681aae
commit
0e436a6926
45 changed files with 1235 additions and 312 deletions
|
|
@ -492,7 +492,7 @@ int pa__init(pa_core *c, pa_module*m) {
|
|||
|
||||
pa_log_info(__FILE__": using %u fragments of size %lu bytes.", periods, (long unsigned)u->fragment_size);
|
||||
|
||||
u->silence.memblock = pa_memblock_new(u->silence.length = u->fragment_size, c->memblock_stat);
|
||||
u->silence.memblock = pa_memblock_new(c->mempool, u->silence.length = u->fragment_size);
|
||||
assert(u->silence.memblock);
|
||||
pa_silence_memblock(u->silence.memblock, &ss);
|
||||
u->silence.index = 0;
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ static void do_read(struct userdata *u) {
|
|||
size_t l;
|
||||
|
||||
if (!u->memchunk.memblock) {
|
||||
u->memchunk.memblock = pa_memblock_new(u->memchunk.length = u->fragment_size, u->source->core->memblock_stat);
|
||||
u->memchunk.memblock = pa_memblock_new(u->source->core->mempool, u->memchunk.length = u->fragment_size);
|
||||
u->memchunk.index = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -235,8 +235,7 @@ static struct output *output_new(struct userdata *u, pa_sink *sink, int resample
|
|||
pa_frame_size(&u->sink->sample_spec),
|
||||
1,
|
||||
0,
|
||||
NULL,
|
||||
sink->core->memblock_stat);
|
||||
NULL);
|
||||
|
||||
snprintf(t, sizeof(t), "%s: output #%u", u->sink->name, u->n_outputs+1);
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ static void io_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event_
|
|||
|
||||
fs = pa_frame_size(&u->source->sample_spec);
|
||||
|
||||
chunk.memblock = pa_memblock_new(chunk.length = u->frames_posted * fs, u->core->memblock_stat);
|
||||
chunk.memblock = pa_memblock_new(u->core->mempool, chunk.length = u->frames_posted * fs);
|
||||
chunk.index = 0;
|
||||
|
||||
for (frame_idx = 0; frame_idx < u->frames_posted; frame_idx ++) {
|
||||
|
|
|
|||
|
|
@ -162,10 +162,10 @@ static void out_fill_memblocks(struct userdata *u, unsigned n) {
|
|||
|
||||
chunk.memblock = u->out_memblocks[u->out_current] =
|
||||
pa_memblock_new_fixed(
|
||||
u->core->mempool,
|
||||
(uint8_t*) u->out_mmap+u->out_fragment_size*u->out_current,
|
||||
u->out_fragment_size,
|
||||
1,
|
||||
u->core->memblock_stat);
|
||||
1);
|
||||
assert(chunk.memblock);
|
||||
chunk.length = chunk.memblock->length;
|
||||
chunk.index = 0;
|
||||
|
|
@ -210,7 +210,7 @@ static void in_post_memblocks(struct userdata *u, unsigned n) {
|
|||
pa_memchunk chunk;
|
||||
|
||||
if (!u->in_memblocks[u->in_current]) {
|
||||
chunk.memblock = u->in_memblocks[u->in_current] = pa_memblock_new_fixed((uint8_t*) u->in_mmap+u->in_fragment_size*u->in_current, u->in_fragment_size, 1, u->core->memblock_stat);
|
||||
chunk.memblock = u->in_memblocks[u->in_current] = pa_memblock_new_fixed(u->core->mempool, (uint8_t*) u->in_mmap+u->in_fragment_size*u->in_current, u->in_fragment_size, 1);
|
||||
chunk.length = chunk.memblock->length;
|
||||
chunk.index = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ static void do_read(struct userdata *u) {
|
|||
}
|
||||
|
||||
do {
|
||||
memchunk.memblock = pa_memblock_new(l, u->core->memblock_stat);
|
||||
memchunk.memblock = pa_memblock_new(u->core->mempool, l);
|
||||
assert(memchunk.memblock);
|
||||
if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
|
||||
pa_memblock_unref(memchunk.memblock);
|
||||
|
|
@ -503,7 +503,7 @@ int pa__init(pa_core *c, pa_module*m) {
|
|||
|
||||
u->out_fragment_size = out_frag_size;
|
||||
u->in_fragment_size = in_frag_size;
|
||||
u->silence.memblock = pa_memblock_new(u->silence.length = u->out_fragment_size, u->core->memblock_stat);
|
||||
u->silence.memblock = pa_memblock_new(u->core->mempool, u->silence.length = u->out_fragment_size);
|
||||
assert(u->silence.memblock);
|
||||
pa_silence_memblock(u->silence.memblock, &ss);
|
||||
u->silence.index = 0;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ static void do_read(struct userdata *u) {
|
|||
pa_module_set_used(u->module, pa_idxset_size(u->source->outputs));
|
||||
|
||||
if (!u->chunk.memblock) {
|
||||
u->chunk.memblock = pa_memblock_new(1024, u->core->memblock_stat);
|
||||
u->chunk.memblock = pa_memblock_new(u->core->mempool, PIPE_BUF);
|
||||
u->chunk.index = chunk.length = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ int pa__init(pa_core *c, pa_module*m) {
|
|||
goto fail;
|
||||
}
|
||||
|
||||
u->memblock = pa_memblock_new(pa_bytes_per_second(&ss), c->memblock_stat);
|
||||
u->memblock = pa_memblock_new(c->mempool, pa_bytes_per_second(&ss));
|
||||
calc_sine(u->memblock->data, u->memblock->length, frequency);
|
||||
|
||||
snprintf(t, sizeof(t), "Sine Generator at %u Hz", frequency);
|
||||
|
|
|
|||
|
|
@ -651,7 +651,7 @@ static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata
|
|||
return;
|
||||
}
|
||||
|
||||
u->pstream = pa_pstream_new(u->core->mainloop, io, u->core->memblock_stat);
|
||||
u->pstream = pa_pstream_new(u->core->mainloop, io, u->core->mempool);
|
||||
u->pdispatch = pa_pdispatch_new(u->core->mainloop, command_table, PA_COMMAND_MAX);
|
||||
|
||||
pa_pstream_set_die_callback(u->pstream, pstream_die_callback, u);
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ static void rtp_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event
|
|||
assert(fd == s->rtp_context.fd);
|
||||
assert(flags == PA_IO_EVENT_INPUT);
|
||||
|
||||
if (pa_rtp_recv(&s->rtp_context, &chunk, s->userdata->core->memblock_stat) < 0)
|
||||
if (pa_rtp_recv(&s->rtp_context, &chunk, s->userdata->core->mempool) < 0)
|
||||
return;
|
||||
|
||||
if (s->sdp_info.payload != s->rtp_context.payload) {
|
||||
|
|
@ -312,10 +312,10 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in
|
|||
s->sink_input->kill = sink_input_kill;
|
||||
s->sink_input->get_latency = sink_input_get_latency;
|
||||
|
||||
silence = pa_silence_memblock_new(&s->sink_input->sample_spec,
|
||||
silence = pa_silence_memblock_new(s->userdata->core->mempool,
|
||||
&s->sink_input->sample_spec,
|
||||
(pa_bytes_per_second(&s->sink_input->sample_spec)/128/pa_frame_size(&s->sink_input->sample_spec))*
|
||||
pa_frame_size(&s->sink_input->sample_spec),
|
||||
s->userdata->core->memblock_stat);
|
||||
pa_frame_size(&s->sink_input->sample_spec));
|
||||
|
||||
s->memblockq = pa_memblockq_new(
|
||||
0,
|
||||
|
|
@ -324,8 +324,7 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in
|
|||
pa_frame_size(&s->sink_input->sample_spec),
|
||||
pa_bytes_per_second(&s->sink_input->sample_spec)/10+1,
|
||||
0,
|
||||
silence,
|
||||
u->core->memblock_stat);
|
||||
silence);
|
||||
|
||||
pa_memblock_unref(silence);
|
||||
|
||||
|
|
|
|||
|
|
@ -297,8 +297,7 @@ int pa__init(pa_core *c, pa_module*m) {
|
|||
pa_frame_size(&ss),
|
||||
1,
|
||||
0,
|
||||
NULL,
|
||||
c->memblock_stat);
|
||||
NULL);
|
||||
|
||||
u->mtu = mtu;
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ pa_rtp_context* pa_rtp_context_init_recv(pa_rtp_context *c, int fd, size_t frame
|
|||
return c;
|
||||
}
|
||||
|
||||
int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_memblock_stat *st) {
|
||||
int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_mempool *pool) {
|
||||
int size;
|
||||
struct msghdr m;
|
||||
struct iovec iov;
|
||||
|
|
@ -170,7 +170,7 @@ int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_memblock_stat *st) {
|
|||
if (!size)
|
||||
return 0;
|
||||
|
||||
chunk->memblock = pa_memblock_new(size, st);
|
||||
chunk->memblock = pa_memblock_new(pool, size);
|
||||
|
||||
iov.iov_base = chunk->memblock->data;
|
||||
iov.iov_len = size;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ pa_rtp_context* pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint32_t ssr
|
|||
int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q);
|
||||
|
||||
pa_rtp_context* pa_rtp_context_init_recv(pa_rtp_context *c, int fd, size_t frame_size);
|
||||
int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_memblock_stat *st);
|
||||
int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_mempool *pool);
|
||||
|
||||
void pa_rtp_context_destroy(pa_rtp_context *c);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue