use PortEngineSharedImpl with PulseAudio backend
This commit is contained in:
parent
04551c39f6
commit
e5507f7072
@ -47,6 +47,7 @@ const size_t PulseAudioBackend::_max_buffer_size = 8192;
|
||||
|
||||
PulseAudioBackend::PulseAudioBackend (AudioEngine& e, AudioBackendInfo& info)
|
||||
: AudioBackend (e, info)
|
||||
, PortEngineSharedImpl (e, s_instance_name)
|
||||
, p_stream (0)
|
||||
, p_context (0)
|
||||
, p_mainloop (0)
|
||||
@ -590,12 +591,7 @@ PulseAudioBackend::_start (bool /*for_latency_measurement*/)
|
||||
return BackendReinitializationError;
|
||||
}
|
||||
|
||||
if (_ports.size () || _portmap.size ()) {
|
||||
PBD::warning << _("PulseAudioBackend: recovering from unclean shutdown, port registry is not empty.") << endmsg;
|
||||
_system_outputs.clear ();
|
||||
_ports.clear ();
|
||||
_portmap.clear ();
|
||||
}
|
||||
clear_ports ();
|
||||
|
||||
/* reset internal state */
|
||||
_dsp_load = 0;
|
||||
@ -824,194 +820,6 @@ PulseAudioBackend::my_name () const
|
||||
return _instance_name;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
PulseAudioBackend::port_name_size () const
|
||||
{
|
||||
return 256;
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::set_port_name (PortEngine::PortHandle port, const std::string& name)
|
||||
{
|
||||
std::string newname (_instance_name + ":" + name);
|
||||
|
||||
if (!valid_port (port)) {
|
||||
PBD::error << _("PulseBackend::set_port_name: Invalid Port(s)") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (find_port (newname)) {
|
||||
PBD::error << _("PulseBackend::set_port_name: Port with given name already exists") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
PulsePort* p = static_cast<PulsePort*> (port);
|
||||
_portmap.erase (p->name ());
|
||||
_portmap.insert (make_pair (newname, p));
|
||||
return p->set_name (newname);
|
||||
}
|
||||
|
||||
std::string
|
||||
PulseAudioBackend::get_port_name (PortEngine::PortHandle port) const
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
PBD::error << _("PulseBackend::get_port_name: Invalid Port(s)") << endmsg;
|
||||
return std::string ();
|
||||
}
|
||||
return static_cast<PulsePort*> (port)->name ();
|
||||
}
|
||||
|
||||
PortFlags
|
||||
PulseAudioBackend::get_port_flags (PortEngine::PortHandle port) const
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
PBD::error << _("PulseBackend::get_port_flags: Invalid Port(s)") << endmsg;
|
||||
return PortFlags (0);
|
||||
}
|
||||
return static_cast<PulsePort*> (port)->flags ();
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::get_port_property (PortHandle port, const std::string& key, std::string& value, std::string& type) const
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
PBD::warning << _("PulseBackend::get_port_property: Invalid Port(s)") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
if (key == "http://jackaudio.org/metadata/pretty-name") {
|
||||
type = "";
|
||||
value = static_cast<PulsePort*> (port)->pretty_name ();
|
||||
if (!value.empty ()) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::set_port_property (PortHandle port, const std::string& key, const std::string& value, const std::string& type)
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
PBD::warning << _("PulseBackend::set_port_property: Invalid Port(s)") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
if (key == "http://jackaudio.org/metadata/pretty-name" && type.empty ()) {
|
||||
static_cast<PulsePort*> (port)->set_pretty_name (value);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
PortEngine::PortHandle
|
||||
PulseAudioBackend::get_port_by_name (const std::string& name) const
|
||||
{
|
||||
PortHandle port = (PortHandle)find_port (name);
|
||||
return port;
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::get_ports (
|
||||
const std::string& port_name_pattern,
|
||||
DataType type, PortFlags flags,
|
||||
std::vector<std::string>& port_names) const
|
||||
{
|
||||
int rv = 0;
|
||||
regex_t port_regex;
|
||||
bool use_regexp = false;
|
||||
if (port_name_pattern.size () > 0) {
|
||||
if (!regcomp (&port_regex, port_name_pattern.c_str (), REG_EXTENDED | REG_NOSUB)) {
|
||||
use_regexp = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) {
|
||||
PulsePort* port = *i;
|
||||
if ((port->type () == type) && flags == (port->flags () & flags)) {
|
||||
if (!use_regexp || !regexec (&port_regex, port->name ().c_str (), 0, NULL, 0)) {
|
||||
port_names.push_back (port->name ());
|
||||
++rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (use_regexp) {
|
||||
regfree (&port_regex);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
DataType
|
||||
PulseAudioBackend::port_data_type (PortEngine::PortHandle port) const
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
return DataType::NIL;
|
||||
}
|
||||
return static_cast<PulsePort*> (port)->type ();
|
||||
}
|
||||
|
||||
PortEngine::PortHandle
|
||||
PulseAudioBackend::register_port (
|
||||
const std::string& name,
|
||||
ARDOUR::DataType type,
|
||||
ARDOUR::PortFlags flags)
|
||||
{
|
||||
if (name.size () == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (flags & IsPhysical) {
|
||||
return 0;
|
||||
}
|
||||
return add_port (_instance_name + ":" + name, type, flags);
|
||||
}
|
||||
|
||||
PortEngine::PortHandle
|
||||
PulseAudioBackend::add_port (
|
||||
const std::string& name,
|
||||
ARDOUR::DataType type,
|
||||
ARDOUR::PortFlags flags)
|
||||
{
|
||||
assert (name.size ());
|
||||
if (find_port (name)) {
|
||||
PBD::error << _("PulseBackend::register_port: Port already exists:")
|
||||
<< " (" << name << ")" << endmsg;
|
||||
return 0;
|
||||
}
|
||||
PulsePort* port = NULL;
|
||||
switch (type) {
|
||||
case DataType::AUDIO:
|
||||
port = new PulseAudioPort (*this, name, flags);
|
||||
break;
|
||||
case DataType::MIDI:
|
||||
port = new PulseMidiPort (*this, name, flags);
|
||||
break;
|
||||
default:
|
||||
PBD::error << _("PulseBackend::register_port: Invalid Data Type.") << endmsg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_ports.insert (port);
|
||||
_portmap.insert (make_pair (name, port));
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
void
|
||||
PulseAudioBackend::unregister_port (PortEngine::PortHandle port_handle)
|
||||
{
|
||||
if (!_run) {
|
||||
return;
|
||||
}
|
||||
PulsePort* port = static_cast<PulsePort*> (port_handle);
|
||||
PortIndex::iterator i = std::find (_ports.begin (), _ports.end (), static_cast<PulsePort*> (port_handle));
|
||||
if (i == _ports.end ()) {
|
||||
PBD::error << _("PulseBackend::unregister_port: Failed to find port") << endmsg;
|
||||
return;
|
||||
}
|
||||
disconnect_all (port_handle);
|
||||
_portmap.erase (port->name ());
|
||||
_ports.erase (i);
|
||||
delete port;
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::register_system_ports ()
|
||||
{
|
||||
@ -1025,159 +833,41 @@ PulseAudioBackend::register_system_ports ()
|
||||
if (!p)
|
||||
return -1;
|
||||
set_latency_range (p, true, lr);
|
||||
PulsePort* ap = static_cast<PulsePort*> (p);
|
||||
BackendPort* ap = static_cast<BackendPort*> (p);
|
||||
//ap->set_pretty_name ("")
|
||||
_system_outputs.push_back (ap);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PulseAudioBackend::unregister_ports (bool system_only)
|
||||
{
|
||||
_system_outputs.clear ();
|
||||
|
||||
for (PortIndex::iterator i = _ports.begin (); i != _ports.end ();) {
|
||||
PortIndex::iterator cur = i++;
|
||||
PulsePort* port = *cur;
|
||||
if (!system_only || (port->is_physical () && port->is_terminal ())) {
|
||||
port->disconnect_all ();
|
||||
_portmap.erase (port->name ());
|
||||
delete port;
|
||||
_ports.erase (cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PulseAudioBackend::update_system_port_latecies ()
|
||||
{
|
||||
for (std::vector<PulsePort*>::const_iterator it = _system_outputs.begin (); it != _system_outputs.end (); ++it) {
|
||||
for (std::vector<BackendPort*>::const_iterator it = _system_outputs.begin (); it != _system_outputs.end (); ++it) {
|
||||
(*it)->update_connected_latency (false);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::connect (const std::string& src, const std::string& dst)
|
||||
BackendPort*
|
||||
PulseAudioBackend::port_factory (std::string const & name, ARDOUR::DataType type, ARDOUR::PortFlags flags)
|
||||
{
|
||||
PulsePort* src_port = find_port (src);
|
||||
PulsePort* dst_port = find_port (dst);
|
||||
BackendPort* port = 0;
|
||||
|
||||
if (!src_port) {
|
||||
PBD::error << _("PulseBackend::connect: Invalid Source port:")
|
||||
<< " (" << src << ")" << endmsg;
|
||||
return -1;
|
||||
switch (type) {
|
||||
case DataType::AUDIO:
|
||||
port = new PulseAudioPort (*this, name, flags);
|
||||
break;
|
||||
case DataType::MIDI:
|
||||
port = new PulseMidiPort (*this, name, flags);
|
||||
break;
|
||||
default:
|
||||
PBD::error << string_compose (_("%1::register_port: Invalid Data Type."), _instance_name) << endmsg;
|
||||
return 0;
|
||||
}
|
||||
if (!dst_port) {
|
||||
PBD::error << _("PulseBackend::connect: Invalid Destination port:")
|
||||
<< " (" << dst << ")" << endmsg;
|
||||
return -1;
|
||||
}
|
||||
return src_port->connect (dst_port);
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::disconnect (const std::string& src, const std::string& dst)
|
||||
{
|
||||
PulsePort* src_port = find_port (src);
|
||||
PulsePort* dst_port = find_port (dst);
|
||||
|
||||
if (!src_port || !dst_port) {
|
||||
PBD::error << _("PulseBackend::disconnect: Invalid Port(s)") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
return src_port->disconnect (dst_port);
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::connect (PortEngine::PortHandle src, const std::string& dst)
|
||||
{
|
||||
PulsePort* dst_port = find_port (dst);
|
||||
if (!valid_port (src)) {
|
||||
PBD::error << _("PulseBackend::connect: Invalid Source Port Handle") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
if (!dst_port) {
|
||||
PBD::error << _("PulseBackend::connect: Invalid Destination Port")
|
||||
<< " (" << dst << ")" << endmsg;
|
||||
return -1;
|
||||
}
|
||||
return static_cast<PulsePort*> (src)->connect (dst_port);
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::disconnect (PortEngine::PortHandle src, const std::string& dst)
|
||||
{
|
||||
PulsePort* dst_port = find_port (dst);
|
||||
if (!valid_port (src) || !dst_port) {
|
||||
PBD::error << _("PulseBackend::disconnect: Invalid Port(s)") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
return static_cast<PulsePort*> (src)->disconnect (dst_port);
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::disconnect_all (PortEngine::PortHandle port)
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
PBD::error << _("PulseBackend::disconnect_all: Invalid Port") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
static_cast<PulsePort*> (port)->disconnect_all ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
PulseAudioBackend::connected (PortEngine::PortHandle port, bool /* process_callback_safe*/)
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
PBD::error << _("PulseBackend::disconnect_all: Invalid Port") << endmsg;
|
||||
return false;
|
||||
}
|
||||
return static_cast<PulsePort*> (port)->is_connected ();
|
||||
}
|
||||
|
||||
bool
|
||||
PulseAudioBackend::connected_to (PortEngine::PortHandle src, const std::string& dst, bool /*process_callback_safe*/)
|
||||
{
|
||||
PulsePort* dst_port = find_port (dst);
|
||||
#ifndef NDEBUG
|
||||
if (!valid_port (src) || !dst_port) {
|
||||
PBD::error << _("PulseBackend::connected_to: Invalid Port") << endmsg;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return static_cast<PulsePort*> (src)->is_connected (dst_port);
|
||||
}
|
||||
|
||||
bool
|
||||
PulseAudioBackend::physically_connected (PortEngine::PortHandle port, bool /*process_callback_safe*/)
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
PBD::error << _("PulseBackend::physically_connected: Invalid Port") << endmsg;
|
||||
return false;
|
||||
}
|
||||
return static_cast<PulsePort*> (port)->is_physically_connected ();
|
||||
}
|
||||
|
||||
int
|
||||
PulseAudioBackend::get_connections (PortEngine::PortHandle port, std::vector<std::string>& names, bool /*process_callback_safe*/)
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
PBD::error << _("PulseBackend::get_connections: Invalid Port") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert (0 == names.size ());
|
||||
|
||||
const std::set<PulsePort*>& connected_ports = static_cast<PulsePort*> (port)->get_connections ();
|
||||
|
||||
for (std::set<PulsePort*>::const_iterator i = connected_ports.begin (); i != connected_ports.end (); ++i) {
|
||||
names.push_back ((*i)->name ());
|
||||
}
|
||||
|
||||
return (int)names.size ();
|
||||
}
|
||||
|
||||
/* MIDI */
|
||||
int
|
||||
@ -1261,7 +951,7 @@ PulseAudioBackend::set_latency_range (PortEngine::PortHandle port, bool for_play
|
||||
if (!valid_port (port)) {
|
||||
PBD::error << _("PulsePort::set_latency_range (): invalid port.") << endmsg;
|
||||
}
|
||||
static_cast<PulsePort*> (port)->set_latency_range (latency_range, for_playback);
|
||||
static_cast<BackendPort*> (port)->set_latency_range (latency_range, for_playback);
|
||||
}
|
||||
|
||||
LatencyRange
|
||||
@ -1274,7 +964,7 @@ PulseAudioBackend::get_latency_range (PortEngine::PortHandle port, bool for_play
|
||||
r.max = 0;
|
||||
return r;
|
||||
}
|
||||
PulsePort* p = static_cast<PulsePort*> (port);
|
||||
BackendPort* p = static_cast<BackendPort*> (port);
|
||||
assert (p);
|
||||
|
||||
r = p->latency_range (for_playback);
|
||||
@ -1291,93 +981,6 @@ PulseAudioBackend::get_latency_range (PortEngine::PortHandle port, bool for_play
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Discovering physical ports */
|
||||
|
||||
bool
|
||||
PulseAudioBackend::port_is_physical (PortEngine::PortHandle port) const
|
||||
{
|
||||
if (!valid_port (port)) {
|
||||
PBD::error << _("PulsePort::port_is_physical (): invalid port.") << endmsg;
|
||||
return false;
|
||||
}
|
||||
return static_cast<PulsePort*> (port)->is_physical ();
|
||||
}
|
||||
|
||||
void
|
||||
PulseAudioBackend::get_physical_outputs (DataType type, std::vector<std::string>& port_names)
|
||||
{
|
||||
for (PortIndex::iterator i = _ports.begin (); i != _ports.end (); ++i) {
|
||||
PulsePort* port = *i;
|
||||
if ((port->type () == type) && port->is_input () && port->is_physical ()) {
|
||||
port_names.push_back (port->name ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PulseAudioBackend::get_physical_inputs (DataType type, std::vector<std::string>& port_names)
|
||||
{
|
||||
for (PortIndex::iterator i = _ports.begin (); i != _ports.end (); ++i) {
|
||||
PulsePort* port = *i;
|
||||
if ((port->type () == type) && port->is_output () && port->is_physical ()) {
|
||||
port_names.push_back (port->name ());
|
||||
}
|
||||
}
|
||||
assert (port_names.size () == 0);
|
||||
}
|
||||
|
||||
ChanCount
|
||||
PulseAudioBackend::n_physical_outputs () const
|
||||
{
|
||||
int n_midi = 0;
|
||||
int n_audio = 0;
|
||||
for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) {
|
||||
PulsePort* port = *i;
|
||||
if (port->is_output () && port->is_physical ()) {
|
||||
switch (port->type ()) {
|
||||
case DataType::AUDIO:
|
||||
++n_audio;
|
||||
break;
|
||||
case DataType::MIDI:
|
||||
++n_midi;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ChanCount cc;
|
||||
cc.set (DataType::AUDIO, n_audio);
|
||||
cc.set (DataType::MIDI, n_midi);
|
||||
return cc;
|
||||
}
|
||||
|
||||
ChanCount
|
||||
PulseAudioBackend::n_physical_inputs () const
|
||||
{
|
||||
int n_midi = 0;
|
||||
int n_audio = 0;
|
||||
for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) {
|
||||
PulsePort* port = *i;
|
||||
if (port->is_input () && port->is_physical ()) {
|
||||
switch (port->type ()) {
|
||||
case DataType::AUDIO:
|
||||
++n_audio;
|
||||
break;
|
||||
case DataType::MIDI:
|
||||
++n_midi;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ChanCount cc;
|
||||
cc.set (DataType::AUDIO, n_audio);
|
||||
cc.set (DataType::MIDI, n_midi);
|
||||
return cc;
|
||||
}
|
||||
|
||||
/* Getting access to the data buffer for a port */
|
||||
|
||||
void*
|
||||
@ -1385,7 +988,7 @@ PulseAudioBackend::get_buffer (PortEngine::PortHandle port, pframes_t nframes)
|
||||
{
|
||||
assert (port);
|
||||
assert (valid_port (port));
|
||||
return static_cast<PulsePort*> (port)->get_buffer (nframes);
|
||||
return static_cast<BackendPort*> (port)->get_buffer (nframes);
|
||||
}
|
||||
|
||||
/* Engine Process */
|
||||
@ -1470,7 +1073,7 @@ PulseAudioBackend::main_process_thread ()
|
||||
assert (_system_outputs.size () == N_CHANNELS);
|
||||
|
||||
/* interleave */
|
||||
for (std::vector<PulsePort *>::const_iterator it = _system_outputs.begin (); it != _system_outputs.end (); ++it, ++i) {
|
||||
for (std::vector<BackendPort *>::const_iterator it = _system_outputs.begin (); it != _system_outputs.end (); ++it, ++i) {
|
||||
const float* src = (const float*)(*it)->get_buffer (_samples_per_period);
|
||||
for (size_t n = 0; n < _samples_per_period; ++n) {
|
||||
buf[N_CHANNELS * n + i] = src[n];
|
||||
@ -1599,178 +1202,28 @@ descriptor ()
|
||||
return &_descriptor;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
PulsePort::PulsePort (PulseAudioBackend& b, const std::string& name, PortFlags flags)
|
||||
: _pulse_backend (b)
|
||||
, _name (name)
|
||||
, _flags (flags)
|
||||
{
|
||||
_capture_latency_range.min = 0;
|
||||
_capture_latency_range.max = 0;
|
||||
_playback_latency_range.min = 0;
|
||||
_playback_latency_range.max = 0;
|
||||
_pulse_backend.port_connect_add_remove_callback (); // XXX -> RT
|
||||
}
|
||||
|
||||
PulsePort::~PulsePort ()
|
||||
{
|
||||
disconnect_all ();
|
||||
_pulse_backend.port_connect_add_remove_callback (); // XXX -> RT
|
||||
}
|
||||
|
||||
int
|
||||
PulsePort::connect (PulsePort* port)
|
||||
{
|
||||
if (!port) {
|
||||
PBD::error << _("PulsePort::connect (): invalid (null) port") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (type () != port->type ()) {
|
||||
PBD::error << _("PulsePort::connect (): wrong port-type") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_output () && port->is_output ()) {
|
||||
PBD::error << _("PulsePort::connect (): cannot inter-connect output ports.") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_input () && port->is_input ()) {
|
||||
PBD::error << _("PulsePort::connect (): cannot inter-connect input ports.") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this == port) {
|
||||
PBD::error << _("PulsePort::connect (): cannot self-connect ports.") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_connected (port)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
_connect (port, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PulsePort::_connect (PulsePort* port, bool callback)
|
||||
{
|
||||
_connections.insert (port);
|
||||
if (callback) {
|
||||
port->_connect (this, false);
|
||||
_pulse_backend.port_connect_callback (name (), port->name (), true);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
PulsePort::disconnect (PulsePort* port)
|
||||
{
|
||||
if (!port) {
|
||||
PBD::error << _("PulsePort::disconnect (): invalid (null) port") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!is_connected (port)) {
|
||||
PBD::error << _("PulsePort::disconnect (): ports are not connected:")
|
||||
<< " (" << name () << ") -> (" << port->name () << ")"
|
||||
<< endmsg;
|
||||
return -1;
|
||||
}
|
||||
_disconnect (port, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PulsePort::_disconnect (PulsePort* port, bool callback)
|
||||
{
|
||||
std::set<PulsePort*>::iterator it = _connections.find (port);
|
||||
assert (it != _connections.end ());
|
||||
_connections.erase (it);
|
||||
if (callback) {
|
||||
port->_disconnect (this, false);
|
||||
_pulse_backend.port_connect_callback (name (), port->name (), false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PulsePort::disconnect_all ()
|
||||
{
|
||||
while (!_connections.empty ()) {
|
||||
std::set<PulsePort*>::iterator it = _connections.begin ();
|
||||
(*it)->_disconnect (this, false);
|
||||
_pulse_backend.port_connect_callback (name (), (*it)->name (), false);
|
||||
_connections.erase (it);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
PulsePort::is_connected (const PulsePort* port) const
|
||||
{
|
||||
return _connections.find (const_cast<PulsePort*> (port)) != _connections.end ();
|
||||
}
|
||||
|
||||
bool
|
||||
PulsePort::is_physically_connected () const
|
||||
{
|
||||
for (std::set<PulsePort*>::const_iterator it = _connections.begin (); it != _connections.end (); ++it) {
|
||||
if ((*it)->is_physical ()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
PulsePort::set_latency_range (const LatencyRange& latency_range, bool for_playback)
|
||||
{
|
||||
if (for_playback) {
|
||||
_playback_latency_range = latency_range;
|
||||
} else {
|
||||
_capture_latency_range = latency_range;
|
||||
}
|
||||
|
||||
for (std::set<PulsePort*>::const_iterator it = _connections.begin (); it != _connections.end (); ++it) {
|
||||
if ((*it)->is_physical ()) {
|
||||
(*it)->update_connected_latency (is_input ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PulsePort::update_connected_latency (bool for_playback)
|
||||
{
|
||||
LatencyRange lr;
|
||||
lr.min = lr.max = 0;
|
||||
for (std::set<PulsePort*>::const_iterator it = _connections.begin (); it != _connections.end (); ++it) {
|
||||
LatencyRange l;
|
||||
l = (*it)->latency_range (for_playback);
|
||||
lr.min = std::max (lr.min, l.min);
|
||||
lr.max = std::max (lr.max, l.max);
|
||||
}
|
||||
set_latency_range (lr, for_playback);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
PulseAudioPort::PulseAudioPort (PulseAudioBackend& b, const std::string& name, PortFlags flags)
|
||||
: PulsePort (b, name, flags)
|
||||
: BackendPort (b, name, flags)
|
||||
{
|
||||
memset (_buffer, 0, sizeof (_buffer));
|
||||
mlock (_buffer, sizeof (_buffer));
|
||||
_backend.port_connect_add_remove_callback (); // XXX -> RT
|
||||
}
|
||||
|
||||
PulseAudioPort::~PulseAudioPort ()
|
||||
{
|
||||
_backend.port_connect_add_remove_callback (); // XXX -> RT
|
||||
}
|
||||
|
||||
void*
|
||||
PulseAudioPort::get_buffer (pframes_t n_samples)
|
||||
{
|
||||
if (is_input ()) {
|
||||
const std::set<PulsePort*>& connections = get_connections ();
|
||||
std::set<PulsePort*>::const_iterator it = connections.begin ();
|
||||
const std::set<BackendPort*>& connections = get_connections ();
|
||||
std::set<BackendPort*>::const_iterator it = connections.begin ();
|
||||
if (it == connections.end ()) {
|
||||
memset (_buffer, 0, n_samples * sizeof (Sample));
|
||||
} else {
|
||||
@ -1792,14 +1245,16 @@ PulseAudioPort::get_buffer (pframes_t n_samples)
|
||||
}
|
||||
|
||||
PulseMidiPort::PulseMidiPort (PulseAudioBackend& b, const std::string& name, PortFlags flags)
|
||||
: PulsePort (b, name, flags)
|
||||
: BackendPort (b, name, flags)
|
||||
{
|
||||
_buffer.clear ();
|
||||
_buffer.reserve (256);
|
||||
_backend.port_connect_add_remove_callback (); // XXX -> RT
|
||||
}
|
||||
|
||||
PulseMidiPort::~PulseMidiPort ()
|
||||
{
|
||||
_backend.port_connect_add_remove_callback (); // XXX -> RT
|
||||
}
|
||||
|
||||
struct MidiEventSorter {
|
||||
@ -1814,8 +1269,8 @@ void* PulseMidiPort::get_buffer (pframes_t /*n_samples*/)
|
||||
{
|
||||
if (is_input ()) {
|
||||
_buffer.clear ();
|
||||
const std::set<PulsePort*>& connections = get_connections ();
|
||||
for (std::set<PulsePort*>::const_iterator i = connections.begin ();
|
||||
const std::set<BackendPort*>& connections = get_connections ();
|
||||
for (std::set<BackendPort*>::const_iterator i = connections.begin ();
|
||||
i != connections.end ();
|
||||
++i) {
|
||||
const PulseMidiBuffer* src = static_cast<PulseMidiPort*> (*i)->const_buffer ();
|
||||
|
@ -31,9 +31,11 @@
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "pbd/natsort.h"
|
||||
|
||||
#include "ardour/audio_backend.h"
|
||||
#include "ardour/dsp_load_calculator.h"
|
||||
#include "pbd/natsort.h"
|
||||
#include "ardour/port_engine_shared.h"
|
||||
|
||||
#define MaxPulseMidiEventSize (256)
|
||||
|
||||
@ -61,67 +63,8 @@ private:
|
||||
|
||||
typedef std::vector<boost::shared_ptr<PulseMidiEvent> > PulseMidiBuffer;
|
||||
|
||||
class PulsePort
|
||||
{
|
||||
protected:
|
||||
PulsePort (PulseAudioBackend& b, const std::string&, PortFlags);
|
||||
|
||||
public:
|
||||
virtual ~PulsePort ();
|
||||
|
||||
const std::string& name () const { return _name; }
|
||||
const std::string& pretty_name () const { return _pretty_name; }
|
||||
PortFlags flags () const { return _flags; }
|
||||
|
||||
int set_name (const std::string& name) { _name = name; return 0; }
|
||||
int set_pretty_name (const std::string& name) { _pretty_name = name; return 0; }
|
||||
|
||||
virtual DataType type () const = 0;
|
||||
|
||||
virtual void* get_buffer (pframes_t nframes) = 0;
|
||||
|
||||
bool is_input () const { return flags () & IsInput; }
|
||||
bool is_output () const { return flags () & IsOutput; }
|
||||
bool is_physical () const { return flags () & IsPhysical; }
|
||||
bool is_terminal () const { return flags () & IsTerminal; }
|
||||
bool is_connected () const { return _connections.size () != 0; }
|
||||
|
||||
bool is_connected (const PulsePort* port) const;
|
||||
bool is_physically_connected () const;
|
||||
|
||||
int connect (PulsePort* port);
|
||||
int disconnect (PulsePort* port);
|
||||
void disconnect_all ();
|
||||
|
||||
const std::set<PulsePort*>&
|
||||
get_connections () const
|
||||
{
|
||||
return _connections;
|
||||
}
|
||||
|
||||
const LatencyRange
|
||||
latency_range (bool for_playback) const
|
||||
{
|
||||
return for_playback ? _playback_latency_range : _capture_latency_range;
|
||||
}
|
||||
|
||||
void set_latency_range (const LatencyRange& latency_range, bool for_playback);
|
||||
void update_connected_latency (bool for_playback);
|
||||
|
||||
private:
|
||||
PulseAudioBackend& _pulse_backend;
|
||||
std::string _name;
|
||||
std::string _pretty_name;
|
||||
const PortFlags _flags;
|
||||
LatencyRange _capture_latency_range;
|
||||
LatencyRange _playback_latency_range;
|
||||
std::set<PulsePort*> _connections;
|
||||
|
||||
void _connect (PulsePort*, bool);
|
||||
void _disconnect (PulsePort*, bool);
|
||||
}; // class PulsePort
|
||||
|
||||
class PulseAudioPort : public PulsePort
|
||||
class PulseAudioPort : public BackendPort
|
||||
{
|
||||
public:
|
||||
PulseAudioPort (PulseAudioBackend& b, const std::string&, PortFlags);
|
||||
@ -137,7 +80,7 @@ private:
|
||||
Sample _buffer[8192];
|
||||
}; // class PulseAudioPort
|
||||
|
||||
class PulseMidiPort : public PulsePort
|
||||
class PulseMidiPort : public BackendPort
|
||||
{
|
||||
public:
|
||||
PulseMidiPort (PulseAudioBackend& b, const std::string&, PortFlags);
|
||||
@ -152,7 +95,7 @@ private:
|
||||
PulseMidiBuffer _buffer;
|
||||
}; // class PulseMidiPort
|
||||
|
||||
class PulseAudioBackend : public AudioBackend
|
||||
class PulseAudioBackend : public AudioBackend, public PortEngineSharedImpl
|
||||
{
|
||||
friend class PulsePort;
|
||||
|
||||
@ -241,32 +184,33 @@ public:
|
||||
void* private_handle () const;
|
||||
const std::string& my_name () const;
|
||||
|
||||
uint32_t port_name_size () const;
|
||||
int set_port_name (PortHandle, const std::string&);
|
||||
std::string get_port_name (PortHandle) const;
|
||||
PortFlags get_port_flags (PortHandle) const;
|
||||
PortHandle get_port_by_name (const std::string&) const;
|
||||
/* PortEngine API - forwarded to PortEngineSharedImpl */
|
||||
|
||||
int get_port_property (PortHandle, const std::string& key, std::string& value, std::string& type) const;
|
||||
int set_port_property (PortHandle, const std::string& key, const std::string& value, const std::string& type);
|
||||
|
||||
int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>&) const;
|
||||
|
||||
DataType port_data_type (PortHandle) const;
|
||||
|
||||
PortHandle register_port (const std::string& shortname, ARDOUR::DataType, ARDOUR::PortFlags);
|
||||
void unregister_port (PortHandle);
|
||||
|
||||
int connect (const std::string& src, const std::string& dst);
|
||||
int disconnect (const std::string& src, const std::string& dst);
|
||||
int connect (PortHandle, const std::string&);
|
||||
int disconnect (PortHandle, const std::string&);
|
||||
int disconnect_all (PortHandle);
|
||||
|
||||
bool connected (PortHandle, bool process_callback_safe);
|
||||
bool connected_to (PortHandle, const std::string&, bool process_callback_safe);
|
||||
bool physically_connected (PortHandle, bool process_callback_safe);
|
||||
int get_connections (PortHandle, std::vector<std::string>&, bool process_callback_safe);
|
||||
bool port_is_physical (PortEngine::PortHandle ph) const { return PortEngineSharedImpl::port_is_physical (ph); }
|
||||
void get_physical_outputs (DataType type, std::vector<std::string>& results) { PortEngineSharedImpl::get_physical_outputs (type, results); }
|
||||
void get_physical_inputs (DataType type, std::vector<std::string>& results) { PortEngineSharedImpl::get_physical_inputs (type, results); }
|
||||
ChanCount n_physical_outputs () const { return PortEngineSharedImpl::n_physical_outputs (); }
|
||||
ChanCount n_physical_inputs () const { return PortEngineSharedImpl::n_physical_inputs (); }
|
||||
uint32_t port_name_size () const { return PortEngineSharedImpl::port_name_size(); }
|
||||
int set_port_name (PortEngine::PortHandle ph, const std::string& name) { return PortEngineSharedImpl::set_port_name (ph, name); }
|
||||
std::string get_port_name (PortEngine::PortHandle ph) const { return PortEngineSharedImpl::get_port_name (ph); }
|
||||
PortFlags get_port_flags (PortEngine::PortHandle ph) const { return PortEngineSharedImpl::get_port_flags (ph); }
|
||||
PortEngine::PortHandle get_port_by_name (std::string const & name) const { return PortEngineSharedImpl::get_port_by_name (name); }
|
||||
int get_port_property (PortEngine::PortHandle ph, const std::string& key, std::string& value, std::string& type) const { return PortEngineSharedImpl::get_port_property (ph, key, value, type); }
|
||||
int set_port_property (PortEngine::PortHandle ph, const std::string& key, const std::string& value, const std::string& type) { return PortEngineSharedImpl::set_port_property (ph, key, value, type); }
|
||||
int get_ports (const std::string& port_name_pattern, DataType type, PortFlags flags, std::vector<std::string>& results) const { return PortEngineSharedImpl::get_ports (port_name_pattern, type, flags, results); }
|
||||
DataType port_data_type (PortEngine::PortHandle ph) const { return PortEngineSharedImpl::port_data_type (ph); }
|
||||
PortEngine::PortHandle register_port (const std::string& shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags) { return PortEngineSharedImpl::register_port (shortname, type, flags); }
|
||||
void unregister_port (PortHandle ph) { if (!_run) return; PortEngineSharedImpl::unregister_port (ph); }
|
||||
int connect (const std::string& src, const std::string& dst) { return PortEngineSharedImpl::connect (src, dst); }
|
||||
int disconnect (const std::string& src, const std::string& dst) { return PortEngineSharedImpl::disconnect (src, dst); }
|
||||
int connect (PortEngine::PortHandle ph, const std::string& other) { return PortEngineSharedImpl::connect (ph, other); }
|
||||
int disconnect (PortEngine::PortHandle ph, const std::string& other) { return PortEngineSharedImpl::disconnect (ph, other); }
|
||||
int disconnect_all (PortEngine::PortHandle ph) { return PortEngineSharedImpl::disconnect_all (ph); }
|
||||
bool connected (PortEngine::PortHandle ph, bool process_callback_safe) { return PortEngineSharedImpl::connected (ph, process_callback_safe); }
|
||||
bool connected_to (PortEngine::PortHandle ph, const std::string& other, bool process_callback_safe) { return PortEngineSharedImpl::connected_to (ph, other, process_callback_safe); }
|
||||
bool physically_connected (PortEngine::PortHandle ph, bool process_callback_safe) { return PortEngineSharedImpl::physically_connected (ph, process_callback_safe); }
|
||||
int get_connections (PortEngine::PortHandle ph, std::vector<std::string>& results, bool process_callback_safe) { return PortEngineSharedImpl::get_connections (ph, results, process_callback_safe); }
|
||||
|
||||
/* MIDI */
|
||||
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index);
|
||||
@ -286,14 +230,6 @@ public:
|
||||
void set_latency_range (PortHandle, bool for_playback, LatencyRange);
|
||||
LatencyRange get_latency_range (PortHandle, bool for_playback);
|
||||
|
||||
/* Discovering physical ports */
|
||||
|
||||
bool port_is_physical (PortHandle) const;
|
||||
void get_physical_outputs (DataType type, std::vector<std::string>&);
|
||||
void get_physical_inputs (DataType type, std::vector<std::string>&);
|
||||
ChanCount n_physical_outputs () const;
|
||||
ChanCount n_physical_inputs () const;
|
||||
|
||||
/* Getting access to the data buffer for a port */
|
||||
|
||||
void* get_buffer (PortHandle, pframes_t);
|
||||
@ -356,25 +292,10 @@ private:
|
||||
};
|
||||
|
||||
/* port engine */
|
||||
PortHandle add_port (const std::string& shortname, ARDOUR::DataType, ARDOUR::PortFlags);
|
||||
BackendPort* port_factory (std::string const & name, ARDOUR::DataType dt, ARDOUR::PortFlags flags);
|
||||
int register_system_ports ();
|
||||
void unregister_ports (bool system_only = false);
|
||||
void update_system_port_latecies ();
|
||||
|
||||
std::vector<PulsePort*> _system_outputs;
|
||||
|
||||
struct SortByPortName {
|
||||
bool operator() (const PulsePort* lhs, const PulsePort* rhs) const
|
||||
{
|
||||
return PBD::naturally_less (lhs->name ().c_str (), rhs->name ().c_str ());
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<std::string, PulsePort*> PortMap; // fast lookup in _ports
|
||||
typedef std::set<PulsePort*, SortByPortName> PortIndex; // fast lookup in _ports
|
||||
PortMap _portmap;
|
||||
PortIndex _ports;
|
||||
|
||||
struct PortConnectData {
|
||||
std::string a;
|
||||
std::string b;
|
||||
@ -404,21 +325,6 @@ private:
|
||||
pthread_mutex_unlock (&_port_callback_mutex);
|
||||
}
|
||||
|
||||
bool
|
||||
valid_port (PortHandle port) const
|
||||
{
|
||||
return std::find (_ports.begin (), _ports.end (), static_cast<PulsePort*> (port)) != _ports.end ();
|
||||
}
|
||||
|
||||
PulsePort*
|
||||
find_port (const std::string& port_name) const
|
||||
{
|
||||
PortMap::const_iterator it = _portmap.find (port_name);
|
||||
if (it == _portmap.end ()) {
|
||||
return NULL;
|
||||
}
|
||||
return (*it).second;
|
||||
}
|
||||
}; // class PulseAudioBackend
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user