platform/upstream/pulseaudio.git
7 years agosource/sink: Don't let pa_{sink, source}_get_latency_within_thread() return -1 if...
Georg Chini [Mon, 17 Apr 2017 17:48:37 +0000 (19:48 +0200)]
source/sink: Don't let pa_{sink, source}_get_latency_within_thread() return -1 if process_msg() fails

None of the callers checks the return value anyway. Return the offset only
if message processing fails. This is in preparation for the next patch.

7 years agoladspa-sink, virtual-surround-sink: fix master sink argument handling
Tanu Kaskinen [Fri, 14 Apr 2017 15:20:40 +0000 (18:20 +0300)]
ladspa-sink, virtual-surround-sink: fix master sink argument handling

The old code worked incorrectly in several situations. For example,
trying to use the "master" argument wouldn't work, because if
"sink_master" wasn't specified, pa_namereg_get() would pick the default
sink as the master sink.

7 years agosample.c: Allow module-loopback to exceed PA_RATE_MAX
Georg Chini [Fri, 14 Apr 2017 13:03:56 +0000 (15:03 +0200)]
sample.c: Allow module-loopback to exceed PA_RATE_MAX

The rate set by module loopback may exceed PA_RATE_MAX by 1%, therefore
allow rates higher than PA_RATE_MAX in pa_sample_rate_valid().

7 years agoloopback: Implement underrun protection
Georg Chini [Fri, 14 Apr 2017 13:02:36 +0000 (15:02 +0200)]
loopback: Implement underrun protection

The latency controller will try to adjust to the configured latency regardless
of underruns. If the configured latency is set too small, it will lead to
periodically occuring underruns. Therefore an underrun protection is implemented
which will increase the target latency if too many underruns are detected.
Underruns are tracked and if more than 3 underruns occur, the target latency
is increased in increments of 5 ms. One underrun per hour is accepted.
The protection ensures, that independent from the configured latency the
module will converge to a stable latency if the configured latency is too
small.

The print_msg argument to update_minimum_latency() had to be re-introduced,
because there is one place where the message should not be logged.

7 years agofilter-apply: Add ability to pass parameters to a filter module
KimjeongYeon [Thu, 13 Apr 2017 19:09:49 +0000 (21:09 +0200)]
filter-apply: Add ability to pass parameters to a filter module

Currently passing parameters to a filter loaded by module-filter-apply is
not possible.

To enable passing parameters to a filter this patch uses an additional property
filter.apply.{MODULE_NAME}.parameters. This way, filters like virtual-surround-sink
and ladspa-sink are fully supported. For example:
paplay file.wav --property=filter.apply=ladspa-sink \
                --property=filter.apply.ladspa-sink.parameters="plugin=ladspa \
                  label=ladspa_stereo control=0"

7 years agoladspa-sink: Add sink_master argument to enable filter-apply to load the module
KimjeongYeon [Thu, 13 Apr 2017 18:58:14 +0000 (20:58 +0200)]
ladspa-sink: Add sink_master argument to enable filter-apply to load the module

Currently, module-filter-apply cannot load module-ladspa-sink because filter-apply
provides the argument "sink_master" but ladspa-sink expects "master" instead.

Therefore this patch adds the sink_master argument to module-ladspa-sink.

Additionally, the autoloaded argument was also added.

7 years agovirtual-surround-sink: Add sink_master argument to enable filter-apply to load the...
KimjeongYeon [Thu, 13 Apr 2017 18:44:41 +0000 (20:44 +0200)]
virtual-surround-sink: Add sink_master argument to enable filter-apply to load the module

Currently, module-filter-apply cannot load module-virtual-surround-sink because filter-apply
provides the argument "sink_master" but virtual-surround-sink expects "master" instead.

Therefore this patch adds the sink_master argument to module-virtual-surround-sink.

Additionally, the autoloaded argument was also added.

7 years agofilter-apply: Fix memory leak in process()
KimjeongYeon [Thu, 13 Apr 2017 18:33:26 +0000 (20:33 +0200)]
filter-apply: Fix memory leak in process()

fltr->name should be freed before freeing fltr. Because filter_free()
can never be called from other places without f set, the pa_assert()
can be removed and filter_free() can be used in process() as well.

7 years agocontext: Check for errno == ECHILD instead of ESRCH after failed waitpid().
Imre Vadász [Sat, 8 Apr 2017 22:15:03 +0000 (00:15 +0200)]
context: Check for errno == ECHILD instead of ESRCH after failed waitpid().

When the specified pid no longer exists as a child of the process (since
it was already reaped by the SIGCHLD handler), errno is set to ECHILD, not
to ESRCH.

7 years agoloopback: Reset sink input rate when source or sink changes
Georg Chini [Tue, 11 Apr 2017 19:49:11 +0000 (21:49 +0200)]
loopback: Reset sink input rate when source or sink changes

If source or sink are changed, the current sink input rate may be different
from the default rate. Switch sink input rate back to default to avoid the
influence of the previous combination of source and sink.

7 years agosink-input: Allow sink_input_set_rate() to be called during a move
Georg Chini [Tue, 11 Apr 2017 19:48:31 +0000 (21:48 +0200)]
sink-input: Allow sink_input_set_rate() to be called during a move

During a move sink_input->sink is not valid. This leads to a crash when
sink_input_set_rate() is called from the moving() callback. This patch
fixes the problem.

7 years agoloopback: Add hooks to track port latency offsets
Georg Chini [Mon, 10 Apr 2017 19:47:23 +0000 (21:47 +0200)]
loopback: Add hooks to track port latency offsets

The previous patch assumed constant port latency offsets. The offsets can
however be changed by the user, therefore these changes need to be tracked
as well. This patch adds the necessary hooks.

Also the print_msg argument was removed from update_minimum_latency() and
update_latency_boundaries() because the message should always be logged.

7 years agoMerge branch 'master' of ssh://git.freedesktop.org/git/pulseaudio/pulseaudio
Georg Chini [Fri, 7 Apr 2017 06:20:43 +0000 (08:20 +0200)]
Merge branch 'master' of ssh://git.freedesktop.org/git/pulseaudio/pulseaudio

7 years agoloopback: Calculate and track minimum possible latency
Georg Chini [Fri, 7 Apr 2017 06:18:08 +0000 (08:18 +0200)]
loopback: Calculate and track minimum possible latency

With the current code, the user can request any end-to-end latency. Because there
is no protection against underruns, setting the latency too small will result in
repetitive underruns.

This patch tries to mitigate the problem by calculating the minimum possible latency
for the current combination of source and sink. The actual calculation has been put
in a separate function so it can easily be changed. To keep the values up to date,
changes in the latency ranges have to be tracked.

The calculated minimum latency is used to limit the configured latency.
The minimum latency is only a "best guess", so the actual minimum may be much
larger (for example for USB devices) or much smaller than the calculated value.

Changes of the port latency offsets are not yet handled, this will be done in a
separate patch.

7 years agomemblock: multiple references should make blocks read-only
Tanu Kaskinen [Wed, 8 Jun 2016 18:18:52 +0000 (21:18 +0300)]
memblock: multiple references should make blocks read-only

The old code makes no sense to me. Why would multiple references mean
that a previously read-only memblock is suddenly writable? I'm pretty
sure that the original intention was to treat multi-referenced blocks
as read-only. I don't have any examples where the old code would have
caused bad behaviour, however.

7 years agoprotocol-native: log who changes card profiles
Tanu Kaskinen [Tue, 4 Apr 2017 09:46:25 +0000 (12:46 +0300)]
protocol-native: log who changes card profiles

Some volume control applications, including gnome-control-center[1],
Budgie Volume Control[2] and possibly something in xfce4 too[3],
sometimes do unwanted card profile changes. This patch makes it possible
to see from the log which application requested a profile change, which
makes it easier to detect when an application misbehaves.

[1] https://bugzilla.gnome.org/show_bug.cgi?id=762932
[2] https://bugs.freedesktop.org/show_bug.cgi?id=93903#c41
[3] https://bugs.freedesktop.org/show_bug.cgi?id=93903#c40

7 years agopipe-sink: set correct latency
Tanu Kaskinen [Fri, 12 Aug 2016 22:12:31 +0000 (01:12 +0300)]
pipe-sink: set correct latency

The old pa_sink_set_fixed_latency() call didn't take into account that
other places use pa_frame_align() on the pa_pipe_buf() result, so the
configured latency could be sometimes slightly too high.

Adding a buffer_size variable in userdata makes it a bit easier to keep
all places that deal with the buffer size in sync.

7 years agothread-mainloop: fix volatile use in example
Tanu Kaskinen [Fri, 28 Oct 2016 16:00:26 +0000 (19:00 +0300)]
thread-mainloop: fix volatile use in example

In the example, drain_result is a volatile pointer to an int, not
a regular pointer to a volatile int.

7 years agoi18n: update the Swedish translation
Tanu Kaskinen [Sun, 2 Apr 2017 18:19:35 +0000 (21:19 +0300)]
i18n: update the Swedish translation

7 years agobluetooth: allow UTF-8 in device descriptions
Tanu Kaskinen [Tue, 11 Oct 2016 14:27:06 +0000 (17:27 +0300)]
bluetooth: allow UTF-8 in device descriptions

Users may configure the device alias to have characters outside the
ASCII range, so our name cleanup routine was too aggressive. Let's just
make sure that the device description is a valid UTF-8 string.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=98160
7 years agosink: Invert priorities to prefer external devices
Christian Kellner [Thu, 9 Mar 2017 14:51:49 +0000 (15:51 +0100)]
sink: Invert priorities to prefer external devices

Currently internal > speaker > headphone and pci > usb > bluetooth.
Invert both of these sets, with the reasoning that a headphone and
speakers are something that a user has actively attached and should
therefore get a higher priority. The same reasoning is applied for
the bus type, i.e. bluetooth and usb should be higher than pci,
because they most likely have been actively attached be a user.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99222
7 years agoloopback: Do not skip audio at startup
Georg Chini [Fri, 31 Mar 2017 05:50:12 +0000 (07:50 +0200)]
loopback: Do not skip audio at startup

The code is now waiting for source and sink to start up, so the skip
logic is not necessary anymore.

7 years agobluetooth: assert that dbus_message_iter_append_basic() doesn't fail
Tanu Kaskinen [Sat, 29 Oct 2016 18:06:53 +0000 (21:06 +0300)]
bluetooth: assert that dbus_message_iter_append_basic() doesn't fail

The function can only fail if there's not enough memory available, and
if that happens, the convention in PulseAudio is to abort.

CID: 1353106, 1353108, 1353140

7 years agoecho-cancel: Try to minimise in-flight chunks in snapshot latency
Arun Raghavan [Thu, 9 Mar 2017 04:28:23 +0000 (09:58 +0530)]
echo-cancel: Try to minimise in-flight chunks in snapshot latency

We don't always know whether the in-flight memory chunks will be
rendered or skipped (if the source is not in RUNNING). This can cause us
to have an erroneous estimate of drift, particularly when the canceller
starts.

To avoid this, we explicitly flush out the send and receive sides of the
message queue of audio chunks going from the sink to the source before
trying to perform a resync.

7 years agoloopback: Fix corking logic of module-loopback
Georg Chini [Wed, 29 Mar 2017 05:11:50 +0000 (07:11 +0200)]
loopback: Fix corking logic of module-loopback

When moving from a user suspended source or sink to an idle suspended source or sink
the sink input or source output would not be uncorked because we did not check for
the suspend cause.

Uncorking also would not be possible in that situation because the state change callback
of the source output or sink input is called before the new source or sink is attached,
leading to a crash of pulseaudio due to a cork() call without valid source or sink.

The previous patch fixes this problem, therefore sink input or source output can now also
be uncorked when the destination is idle suspended.

7 years agosink-input/source-output: Don't crash when cork() is called without valid sink or...
Georg Chini [Wed, 29 Mar 2017 05:10:28 +0000 (07:10 +0200)]
sink-input/source-output: Don't crash when cork() is called without valid sink or source

If pa_sink_input_cork() or pa_source_output_cork() were called without a sink
or source attached, the calls would crash pulseaudio.

This patch fixes the problem, so that a source output or sink input can still
be corked or uncorked while source or sink are invalid. This is needed to
correct the corking logic in module-loopback.

7 years agobluez5-util: fix profile waiting logic
Tanu Kaskinen [Thu, 16 Mar 2017 21:48:43 +0000 (23:48 +0200)]
bluez5-util: fix profile waiting logic

There were two bugs in the old logic. The first one:

If a device has two profiles, the old code would start the wait timer
when the first profile connects, but when the second profile connects,
the timer would not get stopped and the CONNECTION_CHANGED hook would
not get fired, because the code for that was inside an if block that
only gets executed when the first profile connects. As a result,
module-bluez5-device loading would always be delayed until the wait
timeout expires.

The second bug:

A crash was observed in device_start_waiting_for_profiles(). That
function is called whenever the connected profile count changes from 0
to 1. The function also has an assertion that checks that the timer is
not running when the function is called. That assertion crashed in the
following scenario with a headset that supports HSP and A2DP:

1. First HSP gets connected. The timer is started.

2. Then HSP gets disconnected for some reason. The timer is still
running.

3. Then A2DP gets connected. device_start_waiting_for_profiles() is
called, because the connected profile count changed from 0 to 1 again.
The timer is already running, so the assertion fails.

First I thought I'd remove the assertion from
device_start_waiting_for_profiles() and just restart the timer on the
second call, but then I figured that when the device returns to the
"everything disconnected" state in step 2, it would be better to stop
the timer. The purpose of the timer is to delay the notification of the
device becoming connected, but if the device becomes disconnected during
the waiting period, the notification doesn't make sense any more, and
therefore the timer doesn't make sense either.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=100237
7 years agoallow-passthrough: Fix indentation
Jungsup Lee [Mon, 27 Mar 2017 18:29:34 +0000 (20:29 +0200)]
allow-passthrough: Fix indentation

Signed-off-by: Jungsup Lee <jungsup4.lee@samsung.com>
7 years agoecho-cancel: Fix assert with webrtc's built-in drift compensation
Arun Raghavan [Mon, 13 Mar 2017 10:30:41 +0000 (16:00 +0530)]
echo-cancel: Fix assert with webrtc's built-in drift compensation

The webrtc canceller seems to have changed to require that the
set_stream_drift_samples() method be called before every call of
ProcessStream().

So we now call ec->set_stream_drift_samples() before calling
ec->record() by:

1. Always calling do_push_drift_comp() instead of only when the sink is
   running

2. Calling set_stream_drift_samples() in the loop with record() instead
   of outside

We do kind of leak this quirk of the webrtc canceller into the generic
bits of module-echo-cancel, but this should not be harmful in the
general case either.

7 years agobluetooth-policy: retain backwards compatibility
Tanu Kaskinen [Wed, 15 Mar 2017 18:02:48 +0000 (20:02 +0200)]
bluetooth-policy: retain backwards compatibility

The auto_switch argument was added in PulseAudio 10.0. In that release
the argument type was boolean. The type was changed to integer in commit
3397127f00. This patch adds backwards compatibility so that old
configuration files won't break when upgrading PulseAudio to 11.0.

7 years agobluez5-util: Disconnect AG devices when ofono is started and headset=auto
Georg Chini [Tue, 14 Mar 2017 06:32:31 +0000 (07:32 +0100)]
bluez5-util: Disconnect AG devices when ofono is started and headset=auto

With headset=auto it is possible that AG devices are connected and handled
via the native backend when ofono is started. Because the HS role will then
be disabled in the native backend, AG devices must be disconnected and any
future connections will be handled by ofono.

7 years agobluetooth: use native and ofono backends in parallel with headset=auto
Georg Chini [Sat, 11 Mar 2017 18:02:16 +0000 (19:02 +0100)]
bluetooth: use native and ofono backends in parallel with headset=auto

This patch changes the behavior of the headset=auto switch for module-bluez5-discover.
With headset=auto now both backends will be active at the same time for the AG role and
the switching between the backends is only done for the HS role.
headset=ofono and headset=native remain unchanged.

This allows to use old HSP only headsets while running ofono and to have headset support
via pulseaudio if ofono is started with the --noplugin=hfp_ag_bluez5 option.

7 years agopulse: Explicitly ignore pa_mainloop_run() return value in thread function
Peter Meerwald-Stadler [Tue, 7 Mar 2017 20:43:41 +0000 (21:43 +0100)]
pulse: Explicitly ignore pa_mainloop_run() return value in thread function

Coverity ID: #1137975

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agooss: Fix dead code
Peter Meerwald-Stadler [Tue, 7 Mar 2017 20:41:56 +0000 (21:41 +0100)]
oss: Fix dead code

mode cannot be 0
Coverity ID: #1137964

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agocore: Ignore pa_shared_remove() return value
Peter Meerwald-Stadler [Tue, 7 Mar 2017 15:09:56 +0000 (16:09 +0100)]
core: Ignore pa_shared_remove() return value

document behaviour of pa_shared_remove() in case name does not exist

Coverity ID: #1380672

thanks to Georg Chini for suggesting to swap patch title and commit message

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agocore: Assert return value of pa_shared_set/_remove() in dbus-shared
Peter Meerwald-Stadler [Tue, 7 Mar 2017 14:57:28 +0000 (15:57 +0100)]
core: Assert return value of pa_shared_set/_remove() in dbus-shared

it must succeed, or we are leaking memory

Coverity ID: #1380674, #1380673

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agodbus: fix card profile change signals
Tanu Kaskinen [Sat, 18 Feb 2017 16:40:42 +0000 (18:40 +0200)]
dbus: fix card profile change signals

The "profile->card != c->card" check always evaluated to false, so the
CardProfileUpdated signal was never sent. The reason: call_data was
assigned to a pa_card_profile pointer, but the correct type is a pa_card
pointer.

7 years agoudev-detect: don't use readdir_r(), it's deprecated
Tanu Kaskinen [Thu, 13 Oct 2016 14:22:44 +0000 (17:22 +0300)]
udev-detect: don't use readdir_r(), it's deprecated

readdir_r() was supposed to be a thread-safe version of readdir(), but
the interface turned out to be problematic. Due to the problems and the
fact that readdir() is safe enough on modern libc implementations, glibc
deprecated readdir_r() in version 2.24.

The man page contains more information about what's wrong with
readdir_r(): http://man7.org/linux/man-pages/man3/readdir_r.3.html

7 years agoecho-cancel: Limit the maximum sink/source latency
Arun Raghavan [Thu, 9 Mar 2017 05:32:09 +0000 (11:02 +0530)]
echo-cancel: Limit the maximum sink/source latency

On systems with constrained CPUs, we might run into a situation where
the master source/sink is configured to have too high a latency.

On the source side, this would cause us to wake up with a large chunk of
data to process, which might cause us to exhust our RT limit and thus be
killed.

So it makes sense to limit the overall latency that we request from the
source (and correspondingly, the sink, so we don't starve for playback
data on the source side).

The 10 blocks maximum is somewhat arbitrary (I'm assuming the system has
enough headroom to process 10 chunks through the canceller without
getting close to the RT limit). This might make sense to make tunable in
the future.

7 years agoalsa: Avoid creating tiny memchunks on write iterations
Arun Raghavan [Tue, 28 Feb 2017 05:15:25 +0000 (10:45 +0530)]
alsa: Avoid creating tiny memchunks on write iterations

If the ALSA device supports granular pointer reporting, we end up in a
situation where we write out a bunch of data, iterate, and then find a
small amount of data available in the buffer (consumed while we were
writing data into the available buffer space). We do this 10 times
before quitting the write loop.

This is inefficient in itself, but can also have wider consequences. For
example, with module-combine-sink, this will end up pushing the same
small chunks to all other devices too.

Given both of these, it just makes sense to not try to write out data
unless a minimum threshold is available. This could potentially be a
fragment, but it's likely most robust to just work with a fraction of
the total available buffer size.

7 years agoraop: Error out on parsing server port component
Peter Meerwald-Stadler [Wed, 8 Mar 2017 14:57:22 +0000 (15:57 +0100)]
raop: Error out on parsing server port component

don't ignore server port parsing errors as suggested by Hajime Fujita

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: Hajime Fujita <crisp.fujita@nifty.com>
7 years agoraop: Log if pa_atoi() fails, latency is not used anyway
Peter Meerwald-Stadler [Tue, 7 Mar 2017 14:44:06 +0000 (15:44 +0100)]
raop: Log if pa_atoi() fails, latency is not used anyway

Coverity ID: #1398152

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Fix potential NULL dereference
Peter Meerwald-Stadler [Tue, 7 Mar 2017 14:16:54 +0000 (15:16 +0100)]
raop: Fix potential NULL dereference

wath may be NULL, as suggested by Hajime Fujita
Coverity ID: #1398156

setting val = NULL is not needed

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: Hajime Fujita <crisp.fujita@nifty.com>
7 years agoraop: Fix potential dereference after NULL check
Peter Meerwald-Stadler [Tue, 7 Mar 2017 13:43:48 +0000 (14:43 +0100)]
raop: Fix potential dereference after NULL check

Coverity ID: #1398157

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agocombine-sink: Use PA_MAX instead of ternary operator for clarity
Arun Raghavan [Thu, 9 Mar 2017 04:33:06 +0000 (10:03 +0530)]
combine-sink: Use PA_MAX instead of ternary operator for clarity

7 years agoraop: Fix check for invalid file descriptor
Peter Meerwald-Stadler [Tue, 7 Mar 2017 13:29:12 +0000 (14:29 +0100)]
raop: Fix check for invalid file descriptor

file descriptor 0 is valid

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agocore-util: Fix description of pa_split()
Peter Meerwald-Stadler [Tue, 7 Mar 2017 13:53:13 +0000 (14:53 +0100)]
core-util: Fix description of pa_split()

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agobuild: Use #ifdef to check for #defines
Peter Meerwald-Stadler [Tue, 7 Mar 2017 15:29:30 +0000 (16:29 +0100)]
build: Use #ifdef to check for #defines

for example, in case HAVE_MEMFD is #undef, checking with #if HAVE_MEMFD
gives a warning (gcc 5.4.1, Ubuntu)

pulsecore/shm.c: In function 'sharedmem_create':
pulsecore/shm.c:208:5: warning: "HAVE_MEMFD" is not defined [-Wundef]
 #if HAVE_MEMFD

use #ifdef or #if defined() to check for presence of a #define

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agowaveout: add argument deprecation error
Moritz Bruder [Wed, 1 Mar 2017 18:29:53 +0000 (19:29 +0100)]
waveout: add argument deprecation error

7 years agowaveout: fix wrong input device
Moritz Bruder [Wed, 1 Mar 2017 18:29:52 +0000 (19:29 +0100)]
waveout: fix wrong input device

Both input and output device were chosen with the same device number.
This is problematic as those numbers don't have to correspond.
Additionally the input device was named after the output device. This
commit adresses both issues by providing specific parameters for each
type.

7 years agobackend-native: add support for the HSP Headset role
Wim Taymans [Tue, 7 Mar 2017 12:44:54 +0000 (13:44 +0100)]
backend-native: add support for the HSP Headset role

This is a rebase of Wim Taymans patch to support the HSP headset role that has
somehow been forgotten. Original patch can be found at
https://lists.freedesktop.org/archives/pulseaudio-discuss/2015-February/023242.html
Rebase and minor changes by Georg Chini.

In addition to the HSP Audio Gateway, also add support for the headset
role in the native bluetooth backend. In this role, pulseaudio is used as
headset.

In the headset role, we create source and sink to receive and send the samples
from the gateway, respectively. Module-bluetooth-policy will automatically load
loopback modules to link these to a sink and source for playback. Because this
makes the source the speaker and the sink the microphone, we need to reverse the
roles of source and sink compared to the gateway role.

In the gateway role, adjusting the sink volume generates a +VGS command to set
the volume on the headset. Likewise, receiving AT+VGS updates the sink volume.

In the headset role, receiving a +VGS should set the source volume and any
source volume changes should be reported back to the gateway with AT+VGS.

7 years agoiochannel: don't use variable length array in union
Tanu Kaskinen [Sat, 4 Feb 2017 12:19:01 +0000 (14:19 +0200)]
iochannel: don't use variable length array in union

Clang didn't like the variable length array:

pulsecore/iochannel.c:358:17: error: fields must have a constant size:
'variable length array in structure' extension will never be supported
        uint8_t data[CMSG_SPACE(sizeof(int) * nfd)];
                ^

Commit 451d1d6762 introduced the variable length array in order to have
the correct value in msg_controllen. This patch reverts that commit and
uses a different way to achieve the same goal.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=99458
7 years agoraop: Fix potential NULL dereference
Peter Meerwald-Stadler [Wed, 1 Mar 2017 19:37:06 +0000 (20:37 +0100)]
raop: Fix potential NULL dereference

'realm' is mandatory

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Fix potential resource leaks
Peter Meerwald-Stadler [Tue, 28 Feb 2017 07:01:20 +0000 (08:01 +0100)]
raop: Fix potential resource leaks

Coverity ID: #1410204, #1410203, #1410202, #1410201, #1410200, #1410199

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Silence unchecked return value warnings
Peter Meerwald-Stadler [Mon, 27 Feb 2017 22:43:49 +0000 (23:43 +0100)]
raop: Silence unchecked return value warnings

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Fix indentation
Peter Meerwald-Stadler [Mon, 27 Feb 2017 22:39:38 +0000 (23:39 +0100)]
raop: Fix indentation

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Fix potential memory leak
Peter Meerwald-Stadler [Mon, 27 Feb 2017 22:23:04 +0000 (23:23 +0100)]
raop: Fix potential memory leak

Coverity ID: #1410204

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Fix resource leaks
Peter Meerwald-Stadler [Wed, 22 Feb 2017 14:21:00 +0000 (15:21 +0100)]
raop: Fix resource leaks

Coverity ID: #1398158, #1398159

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Fix memleak
Peter Meerwald-Stadler [Wed, 22 Feb 2017 14:09:02 +0000 (15:09 +0100)]
raop: Fix memleak

use local scope for trs variable simplifying cleanup
Coverity ID: #1398160

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Fail after search for port number
Peter Meerwald-Stadler [Tue, 7 Mar 2017 07:22:25 +0000 (08:22 +0100)]
raop: Fail after search for port number

should also fail if port is 0 after the loop, as suggested by Georg Chini

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Fix loop searching for port number
Peter Meerwald-Stadler [Wed, 22 Feb 2017 14:02:43 +0000 (15:02 +0100)]
raop: Fix loop searching for port number

do...while not reachable, loop should try different ports in case EADDRINUSE is returned
Coverity ID: #1398161

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoraop: Fix double free
Peter Meerwald-Stadler [Wed, 22 Feb 2017 13:49:48 +0000 (14:49 +0100)]
raop: Fix double free

make nick variable local, fix double free
Coverity CID: #1398162

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agobuild: Add Coverity scan model
Peter Meerwald-Stadler [Mon, 6 Mar 2017 07:15:29 +0000 (08:15 +0100)]
build: Add Coverity scan model

the modeling file help to avoid false positives and increase scanning
accuracy by explaining code Coverity can't see (out of tree libraries);
the model file must be uploaded by an admin to:
https://scan.coverity.com/projects/pulseaudio?tab=analysis_settings

the pa_assert_se() macro needs to be rewritten for Coverity so that
the assignment is not declared a side-effect

Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
7 years agoloopback: fix up the previous commit
Georg Chini [Mon, 27 Feb 2017 12:54:50 +0000 (13:54 +0100)]
loopback: fix up the previous commit

The previous commit, "loopback: Initialize latency at startup and during
source/sink changes", was an old version of the patch that got
accidentally pushed instead of the last version. This commit does the
changes that were omitted when applying the old patch.

7 years agoloopback: Initialize latency at startup and during source/sink changes
Georg Chini [Sun, 19 Feb 2017 16:15:10 +0000 (17:15 +0100)]
loopback: Initialize latency at startup and during source/sink changes

The current code does not make any attempt to initialize the end-to-end latency
to a value near the desired latency. This leads to underruns at startup because
the memblockq is initially empty and to very long adjustment times for long
latencies because the end-to-end latency at startup is significantly shorter
than the desired value.
This patch initializes the memblockq at startup and during source or sink changes
so that the end-to-end latency will be near the configured value. It also ensures
that there are no underruns if the source is slow to start and that the latency
does not grow too much when the sink is slow to start by adjusting the length of
the memblockq until the source has called push for the first time and the sink
has called pop for the second time. Waiting for the second pop is necessary
because the sink has not been started when the first pop is called.
For clarity, variables have been separated into input, output and main thread
variables.

7 years agocoreaudio-device: fix improper memory handling leading to crashes.
Mihai Moldovan [Sat, 25 Feb 2017 09:38:24 +0000 (10:38 +0100)]
coreaudio-device: fix improper memory handling leading to crashes.

Make sure that we NULL pointers after freeing them. Otherwise bad things
happen.

7 years agobuild-sys: FlatCarbon is dead. Good riddance.
Mihai Moldovan [Sat, 25 Feb 2017 09:35:06 +0000 (10:35 +0100)]
build-sys: FlatCarbon is dead. Good riddance.

FlatCarbon was the flattened Carbon version used in Mac OS Classic
(i.e., pre Mac OS X.)

It was shipped as legacy software until 10.8, then dropped completely.

Using CoreServices is good enough, manually including FlatCarbon headers
only lead to build failures for users who had old versions of Xcode
lingering around their machines.

v2: don't accidentally drop the OS X semaphore implementation.

7 years agoloopback: correct comments about the thread calling a function
Georg Chini [Sun, 19 Feb 2017 16:15:09 +0000 (17:15 +0100)]
loopback: correct comments about the thread calling a function

The comments were wrong and confusing.

7 years agoloopback: Rename sink_input_buffer to loopback_memblockq_length
Georg Chini [Mon, 13 Feb 2017 12:01:58 +0000 (13:01 +0100)]
loopback: Rename sink_input_buffer to loopback_memblockq_length

The variable does no longer represent the length of the whole sink input buffer,
therefore it has been renamed.

7 years agobluez5-device: Use correct constants for fixed latency in PA_{SINK, SOURCE}_MESSAGE_G...
Georg Chini [Wed, 15 Feb 2017 10:32:26 +0000 (11:32 +0100)]
bluez5-device: Use correct constants for fixed latency in PA_{SINK, SOURCE}_MESSAGE_GET_LATENCY

The PA_{SINK,SOURCE}_GET_LATENCY message handlers falsely always added the A2DP latency as fixed
latency instead of the profile specific constant.

7 years agobluetooth: Make use of getsockopt() to determine MTU configurable
Georg Chini [Sat, 4 Feb 2017 19:32:15 +0000 (20:32 +0100)]
bluetooth: Make use of getsockopt() to determine MTU configurable

A recent patch changed the MTU size from the default value of 48 to the value
returned by getsockopt(). This breaks HSP for some setups. To circumvent the
problem, this patch introduces a boolean parameter "autodetect_mtu" for
module-bluetooth-discover, module-bluez5-discover and module-bluez5-device to
make this use of getsockopt() configurable.

7 years agoalsa-util: don't crash on devices with more than 32 channels
Tanu Kaskinen [Sat, 28 Jan 2017 16:08:24 +0000 (18:08 +0200)]
alsa-util: don't crash on devices with more than 32 channels

The pa_channel_map_init_extend() call later in the function crashes if
if ss->channels is greater than PA_CHANNELS_MAX.

Reported here:
https://lists.freedesktop.org/archives/pulseaudio-discuss/2017-January/027404.html

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
7 years agosink, source: Make rate selection more explicit
Arun Raghavan [Mon, 30 Jan 2017 08:37:37 +0000 (14:07 +0530)]
sink, source: Make rate selection more explicit

This serves to explicitly document the various cases we deal with in
pa_sink_update_rate()/pa_source_update_rate() rather than have some of
them hidden behind the initialisation of desired_rate.

7 years agosink, source: Add a mode to avoid resampling if possible
Arun Raghavan [Sat, 28 Jan 2017 07:49:08 +0000 (13:19 +0530)]
sink, source: Add a mode to avoid resampling if possible

This adds an "avoid-resampling" option to daemon.conf that makes the
daemon try to use the stream sample rate if possible (the device needs
to support it, which currently only ALSA does), and there should not be
any other stream connected).

This should enable some of the "audiophile" use-cases where users wish
to play high sample rate audio files without resampling.

We still will do conversion if sample formats don't match, though. This
means that if you want to play 96 kHz/24 bit audio without any
modification the default format will need to be set to be 24-bit as
well. This will force all streams to be upconverted, which, other than
the wasted resources, should be relatively harmless.

7 years agothread-test: fix deadlock
Tanu Kaskinen [Mon, 23 Jan 2017 08:38:59 +0000 (10:38 +0200)]
thread-test: fix deadlock

If we set magic_number to zero, the code will deadlock, because the
thread that is waiting for us to set magic_number to non-zero will
never progress.

The problem was reported here:
https://lists.freedesktop.org/archives/pulseaudio-discuss/2017-January/027368.html

7 years agobuild-sys: Enable clang-based builds on Travis
Arun Raghavan [Tue, 24 Jan 2017 11:47:59 +0000 (17:17 +0530)]
build-sys: Enable clang-based builds on Travis

7 years agosuspend-on-idle: resume on unload
Wim Taymans [Wed, 11 Jan 2017 11:50:13 +0000 (12:50 +0100)]
suspend-on-idle: resume on unload

We need to resume all sinks we know about when unloading the module or
else they will stay suspended forever.

7 years agoraop: Fix #37: OOB access in rtsp_auth_cb
ced2c [Sun, 6 Nov 2016 18:54:27 +0000 (12:54 -0600)]
raop: Fix #37: OOB access in rtsp_auth_cb

Allocation for Apple-Challenge key is now defined to 16 bytes
(instead of 16 bits)

This patch fixes Issue #37
https://github.com/hfujita/pulseaudio-raop2/issues/37

7 years agoraop: Fix #36: invalid access to freed object
ced2c [Sun, 6 Nov 2016 18:54:26 +0000 (12:54 -0600)]
raop: Fix #36: invalid access to freed object

The RTSP client is not waiting anymore a new header after the
previous one (which can never occurs if RAOP is disconnected)
but after sending a command.

This patch fixes Issue #36.
https://github.com/hfujita/pulseaudio-raop2/issues/36

7 years agoraop: Fix memory leaks
Hajime Fujita [Sun, 6 Nov 2016 18:54:25 +0000 (12:54 -0600)]
raop: Fix memory leaks

This patch fixes several memory leaks, and thereby fixes Issue #35.
(https://github.com/hfujita/pulseaudio-raop2/issues/35)

7 years agoraop: Discard data upon getting EAGAIN on a socket
Hajime Fujita [Sun, 6 Nov 2016 18:54:24 +0000 (12:54 -0600)]
raop: Discard data upon getting EAGAIN on a socket

This patch discards audio data when a socket returns EAGAIN.
This was made based on a suggestion by karlstav
(https://github.com/karlstav), and is supposed to solve Issue #32.
(https://github.com/hfujita/pulseaudio-raop2/issues/32)

7 years agoraop: Disable is_recording flag when tearing down the connection
Hajime Fujita [Sun, 6 Nov 2016 18:54:23 +0000 (12:54 -0600)]
raop: Disable is_recording flag when tearing down the connection

This patch is based on a similar idea as the previous one -- disabling
the flag right after the session is getting closed, rather than waiting
for a response from the server.

7 years agoraop: Stop recording when RTSP FLUSH is issued
Hajime Fujita [Sun, 6 Nov 2016 18:54:22 +0000 (12:54 -0600)]
raop: Stop recording when RTSP FLUSH is issued

This patch fixes the issue #31.
https://github.com/hfujita/pulseaudio-raop2/issues/31

This patch sets c->is_recording = false when the RTSP FLUSH command
is issued. This avoids a race between the server response and
the record activation in some cases.

7 years agoraop: Add back initial volume RTSP SET_PARAMETER request on connect
Martin Blanchard [Sun, 6 Nov 2016 18:54:21 +0000 (12:54 -0600)]
raop: Add back initial volume RTSP SET_PARAMETER request on connect

Regression introduced in commit 8c6407f:
raop: Merge TCP and UDP code paths + refactoring

Anyway, we need to determine if initial volume has to be setup before
sending RECORD or after:

- Setting it up *before* shouldn't be a problem: sink.c waits for
CONNECT state, set the volume and client.c triggers RECORD only once
he's got the SET_PARAMETER reply from server.

- Setting it up *after* seems to be more difficult if we try not to
send any audio before receiving the SET_PARAMETER reply form server. A
solution may be to send SET_PARAMETER just after the RECORD server
response is received and hope that it get processed by server during the
2sec latency/buffering time...

Attached patch implement that last solution. Works for me, but I cannot
guaranty it will with your hardware...

7 years agoraop: Silently drop out-of-history retransmission request
Hajime Fujita [Sun, 6 Nov 2016 18:54:20 +0000 (12:54 -0600)]
raop: Silently drop out-of-history retransmission request

7 years agoraop: Correctly wrap RTP packet sequence number
Martin Blanchard [Sun, 6 Nov 2016 18:54:19 +0000 (12:54 -0600)]
raop: Correctly wrap RTP packet sequence number

7 years agoraop: Add IPv6 support
Hajime Fujita [Sun, 6 Nov 2016 18:54:18 +0000 (12:54 -0600)]
raop: Add IPv6 support

7 years agoraop: Add address to RAOP device description
Hajime Fujita [Sun, 6 Nov 2016 18:54:17 +0000 (12:54 -0600)]
raop: Add address to RAOP device description

Some time one device announces multiple addresses (e.g. IPv4 one
and IPv6 one). Or some user may own multiple RAOP devices with
the same model name.
This patch adds device port to device description so that users
can distinguish appropriate RAOP sink by its address.

7 years agoraop: Do not flush when RTSP object is not ready
Stephen Paul Weber [Sun, 6 Nov 2016 18:54:16 +0000 (12:54 -0600)]
raop: Do not flush when RTSP object is not ready

This patch fixes a crash issue reported at
https://github.com/hfujita/pulseaudio-raop2/issues/9

7 years agoraop: Fix packet retransmission
Colin Leroy [Sun, 6 Nov 2016 18:54:15 +0000 (12:54 -0600)]
raop: Fix packet retransmission

Fix UDP header decoding (sequence number and number of packets);
Fix missing pa_memblock_release() causing assertions after retransmission.

7 years agoraop: fix typos
Colin Leroy [Sun, 6 Nov 2016 18:54:14 +0000 (12:54 -0600)]
raop: fix typos

7 years agoraop: fix sequence number overflow
Colin Leroy [Sun, 6 Nov 2016 18:54:13 +0000 (12:54 -0600)]
raop: fix sequence number overflow

Wrap sequence number when we reach uint16_t's max 0xFFFF.

7 years agoraop: Fix sink getting destroyed after one use
Colin Leroy [Sun, 6 Nov 2016 18:54:12 +0000 (12:54 -0600)]
raop: Fix sink getting destroyed after one use

It is expected to get disconnected after switching back to a
different sink.

7 years agoraop: Remove unimplemented code (PCM and AAC)
Martin Blanchard [Sun, 6 Nov 2016 18:54:11 +0000 (12:54 -0600)]
raop: Remove unimplemented code (PCM and AAC)

7 years agoraop: Rework packet's store memory management
Martin Blanchard [Sun, 6 Nov 2016 18:54:10 +0000 (12:54 -0600)]
raop: Rework packet's store memory management

This patch switch the packet-buffer to use core memory pool instead of
manually allocating the room required for storing TCP/UDP packets. Packets
are now stored using pa_memchunk instead of internal struct. Quite a few
malloc saved compare to previous design.

7 years agoraop: Update and standardise source file headers
Martin Blanchard [Sun, 6 Nov 2016 18:54:09 +0000 (12:54 -0600)]
raop: Update and standardise source file headers

7 years agoraop: Prefer ALAC encoding to raw PCM if supported by server
Martin Blanchard [Sun, 6 Nov 2016 18:54:08 +0000 (12:54 -0600)]
raop: Prefer ALAC encoding to raw PCM if supported by server

ALAC encoding is to be prefered simply because ALAC audio packet reverse-
engineering and implementation is in better shape than raw PCM. Sending ALAC
audio does not mean compressing audio and thus linking an external library to
do so. ALAC packets has the ability to carry uncompressed PCM frames, and
that's what is implemented at the time.

7 years agoraop: Merge TCP and UDP code paths + refactoring
Martin Blanchard [Sun, 6 Nov 2016 18:54:07 +0000 (12:54 -0600)]
raop: Merge TCP and UDP code paths + refactoring

TCP and UDP implementation are following two diffrent code path while code
logic is quite the same. This patch merges both code path into a unique one
and, thus, leads to a big refactoring. Major changes include:
  - moving sink implementation to a separate file (raop-sink.c)
  - move raop-sink.c protocol specific code to raop-client.c
  - modernise RTSP session handling in TCP mode
  - reduce code duplications between TCP and UDP modes
  - introduce authentication support
  - TCP mode does not constantly send silent audio anymore

About authentication: OPTIONS is now issued when the sink is preliminary
loaded. Client authentication appends at that time and credential is kept
for the whole sink lifetime. Later RTSP connection will thus look like this:
ANNOUNCE > 200 OK > SETUP > 200 OK > RECORD > 200 OK (no more OPTIONS). This
behaviour is similar to iTunes one.

Also this patch includes file name changes to match Pulseaudio naming
rules, as most of pulseaudio source code files seem to be using '-'
instead of '_' as a word separator.

7 years agoraop: Add BA (Basic) and DA (Digest) HTTP authentication helpers
Martin Blanchard [Sun, 6 Nov 2016 18:54:06 +0000 (12:54 -0600)]
raop: Add BA (Basic) and DA (Digest) HTTP authentication helpers

RAOP authentication is using standard HTTP challenge-response authentication
scheme. This patch adds two helper functions that generate the proper hash
(for both techniques) given a username, a password and session related tokens.

7 years agoraop: Add a MD5 hashing fuction
Martin Blanchard [Sun, 6 Nov 2016 18:54:05 +0000 (12:54 -0600)]
raop: Add a MD5 hashing fuction

MD5 hashing will be needed during the authentication process.

Original patch by Martin Blanchard. Patch splitted by
Hajime Fujita <crisp.fujita@nifty.com>.