Commit graph

576 commits

Author SHA1 Message Date
Luiz Augusto von Dentz
75df8714d7 bluetooth: Don't force any profile on discovery module
Let device module figure out the priority based on the state of the
profiles.

Note that most likely all profiles will be in PA_BT_AUDIO_STATE_CONNECTED
state so 'Off' will be the initial profile then it is up to the policy
module to switch to the most suitable profile.
2012-09-06 15:59:34 +03:00
Luiz Augusto von Dentz
8228db051e bluetooth: Remove built-in/static SBC codec
SBC shared library is now available at:

http://git.kernel.org/?p=bluetooth/sbc.git;a=summary
2012-09-06 15:59:24 +03:00
Mikel Astiz
9f924a9dda bluetooth: Support HFGW in module-bluetooth-policy
Add support for hfgw card profile in module-bluetooth-policy, just like
a2dp_source is handled.

In this case also the sink needs to be connected using module-loopback.
2012-08-22 10:19:20 +03:00
Mikel Astiz
2d6db0335f bluetooth: Generalize module-bluetooth-policy
Instead of focusing on a2dp_source only, prepare the module to support
several profiles. It will be possible to enable/disable each of them
using module arguments.
2012-08-22 10:18:22 +03:00
Mikel Astiz
69f4d4af16 bluetooth: Trivial style fix
Use consistent style for pointer types in module-bluetooth-policy.
2012-08-22 10:17:48 +03:00
Mikel Astiz
2ef75a07b5 bluetooth: Fix bluetooth.protocol property
Property bluetooth.protocol did make a distinction between A2DP sink and
source roles but on the contrary did not separate HFP roles (headset vs
gateway). For consistency, they should both behave similarly.

This automatically fixes another incosistency: the HFGW (or HSP) sink
was set to bluetooth.protocol="sco", while the source was set to "hsp".
There is no use for this distinction, since the protocol (including the
role) is the same.
2012-08-22 10:12:45 +03:00
Tanu Kaskinen
3d6092bb0f memblock: Add pa_memblock_acquire_chunk().
Besides making the code a bit cleaner, this also gets rid of
a few "cast increases required alignment of target type"
warnings.
2012-08-22 09:47:03 +03:00
Mikel Astiz
33e5802df2 bluetooth: Fix missing state checks for a2dp_source
Profile a2dp_source, just like any other card profile, should have
state guards when the profile is being changed. If the BlueZ interface
is not connected, the profile should be set to "off".
2012-08-21 19:50:29 +03:00
Mikel Astiz
d59275599a bluetooth: Minor style fix
Else clause should be in the same line as the closing brace.
2012-08-21 19:24:06 +03:00
Mikel Astiz
57469ce734 bluetooth: Remove minor unnecessary check
The return value of dbus_message_iter_next() doesn't need to be checked
since the while condition will be false anyway (arg type will be
DBUS_TYPE_INVALID).
2012-07-28 16:58:59 +03:00
Mikel Astiz
ffe723d506 bluetooth: Replace deprecated ListDevices()
The method ListDevices() in org.bluez.Adapter was deprecated in BlueZ
4.61, and is going to be removed in future releases. Instead, a property
was introduced for this purpose in BlueZ 4.7.
2012-07-28 16:57:36 +03:00
Mikel Astiz
f70f984017 bluetooth: Replace deprecated ListAdapters()
The method ListAdapters() in org.bluez.Manager was deprecated in BlueZ
4.61, and is going to be removed in future releases. Instead, a property
was introduced for this purpose in BlueZ 4.22.
2012-07-28 16:53:28 +03:00
Mikel Astiz
00cc8af995 bluetooth: Avoid duplicating profile argument twice
The module module-bluetooth-device should never be given parameter
'profile' twice, even if both HFGW and A2DP are playing. This patch
proposed to consider HFGW first.
2012-07-28 15:55:44 +03:00
Mikel Astiz
5c7672f79e bluetooth: Consider different input and output MTU
Previous implementation assumes these values are equal, but this doesn't
necessarily have to be so.
2012-07-28 15:55:44 +03:00
Mikel Astiz
8f0df3326b bluetooth: Minor style fixes
Fix some minor style fixes to be consistent with the project coding
style.
2012-07-28 15:55:44 +03:00
Mikel Astiz
d16546ceca bluetooth: Remove library for IPC to BlueZ
This library is not used anymore after the definitive transition to
Media API.
2012-07-26 09:23:56 +03:00
Mikel Astiz
8a402a7d08 bluetooth: Refactor property parsing code
Use a separate method to perform the common checks when a property needs
to be parsed.
2012-07-26 08:31:09 +03:00
Mikel Astiz
518d1dee45 bluetooth: Don't use the old socket IPC mechanism with BlueZ
This simplifies the code a lot, in favour of the D-Bus Media interface
in BlueZ. The old socket-based IPC mechanism has been deprecated and is
about to be removed soon.
2012-07-22 11:54:18 +03:00
Deng Zhengrong
d591d7f37d bluetooth: add a parenthesis around pa_streq()
I know that pa_streq() is defined with an extra parenthesis, but everytime I
look at it, it makes me nervous. :D

So it's better to add the parenthesis here.
2012-07-17 11:09:33 +05:30
Frédéric Dalleau
f6d5476e7a bluetooth: module-bluetooth-policy initial commit
This is a basic module for enabling loopback as soon as a new bluetooth A2DP
source is created. The module is given a source and a media role using command
line. This allows module-intended-roles or module-device-manager to choose a
target sink for the stream.
2012-07-04 19:25:29 +03:00
Tanu Kaskinen
12af302ac7 card: Ensure that there's always at least one profile.
In practice there is always at least one profile, and I
don't think there will ever be cards without profiles.
Therefore, I added assertions to pa_card_new() stating that
the card new data must always contain at least one profile.
Now a lot of code can be simplified, because it's guaranteed
that the profiles hashmap and the active_profile field are
always non-NULL.
2012-06-29 14:24:43 +03:00
Tanu Kaskinen
1a6da64b16 sink, source: Always create a hashmap for ports.
Having the hashmap sometimes NULL requires a lot of checking
here and there, so ensuring that the hashmap is always
non-NULL simplifies the code.
2012-06-29 14:24:43 +03:00
Frédéric Danis
017e1c4dda bluetooth: Fix bluetooth.nrec property not updated
PropertyChanged signal of org.BlueZ.MediaTransport is processed in
pa_bluetooth_transport_parse_property() which updates t->nrec.
This is called by :
- First by filter_cb() of bluetooth-util.c
- Then by filter_cb() of module-bluetooth-device.c which retrieve value
  of t->nrec before calling parse function, then it checks if t->nrec
  has changed before updating bluetooth.nrec property.
  As t->nrec has alreday been changed during first process, property
  update is never performed.

This patch creates a new hook in pa_bluetooth_transport called
PA_BLUETOOTH_TRANSPORT_HOOK_NREC_CHANGED.
The hook is fired by bluetooth-util.c when the transport's NREC
property changes.
module-bluetooth-device.c won't listen the PropertyChanged signal of
MediaTransport anymore. Instead, it will use the hook in
pa_bluetooth_transport to get a notification when the NREC property
changes, and update the sink or source proplist accordingly.

const qualifier for returned pointer of
pa_bluetooth_discovery_get_transport() is removed.
2012-06-15 21:06:01 +03:00
Arti Trivedi Bora
e5954aca8e modules: Use pa_streq instead of strcmp. 2012-06-09 16:21:41 +03:00
poljar
e7b077681b bluetooth: Add ports to the bluetooth sink/source
The bluetooth device should have ports so we can attach a latency to
the ports.

Every profile (a2dp, hsp...) has his own set of ports depending on the
number of sinks and sources it provides.
2012-06-08 16:30:01 +03:00
Jarkko Suontausta
0236977408 bluetooth: Release transport when the pa_rtpoll_run loop finishes.
Based on a patch by Marko Ollonen.
2012-05-29 09:24:27 +05:30
Frédéric Danis
21b1d92b79 bluetooth: Fix crash on disconnection
When a Bluetooth headset is connected only to HFP profile (not connected
to A2DP) and host streams to it, a crash occurs if host disconnects.

When HFP disconnects, audio thread will fail on POLLHUP then generate
a message to set PA profile to Off before ending.
If this message is managed before PA unload bluetooth device module,
all works fine.
But, if this message is managed during module unload, this finish by
re-entrance in release code (stop_thread) and a crash.

This fix prevents to process profile change when module is unloading.
2012-05-16 06:26:00 +03:00
Arun Raghavan
ec316b04ac bluetooth: Fix crash due to usage of pa_bool_t instead of dbus_bool_t
pa_bool_t and dbus_bool_t cannot be used interchangably since their size
might (and do) vary. This caused a crash on some systems which was
reported and root caused by: Aidan Thornton <makosoft@googlemail.com>.

Ref: https://bugs.gentoo.org/show_bug.cgi?id=398097
2012-05-11 17:32:20 +05:30
Tanu Kaskinen
4502d7cb28 bluetooth: Remove unused variable. 2012-03-22 19:39:46 +02:00
Colin Guthrie
3927b4b607 bluetooth: Run update-sbc
This is primarily for the bluez commit 03bb9d3 by Siamashka Siamashka
which fixes a compilation error with gcc 4.7
2012-02-24 21:22:41 +00:00
Luiz Augusto von Dentz
014511310a bluetooth: Fix calling many times Audio.GetProperties for the same device
Audio.GetProperties is been called for as many times as there are UUIDs
instead of just once when the UUIDs are discovered.
2012-02-21 08:36:21 +05:30
Tanu Kaskinen
54ca23df6f bluetooth: Change function name add_matches to update_matches.
A function that is used for removing matches should not be
called add_matches.
2012-01-28 14:16:23 +02:00
Tanu Kaskinen
8846239be7 bluetooth: Remove the right match in the proximity module.
The original intention of this code was probably that if
adding filter1 succeeded but adding filter2 failed, then
filter1 should be removed so that either both or none of the
filters get added.
2012-01-28 14:16:16 +02:00
Tanu Kaskinen
7e4eef2179 dbus: Give NULL as the error parameter to dbus_bus_remove_match().
We didn't do anything anyway in case of failures. When we
give NULL as the error, dbus_bus_remove_match() can act
asynchronously, so it becomes faster. Also, the bus daemon
can avoid sending any replies, which reduces the amount of
traffic.
2012-01-28 14:15:42 +02:00
Tanu Kaskinen
717701aa71 bluetooth: When receiving D-Bus errors, print also the error message. 2012-01-14 16:57:03 +02:00
Mikel Astiz
e199077eca bluetooth: Fix property reply handling for hfgw 2011-11-27 14:54:01 +00:00
Frédéric Dalleau
6124bf8951 bluetooth: Remove match for org.bluez.MediaTransport.PropertyChanged 2011-11-03 00:29:00 +05:30
Frédéric Dalleau
12abb05ebd bluetooth: Use static string in DBUS signal handler description 2011-11-03 00:29:00 +05:30
Frédéric Dalleau
79c836ec6a bluetooth: Set hfgw profile when HandsfreeGateway is playing
Allow module-bluetooth-device to listens to HandsfreeGateway state
changes using DBUS signals. When an handsfree connects, module-bluetooth-device
is loaded and goes to playing state. When the handsfree disconnect audio,
the card profile is set to "off". If the headset connects audio again after
that, the card profile should switch to "hfgw" again to match state of audio
connection.
2011-11-03 00:29:00 +05:30
Frédéric Dalleau
2f24a6e627 bluetooth: Set off profile on SCO disconnect
Sends a message from IO thread to main thread using pa_msgobject when POLLERR
or POLLHUP is received on SCO socket.
2011-11-03 00:21:43 +05:30
Frédéric Dalleau
2c213607e2 bluetooth: Release MediaEnpoint if card profile is set to Off
If card profile is set to "off", the audio stream should be released.
Current implementation releases the stream when the card profile
is changed to "hsp" or "hfgw" again and immediatly reconnects after that.
2011-11-03 00:21:39 +05:30
Frédéric Dalleau
54f3b9a6fa bluetooth: Do not unload module-bluetooth-device on ERR or HUP
This happens in the following scenario :
An HandsfreeGateway connects RFCOMM and then SCO. A card appears in
PA and can be used. If for some reason, SCO is disconnected,
module-bluetooth-device is unloaded. The card will disappear, even
if RFCOMM is still connected. After that, it is not possible to
connect SCO again from PA.
2011-11-03 00:21:35 +05:30
Frédéric Dalleau
3f6aa03912 bluetooth: Fix Media Endpoint for HandsfreeGateway
This patch will add the necessary quirks so that pulseaudio can register
an endpoint on the /MediaEndpoint/HFPHS path. This endpoint is to be
used for HFP Handsfree profile.
2011-11-03 00:18:49 +05:30
Johan Hedberg
8c0cca7905 bluetooth: sbc: Reduce for-loop induced indentation in sbc_unpack_frame 2011-10-28 15:43:56 +02:00
Siarhei Siamashka
00602537ba bluetooth: sbc: overflow bugfix and audio decoding quality improvement
The "(((audio_sample << 1) | 1) << frame->scale_factor[ch][sb])"
part of expression
    "frame->sb_sample[blk][ch][sb] =
        (((audio_sample << 1) | 1) << frame->scale_factor[ch][sb]) /
        levels[ch][sb] - (1 << frame->scale_factor[ch][sb])"
in "sbc_unpack_frame" function can sometimes overflow 32-bit signed int.
This problem can be reproduced by first using bitpool 128 and encoding
some random noise data, and then feeding it to sbc decoder. The obvious
thing to do would be to change "audio_sample" variable type to uint32_t.

However the problem is a little bit more complicated. According
to the section "12.6.2 Scale Factors" of A2DP spec:
    scalefactor[ch][sb] = pow(2.0, (scale_factor[ch][sb] + 1))

And according to "12.6.4 Reconstruction of the Subband Samples":
    sb_sample[blk][ch][sb] = scalefactor[ch][sb] *
        ((audio_sample[blk][ch][sb]*2.0+1.0) / levels[ch][sb]-1.0);

Hence the current code for calculating "sb_sample[blk][ch][sb]" is
not quite correct, because it loses one least significant bit of
sample data and passes twice smaller sample values to the synthesis
filter (the filter also deviates from the spec to compensate this).
This all has quite a noticeable impact on audio quality. Moreover,
it makes sense to keep a few extra bits of precision here in order
to minimize rounding errors. So the proposed patch introduces a new
SBCDEC_FIXED_EXTRA_BITS constant and uses uint64_t data type
for intermediate calculations in order to safeguard against
overflows. This patch intentionally addresses only the quality
issue, but performance can be also improved later (like replacing
division with multiplication by reciprocal).

Test for the difference of sbc encoding/decoding roundtrip vs.
the original audio file for joint stereo, bitpool 128, 8 subbands
and http://media.xiph.org/sintel/sintel-master-st.flac sample
demonstrates some quality improvement:

=== before ===
    --- comparing original / sbc_encoder.exe + sbcdec ---
    stddev:    4.64 PSNR: 82.97 bytes:170495708/170496000
=== after ===
    --- comparing original / sbc_encoder.exe + sbcdec ---
    stddev:    1.95 PSNR: 90.50 bytes:170495708/170496000
2011-10-28 15:43:48 +02:00
Marcel Holtmann
7aec17c3b6 bluetooth: audio: Update license for shared header files
The header files with constants and structures for audio specific
interaction with Pulseaudio are suppose to be under LGPL license.

For some odd reason a2dp-codecs.h ended up being under GPL license
which is against the intention of this being shared and re-used by
non-GPL programs. Fix this now to avoid any future confusion.
2011-10-28 15:43:42 +02:00
Colin Guthrie
69fe26206f bluetooth: Bump DBus version to 1.3.0 and drop conditional code.
We used to support older DBus versions but 1.3.0 is two years old
now and by requiring it we cut down of deviated code paths at
runtime and thus have less support issues.

fdo#40635
2011-09-07 20:33:13 +01:00
Maarten Bosmans
3d04a05736 bluetooth/sbc: Use __asm__ keyword 2011-09-03 12:16:49 +02:00
Maarten Bosmans
92219b01b9 Initialise variables
These were detected using clang static analyzer.
2011-08-15 09:41:56 +01:00
Maarten Bosmans
b4e938e194 Move i18n.[ch] to src/pulsecore
The header is used in files troughout the tree and is not included in the public api,
so it belongs in pulsecore, not in pulse.
2011-08-11 13:23:42 +02:00