Add an option to auto-connect JACK ports

This commit is contained in:
Chris Robinson
2020-08-05 00:27:12 -07:00
parent 516de157d8
commit f138369808
2 changed files with 20 additions and 11 deletions
+14 -11
View File
@@ -384,15 +384,17 @@ void JackPlayback::start()
if(jack_activate(mClient))
throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to activate client"};
const char **ports{jack_get_ports(mClient, nullptr, nullptr,
JackPortIsPhysical|JackPortIsInput)};
if(ports == nullptr)
const char *devname{mDevice->DeviceName.c_str()};
if(ConfigValueBool(devname, "jack", "connect-ports").value_or(true))
{
jack_deactivate(mClient);
throw al::backend_exception{ALC_INVALID_DEVICE, "No physical playback ports found"};
}
std::mismatch(mPort.begin(), mPort.end(), ports,
[this](const jack_port_t *port, const char *pname) -> bool
const char **ports{jack_get_ports(mClient, nullptr, nullptr,
JackPortIsPhysical|JackPortIsInput)};
if(ports == nullptr)
{
jack_deactivate(mClient);
throw al::backend_exception{ALC_INVALID_DEVICE, "No physical playback ports found"};
}
auto connect_port = [this](const jack_port_t *port, const char *pname) -> bool
{
if(!port) return false;
if(!pname)
@@ -404,8 +406,10 @@ void JackPlayback::start()
ERR("Failed to connect output port \"%s\" to \"%s\"\n", jack_port_name(port),
pname);
return true;
});
jack_free(ports);
};
std::mismatch(mPort.begin(), mPort.end(), ports, connect_port);
jack_free(ports);
}
/* Reconfigure buffer metrics in case the server changed it since the reset
* (it won't change again after jack_activate), then allocate the ring
@@ -415,7 +419,6 @@ void JackPlayback::start()
mDevice->UpdateSize = jack_get_buffer_size(mClient);
mDevice->BufferSize = mDevice->UpdateSize * 2;
const char *devname{mDevice->DeviceName.c_str()};
ALuint bufsize{ConfigValueUInt(devname, "jack", "buffer-size").value_or(mDevice->UpdateSize)};
bufsize = maxu(NextPowerOf2(bufsize), mDevice->UpdateSize);
mDevice->BufferSize = bufsize + mDevice->UpdateSize;
+6
View File
@@ -469,6 +469,12 @@
# backend, opening devices, etc).
#spawn-server = false
## connect-ports:
# Attempts to automatically connect the client ports to physical server ports.
# Client ports that fail to connect will leave the remaining channels
# unconnected and silent (the device format won't change to accommodate).
#connect-ports = true
## buffer-size:
# Sets the update buffer size, in samples, that the backend will keep buffered
# to handle the server's real-time processing requests. This value must be a