mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-16 03:36:32 +01:00
use PortEngineSharedImpl with PulseAudio backend
This commit is contained in:
parent
04551c39f6
commit
e5507f7072
2 changed files with 66 additions and 705 deletions
|
|
@ -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 ();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue