Commit graph

245 commits

Author SHA1 Message Date
poljar (Damir Jelić)
e95d054e40 Style fix: Remove new lines from opening brackets
This patch replaces every occurrence of ')\n{' with ') {'.

Command used for this:
    find .  -type d \( -name ffmpeg \) -prune -o \
        -regex '\(.*\.[hc]\|.*\.cc\)' \
        -a -not -name core-util.c -a -not \
        -name adrian-aec.c -a -not -name g711.c \
        -exec sed -i -e '/)$/{N;s/)\n{$/) {/}' {} \;

The excluded files are mirrored files from external sources.
2013-06-24 16:56:24 +03:00
Tanu Kaskinen
e05c12f28b bluetooth: Fix too late assertion
u was dereferenced before the assertion that checks that u isn't NULL.
2013-06-19 18:25:56 +03:00
Tanu Kaskinen
50af14bd5b bluetooth: Fix input port description 2013-06-04 00:38:43 +05:30
Mikel Astiz
9615def4b9 bluetooth: Update to new BlueZ 5 transport acquire/release API
The new D-Bus API doesn't support access rights, which weren't used by
PulseAudio anyway, but it does solve a race condition: now optional
acquires can be implemented by bluetooth-util atomically using the D-Bus
TryAcquire() method.
2013-06-04 00:38:42 +05:30
João Paulo Rechi Vita
6cc974844e bluetooth: Remove the 'bluez.name' property
The 'Name' property of the Device interface became optional in BlueZ 5
and may not be present anymore (that happens when testing against the
PTS 4.7.0), so it's better not to expose it to clients so they don't
rely on its existence.
2013-06-04 00:38:41 +05:30
João Paulo Rechi Vita
5b48062f94 bluetooth: Use 'Alias' value as the device description
The 'Alias' property should be preffered over the 'Name' property,
according to the BlueZ API documentation.
2013-06-04 00:38:40 +05:30
João Paulo Rechi Vita
6e73c05cbc bluetooth: Add 'bluez.alias' property 2013-06-04 00:38:40 +05:30
poljar (Damir Jelić)
80b0e285a5 device-port: Introduce pa_device_port_new_data
Port creation is now slightly different. It is now similar to how
other objects are created (e.g. sinks/sources/cards).

This should become more useful in the future when we move more stuff to
the ports.

Functionally nothing has changed.
2013-06-04 00:38:39 +05:30
Tanu Kaskinen
0bbef56976 device-port: Make it impossible to have dual-direction ports 2013-06-04 00:38:39 +05:30
Mikel Astiz
b156325c68 bluetooth: Fix missing port->profile association
Commit 17b3cb954b merged Bluetooth ports
into two ports (one for input, one for output) but the association
between ports and profiles was lost.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=64713
2013-05-21 14:46:38 +02:00
Mikel Astiz
305f8c7af1 bluetooth: Create ports before card profiles
Both operations are currently independent and their order can therefore
be swapped.
2013-05-21 14:46:31 +02:00
David Henningsson
135afa28e7 bluetooth: Never allow microphone output ports
If we find a microphone output port, it is probably something else
than a microphone. Therefore label it "Bluetooth output" instead of
"Microphone".

Same goes for Headphones and Speakers, but in the other direction.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2013-03-08 18:23:41 +01:00
Mikel Astiz
0a280ceed7 bluetooth: Use form factor to set port name and description
Use the information provided by the form factor to decide which name and
description should be used during port creation.
2013-03-08 18:22:17 +01:00
Mikel Astiz
11d7a2d197 bluetooth: Use enum to represent form factors
Avoid using strings only to represent form factors in the bluetooth-util
API and instead use a new dedicated enum type: pa_bt_form_factor_t.
2013-03-08 18:22:11 +01:00
Mikel Astiz
17b3cb954b bluetooth: Merge all ports into "bluetooth-input" and "bluetooth-output"
The card profile availability flag already provides all the necessary
information and therefore all Bluetooth ports can be merged, leaving
the two generic ones only: "bluetooth-input" and "bluetooth-output". The
availability of these port now represents whether the device is
streaming audio, with the following mapping:
- PA_AVAILABLE_UNKNOWN: some profile connected but not streaming
- PA_AVAILABLE_NO: no profiles connected
- PA_AVAILABLE_YES: some profile streaming (regardless of which)

Each port's flag represents the profiles with the corresponding I/O
capabilities (pa_direction_t).
2013-02-18 18:39:12 +02:00
Mikel Astiz
966a827d77 bluetooth: Expose card profile availability
Use the transport's state to not only update the ports availability, but
also to update the card profile availability flag. The interpretation is
as follows:
- PA_AVAILABLE_UNKNOWN: BT profile is connected but no audio streaming
- PA_AVAILABLE_NO: BT profile disconnected
- PA_AVAILABLE_YES: BT profile connected and audio streaming
2013-02-18 17:48:43 +02:00
Mikel Astiz
8851644a3c core: Internally deprecate pa_port_available_t to use pa_available_t
Generalize the availability flag in order to be used beyond the scope of
ports.

However, pa_port_availability_t is left unchanged to avoid modifying the
protocol and the client API. This should be replaced by pa_available_t
after a validation phase of this new generic enum type.
2013-02-18 17:25:53 +02:00
Tanu Kaskinen
77b3ba514c bluetooth: Fix thread teardown code ordering
thread_mq.outq may contain some unprocessed messages, which should be
dispatched before unreffing the sink and source. If the sink and
source are unreffed before all messages to them have been dispatched,
the unreffing won't free the sink and source, and that in turn will
likely cause problems with things getting freed in a wrong order.
2013-02-16 20:48:55 +02:00
Mikel Astiz
5d4b7c4a89 bluetooth: Fix premature acquire attempts
A transport should be considered connected only after the connection
procedure is complete, as expressed in audio_state_to_transport_state().

module-bluetooth-device should be loaded only after at least one
transport is not only created (during configuration), but also
connected.

This fixes the issue of premature acquire attempts sometimes experienced
when a headset is connected (issue not present in v3.0 though).
2013-02-16 16:53:42 +02:00
Tanu Kaskinen
43e7868008 device-port: Remove pa_device_port_hashmap_free() 2013-02-16 01:13:57 +02:00
Mikel Astiz
19be6a4748 bluetooth: Fix potential assertion failure due to unaligned packet size
While reading from the SCO socket, there is no guarantee regarding the
resulting packet size. In some rare cases, it might not even match the
alignment expected in pa_source_post(), resulting in an assertion
failure inside pa_volume_memchunk():

I: [alsa-sink] module-loopback.c: Could not peek into queue
I: [alsa-sink] module-loopback.c: Could not peek into queue
I: [alsa-sink] module-loopback.c: Could not peek into queue
E: [bluetooth] sample-util.c: Assertion 'pa_frame_aligned(c->length, spec)' failed at pulsecore/sample-util.c:725, function pa_volume_memchunk(). Aborting.

Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffda98f700 (LWP 8058)]
0x00007ffff6177935 in raise () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install alsa-lib-1.0.26-1.fc17.x86_64 dbus-libs-1.4.10-7.fc17.x86_64 flac-1.2.1-9.fc17.x86_64 glibc-2.15-58.fc17.x86_64 gsm-1.0.13-6.fc17.x86_64 json-c-0.10-2.fc17.x86_64 libICE-1.0.8-1.fc17.x86_64 libSM-1.2.1-1.fc17.x86_64 libX11-1.5.0-2.fc17.x86_64 libXau-1.0.6-3.fc17.x86_64 libXext-1.3.1-1.fc17.x86_64 libXi-1.6.1-1.fc17.x86_64 libXtst-1.2.0-3.fc17.x86_64 libogg-1.3.0-1.fc17.x86_64 libsndfile-1.0.25-2.fc17.x86_64 libtool-ltdl-2.4.2-3.1.fc17.x86_64 libudev-182-3.fc17.x86_64 libuuid-2.21.2-3.fc17.x86_64 libvorbis-1.3.3-1.fc17.x86_64 libxcb-1.9-1.fc17.x86_64 speex-1.2-0.14.rc1.fc17.x86_64
2013-01-29 06:59:31 +02:00
Mikel Astiz
132814f114 bluetooth: Fix potential assertion failure if MTU changes
The assertion in hsp_process_render() assumes that, if a memory block is
already set by the time the function is reached, its size matches
write_block_size.

This can however fail if a transport has been released and acquired
back, in the unlikely case where the MTU has changed in the meantime,
assuming the memory block wasn't released.
2013-01-24 15:55:31 +02:00
Tanu Kaskinen
b1e47df72c bluetooth: Convert booleans to stdbool. 2013-01-11 22:11:04 +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
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
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
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
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
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
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
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
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
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
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