Commit graph

576 commits

Author SHA1 Message Date
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
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
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
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
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
Mikel Astiz
726435045e bluetooth: Use array to store profile states
Refactor the code to use an array of states instead of independent
member fields, avoiding duplicated code and improving readability.
2012-12-19 12:31:48 +02:00
Mikel Astiz
689f9413ad bluetooth: Move device hooks into pa_bluetooth_hook_t
Centralize the Bluetooth hooks in one single place, starting with
the device hooks, while removing the duplicated ones (in this case
PA_BLUETOOTH_DEVICE_HOOK_REMOVED).
2012-12-19 12:31:48 +02:00
Mikel Astiz
e425fd61b8 bluetooth: Extend discovery to support multiple hooks
Add the infrastructure to support several hooks inside
pa_bluetooth_discovery, while using hook names that describe more
accurately their purpose.
2012-12-19 12:31:48 +02:00
Mikel Astiz
c8944dbb4b bluetooth: Avoid PA_BLUETOOTH_DEVICE_HOOK_REMOVED
The hook PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED gets fired also
when a device is being removed, so there is actually no need to have
this duplicated hook.
2012-12-19 12:31:48 +02:00
Tanu Kaskinen
0a8068d28e bluetooth: Check if BlueZ tries to set the configuration twice for the same transport. 2012-12-19 12:31:48 +02:00
Mikel Astiz
ebdb18bca4 bluetooth: Remove pa_bluetooth_device_get_transport()
With the use of an array to represent a device's transpors, the function
becomes trivial and thus can be removed.
2012-12-19 12:31:48 +02:00
Mikel Astiz
faaf8cd39e bluetooth: Use transport array instead of hashmap for devices
Devices will have zero or one transports per profile, and besides the
typical lookup is also profile-based. Therefore, replace the old hashmap
(which used the transport path as key) with a simple array which holds
a transport pointer per profile.
2012-12-19 12:31:48 +02:00
Mikel Astiz
51d28e6331 bluetooth: Add transport hashmap to discovery
Path-based transport lookups are required in a discovery basis, before
the associated device is known. Therefore, it makes more sense to
maintain a hashmap in the discovery structure itself, instead of
iterating all devices.
2012-12-19 12:31:47 +02:00
Mikel Astiz
ccc9a58dd0 bluetooth: Use round() to convert PA<->BT volumes
The code can be simplified since it's just trying to round the result of
the division. Note that the resulting behavior is slightly different,
specially when the volume is 0. In this case, it will remain at 0,
instead of being set to 1.
2012-12-19 12:31:47 +02:00
Mikel Astiz
b36686ea9a bluetooth: Add device pointer to transport
Transports always have an associated device, so add the pointer as a
member to the structure, and remove the discovery pointer since it
already exists in the device object.
2012-12-19 12:31:47 +02:00
Mikel Astiz
80dd7c1070 bluetooth: Remove unused pa_bluetooth_discovery_get_transport()
The function is not used and it also exposes D-Bus-related information
in the internal API, which is in general undesired.
2012-12-19 12:31:47 +02:00
Mikel Astiz
28251e7243 bluetooth: Make pa_bluetooth_transport_parse_property() private
The function is not being used outside bluetooth-util and thus can be
made private.
2012-12-19 12:31:47 +02:00
Mikel Astiz
3f41a4a538 bluetooth: Fix condition to load module
d->hfgw_state is just another profile that should be considered exactly
as the rest inside device_audio_is_ready(), which is being used to
decide if the discovery hook gets triggered.

Therefore, there seems to be no reason to make an exception for this
profile and skip checking if the condition d->audio_state !=
PA_BT_AUDIO_STATE_INVALID holds true.

This change makes no practical difference but delaying the load of the
module also for HFGW until Audio.State is received. The benefit is
that the behavior and the code are more consistent across profiles.
2012-12-19 12:31:47 +02:00
Tanu Kaskinen
0f44b1e820 Log the reason for every suspend/resume.
I was looking at a log that showed that a suspend happened (at
a strange time), but the log didn't tell me why the suspend was done.
This patch tries to make sure that that won't happen again.
2012-12-19 12:31:47 +02:00
Luiz Augusto von Dentz
31d905aaae bluetooth: Add support for transport created by external profile
With BlueZ 5 it is possible to have profile registered by a third party
process which does not share the same bus id as bluetoothd so it is
necessary to store the sender of the transport to be able to talk to it.

Note that this is backward compatible.
2012-12-19 12:31:47 +02:00
Mikel Astiz
d4368aa608 bluetooth: Handle UUIDs announced later
In some cases (typically during pairing) UUIDs might be reported by
BlueZ incrementally, that is, as soon as they have been discovered. At
this point module-bluetooth-device might already be loaded, so the late
UUID announcements need to be handled and additional card profiles
might need to be created accordingly.
2012-12-19 12:31:47 +02:00
Mikel Astiz
5a791f8a16 bluetooth: Fix unacquired transports during sink resume
The sink can be resumed while the source is still in PA_SOURCE_INIT.
This is the case if a module such as module-stream-restore routes the
audio to the sink during pa_sink_put(), leading to an inconsistent
state: the sink stays RUNNING but the transport is not actually
acquired.
2012-12-05 09:11:27 +05:30
Mikel Astiz
bbb47c67bb bluetooth: Request headset audio during profile switch
When a headset is having a profile switch, we can either leave the
SCO state unmodified (as it was before this patch) or we can
alternatively request it (as older versions of PA).

This patch tries to avoid a potential regression in case a module
such as module-suspend-on-idle is not present, due to the provided
resume-on-running policy. Without this patch, and without such a policy,
the sink and sources would stay suspended until the user manually
performed another profile switch (i.e. hsp->off->hsp).

There are several other solutions currently being discussed as a longer
term solution, some of which require extendind the core. This patch is
therefore proposed as a short-term workaround to avoid the regression.
2012-12-04 03:11:23 +02:00
Mikel Astiz
01435e6134 bluetooth: Do not setup stream before thread starts
bt_transport_acquire() might get called from the main thread, in case
the IO thread hasn't been started yet. In this case, we should not call
setup_stream() since this is going to be called in the beginning of
thread_func().
2012-12-04 03:08:57 +02:00
Mikel Astiz
1dcdb96ee5 bluetooth: Trivially refactor to call setup_stream() directly
If the transport is already acquired and the stream needs to be started,
call setup_stream() directly instead of bt_transport_acquire(u, TRUE).
Both calls are identical in these conditions, with the exception of the
log trace which has now been moved to setup_stream().
2012-12-04 03:07:44 +02:00
Mikel Astiz
71bd458bd1 bluetooth: Disable profile auto-switch policy for headsets
Given that headsets have just one single port exposing whether the
audio is streaming (playing) or not, it's not possible that
module-bluetooth-policy would distinguish A2DP/HSP cases, and thus
the automatic selection of the card profile is not deterministic.

For this reason, disable the policy entirely for headsets and focus
only on HFGW and A2DP source profiles.
2012-11-29 05:37:45 +02:00