mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2026-01-06 11:08:41 -05:00
modernize play-memchunk and port it to the new core
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1571 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
34e41657e7
commit
36dd7819da
1 changed files with 115 additions and 47 deletions
|
|
@ -26,7 +26,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
@ -37,51 +36,105 @@
|
||||||
|
|
||||||
#include "play-memchunk.h"
|
#include "play-memchunk.h"
|
||||||
|
|
||||||
static void sink_input_kill_cb(pa_sink_input *i) {
|
typedef struct memchunk_stream {
|
||||||
pa_memchunk *c;
|
pa_msgobject parent;
|
||||||
assert(i && i->userdata);
|
pa_core *core;
|
||||||
c = i->userdata;
|
pa_sink_input *sink_input;
|
||||||
|
pa_memchunk memchunk;
|
||||||
|
} memchunk_stream;
|
||||||
|
|
||||||
pa_sink_input_disconnect(i);
|
enum {
|
||||||
pa_sink_input_unref(i);
|
MEMCHUNK_STREAM_MESSAGE_UNLINK,
|
||||||
|
};
|
||||||
|
|
||||||
pa_memblock_unref(c->memblock);
|
PA_DECLARE_CLASS(memchunk_stream);
|
||||||
pa_xfree(c);
|
#define MEMCHUNK_STREAM(o) (memchunk_stream_cast(o))
|
||||||
|
static PA_DEFINE_CHECK_TYPE(memchunk_stream, pa_msgobject);
|
||||||
|
|
||||||
|
static void memchunk_stream_unlink(memchunk_stream *u) {
|
||||||
|
pa_assert(u);
|
||||||
|
|
||||||
|
if (!u->sink_input)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pa_sink_input_disconnect(u->sink_input);
|
||||||
|
|
||||||
|
pa_sink_input_unref(u->sink_input);
|
||||||
|
u->sink_input = NULL;
|
||||||
|
|
||||||
|
/* Make sure we don't decrease the ref count twice. */
|
||||||
|
memchunk_stream_unref(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
|
static void memchunk_stream_free(pa_object *o) {
|
||||||
pa_memchunk *c;
|
memchunk_stream *u = MEMCHUNK_STREAM(o);
|
||||||
assert(i && chunk && i->userdata);
|
pa_assert(u);
|
||||||
c = i->userdata;
|
|
||||||
|
|
||||||
if (c->length <= 0)
|
memchunk_stream_unlink(u);
|
||||||
return -1;
|
|
||||||
|
|
||||||
assert(c->memblock);
|
if (u->memchunk.memblock)
|
||||||
*chunk = *c;
|
pa_memblock_unref(u->memchunk.memblock);
|
||||||
pa_memblock_ref(c->memblock);
|
|
||||||
|
pa_xfree(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int memchunk_stream_process_msg(pa_msgobject *o, int code, void*userdata, int64_t offset, pa_memchunk *chunk) {
|
||||||
|
memchunk_stream *u = MEMCHUNK_STREAM(o);
|
||||||
|
memchunk_stream_assert_ref(u);
|
||||||
|
|
||||||
|
switch (code) {
|
||||||
|
case MEMCHUNK_STREAM_MESSAGE_UNLINK:
|
||||||
|
memchunk_stream_unlink(u);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void si_kill_cb(PA_GCC_UNUSED pa_mainloop_api *m, void *i) {
|
static void sink_input_kill_cb(pa_sink_input *i) {
|
||||||
sink_input_kill_cb(i);
|
pa_sink_input_assert_ref(i);
|
||||||
|
|
||||||
|
memchunk_stream_unlink(MEMCHUNK_STREAM(i->userdata));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sink_input_peek_cb(pa_sink_input *i, pa_memchunk *chunk) {
|
||||||
|
memchunk_stream *u;
|
||||||
|
|
||||||
|
pa_assert(i);
|
||||||
|
pa_assert(chunk);
|
||||||
|
u = MEMCHUNK_STREAM(i->userdata);
|
||||||
|
memchunk_stream_assert_ref(u);
|
||||||
|
|
||||||
|
if (!u->memchunk.memblock)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (u->memchunk.length <= 0) {
|
||||||
|
pa_memblock_unref(u->memchunk.memblock);
|
||||||
|
u->memchunk.memblock = NULL;
|
||||||
|
pa_asyncmsgq_post(u->core->asyncmsgq, PA_MSGOBJECT(u), MEMCHUNK_STREAM_MESSAGE_UNLINK, NULL, 0, NULL, NULL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_assert(u->memchunk.memblock);
|
||||||
|
*chunk = u->memchunk;
|
||||||
|
pa_memblock_ref(chunk->memblock);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sink_input_drop_cb(pa_sink_input *i, size_t length) {
|
static void sink_input_drop_cb(pa_sink_input *i, size_t length) {
|
||||||
pa_memchunk *c;
|
memchunk_stream *u;
|
||||||
assert(i && length && i->userdata);
|
|
||||||
c = i->userdata;
|
|
||||||
|
|
||||||
if (length >= c->length) {
|
pa_assert(i);
|
||||||
c->length -= length;
|
pa_assert(length > 0);
|
||||||
c->index += length;
|
u = MEMCHUNK_STREAM(i->userdata);
|
||||||
} else {
|
memchunk_stream_assert_ref(u);
|
||||||
|
|
||||||
c->length = 0;
|
if (length >= u->memchunk.length) {
|
||||||
|
u->memchunk.length -= length;
|
||||||
pa_mainloop_api_once(i->sink->core->mainloop, si_kill_cb, i);
|
u->memchunk.index += length;
|
||||||
}
|
} else
|
||||||
|
u->memchunk.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pa_play_memchunk(
|
int pa_play_memchunk(
|
||||||
|
|
@ -92,36 +145,51 @@ int pa_play_memchunk(
|
||||||
const pa_memchunk *chunk,
|
const pa_memchunk *chunk,
|
||||||
pa_cvolume *volume) {
|
pa_cvolume *volume) {
|
||||||
|
|
||||||
pa_sink_input *si;
|
memchunk_stream *u = NULL;
|
||||||
pa_memchunk *nchunk;
|
|
||||||
pa_sink_input_new_data data;
|
pa_sink_input_new_data data;
|
||||||
|
|
||||||
assert(sink);
|
pa_assert(sink);
|
||||||
assert(ss);
|
pa_assert(ss);
|
||||||
assert(chunk);
|
pa_assert(chunk);
|
||||||
|
|
||||||
if (volume && pa_cvolume_is_muted(volume))
|
if (volume && pa_cvolume_is_muted(volume))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
u = pa_msgobject_new(memchunk_stream);
|
||||||
|
u->parent.parent.free = memchunk_stream_free;
|
||||||
|
u->parent.process_msg = memchunk_stream_process_msg;
|
||||||
|
u->core = sink->core;
|
||||||
|
u->sink_input = NULL;
|
||||||
|
u->memchunk = *chunk;
|
||||||
|
pa_memblock_ref(u->memchunk.memblock);
|
||||||
|
|
||||||
pa_sink_input_new_data_init(&data);
|
pa_sink_input_new_data_init(&data);
|
||||||
data.sink = sink;
|
data.sink = sink;
|
||||||
data.name = name;
|
|
||||||
data.driver = __FILE__;
|
data.driver = __FILE__;
|
||||||
|
data.name = name;
|
||||||
pa_sink_input_new_data_set_sample_spec(&data, ss);
|
pa_sink_input_new_data_set_sample_spec(&data, ss);
|
||||||
pa_sink_input_new_data_set_channel_map(&data, map);
|
pa_sink_input_new_data_set_channel_map(&data, map);
|
||||||
pa_sink_input_new_data_set_volume(&data, volume);
|
pa_sink_input_new_data_set_volume(&data, volume);
|
||||||
|
|
||||||
if (!(si = pa_sink_input_new(sink->core, &data, 0)))
|
if (!(u->sink_input = pa_sink_input_new(sink->core, &data, 0)))
|
||||||
return -1;
|
goto fail;
|
||||||
|
|
||||||
si->peek = sink_input_peek_cb;
|
u->sink_input->peek = sink_input_peek_cb;
|
||||||
si->drop = sink_input_drop_cb;
|
u->sink_input->drop = sink_input_drop_cb;
|
||||||
si->kill = sink_input_kill_cb;
|
u->sink_input->kill = sink_input_kill_cb;
|
||||||
|
u->sink_input->userdata = u;
|
||||||
|
|
||||||
si->userdata = nchunk = pa_xnew(pa_memchunk, 1);
|
pa_sink_input_put(u->sink_input);
|
||||||
*nchunk = *chunk;
|
|
||||||
|
|
||||||
pa_memblock_ref(chunk->memblock);
|
/* The reference to u is dangling here, because we want to keep
|
||||||
|
* this stream around until it is fully played. */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
if (u)
|
||||||
|
memchunk_stream_unref(u);
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue