Commit graph

2073 commits

Author SHA1 Message Date
Tanu Kaskinen
dd7cf7ad5e Call change_cb() only when there's an actual change.
Calling change_cb() whenever anything happens in the ownership of the
bus name caused trouble in PulseAudio in this scenario:

1. PulseAudio is using a device and owns the corresponding service
   name.
2. Another application requests device release.
3. PulseAudio releases the device.
4. Change in the bus name ownership: PulseAudio gives up the
   ownership, and nobody owns the name.
5. reserve-monitor notices that, and notifies PulseAudio.
6. Since reserve-monitor reports the device as "not busy", PulseAudio
   decides to reserve the bus name immediately back to itself and
   opens the device again.

The other application will forcibly take the bus name to itself, as
it should according to the protocol, but the other application may
have trouble opening the device if it tries to do that before
PulseAudio has had time to react to the NameLost signal.

This can be solved by not calling change_cb() if there are no changes
in the device busy status. In this scenario the device is considered
"not busy" while PulseAudio is owning the bus name, so PulseAudio gets
no notification when the ownership changes from PulseAudio to nobody.
2013-01-17 11:12:44 +01:00
Tanu Kaskinen
b1e47df72c bluetooth: Convert booleans to stdbool. 2013-01-11 22:11:04 +02:00
Mikel Astiz
a0cc0136ea bluetooth: Simplify redundant error check
As pointed out by Tanu, checking both error conditions is redundant and
raises the question whether it's possible that one of the conditions is
true while the other is false.

Therefore, simplify the condition by just checking one part of the
disjunction.
2013-01-11 21:54:05 +02:00
Mikel Astiz
241059de70 bluetooth: Remove device_is_audio_ready()
The function was used to check whether the basic properties of the
Bluetooth device have been received. This can be simplified by just
checking d->device_info_valid, since the state of the audio interface
is only relevant inside pa_bluetooth_device_any_audio_connected(), which
is used to trigger the discovery callback.

While checking device_info_valid, special care must be taken with all
three possible values: when set to -1, it means some error was triggered
while getting the device properties. Therefore, these devices can also
be ignored outside bluetooth-util.

Besides that, the patch slightly modifies the behavior of the internal
API affecting pa_bluetooth_discovery_get_by_address() and
pa_bluetooth_discovery_get_by_path(), since they will return the device
no matter the state of the audio interface. This however makes sense and
should have no influence in the current codebase given that the modules
make use of devices only after the discovery hook has been triggered.
2013-01-11 21:51:10 +02:00
Mikel Astiz
8eb3d14b13 bluetooth: Do not check profile states is device_audio_is_ready()
The function is used to make sure some basic information has already
been gathered before the device is being used. At this point profile
states can be ignored, since their initial value will be
PA_BT_AUDIO_STATE_INVALID and thus effectively similar to
PA_BT_AUDIO_STATE_DISCONNECTED due to audio_state_to_transport_state().

The change should make no difference given that the behavior of
pa_bluetooth_device_any_audio_connected() doesn't change: by the time
TRUE is returned, a transport needs to exist. This means a profile
will exist in CONNECTING or CONNECTED state and thus the old
implementation of device_audio_is_ready() would also have returned TRUE.
2013-01-11 21:47:57 +02:00
Mikel Astiz
93e19c884b bluetooth: Use stdbool for pa_bool_t
Use lowercase true/false instead of TRUE/FALSE for pa_bool_t.
2013-01-11 21:44:36 +02:00
Mikel Astiz
4e93d8711b bluetooth: Check message signature for SetConfiguration
Make sure inside endpoint_set_configuration() that the received D-Bus
message matches the expected signature.
2013-01-11 21:39:22 +02:00
Mikel Astiz
e2bee0e27b bluetooth: Fix minor style issues
Trivially fix some style issues affecting line wrap (128 chars max with
the exception of multi-line comments, which are limited to 80),
indentation and unnecessary parentheses.
2013-01-11 21:35:09 +02:00
Mikel Astiz
1c8fe4ad2f bluetooth: Fix incorrect error messages
err.message doesn't contain anything useful in these error cases so
fix the mistake and avoid misleading messages.
2013-01-11 21:29:51 +02:00
Peter Meerwald
00b5a0eb9f echo-cancel: Fix error cleanup of pa_speex_ec_init()
Signed-off-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2013-01-11 21:24:24 +02:00
Tanu Kaskinen
c3207d4080 solaris: When suspending, flush the device instead of draining it.
Patch by Brian Cameron <brian.cameron@oracle.com>.
2013-01-04 17:13:32 +02:00
Tanu Kaskinen
e530feb62c solaris: Fix get_playback_buffered_bytes() return value.
Based on a patch by Brian Cameron <brian.cameron@oracle.com>.
2013-01-04 16:49:52 +02:00
Peter Nelson
c1f3634729 jackdbus-detect: Add channel count override.
Allow configuration of number of channels when using module-jackdbus-detect
to load jack-sink and jack-source. This is useful when the default channel
count doesn't match the logical channel count desired, e.g. with multi-
channel audio interfaces.

Signed-off-by: Peter Nelson <peter@fuzzle.org>
2012-12-30 11:54:34 +02:00
Tanu Kaskinen
baa62fb615 bluetooth: Remove pa_bluetooth_discovery_sync().
pa_bluetooth_discovery_sync() waited until all pending method calls
had completed. I don't understand what the benefit of that could be,
so I removed the function. We should avoid blocking as much as
possible, and the code that used pa_bluetooth_discovery_sync() didn't
look like it really needed to wait for anything.
2012-12-20 13:01:00 +02:00
Stefan Huber
de73a3ed98 echo-cancel: Extend null implementation to arbitary sample specs
The new null implementation works with arbitrary sample specs for source
and sink. In particular, it handles a different number of channels for
source and sink.

Signed-off-by: Stefan Huber <s.huber@bct-electronic.com>
Acked-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2012-12-20 12:58:45 +02:00
Stefan Huber
3a92be3c5c echo-cancel: Enable different blocksizes for sink and source
In order to support different blocksizes for source and sink (e.g, for
4-to-1 beamforming/echo canceling which involves 4 record channels and 1
playback channel) the AEC API is altered:

The blocksize for source and sink may differ (due to different sample
specs) but the number of frames that are processed in one invokation of
the AEC implementation's run() function is the same for the playback and
the record stream. Consequently, the AEC implementation's init()
function initalizes 'nframes' instead of 'blocksize' and the source's
and sink's blocksizes are derived from 'nframes'. The old API also
caused code duplication in each AEC implementation's init function for
the compution of the blocksize, which is eliminated by the new API.

Signed-off-by: Stefan Huber <s.huber@bct-electronic.com>
Acked-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2012-12-20 12:56:01 +02:00
Stefan Huber
84e4584322 echo-cancel: Fix calc_diff for asymmetric sample specs
In case that source and sink use different sample specs (e.g., different
number of channels) the computation of the latency difference fails.
To fix this, we obtain the corresponding latencies in terms of time using
the respective sample specs instead of buffer sizes.

Signed-off-by: Stefan Huber <s.huber@bct-electronic.com>
Acked-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2012-12-20 10:24:43 +02:00
Stefan Huber
fc9ad93bb4 echo-cancel: Fix missing setup of sink_ss in echo-cancel-test.
In main() of echo-cancel-test it is wrongly assumed that the EC
implementation's init() function properly initializes sink_ss. In
contrast, pa__init() sets sink_ss by default to
sink_master->sample_spec. Fix this by setting sink_ss to default
parameters and let EC implementation's init() override these settings.

Signed-off-by: Stefan Huber <s.huber@bct-electronic.com>
Acked-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2012-12-20 10:16:13 +02:00
Stefan Huber
a99e31fb6b echo-cancel: Fix echo-cancel-test's argument number checking
Argument argv[5] is accessed when argc>4, which leads to an invalid
access for argc==5. Fix this.

Signed-off-by: Stefan Huber <s.huber@bct-electronic.com>
Acked-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2012-12-20 10:13:56 +02:00
Tanu Kaskinen
af0c45386f bluetooth: Don't access a transport after it's freed.
In addition to moving the freeing a bit later, unnecessary checks for
t->device are removed. t->device is initialized to a non-NULL value
when the transport is created, and it's never changed.
2012-12-19 12:31:50 +02:00
Tanu Kaskinen
da5a02e97d device-restore: Fix empty argument list declaration. 2012-12-19 12:31:50 +02:00
Ștefan Săftescu
fb293db68d virtual-sink: Removed the option to specify sample format.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=46529
2012-12-19 12:31:50 +02:00
Tanu Kaskinen
46eb6f11e2 oss: Check pa_read() return value. 2012-12-19 12:31:50 +02:00
Tanu Kaskinen
9f832ca565 bluetooth: Don't free read_smoother in pa__done().
pa__done() calls stop_thread(), and stop_thread() already
frees the smoother. The duplicate freeing is not strictly
a bug, but static analyzers (in this case Coverity) may
complain about double-freeing, because when pa__done()
"frees" the smoother (which doesn't actually ever happen),
the pointer is not nulled. pa__done() then calls
bt_transport_release(), which will also free the smoother
if it's not NULL.

The analyzer complaint could be silenced also by nulling
the pointer in pa__done(), but since this is clearly
redundant code, I chose to remove it.
2012-12-19 12:31:49 +02:00
Tanu Kaskinen
7b8681de07 bluetooth: Make pa_bt_audio_state_from_string() private. 2012-12-19 12:31:49 +02:00
Tanu Kaskinen
51c88fb8b9 bluetooth: Improve transport state change log message. 2012-12-19 12:31:49 +02:00
Mikel Astiz
e6139c8d37 bluetooth: Replace acquire param 'start' with 'optional'
Make the internal function bt_transport_acquire() consistent with the
API in bluetooth-util by replacing the old 'start' parameter with
exactly the opposite: 'optional'.

Therefore, all calls to the function need to negate the second
parameter.

Note also that the name is more accurate now that setup_stream() is not
called inside bt_transport_acquire().
2012-12-19 12:31:49 +02:00
Mikel Astiz
04d60ae2a0 bluetooth: Call setup_stream() manually
Do not call setup_stream() automatically inside bt_transport_acquire().
Instead, the caller is responsible to use both functions as necessary.

As a first trivial step, setup_stream() is now called manually after
all calls to bt_transport_acquire(u, TRUE), with the exception of
setup_transport() where the thread is still about to start and thus
setup_stream() will be called later on from thread_func().
2012-12-19 12:31:49 +02:00
Mikel Astiz
0fc6aa5034 bluetooth: Remove D-Bus dependency in module-bluetooth-device
All D-Bus infrastructure is now unused after bluetooth-util has covered
the pieces that were pending. Therefore, all D-Bus related code in
module-bluetooth-device can be safely removed.
2012-12-19 12:31:49 +02:00
Mikel Astiz
d2bd3aa444 bluetooth: Use transport state instead of profile states
The transport state also reflects the state of the audio interface. The
state redundancy can thus be minimized by always using the first one,
and avoiding the use of profile-specific states with the exception of
finding out the initial state of a transport.
2012-12-19 12:31:49 +02:00
Mikel Astiz
468c67bb62 bluetooth: Refactor dependency to org.bluez.Audio
The state of this interface is needed for one single reason: we need to
wait until all profiles have been connected (or more precisely, until
are connection attempts are finished). This can be made more explicit in
the code by just checking the CONNECTING state (and not loading
module-bluetooth-device during that state), but otherwise treating all
transport types equally.

Ideally, audio_state should be completely removed but it's left there to
avoid an issue with module-card-restore, as documented in the source
code's comments.
2012-12-19 12:31:49 +02:00
Mikel Astiz
203c6f8ed4 bluetooth: Trivially remove bt_transport_is_acquired()
The function body is now trivial and can thus be inlined.
2012-12-19 12:31:49 +02:00
Mikel Astiz
d2080a59f3 bluetooth: Abstract transport access types inside bluetooth-util
Transports can be acquired with different access rights, but in practice
"rw" was always used inside module-bluetooth-device. In addition, this
feature is removed in BlueZ 5.0 and therefore it is convenient to
abstract all this inside bluetooth-util.
2012-12-19 12:31:49 +02:00
Mikel Astiz
0c126bdf5b bluetooth: Use transport state to update port availability
Use transport state to calculate the corresponding port availability,
and while doing so use bluetooth-util to receive profile state updates
instead of directly parsing D-Bus PropertyChanged signals.
2012-12-19 12:31:49 +02:00
Mikel Astiz
8ae8b51937 bluetooth: Refactor parsing of profile state changes
Split filter_cb() to separate the parsing of the D-Bus message from
the internal logic handling the new state.
2012-12-19 12:31:49 +02:00
Mikel Astiz
f5a4626ffb bluetooth: Move profile_to_string() to bluetooth-util
Move the function to the utility library where the enum is defined. At
same time avoid using the default clause in order to make sure the
compiler will complain if the enum type gets extended.
2012-12-19 12:31:49 +02:00
Mikel Astiz
d6d6770a04 bluetooth: Use bluetooth-util for mic/speaker gain control
Use the new abstraction in bluetooth-util to both receive volume updates
and request them.
2012-12-19 12:31:49 +02:00
Mikel Astiz
0b524c1078 bluetooth: Abstract speaker gain in transport
Similarly to the microphone gain, the speaker gain can be abstracted
inside the transport object, even though the actual D-Bus interface in
BlueZ differs.
2012-12-19 12:31:49 +02:00
Mikel Astiz
ce24ef460a bluetooth: Abstract microphone gain in transport
The microphone gain represents the volume of the incoming audio stream
from the headset. This can be nicely abstracted inside the transport
object in bluetooth-util, so the modules don't have to take care about
the D-Bus details.
2012-12-19 12:31:49 +02:00
Stefan Huber
dc19d3eb29 echo-cancel: Fix null implementation to setup one channel
memcpy() of the null implementation's run() copied data for only one
channel. Set the number of channels to 1 in init() in order to guarantee
this.

Signed-off-by: Stefan Huber <s.huber@bct-electronic.com>
Acked-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2012-12-19 12:31:48 +02:00
Stefan Huber
53f2964b40 echo-cancel: Fix apply_diff_time() to use correct sample spec
apply_diff_time() fails when dropping bytes from the playback stream
and the sample spec of sink and source differ as source's sample spec is
used. Fix this by using sink's sample spec.

Signed-off-by: Stefan Huber <s.huber@bct-electronic.com>
Acked-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2012-12-19 12:31:48 +02:00
Flavio Ceolin
4d65c9582d role-ducking: Apply a ducking effect based on streams roles
This module works pretty similar to the module-role-cork.
It should be used as an alternative to that module. Basically
it decreases the volume of the streams specified in ducking_roles
in the presence of at least one stream specified in trigger_roles.
Also, it's possible to choice the volume that will be used in the
ducking streams and if it should operates in all devices or not.

For basic reference: http://en.wikipedia.org/wiki/Ducking
2012-12-19 12:31:48 +02:00
Mikel Astiz
d3290e958b bluetooth: Connect all hooks during module load/unload
Move the connection of sink/source-related hooks to module
initialization and shutdown, to group all of them together. There is
no need to connect them every time the card profile is changed.
2012-12-19 12:31:48 +02:00
Tanu Kaskinen
29bcddcfae bluetooth: Remove prefixing from static functions. 2012-12-19 12:31:48 +02:00
Mikel Astiz
abcb741299 bluetooth: Remove deprecated transport hooks
All code has migrated to the new centralized hooks listed in
pa_bluetooth_hook_t so the old transport-specific hooks can be removed.
2012-12-19 12:31:48 +02:00
Mikel Astiz
7c2465d5f9 bluetooth: Avoid PA_BLUETOOTH_TRANSPORT_HOOK_NREC_CHANGED
The hook has been recently moved to pa_bluetooth_hook_t, so make use
of the new version.
2012-12-19 12:31:48 +02:00
Mikel Astiz
2a3874dc36 bluetooth: Avoid PA_BLUETOOTH_TRANSPORT_HOOK_REMOVED
The hook is now deprecated so avoid using it and instead use the
recently introduced PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED which also
reports the disconnection event.
2012-12-19 12:31:48 +02:00
Mikel Astiz
f035ffe3c0 bluetooth: Add transport hooks into pa_bluetooth_hook_t
Add the transport-handling hooks to the centralized list of hooks in
pa_bluetooth_hook_t. These are intended to replace the now deprecated
transport-specific hook list in pa_bluetooth_transport_hook_t.
2012-12-19 12:31:48 +02:00
Mikel Astiz
439745505a bluetooth: Add state to transport objects
Transport objects have an associated state even though it's not
explicitly exposed in BlueZ's D-Bus API (prior to 5.0). Instead, the
state is implicitly represented in the profile-specific D-Bus interface
(i.e. org.bluez.Headset, org.bluez.AudioSink, etc.) but it can be
convenient that bluetooth-util would abstract this separation.
2012-12-19 12:31:48 +02:00
Mikel Astiz
ab26cafaf4 bluetooth: Refactor parse_audio_property() to support more properties
The old implementation is limited to parsing the profile state, but
the D-Bus API actually exposes many more properties that are currently
not being considered, specially within org.bluez.Headset.
2012-12-19 12:31:48 +02:00