Commit graph

576 commits

Author SHA1 Message Date
Tanu Kaskinen
15e3d828dd bluetooth: unify BlueZ 4 and BlueZ 5 profile constant names
This should make it slightly easier to copy code between BlueZ 4 and
BlueZ 5.
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
52a9ee618f bluetooth: unify BlueZ 4 and BlueZ 5 UUID handling
A hashmap is more convenient than a linked list for storing the UUIDs,
so change the BlueZ 4 code accordingly.

Rename the BlueZ 4 UUID constants to match the BlueZ 5 naming.

The only changes to the BlueZ 5 code are the addition of one comment
and making another comment a bit clearer.
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
570288ccc9 bluetooth: update device's valid flag after parsing properties
The properties_received flag affects whether the device should be
considered valid, so let's update the valid flag after setting the
properties_received flag.

There's a call to device_update_valid() anyway later when setting
the device adapters, so this change isn't strictly necessary, but
this makes it more obvious that the code is correct (and less
fragile).
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
eec4d29247 bluetooth: remove a redundant assignment
pa_bluetooth_transport_put() assigns the transport to the device's
transports array, so the caller doesn't have to do that.
2016-08-10 21:37:33 +03:00
Tanu Kaskinen
d9b885e0f1 bluetooth: wait for all profiles to connect before creating card
The CONNECTION_CHANGED hook is used to notify the discovery module
about new and removed devices. When a bluetooth device connects, the
hook used to be called immediately when the first profile connected.
That meant that only one profile was marked as available during the
card creation, other profiles would get marked as available later.

That makes it hard for module-card-restore to restore the saved
profile, if the saved profile becomes available with some delay.
module-card-restore has a workaround for this problem, but that turned
out to interfere with module-bluetooth-policy, so the workaround will
be removed in the next patch.

The BlueZ 4 code doesn't need changes, because we use the
org.bluez.Audio interface to get a notification when all profiles are
connected.
2016-08-10 21:37:33 +03:00
Pali Rohár
bde2ff8794 bluetooth: Add support for automatic switch between hsp and a2dp profiles
With this patch module-bluetooth-policy automatically switch from a2dp profile
to hsp profile if some VOIP application with media.role=phone wants to start
recording audio.

By default a2dp profile is used for listening music, but for VOIP calls is
needed profile with microphone support (hsp). So this patch will switch to
hsp profile if some application want to use microphone (and specify it in
media.role as "phone). After recording is stopped profile is switched back
to a2dp. So this patch allows to use bluetooth microphone for VOIP applications
with media.role=phone automatically without need of user interaction.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2016-07-22 16:30:25 +05:30
Tanu Kaskinen
7b62601401 card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().

pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.

An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).

The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2016-06-28 16:55:42 +03:00
Tanu Kaskinen
59e76ca949 alsa, bluetooth: fail if user-requested profile doesn't exist
If we can't fulfill the user request fully, I think we shouldn't
fulfill it at all, to make it clear that the requested operation
didn't succeed.
2016-06-28 16:55:42 +03:00
Jason Gerecke
00ba340618 bluetooth: Prevent aborts caused by invalid module arguments
If 'pa_modargs_new' returns a NULL, we need to be careful to not call
'pa_modargs_free' in the failure path since it requires that we pass it
a non-null argument. Also updates 'module-bluetooth-policy.c:pa__init'
to follow the standard "goto fail" pattern used everywhere else.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
2016-01-15 16:20:53 +05:30
Kiran Krishnappa
96b368b960 module: Remove redundant core argument from pa_module_unload()
pa_module_unload() takes two pointers: pa_module and pa_core.
The pa_core pointer is also available via the pa_module object,
so the pa_core argument is redundant

[David Henningsson: Rebased to git HEAD]
2015-12-07 09:31:58 +01:00
Manish Sogi
ff24ea7695 bluetooth: bluez4: Remove the unused "auto_connect" parameter as it is not used in bluez4
<EP-F69A421D31544C56BDE97C590307C014>
Signed-off-by: Manish Sogi <manish.sogi@samsung.com>
2015-09-25 15:05:43 +03:00
Shawn Walker
954503d074 modules: Fix struct namespace collision on Solaris 2015-07-29 08:09:41 +05:30
Sagar Nageshmurthy
ff329cdabb Fix: Prevent calling pa_rtpoll_free() for a NULL rtpoll
Flushing the asyncmsgq can cause arbitrarily callbacks to run, potentially
causing recursion into pa_thread_mq_done again. Because of this; rtpoll which
is cleared in the second iteration is tried to free once again by the first
iteration leading to PA crash.
2015-03-27 14:34:15 +01:00
Ondrej Holecek
5effc83479 update FSF addresses to FSF web page
FSF addresses used in PA sources are no longer valid and rpmlint
generates numerous warnings during packaging because of this.
This patch changes all FSF addresses to FSF web page according to
the GPL how-to: https://www.gnu.org/licenses/gpl-howto.en.html

Done automatically by sed-ing through sources.
2015-01-14 22:20:40 +02:00
David Henningsson
de1e78a47c bluez5: Do not suspend on no -> unknown profile transitions
In case a transport is currently disconnected and transitions to
idle, that should not count as a "remote hang up" event.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-12-19 11:50:28 +01:00
David Henningsson
9793870b23 bluez5: Fix free order of adapters and devices
Because the adapters reference the devices hashmap on free, we mush
free the adapters hashmap first and then the devices hashmap.

Reported-by: Alexander Patrakov <patrakov@gmail.com>
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-12-03 12:04:29 +01:00
Wim Taymans
398337f3db bluetooth: set gain correctly
Send the right command to set the speaker and microphone gain.

Note that setting the volume on the Headset should use the unsolicited
result code. Receiving the volume from the Headset uses the AT
command.
2014-11-21 11:55:24 +01:00
Peter Meerwald
68cc36140b core: Annotate variables only used within assert()s to be PA_UNUSED
supresses a warning when compiling with NDEBUG:

pulsecore/aupdate.c: In function 'pa_aupdate_read_end':
pulsecore/aupdate.c:82:14: warning: variable 'n' set but not used [-Wunused-but-set-variable]
     unsigned n;

pulsecore/sink-input.c: In function 'pa_sink_input_unlink':
pulsecore/sink-input.c:648:27: warning: variable 'p' set but not used [-Wunused-but-set-variable]
     pa_source_output *o, *p = NULL;

pulsecore/sink-input.c: In function 'find_filter_sink_input':
pulsecore/sink-input.c:1523:14: warning: unused variable 'i' [-Wunused-variable]
     unsigned i = 0;

pulsecore/sink-input.c: In function 'pa_sink_input_start_move':
pulsecore/sink-input.c:1569:27: warning: variable 'p' set but not used [-Wunused-but-set-variable]
     pa_source_output *o, *p = NULL;

  CC       pulsecore/libpulsecore_5.0_la-sink.lo
pulsecore/sink.c: In function 'pa_sink_unlink':
pulsecore/sink.c:673:24: warning: variable 'j' set but not used [-Wunused-but-set-variable]
     pa_sink_input *i, *j = NULL;

   pulsecore/source-output.c: In function 'find_filter_source_output':
pulsecore/source-output.c:1179:9: warning: unused variable 'i' [-Wunused-variable]
     int i = 0;

  CC       pulsecore/libpulsecore_5.0_la-source.lo
pulsecore/source.c: In function 'pa_source_unlink':
pulsecore/source.c:616:27: warning: variable 'j' set but not used [-Wunused-but-set-variable]
     pa_source_output *o, *j = NULL;

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-11-17 13:24:51 +01:00
David Henningsson
9ae85b1a29 bluetooth: Select headset backend through module argument
This patch adds a module argument "headset=ofono|native|auto" to
module-bluetooth-discover and module-bluez5-discover.

To make Arun's happy, the default is 'native' if compiled in, otherwise
'ofono'. 'Auto' will try to autoswitch depending on whether ofono is
running or not.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-11-14 11:44:33 +01:00
David Henningsson
d63305f103 bluez 5: remove null headset backend
There is no need to have a "null" backend anymore.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-11-14 11:44:33 +01:00
David Henningsson
5f6cb5872b bluez 5: Fix a debug message
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-11-14 11:44:33 +01:00
David Henningsson
aea3518569 bluez 5: Load the native headset backend if the oFono one is unavailable
This implements some autodetect if both headset backends are compiled in:
First we try to contact the oFono service, if that's not working,
then we start the native backend instead.

Likewise if the oFono service is going offline/online, we load/unload
the native backend accordingly.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-11-14 11:44:33 +01:00
David Henningsson
1ffede3c85 bluez 5: Build both headset backends, if available
Enable both ofono and native backends to be built into the same
libbluez5-util. Never build the null backend.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-11-14 11:44:33 +01:00
Peter Meerwald
fa092af59c rtpoll: Drop extra wait_op argument to pa_rtpoll_run()
is always true, not used

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-11-09 22:53:06 +01:00
Arun Raghavan
5dfa83385c bluetooth: Fix some native backend command sending
We weren't writing out one character from the "OK" response, and the
"AT" part of the "+VGS" and "+VGM" commands was missing. Also, the spec
says that the command is terminated by only a CR and not an LF (probably
doesn't hurt, but let's adhere to the spec for now).
2014-10-31 10:47:56 +05:30
Wim Taymans
34a5c754a9 backend-native: implement volume control
Parse the gain changed AT commands from the headset and fire 2 new
hooks as a result. The device will connect to those hooks and change the
source/sink volumes.

When the source/sink volume changes, set the gain on the microphone or
speaker respectively. Make sure we do nothing if the transport can not
handle the gain changes.
2014-10-31 10:46:10 +05:30
Wim Taymans
7d4a497b3d backend-native: add a new native headset backend
Add a simple native headset backend that implements support for the
blutooth HSP profile.
This allows pulseaudio to output audio to a Headset using the HSP profile.

Make the native backend the default.
2014-10-31 10:46:10 +05:30
Wim Taymans
d7199bafea bluez5-util: add destroy function
Add a destroy function to the transport that is called before freeing
the transport. Useful for cleaning up extra userdata.
2014-10-31 10:46:10 +05:30
Wim Taymans
2251085dda bluez5-device: use get_profile_direction
Use the get_profile_direction() helper function to decide when to add a
source and a sink instead of enumerating profiles.
2014-10-31 10:46:10 +05:30
Tanu Kaskinen
0df4d56cf8 bluetooth: Move stuff to pa_bluetooth_transport_put/unlink()
This should not have any effect on behaviour. The goal is to align
with the pattern that I think we should follow:

Object initialization:
 - put() is the place to create references from other objects to the
   newly created object. In this case, adding the transport to
   discovery->transports was moved from new() to put, and adding the
   transport to device->transports was moved from set_state() to
   put().

Object destruction:
 - unlink() undoes put() and removes all references from other objects
   to the object being unlinked. In this case setting the
   device->transports pointer to NULL was moved from set_state() to
   unlink(), and setting the discovery->transports pointer to NULL was
   moved from free() to unlink().
 - free() undoes new(), but also calls unlink() so that object owners
   don't need to remember to call unlink() before free().
2014-10-19 14:04:46 +03:00
Pali Rohár
380a7fc240 bluetooth: bluez4: Add profile name to sinks and sources
Now a2dp and hsp sinks and sources will have different names which means that
applications and other modules can use sink/source to distinguish selected
profile.

Module module-device-restore uses sink/source name and port name as identifier,
so if different profiles have different names module-device-restore can store
volume settings for each profile.

So with this patch it is possible to configure different volume settings for
a2dp and hsp profiles.

This patch does not change port names so gnome applications will be happy.

Note that similar patch is needed also for bluez5, but I'm not using bluez5
so I cannot write or test it.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
2014-09-28 13:34:27 +03:00
Luiz Augusto von Dentz
eb108b3539 bluetooth: Allow policy module to pick 'off' profile
This allow 'off' profile to be choosen when no other profile is available
which is considered better since it requires less resources than other
profiles.
2014-09-18 10:54:23 +03:00
João Paulo Rechi Vita
7fac520d89 bluetooth: Switch transport state to idle in case of HUP
In case the socket HUP the transport state should be set to idle which
will indicate the profile is no longer available.
2014-09-18 10:53:49 +03:00
João Paulo Rechi Vita
75bf00a507 bluetooth: Implement org.ofono.HandsfreeAudioAgent.NewConnection() 2014-09-16 14:46:40 +03:00
João Paulo Rechi Vita
f7c7cd1825 bluetooth: Implement org.ofono.HandsfreeAudioAgent.Release() 2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
b1a09ebf7e bluetooth: Handle CardRemoved signal 2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
8f838b1f31 bluetooth: Handle CardAdded signal 2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
0e7f303256 bluetooth: Track oFono service 2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
c4c4de532d bluetooth: Implement transport release for hf_audio_agent transports 2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
8dd4aa1f00 bluetooth: Implement transport acquire for hf_audio_agent transports 2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
c098665820 bluetooth: Parse HandsfreeAudioCard properties 2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
a5a0506c4e bluetooth: List HandsfreeAudioCard objects from oFono 2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
374c28a40e bluetooth: Register/Unregister Handsfree Audio Agent with oFono
Register as a HandsfreeAudioAgent with oFono during backend
initialization and unregiter during backend finalization. This commit
also adds a check when receiving method calls or signals to make sure
the sender matches with the D-Bus service we're registered with.
2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
d7a8ccce89 bluetooth: Create hf_dbus_send_and_add_to_pending() for oFono backend 2014-09-11 14:00:15 +03:00
João Paulo Rechi Vita
98d3d85705 bluetooth: Monitor D-Bus signals 2014-09-11 14:00:15 +03:00
Luiz Augusto von Dentz
f508b34b8b bluetooth: Add discovery to pa_bluetooth_backend_new 2014-09-10 13:25:36 +03:00
Luiz Augusto von Dentz
5c2ed8abed bluetooth: Only create backend instance once objects are listed
This makes sure the devices are discovered before the backend start
creating new transports.
2014-09-10 13:25:36 +03:00
Luiz Augusto von Dentz
19180345fa bluetooth: Add pa_bluetooth_transport_unlink 2014-09-08 13:19:59 +03:00
Luiz Augusto von Dentz
4e041f7b36 bluetooth: Add pa_bluetooth_transport_set_state 2014-09-08 13:00:54 +03:00
Tanu Kaskinen
638d0a51e2 bluetooth: Always initialize profile->available
If the transport for the profile doesn't exist, the old behaviour was
to leave cp->available at the default value, which is
PA_AVAILABLE_UNKNOWN, but if there's no transport, the profile should
be marked as unavailable.
2014-08-24 12:38:18 +03:00