enum {
SINK_MESSAGE_RENDER = PA_SINK_MESSAGE_MAX,
+ SINK_MESSAGE_BUFFER_SIZE,
SINK_MESSAGE_ON_SHUTDOWN
};
return 0;
+ case SINK_MESSAGE_BUFFER_SIZE:
+ pa_sink_set_max_request_within_thread(u->sink, (size_t) offset * pa_frame_size(&u->sink->sample_spec));
+ return 0;
+
case SINK_MESSAGE_ON_SHUTDOWN:
pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL);
return 0;
return 0;
}
+
}
return pa_sink_process_msg(o, code, data, offset, memchunk);
static void jack_shutdown(void* arg) {
struct userdata *u = arg;
- pa_log_info("JACK thread shutting down..");
+ pa_log_info("JACK thread shutting down.");
pa_asyncmsgq_post(u->jack_msgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_ON_SHUTDOWN, NULL, 0, NULL, NULL);
}
+static int jack_buffer_size(jack_nframes_t nframes, void *arg) {
+ struct userdata *u = arg;
+
+ pa_log_info("JACK buffer size changed.");
+ pa_asyncmsgq_post(u->jack_msgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_BUFFER_SIZE, NULL, nframes, NULL, NULL);
+ return 0;
+}
+
int pa__init(pa_module*m) {
struct userdata *u = NULL;
pa_sample_spec ss;
server_name = pa_modargs_get_value(ma, "server_name", NULL);
client_name = pa_modargs_get_value(ma, "client_name", "PulseAudio JACK Sink");
- u = pa_xnew0(struct userdata, 1);
+ m->userdata = u = pa_xnew0(struct userdata, 1);
u->core = m->core;
u->module = m;
- m->userdata = u;
u->saved_frame_time_valid = FALSE;
u->rtpoll = pa_rtpoll_new();
pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
pa_sink_set_rtpoll(u->sink, u->rtpoll);
+ pa_sink_set_max_request(u->sink, jack_get_buffer_size(u->client) * pa_frame_size(&u->sink->sample_spec));
jack_set_process_callback(u->client, jack_process, u);
jack_on_shutdown(u->client, jack_shutdown, u);
jack_set_thread_init_callback(u->client, jack_init, u);
+ jack_set_buffer_size_callback(u->client, jack_buffer_size, u);
if (!(u->thread = pa_thread_new(thread_func, u))) {
pa_log("Failed to create thread.");
server_name = pa_modargs_get_value(ma, "server_name", NULL);
client_name = pa_modargs_get_value(ma, "client_name", "PulseAudio JACK Source");
- u = pa_xnew0(struct userdata, 1);
+ m->userdata = u = pa_xnew0(struct userdata, 1);
u->core = m->core;
u->module = m;
m->userdata = u;
u->saved_frame_time_valid = FALSE;
-
u->rtpoll = pa_rtpoll_new();
pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
for (i = 0, p = ports; i < ss.channels; i++, p++) {
if (!*p) {
- pa_log("not enough physical output ports, leaving unconnected.");
+ pa_log("Not enough physical output ports, leaving unconnected.");
break;
}
- pa_log_info("connecting %s to %s", jack_port_name(u->port[i]), *p);
+ pa_log_info("Connecting %s to %s", jack_port_name(u->port[i]), *p);
if (jack_connect(u->client, *p, jack_port_name(u->port[i]))) {
- pa_log("failed to connect %s to %s, leaving unconnected.", jack_port_name(u->port[i]), *p);
+ pa_log("Failed to connect %s to %s, leaving unconnected.", jack_port_name(u->port[i]), *p);
break;
}
}