Commit graph

261 commits

Author SHA1 Message Date
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
Colin Guthrie
a9cf320bc1 devices: Set certain sink/source flags automatically.
Some sink flags are really just a product of what callbacks
are set on the device. We still enforce a degree of sanity
that the flags match the callbacks set, but we also set the
flags automatically in our callback setter functions to
help ensure that a) people use them and b) flags & callbacks
are kept in sync.
2011-07-20 22:20:37 +01:00
Colin Guthrie
ded07a5898 devices: Use wrapper functions to set the *_volume and *_mute callbacks.
This is not currently useful but future commits will make further
changes concerning automatic setting of flags and event delivery
that makes this structure necessary.
2011-07-19 19:50:43 +01:00
Maarten Bosmans
dd9265ac78 Remove unnecessary #includes 2011-06-22 23:12:20 +01:00
Colin Guthrie
dffc4d18d3 capture: Implement per-stream volume control for capture streams.
This piggy backs onto the previous changes for protocol 22 and
thus does not bump the version. This and the previous commits should be
seen as mostly atomic. Apologies for any bisecting issues this causes
(although I would expect these to be minimal)
2011-06-22 22:45:27 +01:00
Tanu Kaskinen
62e43f9181 bluetooth-discover: Remove remaining ifdef NOKIAs.
These were supposed to be removed already in 13849f153, but
at that time I missed the ifdefs in
module-bluetooth-discover.c.
2011-06-22 14:56:32 +01:00
Colin Guthrie
ce8b03bb26 bluetooth: Fix early return styling and add missing return value
Thanks to Tanu Kaskinen for pointing out the missing return.
2011-05-15 15:05:55 +01:00
Luiz Augusto von Dentz
94e12b9aec bluetooth: Only close SCO if status has changed
In case the io thread is starting there is no point on closing SCO just
to resume it latter when the source/sink changes to opened state.
2011-04-30 14:26:46 +01:00
Luiz Augusto von Dentz
6f99198c41 bluetooth: Fix using pointer-pointer when appending an array as variant
pa_dbus_append_basic_array_variant_dict_entry should take the direct
pointer to the array.
2011-04-30 14:26:45 +01:00
Luiz Augusto von Dentz
95422110ba bluetooth: Fix not updating sample spec when using Media API
When using transport configured via Media API sample spec needs to be
updated since codec configuration may affect it when e.g. headset
configure a different frequency or number of channels from default.
2011-04-30 14:26:45 +01:00
Juho Hämäläinen
aaab340d4e bluetooth-device: fix rounding errors caused by few bt volume steps
When volume changes in bluetooth device PulseAudio volume is rounded
one too low, so if bluetooth headset changes volume and that volume
is immediately set again for bluetooth device, bluetooth step drifts
lower all the time. Volume is incremented by one in the conversion so
that we get right bluetooth step when re-applying volume.

Signed-off-by: Juho Hämäläinen <ext-juho.hamalainen@nokia.com>
2011-04-05 11:24:12 +01:00
Marc-André Lureau
5d43aba3d5 bluetooth: drop data every 500ms on oor condition 2011-04-04 13:33:56 +01:00
Tanu Kaskinen
35c93f711d bluetooth: Fix HSP volume handling.
Previously the userdata for the volume callbacks was saved to
pa_core.shared only once when loading module-bluetooth-device, and only when
the SCO over PCM feature was used. That breaks volume handling in cases where
the HSP profile is used without the SCO over PCM setup. Now the userdata is
set always when a sink or source is created, and removed when a sink or source
is removed.
2011-04-01 13:33:50 +01:00
Marc-André Lureau
ccbf7a3006 bluetooth: restore original sco_{sink, src}->set_volume when unloading 2011-04-01 13:33:08 +01:00
Marc-André Lureau
2386471e10 bluetooth: fix set_volume_cb on sco over pcm
The current implementation is totally bogus, it cast the over_sink
userdata to the bluetooth-device userdata... It was failing nicely
because the previous code had a gentle safe-guard in u->profile ==
PROFILE_HSP, and u->profile was just random.

There is no easy way to associate additional data to a sink or
source. Two solutions seems possible: looking up loaded modules and
check which one was handling the sink/source, or using pa_shared. I
went for the second solution.
2011-04-01 13:32:11 +01:00
Marc-André Lureau
209b7b781d bluetooth: use sco_sink/source to start with right state
Note from Tanu Kaskinen: I resolved some conflicts with newer upstream code, so
if this patch is broken, blame me..
2011-04-01 13:30:50 +01:00