virtual-source: Fix crash in combination with module-loopback

Similar to module-tunnel-sink-new, module-virtual-source did not create
a rtpoll for the uplink sink. This lead to a crash when the uplink sink
was used by module loopback, because module-loopback relies on the sink
to provide a rtpoll. Additionally, the sink was not unlinked when the
module was unloaded.

This patch fixes both issues. The rtpoll created is never run by the sink,
so the patch is no real fix but just a workaround to make module-loopback
happy.
This commit is contained in:
Georg Chini 2019-02-03 19:13:22 +01:00
parent 7525cc8215
commit a53b371a4f

View file

@ -38,6 +38,7 @@
#include <pulsecore/sample-util.h> #include <pulsecore/sample-util.h>
#include <pulsecore/ltdl-helper.h> #include <pulsecore/ltdl-helper.h>
#include <pulsecore/mix.h> #include <pulsecore/mix.h>
#include <pulsecore/rtpoll.h>
PA_MODULE_AUTHOR("Pierre-Louis Bossart"); PA_MODULE_AUTHOR("Pierre-Louis Bossart");
PA_MODULE_DESCRIPTION("Virtual source"); PA_MODULE_DESCRIPTION("Virtual source");
@ -77,6 +78,7 @@ struct userdata {
pa_sink *sink; pa_sink *sink;
pa_usec_t block_usec; pa_usec_t block_usec;
pa_memblockq *sink_memblockq; pa_memblockq *sink_memblockq;
pa_rtpoll *rtpoll;
}; };
@ -543,6 +545,13 @@ int pa__init(pa_module*m) {
} }
u->channels = ss.channels; u->channels = ss.channels;
/* The rtpoll created here is never run. It is only necessary to avoid crashes
* when module-virtual-source is used together with module-loopback or
* module-combine-sink. Both modules base their asyncmsq on the rtpoll provided
* by the sink. module-loopback and combine-sink only work because they
* call pa_asyncmsq_process_one() themselves. */
u->rtpoll = pa_rtpoll_new();
/* Create source */ /* Create source */
pa_source_new_data_init(&source_data); pa_source_new_data_init(&source_data);
source_data.driver = __FILE__; source_data.driver = __FILE__;
@ -671,6 +680,7 @@ int pa__init(pa_module*m) {
u->sink->userdata = u; u->sink->userdata = u;
pa_sink_set_asyncmsgq(u->sink, master->asyncmsgq); pa_sink_set_asyncmsgq(u->sink, master->asyncmsgq);
pa_sink_set_rtpoll(u->sink, u->rtpoll);
/* FIXME: no idea what I am doing here */ /* FIXME: no idea what I am doing here */
u->block_usec = BLOCK_USEC; u->block_usec = BLOCK_USEC;
@ -732,8 +742,10 @@ void pa__done(pa_module*m) {
if (u->source) if (u->source)
pa_source_unref(u->source); pa_source_unref(u->source);
if (u->sink) if (u->sink) {
pa_sink_unlink(u->sink);
pa_sink_unref(u->sink); pa_sink_unref(u->sink);
}
if (u->memblockq) if (u->memblockq)
pa_memblockq_free(u->memblockq); pa_memblockq_free(u->memblockq);
@ -741,5 +753,8 @@ void pa__done(pa_module*m) {
if (u->sink_memblockq) if (u->sink_memblockq)
pa_memblockq_free(u->sink_memblockq); pa_memblockq_free(u->sink_memblockq);
if (u->rtpoll)
pa_rtpoll_free(u->rtpoll);
pa_xfree(u); pa_xfree(u);
} }