combine-sink: rework output add/remove

Add the output from its sink-input attached callback and remove it
again from the detach callback. This simplifies some output_enable
and we can also avoid posting 2 messages for the sink.
source, sink: Support weird sample rates

This fixes assertion failures that manifest themselves with cards that
support only weird rates such as 37286Hz. Tested with snd-pcsp.

Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=48109
rtp-recv: fix crash on empty UDP packets (CVE-2014-3970)

On FIONREAD returning 0 bytes, we cannot return success, as the caller
(rtpoll_work_cb in module-rtp-recv.c) would then try to
pa_memblock_unref(chunk.memblock) and, because memblock is NULL, trigger
an assertion.

Also we have to read out the possible empty packet from the socket, so
that the kernel doesn't tell us again and again about it.

Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
bluetooth: Add "valid" flag to pa_bluetooth_adapter

This is a cosmetic change. There are a couple of places where we check
whether the adapter object is valid, and while checking whether the
address property is set works just fine, I find it nicer to have a
dedicated flag for the object validity. This improves maintainability
too, because if there will ever be more adapter properties that affect
the adapter validity, the places that check if the adapter is valid
don't need to be updated.
bluetooth: Refactor device validity management

There are several intertwined changes that I couldn't separate into
nicer commits. This is mostly just refactoring, but this also fixes
a bug: the old code set the device valid in parse_device_properties()
even if the device's adapter was invalid (had NULL address).

To improve the clarity of the code, I split the device_info_valid
variable into two booleans: properties_received and valid.

I added function device_update_valid() that checks all conditions that
affect the device validity. The function can then be called from any
place where something changes that potentially affects the device
validity. However, currently the only validity-affecting thing that
can change is the device adapter, so device_update_valid() is only
called from set_device_adapter().

I added the aforementioned set_device_adapter() function so that
whenever the adapter is set, the device validity gets updated
automatically.

The new properties_received variable allowed me to remove the
is_property_update function parameters.
build-sys: don't build raop modules on win32 as they need librtp

librtp is very posix-y and cannot currently be built for Windows.
So avoid trying to build any modules that depend on it.
mainloop: avoid race-y double wakeup status

Having an extra variable that tracks the wakeup status introduces a
race where the variable is set but the data has yet to propagate from
the write end of the pipe to the read end. When this happens the
system goes into a tight loop as select() always returns immediately.
poll: don't use shared event in Windows pa_poll()

We call pa_poll concurrently from multiple threads, so we cannot
have an event object that is reused.
poll: don't let select() block on Windows

We cannot let select() block as we won't wake up on the other
things that MsgWaitForMultipleObjects() can monitor.
daemon: get rid of win32 message timer

We don't need a timer to check for Windows messages anymore
now that our fancy new poll() implementation does that for us.
rescue-streams: try to find best one using availability and priority

Recently met a problem: when I disconnect the bluetooth headset, the
pulseaudio automatically switch the sound to sink of HDMI output
instead of the sink of internal speaker even though there is no HDMI
cable connected.

To fix this problem, I want to change the rule of selecting the target
sink if the default sink is not available. (same rules apply to the
source selecting):
construct a new hashmap with all ports (of all relevant sinks) and
then call find_best on the new hashmap to find the best port, finally
find the corresponding sink using the best port.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
module-rescue-streams: Fixup previous patch w r t fallback sink/sources

 - Make sure "no evacuation sink/source found" is not printed when
   fallback source/sink is selected
 - Restore previous behaviour of fallback sink/source selected
   (first one instead of last one)

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
combine-sink: add support for DYNAMIC_LATENCY

Mark the sink as DYNAMIC_LATENCY and implement update_sink_latency_range
on its sink-input to collect the combined latency range of all sinks.

Implement update_requested_latency on the sink to configure the final
latency by combining the sink-input requested latencies. This makes us
honour the client latency request.

Also add more debug log.

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=47899
combine-sink: Make the latency range calculation easier to read

I think this is much easier to understand. This should not result in
any functional change.
combine-sink: Add a convenience variable
combine-sink: Fix the initial requested latency of new outputs

If the combine-sink is running with low latency, and a new output is
added, the new output was not configured with low latency.
combine-sink: Rearrange block_usec initialization

block_usec should be determined by the sink max latency, not the other
way around. This change doesn't cause any change in behaviour, but
makes the code more logical. Further updates to block_usec are already
done correctly, so this is the only place that needs modification.
client-conf: Don't report failure from pa_client_conf_load()

pa_context already ignored the return value of pa_client_conf_load(),
so the only places where the return value was not ignored were the
D-Bus server lookup thing and pax11publish. I don't think those cases
are negatively affected if they ignore errors in opening or parsing
client.conf.

pa_client_conf_env() never failed anyway, so returning int was
obviously redundant.
client-conf: Move x11 and env loading to pa_client_conf_load()

This simplifies the code a bit.
authkey: Remove pa_authkey_load(), it's redundant

The only place where pa_authkey_load() was called was in
pa_authkey_load_auto(), and the only functionality that
pa_authkey_load() was to log a warning if load() fails. That log
message is now in pa_authkey_load_auto(), so pa_authkey_load() has no
use any more.