mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2026-02-09 10:07:23 -05:00
virtual-surround-sink: Use common code
Using the library fixes a crash bug in module-virtual-surround sink when used with use_volume_sharing=0. The old code did not remap the volumes.
This commit is contained in:
parent
8098bfde4a
commit
668a22e902
2 changed files with 87 additions and 602 deletions
|
|
@ -174,7 +174,7 @@ endif
|
|||
|
||||
if fftw_dep.found()
|
||||
all_modules += [
|
||||
[ 'module-virtual-surround-sink', 'module-virtual-surround-sink.c', [], [], [fftw_dep, libm_dep] ],
|
||||
[ 'module-virtual-surround-sink', 'module-virtual-surround-sink.c', [], [], [fftw_dep, libm_dep], libvirtual_sink ],
|
||||
]
|
||||
endif
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include <fftw3.h>
|
||||
|
||||
#include <modules/virtual-sink-common.h>
|
||||
|
||||
#include <pulse/gccmacro.h>
|
||||
#include <pulse/xmalloc.h>
|
||||
|
||||
|
|
@ -73,14 +75,7 @@ PA_MODULE_USAGE(
|
|||
struct userdata {
|
||||
pa_module *module;
|
||||
|
||||
bool autoloaded;
|
||||
|
||||
pa_sink *sink;
|
||||
pa_sink_input *sink_input;
|
||||
|
||||
pa_memblockq *memblockq_sink;
|
||||
|
||||
bool auto_desc;
|
||||
pa_vsink *vsink;
|
||||
|
||||
size_t fftlen;
|
||||
size_t hrir_samples;
|
||||
|
|
@ -111,6 +106,76 @@ static const char* const valid_modargs[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
static void filter_process_chunk(uint8_t *src_p, uint8_t *dst_p, unsigned in_count, unsigned out_count, void *userdata) {
|
||||
struct userdata *u;
|
||||
int ear;
|
||||
unsigned c;
|
||||
size_t s, fftlen;
|
||||
float fftlen_if, *revspace;
|
||||
float *src, *dst;
|
||||
|
||||
pa_assert_se(u = userdata);
|
||||
pa_assert(in_count == u->fftlen);
|
||||
pa_assert(out_count == BLOCK_SIZE);
|
||||
|
||||
src = (float *)src_p;
|
||||
dst = (float *)dst_p;
|
||||
|
||||
for (c = 0; c < u->inputs; c++) {
|
||||
for (s = 0, fftlen = u->fftlen; s < fftlen; s++) {
|
||||
u->inspace[c][s] = src[s * u->inputs + c];
|
||||
}
|
||||
}
|
||||
|
||||
fftlen_if = 1.0f / (float)u->fftlen;
|
||||
revspace = u->revspace + u->fftlen - BLOCK_SIZE;
|
||||
|
||||
pa_memzero(u->outspace[0], BLOCK_SIZE * 4);
|
||||
pa_memzero(u->outspace[1], BLOCK_SIZE * 4);
|
||||
|
||||
for (c = 0; c < u->inputs; c++) {
|
||||
fftwf_complex *f_in = u->f_in;
|
||||
fftwf_complex *f_out = u->f_out;
|
||||
|
||||
fftwf_execute(u->p_fw[c]);
|
||||
|
||||
for (ear = 0; ear < 2; ear++) {
|
||||
fftwf_complex *f_ir = u->f_ir[c * 2 + ear];
|
||||
float *outspace = u->outspace[ear];
|
||||
|
||||
for (s = 0, fftlen = u->fftlen / 2 + 1; s < fftlen; s++) {
|
||||
float re = f_ir[s][0] * f_in[s][0] - f_ir[s][1] * f_in[s][1];
|
||||
float im = f_ir[s][1] * f_in[s][0] + f_ir[s][0] * f_in[s][1];
|
||||
f_out[s][0] = re;
|
||||
f_out[s][1] = im;
|
||||
}
|
||||
|
||||
fftwf_execute(u->p_bw);
|
||||
|
||||
for (s = 0, fftlen = BLOCK_SIZE; s < fftlen; ++s)
|
||||
outspace[s] += revspace[s] * fftlen_if;
|
||||
}
|
||||
}
|
||||
|
||||
for (s = 0, fftlen = BLOCK_SIZE; s < fftlen; s++) {
|
||||
float output;
|
||||
float *outspace = u->outspace[0];
|
||||
|
||||
output = outspace[s];
|
||||
if (output < -1.0) output = -1.0;
|
||||
if (output > 1.0) output = 1.0;
|
||||
dst[s * 2 + 0] = output;
|
||||
|
||||
outspace = u->outspace[1];
|
||||
|
||||
output = outspace[s];
|
||||
if (output < -1.0) output = -1.0;
|
||||
if (output > 1.0) output = 1.0;
|
||||
dst[s * 2 + 1] = output;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Vector size of 4 floats */
|
||||
#define v_size 4
|
||||
static void * alloc(size_t x, size_t s) {
|
||||
|
|
@ -124,26 +189,6 @@ static void * alloc(size_t x, size_t s) {
|
|||
return t;
|
||||
}
|
||||
|
||||
static size_t sink_input_samples(size_t nbytes)
|
||||
{
|
||||
return nbytes / 8;
|
||||
}
|
||||
|
||||
static size_t sink_input_bytes(size_t nsamples)
|
||||
{
|
||||
return nsamples * 8;
|
||||
}
|
||||
|
||||
static size_t sink_samples(const struct userdata *u, size_t nbytes)
|
||||
{
|
||||
return nbytes / (u->inputs * 4);
|
||||
}
|
||||
|
||||
static size_t sink_bytes(const struct userdata *u, size_t nsamples)
|
||||
{
|
||||
return nsamples * (u->inputs * 4);
|
||||
}
|
||||
|
||||
/* Mirror channels for symmetrical impulse */
|
||||
static pa_channel_position_t mirror_channel(pa_channel_position_t channel) {
|
||||
switch (channel) {
|
||||
|
|
@ -255,449 +300,6 @@ static void normalize_hrir_stereo(float * hrir_data, float * hrir_right_data, un
|
|||
}
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
|
||||
struct userdata *u = PA_SINK(o)->userdata;
|
||||
|
||||
switch (code) {
|
||||
|
||||
case PA_SINK_MESSAGE_GET_LATENCY:
|
||||
|
||||
/* The sink is _put() before the sink input is, so let's
|
||||
* make sure we don't access it in that time. Also, the
|
||||
* sink input is first shut down, the sink second. */
|
||||
if (!PA_SINK_IS_LINKED(u->sink->thread_info.state) ||
|
||||
!PA_SINK_INPUT_IS_LINKED(u->sink_input->thread_info.state)) {
|
||||
*((pa_usec_t*) data) = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*((pa_usec_t*) data) =
|
||||
|
||||
/* Get the latency of the master sink */
|
||||
pa_sink_get_latency_within_thread(u->sink_input->sink, true) +
|
||||
|
||||
/* Add the latency internal to our sink input on top */
|
||||
pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
|
||||
|
||||
/* Add resampler latency */
|
||||
*((int64_t*) data) += pa_resampler_get_delay_usec(u->sink_input->thread_info.resampler);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pa_sink_process_msg(o, code, data, offset, chunk);
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
static int sink_set_state_in_main_thread_cb(pa_sink *s, pa_sink_state_t state, pa_suspend_cause_t suspend_cause) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_assert_ref(s);
|
||||
pa_assert_se(u = s->userdata);
|
||||
|
||||
if (!PA_SINK_IS_LINKED(state) ||
|
||||
!PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
|
||||
return 0;
|
||||
|
||||
pa_sink_input_cork(u->sink_input, state == PA_SINK_SUSPENDED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Called from the IO thread. */
|
||||
static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state, pa_suspend_cause_t new_suspend_cause) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_assert(s);
|
||||
pa_assert_se(u = s->userdata);
|
||||
|
||||
/* When set to running or idle for the first time, request a rewind
|
||||
* of the master sink to make sure we are heard immediately */
|
||||
if (PA_SINK_IS_OPENED(new_state) && s->thread_info.state == PA_SINK_INIT) {
|
||||
pa_log_debug("Requesting rewind due to state change.");
|
||||
pa_sink_input_request_rewind(u->sink_input, 0, false, true, true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static void sink_request_rewind_cb(pa_sink *s) {
|
||||
struct userdata *u;
|
||||
size_t nbytes_sink, nbytes_input;
|
||||
|
||||
pa_sink_assert_ref(s);
|
||||
pa_assert_se(u = s->userdata);
|
||||
|
||||
if (!PA_SINK_IS_LINKED(u->sink->thread_info.state) ||
|
||||
!PA_SINK_INPUT_IS_LINKED(u->sink_input->thread_info.state))
|
||||
return;
|
||||
|
||||
nbytes_sink = s->thread_info.rewind_nbytes + pa_memblockq_get_length(u->memblockq_sink);
|
||||
nbytes_input = sink_input_bytes(sink_samples(u, nbytes_sink));
|
||||
|
||||
/* Just hand this one over to the master sink */
|
||||
pa_sink_input_request_rewind(u->sink_input, nbytes_input, true, false, false);
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static void sink_update_requested_latency_cb(pa_sink *s) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_assert_ref(s);
|
||||
pa_assert_se(u = s->userdata);
|
||||
|
||||
if (!PA_SINK_IS_LINKED(u->sink->thread_info.state) ||
|
||||
!PA_SINK_INPUT_IS_LINKED(u->sink_input->thread_info.state))
|
||||
return;
|
||||
|
||||
/* Just hand this one over to the master sink */
|
||||
pa_sink_input_set_requested_latency_within_thread(
|
||||
u->sink_input,
|
||||
pa_sink_get_requested_latency_within_thread(s));
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
static void sink_set_volume_cb(pa_sink *s) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_assert_ref(s);
|
||||
pa_assert_se(u = s->userdata);
|
||||
|
||||
if (!PA_SINK_IS_LINKED(s->state) ||
|
||||
!PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
|
||||
return;
|
||||
|
||||
pa_sink_input_set_volume(u->sink_input, &s->real_volume, s->save_volume, true);
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
static void sink_set_mute_cb(pa_sink *s) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_assert_ref(s);
|
||||
pa_assert_se(u = s->userdata);
|
||||
|
||||
if (!PA_SINK_IS_LINKED(s->state) ||
|
||||
!PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
|
||||
return;
|
||||
|
||||
pa_sink_input_set_mute(u->sink_input, s->muted, s->save_muted);
|
||||
}
|
||||
|
||||
static size_t memblockq_missing(pa_memblockq *bq) {
|
||||
size_t l, tlength;
|
||||
pa_assert(bq);
|
||||
|
||||
tlength = pa_memblockq_get_tlength(bq);
|
||||
if ((l = pa_memblockq_get_length(bq)) >= tlength)
|
||||
return 0;
|
||||
|
||||
l = tlength - l;
|
||||
return l >= pa_memblockq_get_minreq(bq) ? l : 0;
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes_input, pa_memchunk *chunk) {
|
||||
struct userdata *u;
|
||||
float *src, *dst;
|
||||
int c, ear;
|
||||
size_t s, bytes_missing, fftlen;
|
||||
pa_memchunk tchunk;
|
||||
float fftlen_if, *revspace;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert(chunk);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
/* Hmm, process any rewind request that might be queued up */
|
||||
pa_sink_process_rewind(u->sink, 0);
|
||||
|
||||
while ((bytes_missing = memblockq_missing(u->memblockq_sink)) != 0) {
|
||||
pa_memchunk nchunk;
|
||||
|
||||
pa_sink_render(u->sink, bytes_missing, &nchunk);
|
||||
pa_memblockq_push(u->memblockq_sink, &nchunk);
|
||||
pa_memblock_unref(nchunk.memblock);
|
||||
}
|
||||
|
||||
pa_memblockq_rewind(u->memblockq_sink, sink_bytes(u, u->fftlen - BLOCK_SIZE));
|
||||
pa_memblockq_peek_fixed_size(u->memblockq_sink, sink_bytes(u, u->fftlen), &tchunk);
|
||||
|
||||
pa_memblockq_drop(u->memblockq_sink, tchunk.length);
|
||||
|
||||
/* Now tchunk contains enough data to perform the FFT
|
||||
* This should be equal to u->fftlen */
|
||||
|
||||
chunk->index = 0;
|
||||
chunk->length = sink_input_bytes(BLOCK_SIZE);
|
||||
chunk->memblock = pa_memblock_new(i->sink->core->mempool, chunk->length);
|
||||
|
||||
src = pa_memblock_acquire_chunk(&tchunk);
|
||||
|
||||
for (c = 0; c < u->inputs; c++) {
|
||||
for (s = 0, fftlen = u->fftlen; s < fftlen; s++) {
|
||||
u->inspace[c][s] = src[s * u->inputs + c];
|
||||
}
|
||||
}
|
||||
|
||||
pa_memblock_release(tchunk.memblock);
|
||||
pa_memblock_unref(tchunk.memblock);
|
||||
|
||||
fftlen_if = 1.0f / (float)u->fftlen;
|
||||
revspace = u->revspace + u->fftlen - BLOCK_SIZE;
|
||||
|
||||
pa_memzero(u->outspace[0], BLOCK_SIZE * 4);
|
||||
pa_memzero(u->outspace[1], BLOCK_SIZE * 4);
|
||||
|
||||
for (c = 0; c < u->inputs; c++) {
|
||||
fftwf_complex *f_in = u->f_in;
|
||||
fftwf_complex *f_out = u->f_out;
|
||||
|
||||
fftwf_execute(u->p_fw[c]);
|
||||
|
||||
for (ear = 0; ear < 2; ear++) {
|
||||
fftwf_complex *f_ir = u->f_ir[c * 2 + ear];
|
||||
float *outspace = u->outspace[ear];
|
||||
|
||||
for (s = 0, fftlen = u->fftlen / 2 + 1; s < fftlen; s++) {
|
||||
float re = f_ir[s][0] * f_in[s][0] - f_ir[s][1] * f_in[s][1];
|
||||
float im = f_ir[s][1] * f_in[s][0] + f_ir[s][0] * f_in[s][1];
|
||||
f_out[s][0] = re;
|
||||
f_out[s][1] = im;
|
||||
}
|
||||
|
||||
fftwf_execute(u->p_bw);
|
||||
|
||||
for (s = 0, fftlen = BLOCK_SIZE; s < fftlen; ++s)
|
||||
outspace[s] += revspace[s] * fftlen_if;
|
||||
}
|
||||
}
|
||||
|
||||
dst = pa_memblock_acquire_chunk(chunk);
|
||||
|
||||
for (s = 0, fftlen = BLOCK_SIZE; s < fftlen; s++) {
|
||||
float output;
|
||||
float *outspace = u->outspace[0];
|
||||
|
||||
output = outspace[s];
|
||||
if (output < -1.0) output = -1.0;
|
||||
if (output > 1.0) output = 1.0;
|
||||
dst[s * 2 + 0] = output;
|
||||
|
||||
outspace = u->outspace[1];
|
||||
|
||||
output = outspace[s];
|
||||
if (output < -1.0) output = -1.0;
|
||||
if (output > 1.0) output = 1.0;
|
||||
dst[s * 2 + 1] = output;
|
||||
}
|
||||
|
||||
pa_memblock_release(chunk->memblock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes_input) {
|
||||
struct userdata *u;
|
||||
size_t amount = 0;
|
||||
size_t nbytes_sink;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
nbytes_sink = sink_bytes(u, sink_input_samples(nbytes_input));
|
||||
|
||||
if (u->sink->thread_info.rewind_nbytes > 0) {
|
||||
size_t max_rewrite;
|
||||
|
||||
max_rewrite = nbytes_sink + pa_memblockq_get_length(u->memblockq_sink);
|
||||
amount = PA_MIN(u->sink->thread_info.rewind_nbytes, max_rewrite);
|
||||
u->sink->thread_info.rewind_nbytes = 0;
|
||||
|
||||
if (amount > 0) {
|
||||
pa_memblockq_seek(u->memblockq_sink, - (int64_t) amount, PA_SEEK_RELATIVE, true);
|
||||
}
|
||||
}
|
||||
|
||||
pa_sink_process_rewind(u->sink, amount);
|
||||
|
||||
pa_memblockq_rewind(u->memblockq_sink, nbytes_sink);
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static void sink_input_update_max_rewind_cb(pa_sink_input *i, size_t nbytes_input) {
|
||||
struct userdata *u;
|
||||
size_t nbytes_sink, nbytes_memblockq;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
nbytes_sink = sink_bytes(u, sink_input_samples(nbytes_input));
|
||||
nbytes_memblockq = sink_bytes(u, sink_input_samples(nbytes_input) + u->fftlen);
|
||||
|
||||
/* FIXME: Too small max_rewind:
|
||||
* https://bugs.freedesktop.org/show_bug.cgi?id=53709 */
|
||||
pa_memblockq_set_maxrewind(u->memblockq_sink, nbytes_memblockq);
|
||||
pa_sink_set_max_rewind_within_thread(u->sink, nbytes_sink);
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static void sink_input_update_max_request_cb(pa_sink_input *i, size_t nbytes_input) {
|
||||
struct userdata *u;
|
||||
|
||||
size_t nbytes_sink;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
nbytes_sink = sink_bytes(u, sink_input_samples(nbytes_input));
|
||||
|
||||
nbytes_sink = PA_ROUND_UP(nbytes_sink, sink_bytes(u, BLOCK_SIZE));
|
||||
pa_sink_set_max_request_within_thread(u->sink, nbytes_sink);
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static void sink_input_update_sink_latency_range_cb(pa_sink_input *i) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
pa_sink_set_latency_range_within_thread(u->sink, i->sink->thread_info.min_latency, i->sink->thread_info.max_latency);
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static void sink_input_update_sink_fixed_latency_cb(pa_sink_input *i) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
pa_sink_set_fixed_latency_within_thread(u->sink, i->sink->thread_info.fixed_latency);
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static void sink_input_detach_cb(pa_sink_input *i) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
if (PA_SINK_IS_LINKED(u->sink->thread_info.state))
|
||||
pa_sink_detach_within_thread(u->sink);
|
||||
|
||||
pa_sink_set_rtpoll(u->sink, NULL);
|
||||
}
|
||||
|
||||
/* Called from I/O thread context */
|
||||
static void sink_input_attach_cb(pa_sink_input *i) {
|
||||
struct userdata *u;
|
||||
size_t max_request;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
pa_sink_set_rtpoll(u->sink, i->sink->thread_info.rtpoll);
|
||||
pa_sink_set_latency_range_within_thread(u->sink, i->sink->thread_info.min_latency, i->sink->thread_info.max_latency);
|
||||
|
||||
pa_sink_set_fixed_latency_within_thread(u->sink, i->sink->thread_info.fixed_latency);
|
||||
|
||||
max_request = sink_bytes(u, sink_input_samples(pa_sink_input_get_max_request(i)));
|
||||
max_request = PA_ROUND_UP(max_request, sink_bytes(u, BLOCK_SIZE));
|
||||
pa_sink_set_max_request_within_thread(u->sink, max_request);
|
||||
|
||||
/* FIXME: Too small max_rewind:
|
||||
* https://bugs.freedesktop.org/show_bug.cgi?id=53709 */
|
||||
pa_sink_set_max_rewind_within_thread(u->sink, sink_bytes(u, sink_input_samples(pa_sink_input_get_max_rewind(i))));
|
||||
|
||||
pa_sink_attach_within_thread(u->sink);
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
static void sink_input_kill_cb(pa_sink_input *i) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
/* The order here matters! We first kill the sink input, followed
|
||||
* by the sink. That means the sink callbacks must be protected
|
||||
* against an unconnected sink input! */
|
||||
pa_sink_input_cork(u->sink_input, true);
|
||||
pa_sink_input_unlink(u->sink_input);
|
||||
pa_sink_unlink(u->sink);
|
||||
|
||||
pa_sink_input_unref(u->sink_input);
|
||||
u->sink_input = NULL;
|
||||
|
||||
pa_sink_unref(u->sink);
|
||||
u->sink = NULL;
|
||||
|
||||
pa_module_unload_request(u->module, true);
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
static bool sink_input_may_move_to_cb(pa_sink_input *i, pa_sink *dest) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
if (u->autoloaded)
|
||||
return false;
|
||||
|
||||
return u->sink != dest;
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
static void sink_input_moving_cb(pa_sink_input *i, pa_sink *dest) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
if (dest) {
|
||||
pa_sink_set_asyncmsgq(u->sink, dest->asyncmsgq);
|
||||
pa_sink_update_flags(u->sink, PA_SINK_LATENCY|PA_SINK_DYNAMIC_LATENCY, dest->flags);
|
||||
} else
|
||||
pa_sink_set_asyncmsgq(u->sink, NULL);
|
||||
|
||||
if (u->auto_desc && dest) {
|
||||
const char *z;
|
||||
pa_proplist *pl;
|
||||
|
||||
pl = pa_proplist_new();
|
||||
z = pa_proplist_gets(dest->proplist, PA_PROP_DEVICE_DESCRIPTION);
|
||||
pa_proplist_setf(pl, PA_PROP_DEVICE_DESCRIPTION, "Virtual Surround Sink %s on %s",
|
||||
pa_proplist_gets(u->sink->proplist, "device.vsurroundsink.name"), z ? z : dest->name);
|
||||
|
||||
pa_sink_update_proplist(u->sink, PA_UPDATE_REPLACE, pl);
|
||||
pa_proplist_free(pl);
|
||||
}
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
static void sink_input_volume_changed_cb(pa_sink_input *i) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
pa_sink_volume_changed(u->sink, &i->volume);
|
||||
}
|
||||
|
||||
/* Called from main context */
|
||||
static void sink_input_mute_changed_cb(pa_sink_input *i) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_sink_input_assert_ref(i);
|
||||
pa_assert_se(u = i->userdata);
|
||||
|
||||
pa_sink_mute_changed(u->sink, i->muted);
|
||||
}
|
||||
|
||||
int pa__init(pa_module*m) {
|
||||
struct userdata *u;
|
||||
pa_sample_spec ss_input, ss_output;
|
||||
|
|
@ -707,12 +309,7 @@ int pa__init(pa_module*m) {
|
|||
const char *hrir_left_file;
|
||||
const char *hrir_right_file;
|
||||
pa_sink *master=NULL;
|
||||
pa_sink_input_new_data sink_input_data;
|
||||
pa_sink_new_data sink_data;
|
||||
bool use_volume_sharing = true;
|
||||
bool force_flat_volume = false;
|
||||
pa_memchunk silence;
|
||||
const char* z;
|
||||
unsigned i, j, ear, found_channel_left, found_channel_right;
|
||||
|
||||
pa_sample_spec ss;
|
||||
|
|
@ -722,7 +319,7 @@ int pa__init(pa_module*m) {
|
|||
float *hrir_temp_data;
|
||||
size_t hrir_samples;
|
||||
size_t hrir_copied_length, hrir_total_length;
|
||||
int hrir_channels;
|
||||
unsigned hrir_channels;
|
||||
int fftlen;
|
||||
|
||||
float *impulse_temp=NULL;
|
||||
|
|
@ -823,114 +420,20 @@ int pa__init(pa_module*m) {
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (pa_modargs_get_value_boolean(ma, "force_flat_volume", &force_flat_volume) < 0) {
|
||||
pa_log("force_flat_volume= expects a boolean argument");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (use_volume_sharing && force_flat_volume) {
|
||||
pa_log("Flat volume can't be forced when using volume sharing.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_channel_map_init_stereo(&map_output);
|
||||
|
||||
u = pa_xnew0(struct userdata, 1);
|
||||
u->module = m;
|
||||
m->userdata = u;
|
||||
|
||||
/* Create sink */
|
||||
pa_sink_new_data_init(&sink_data);
|
||||
sink_data.driver = __FILE__;
|
||||
sink_data.module = m;
|
||||
if (!(sink_data.name = pa_xstrdup(pa_modargs_get_value(ma, "sink_name", NULL))))
|
||||
sink_data.name = pa_sprintf_malloc("%s.vsurroundsink", master->name);
|
||||
pa_sink_new_data_set_sample_spec(&sink_data, &ss_input);
|
||||
pa_sink_new_data_set_channel_map(&sink_data, &map);
|
||||
pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_MASTER_DEVICE, master->name);
|
||||
pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_CLASS, "filter");
|
||||
pa_proplist_sets(sink_data.proplist, "device.vsurroundsink.name", sink_data.name);
|
||||
|
||||
if (pa_modargs_get_proplist(ma, "sink_properties", sink_data.proplist, PA_UPDATE_REPLACE) < 0) {
|
||||
pa_log("Invalid properties");
|
||||
pa_sink_new_data_done(&sink_data);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
u->autoloaded = DEFAULT_AUTOLOADED;
|
||||
if (pa_modargs_get_value_boolean(ma, "autoloaded", &u->autoloaded) < 0) {
|
||||
pa_log("Failed to parse autoloaded value");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ((u->auto_desc = !pa_proplist_contains(sink_data.proplist, PA_PROP_DEVICE_DESCRIPTION))) {
|
||||
z = pa_proplist_gets(master->proplist, PA_PROP_DEVICE_DESCRIPTION);
|
||||
pa_proplist_setf(sink_data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Virtual Surround Sink %s on %s", sink_data.name, z ? z : master->name);
|
||||
}
|
||||
|
||||
u->sink = pa_sink_new(m->core, &sink_data, (master->flags & (PA_SINK_LATENCY|PA_SINK_DYNAMIC_LATENCY))
|
||||
| (use_volume_sharing ? PA_SINK_SHARE_VOLUME_WITH_MASTER : 0));
|
||||
pa_sink_new_data_done(&sink_data);
|
||||
|
||||
if (!u->sink) {
|
||||
pa_log("Failed to create sink.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
u->sink->parent.process_msg = sink_process_msg_cb;
|
||||
u->sink->set_state_in_main_thread = sink_set_state_in_main_thread_cb;
|
||||
u->sink->set_state_in_io_thread = sink_set_state_in_io_thread_cb;
|
||||
u->sink->update_requested_latency = sink_update_requested_latency_cb;
|
||||
u->sink->request_rewind = sink_request_rewind_cb;
|
||||
pa_sink_set_set_mute_callback(u->sink, sink_set_mute_cb);
|
||||
if (!use_volume_sharing) {
|
||||
pa_sink_set_set_volume_callback(u->sink, sink_set_volume_cb);
|
||||
pa_sink_enable_decibel_volume(u->sink, true);
|
||||
}
|
||||
/* Normally this flag would be enabled automatically but we can force it. */
|
||||
if (force_flat_volume)
|
||||
u->sink->flags |= PA_SINK_FLAT_VOLUME;
|
||||
u->sink->userdata = u;
|
||||
|
||||
pa_sink_set_asyncmsgq(u->sink, master->asyncmsgq);
|
||||
|
||||
/* Create sink input */
|
||||
pa_sink_input_new_data_init(&sink_input_data);
|
||||
sink_input_data.driver = __FILE__;
|
||||
sink_input_data.module = m;
|
||||
pa_sink_input_new_data_set_sink(&sink_input_data, master, false, true);
|
||||
sink_input_data.origin_sink = u->sink;
|
||||
pa_proplist_setf(sink_input_data.proplist, PA_PROP_MEDIA_NAME, "Virtual Surround Sink Stream from %s", pa_proplist_gets(u->sink->proplist, PA_PROP_DEVICE_DESCRIPTION));
|
||||
pa_proplist_sets(sink_input_data.proplist, PA_PROP_MEDIA_ROLE, "filter");
|
||||
pa_sink_input_new_data_set_sample_spec(&sink_input_data, &ss_output);
|
||||
pa_sink_input_new_data_set_channel_map(&sink_input_data, &map_output);
|
||||
|
||||
pa_sink_input_new(&u->sink_input, m->core, &sink_input_data);
|
||||
pa_sink_input_new_data_done(&sink_input_data);
|
||||
|
||||
if (!u->sink_input)
|
||||
/* Create virtual sink */
|
||||
if (!(u->vsink = pa_virtual_sink_create(master, "vsurroundsink", "Virtual Surround Sink", &ss_input, &map,
|
||||
&ss_output, &map_output, m, u, ma, use_volume_sharing, true, 0)))
|
||||
goto fail;
|
||||
|
||||
u->sink_input->pop = sink_input_pop_cb;
|
||||
u->sink_input->process_rewind = sink_input_process_rewind_cb;
|
||||
u->sink_input->update_max_rewind = sink_input_update_max_rewind_cb;
|
||||
u->sink_input->update_max_request = sink_input_update_max_request_cb;
|
||||
u->sink_input->update_sink_latency_range = sink_input_update_sink_latency_range_cb;
|
||||
u->sink_input->update_sink_fixed_latency = sink_input_update_sink_fixed_latency_cb;
|
||||
u->sink_input->kill = sink_input_kill_cb;
|
||||
u->sink_input->attach = sink_input_attach_cb;
|
||||
u->sink_input->detach = sink_input_detach_cb;
|
||||
u->sink_input->may_move_to = sink_input_may_move_to_cb;
|
||||
u->sink_input->moving = sink_input_moving_cb;
|
||||
u->sink_input->volume_changed = use_volume_sharing ? NULL : sink_input_volume_changed_cb;
|
||||
u->sink_input->mute_changed = sink_input_mute_changed_cb;
|
||||
u->sink_input->userdata = u;
|
||||
u->vsink->process_chunk = filter_process_chunk;
|
||||
|
||||
u->sink->input_to_master = u->sink_input;
|
||||
|
||||
pa_sink_input_get_silence(u->sink_input, &silence);
|
||||
|
||||
resampler = pa_resampler_new(u->sink->core->mempool, &hrir_left_temp_ss, &hrir_map, &ss_input, &hrir_map, u->sink->core->lfe_crossover_freq,
|
||||
resampler = pa_resampler_new(u->vsink->sink->core->mempool, &hrir_left_temp_ss, &hrir_map, &ss_input, &hrir_map, u->vsink->sink->core->lfe_crossover_freq,
|
||||
PA_RESAMPLER_SRC_SINC_BEST_QUALITY, PA_RESAMPLER_NO_REMAP);
|
||||
|
||||
hrir_samples = hrir_left_temp_chunk.length / pa_frame_size(&hrir_left_temp_ss) * ss_input.rate / hrir_left_temp_ss.rate;
|
||||
|
|
@ -1128,14 +631,11 @@ int pa__init(pa_module*m) {
|
|||
pa_xfree(mapping_left);
|
||||
pa_xfree(mapping_right);
|
||||
|
||||
u->memblockq_sink = pa_memblockq_new("module-virtual-surround-sink memblockq (input)", 0, MEMBLOCKQ_MAXLENGTH, sink_bytes(u, BLOCK_SIZE), &ss_input, 0, 0, sink_bytes(u, u->fftlen), &silence);
|
||||
pa_memblock_unref(silence.memblock);
|
||||
u->vsink->fixed_block_size = BLOCK_SIZE;
|
||||
u->vsink->overlap_frames = u->fftlen - BLOCK_SIZE;
|
||||
|
||||
pa_memblockq_seek(u->memblockq_sink, sink_bytes(u, u->fftlen - BLOCK_SIZE), PA_SEEK_RELATIVE, false);
|
||||
pa_memblockq_flush_read(u->memblockq_sink);
|
||||
|
||||
pa_sink_put(u->sink);
|
||||
pa_sink_input_put(u->sink_input);
|
||||
if (pa_virtual_sink_activate(u->vsink) < 0)
|
||||
goto fail;
|
||||
|
||||
pa_modargs_free(ma);
|
||||
|
||||
|
|
@ -1183,7 +683,7 @@ int pa__get_n_used(pa_module *m) {
|
|||
pa_assert(m);
|
||||
pa_assert_se(u = m->userdata);
|
||||
|
||||
return pa_sink_linked_by(u->sink);
|
||||
return pa_sink_linked_by(u->vsink->sink);
|
||||
}
|
||||
|
||||
void pa__done(pa_module*m) {
|
||||
|
|
@ -1195,23 +695,8 @@ void pa__done(pa_module*m) {
|
|||
if (!(u = m->userdata))
|
||||
return;
|
||||
|
||||
/* See comments in sink_input_kill_cb() above regarding
|
||||
* destruction order! */
|
||||
|
||||
if (u->sink_input)
|
||||
pa_sink_input_unlink(u->sink_input);
|
||||
|
||||
if (u->sink)
|
||||
pa_sink_unlink(u->sink);
|
||||
|
||||
if (u->sink_input)
|
||||
pa_sink_input_unref(u->sink_input);
|
||||
|
||||
if (u->sink)
|
||||
pa_sink_unref(u->sink);
|
||||
|
||||
if (u->memblockq_sink)
|
||||
pa_memblockq_free(u->memblockq_sink);
|
||||
if (u->vsink)
|
||||
pa_virtual_sink_destroy(u->vsink);
|
||||
|
||||
if (u->p_fw) {
|
||||
for (i = 0, j = u->inputs; i < j; i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue