echo-cancel: Do not bypass EC implementation when play stream is empty

When the play stream from the EC sink has not enough data available then
the EC implementation is currently bypassed by directly forwarding the
record bytes to the EC source. Since EC implementations maintain their
own buffers and cause certain latencies, a bypass leads to glitches as
the out stream stream jumps forth and back in time. Furthermore, some
EC implementations may also apply noise reduction or other sound
enhancing techniques, which are therefore bypassed, too.

Fix this by passing silence bytes to the EC implementation if the play
stream runs empty. Hence, this patch keeps the EC implementation running
even if the play stream has no data available.
core: Internally deprecate pa_port_available_t to use pa_available_t

Generalize the availability flag in order to be used beyond the scope of
ports.

However, pa_port_availability_t is left unchanged to avoid modifying the
protocol and the client API. This should be replaced by pa_available_t
after a validation phase of this new generic enum type.
card: Add card profile availability

Some cards are capable to announce if a specific profile is available or
not, effectively predicting whether a profile switch would fail or would
likely succeed. This can for example be useful for a UI that would gray
out any unavailable profile.

In addition, this information can be useful for internal modules
implementing automatic profile-switching policies, such as
module-switch-on-port-available or module-bluetooth-policy.

In particular, this information is essential when a port is associated
to multiple card profiles and therefore the port availability flag does
not provide enough information. The port "bluetooth-output" falls into
this category, for example, since it doesn't distinguish HSP/HFP from
A2DP.
cli: Show card profile availability status

Expose the newly added card profile availability in pacmd.
bluetooth: Expose card profile availability

Use the transport's state to not only update the ports availability, but
also to update the card profile availability flag. The interpretation is
as follows:
- PA_AVAILABLE_UNKNOWN: BT profile is connected but no audio streaming
- PA_AVAILABLE_NO: BT profile disconnected
- PA_AVAILABLE_YES: BT profile connected and audio streaming
bluetooth: Use profile availability to auto-switch profiles

Use the card profile availability flag instead of port availability in
order to automatically switch profiles, for example when a paired phone
starts streaming A2DP audio.
bluetooth: Merge all ports into "bluetooth-input" and "bluetooth-output"

The card profile availability flag already provides all the necessary
information and therefore all Bluetooth ports can be merged, leaving
the two generic ones only: "bluetooth-input" and "bluetooth-output". The
availability of these port now represents whether the device is
streaming audio, with the following mapping:
- PA_AVAILABLE_UNKNOWN: some profile connected but not streaming
- PA_AVAILABLE_NO: no profiles connected
- PA_AVAILABLE_YES: some profile streaming (regardless of which)

Each port's flag represents the profiles with the corresponding I/O
capabilities (pa_direction_t).
echo-cancel: Enable different sample specs for rec and out stream

Enable advanced AEC methods to use different specs (i.e., number of
channels) for rec and out stream. A typical application is beam forming
resp. multi-channel AEC, which takes multiple record channels to produce
an echo-canceled output stream.
This commit alters the EC API as follows: the EC's init() used to get
source and sink's sample spec/channel map. The new interface renamed
source to rec and sink to play and additionally passes sample spec and
channel map of the out stream. The new parameter names of init()
{rec,play,out}_{ss,map} are more intuitive and also resemble to the
parameter names known from run(). Both rec_{ss,map} and out_{ss,map} are
initialized as we knew it from source_{ss,map} before being passed to
init(). The previous EC implementations only require trivial changes,
i.e., setting rec_{ss,map} to out_{ss,map} at the end of init() in case
that out_{ss,map} is modified in init().
bluetooth: Fix possible adapter duplicates

The D-Bus signal AdapterAdded can be received during our call to
GetProperties(), before the reply is received. In this case, the adapter
will be listed twice and thus the endpoint registration will fail with
"AlreadyExists" as follows:

D: [pulseaudio] bluetooth-util.c: dbus: interface=org.bluez.Manager, path=/, member=AdapterAdded
D: [pulseaudio] bluetooth-util.c: Adapter /org/bluez/21220/hci0 created
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPAG on adapter /org/bluez/21220/hci0.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPHS on adapter /org/bluez/21220/hci0.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSource on adapter /org/bluez/21220/hci0.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSink on adapter /org/bluez/21220/hci0.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPAG on adapter /org/bluez/21220/hci0.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPHS on adapter /org/bluez/21220/hci0.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSource on adapter /org/bluez/21220/hci0.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSink on adapter /org/bluez/21220/hci0.
E: [pulseaudio] bluetooth-util.c: RegisterEndpoint() failed: org.bluez.Error.AlreadyExists: Already Exists
E: [pulseaudio] bluetooth-util.c: RegisterEndpoint() failed: org.bluez.Error.AlreadyExists: Already Exists
E: [pulseaudio] bluetooth-util.c: RegisterEndpoint() failed: org.bluez.Error.AlreadyExists: Already Exists
E: [pulseaudio] bluetooth-util.c: RegisterEndpoint() failed: org.bluez.Error.AlreadyExists: Already Exists
bluetooth: Fix assertion failure if BlueZ crashes during GetProperties

If BlueZ crashes exactly while PulseAudio waits for the GetProperties reply, the
device has already been removed from the hashmap and therefore an assertion
failure is experienced.

The solution consists of ignoring the reply in these cases.

The problem can be observed in the following traces:

D: [pulseaudio] bluetooth-util.c: Bluetooth daemon appeared.
D: [pulseaudio] bluetooth-util.c: dbus: interface=org.bluez.Manager, path=/, member=AdapterAdded
D: [pulseaudio] bluetooth-util.c: Adapter /org/bluez/497/hci1 created
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPAG on adapter /org/bluez/497/hci1.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/HFPHS on adapter /org/bluez/497/hci1.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSource on adapter /org/bluez/497/hci1.
D: [pulseaudio] bluetooth-util.c: Registering /MediaEndpoint/A2DPSink on adapter /org/bluez/497/hci1.
D: [pulseaudio] bluetooth-util.c: dbus: interface=org.bluez.Adapter, path=/org/bluez/497/hci1, member=DeviceCreated
D: [pulseaudio] bluetooth-util.c: Device /org/bluez/497/hci1/dev_90_84_0D_B2_C7_04 created
D: [pulseaudio] bluetooth-util.c: dbus: interface=org.freedesktop.DBus, path=/org/freedesktop/DBus, member=NameOwnerChanged
D: [pulseaudio] bluetooth-util.c: Bluetooth daemon disappeared.
E: [pulseaudio] bluetooth-util.c: Assertion 'p->call_data == d' failed at modules/bluetooth/bluetooth-util.c:685, function get_properties_reply(). Aborting.
card: Set initial profile availability state

Commit afd33da56a0b174c43ca44bce21b8ef0efaca1fa introduces this new
flag but the default initial value is missing, considering that
pa_xmalloc is used to allocate the memory.
alsa-util: Add a function to read ELD info

Currently, this function only reads the monitor name, but could
be extended to read e g supported formats as well.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
alsa-mixer: Add possibility to configure ELD device

The alsa mixer kcontrol has "device index" 3, 7, 8, and 9.
We need to configure this properly.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
alsa-card: Make ELD monitor name a port property

If there is a proper monitor name, we expose this as a device.product.name
property on the port. This can be useful for UIs who might want to show
this name.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
format: Add #defines for enum values
bluetooth: Detect BlueZ 5

Check the existence of ObjectManager to detect the version of the
running daemon. If the interface exists, it should be BlueZ 5.
bluetooth: Parse the tree returned by ObjectManager

Parse the result of ObjectManager.GetManagedObjects(), which includes
all objects registered, their interfaces and the corresponding
properties per interface.
bluetooth: Support ObjectManager interface add/remove

Install matches for signals ObjectManager.InterfacesAdded and
ObjectManager.InterfacesRemoved, and process the devices that are
registered and unregistered dynamically.
bluetooth: Support Properties.PropertiesChanged signal

Install matches for signal Properties.PropertiesChanged and process the
properties corresponding to the tracked devices.
bluetooth: Add HFP 1.6 codec ID

According to the HFP 1.6 spec, the default codec (CVSD) has ID 0x01.

This change has no effect in older versions of BlueZ since the codec ID
was ignored for HFP, due to the fact that HFP versions prior to 1.6 do
not have such a field.