Improving the A2DP Receiver

I tried to improve the Raspberry Pi A2DP receiver by having the Java process monitor the output of the “pactl subscribe” command. That way it would be able to respond immediately when a Bluetooth client is connected.

Unfortunately it seems that the “pactl subscribe” command does not flush its output every time it has anything to say. I don’t see output until I kill the pactl process, at which point it all arrives at once.

Checking the PACTL source code I see it doesn’t flush. It’s also not localised, which means no need to worry about handling foreign text

static void context_subscribe_callback(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
    pa_assert(c);

    printf(_("Event '%s' on %s #%u\n"),
           subscription_event_type_to_string(t),
           subscription_event_facility_to_string(t),
           idx);
}

A more complete, but time consuming, approach would be to implement the Pulse Audio network protocol in Java. JNI may help here now I have the Pulse source code. The source seems easy to work with. A simple bridge layer may adapt those callbacks to Java and allow Java access to Pulse Audio commands. This would completely remove the need to start external processes.

For now I cannot use pactl subscribe. I also have a lot of other things to look at.
The current polling system appears to work well enough.

This entry was posted in java, Programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.