linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
To: "Pali Rohár" <pali.rohar@gmail.com>,
	"Denis Kenzior" <denkenz@gmail.com>,
	linux-bluetooth@vger.kernel.org,
	"General PulseAudio Discussion"
	<pulseaudio-discuss@lists.freedesktop.org>,
	ofono@ofono.org, devkit-devel@lists.freedesktop.org,
	"Bastien Nocera" <hadess@hadess.net>,
	"Georg Chini" <georg@chini.tk>,
	"Russell Treleaven" <rtreleaven@bunnykick.ca>,
	"Luiz Augusto von Dentz" <luiz.dentz@gmail.com>,
	"Tanu Kaskinen" <tanuk@iki.fi>,
	"Arun Raghavan" <arun@arunraghavan.net>,
	"Marcel Holtmann" <marcel@holtmann.org>,
	"Sebastian Reichel" <sre@ring0.de>, "Pavel Machek" <pavel@ucw.cz>,
	"Wim Taymans" <wim.taymans@gmail.com>,
	"Arkadiusz Bokowy" <arkadiusz.bokowy@gmail.com>
Subject: Re: Proposal for a new API and usage of Bluetooth HSP and HFP profiles on Linux
Date: Mon, 9 Dec 2019 11:43:08 +0200	[thread overview]
Message-ID: <c37951ef-77ff-d5eb-8b35-19bd5725a7c9@collabora.com> (raw)
In-Reply-To: <20191207200942.nbao4mxsqw4sp67v@pali>

+ the bluez-alsa maintainer

See my comments below...

On 07/12/2019 22:09, Pali Rohár wrote:

> +Denis from ofono
>
> ofono and pulseaudio are two main users of HFP profile on Linux...
>
> On Sunday 01 December 2019 19:57:40 Pali Rohár wrote:
>> Hello!
>>
>> I'm sending this email to relevant mailing lists and other people who
>> could be interested in it. (I'm not subscribed to all of ML, so please
>> CC me when replying).
>>
>>
>> I would like to open a discussion about a completely new way of handling
>> Bluetooth HSP and HFP profiles on Linux. These two profiles are the only
>> standard way how to access microphone data from Bluetooth Headsets.
>>
>>
>> Previously in bluez4, HFP profile was implemented by bluez daemon and
>> telephony HFP functionality was provided by either dummy modem, ofono
>> modem or by Nokia's CSD Maemo modem.
>>
>> In bluez5 version was modem code together with implementation of HFP
>> profile removed. And let implementation of HSP and HFP profiles to
>> external application.
>>
>> Currently HSP profile is implemented in pulseaudio daemon to handle
>> microphone and Bluetooth speakers. HFP profile is not implemented yet.
>>
>>
>> HSP and HFP profiles use AT modem commands, so its implementation needs
>> to parse and generates AT commands, plus implement needed state machine
>> for it.
>>
>> And now problem is that last version of HFP profile specification is too
>> complicated, plus Bluetooth headsets vendors started to inventing and
>> using of own custom extensions to HFP profile and AT commands.
>>
>> Main problem of this "external" implementation outside of bluez is that
>> only one application can communicate with remote Bluetooth device. It
>> is application which received needed socket from bluez.
>>
>> So in this design if audio daemon (pulseaudio) implements HFP profile
>> for processing audio, and e.g. power supply application wants to
>> retrieve battery level from Bluetooth device, it means that audio daemon
>> needs to implement also battery related functionality.
>>
>> It does not make sense to force power supply daemon (upower) to
>> implement audio routing/encoding/decoding or audio daemon (power supply)
>> to force implementing battery related operations.
>>
>>
>> For handle this problem I would like to propose a new way how to use and
>> implement HSP and HFP profiles on Linux.
>>
>> Implement a new HSP/HFP daemon (I called it hsphfpd) which register HSP
>> and HFP profiles in bluez and then exports functionality for all other
>> specific applications via DBus API (API for audio, power supply, input
>> layer, telephony functions, vendor extensions, etc...). So it would acts
>> as proxy daemon between bluez and target applications (pulseaudio,
>> upower, ofono, ...)
>>
>> This would simplify whole HFP usage as applications would not need to
>> re-implement parsing and processing of AT commands and it would allow
>> more applications to use HFP profile at one time. And also it means that
>> audio software does not have to implement telephony stack or power
>> supply operations.
>>
>>
>> I wrote a document how such DBus API could look like, see here:
>>
>>   https://github.com/pali/hsphfpd-prototype/raw/prototype/hsphfpd.txt
>>
>>
>> And also I implemented "prototype" implementation to verify that
>> designed API make sense and can be really implemented. Prototype fully
>> supports HSP profile in both HS and AG role, plus HFP profile in HF
>> role. This prototype implementation is available here:
>>
>>   https://github.com/pali/hsphfpd-prototype
>>
>> Some other details are written in README:
>>
>>   https://github.com/pali/hsphfpd-prototype/raw/prototype/README
>>
>>
>> What do you think about it? Does it make sense to have such design?
>> Would you accept usage of such hsphfpd daemon, implemented according to
>> specification, on Linux desktop?
>>
>> I would like to hear your opinion if I should continue with this hsphfpd
>> design, or not.
>>
>>
>> With this design and implementation of hsphfpd is possible to easily fix
>> pulseaudio issue about power supply properties:
>>
>>   https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/722
>>
>>

In general, I agree that HFP/HSP AT protocol handling is something that
the audio daemons should not have to worry about. However, I am
concerned with the level of fragmentation that exists in the bluetooth
stack.

At the moment, the best case scenario is that we have 2 processes
involved in bluetooth audio (in the case where we route directly to/from
the speakers & microphone of the linux host in question):

  bluez5 <-> pulseaudio

With pipewire & bluez-alsa, we have 3 processes:

  bluez5 <-> pipewire bluetooth session <-> pipewire daemon

  bluez5 <-> bluez-alsa <-> alsa application

The 3 process separation here happens so that the bluetooth codecs run
in the process that sits in the middle. This avoids having to care about
codecs on the right side and also avoids slowing down the pipewire
daemon (so that it can still do low-latency audio processing)

When ofono comes into play, we increase this by 1:

   bluez5 <-> ofono <-> pulseaudio

  bluez5 <-> ofono <-> pipewire bluetooth session <-> pipewire daemon

  bluez5 <-> ofono <-> bluez-alsa <-> alsa application

With your proposal, we have one more:

   bluez5 <-> hfphspd <-> ofono <-> pulseaudio

  bluez5 <-> hfphspd <-> ofono <-> pipewire bluetooth session <->
pipewire daemon

  bluez5 <-> hfphspd <-> ofono <-> bluez-alsa <-> alsa application

And it can become even more crazy when you do ugly hacks like what I
have done in Automotive Grade Linux, where I use bluez-alsa for its
codec implementation & HFP/HSP handling, and then route the audio using
a gstreamer-based helper process to the pipewire daemon process
(temporarily, to workaround issues in the pipewire native implementation):

  bluez5 <-> hfphspd <-> ofono <-> bluez-alsa <-> gstreamer helper <->
pipewire daemon

Instead of all of this crazy context switching, what I would prefer to
see is a standalone component library that someone could combine in a
single process to get things done. This would:

* avoid re-implementing all kinds of stuff over and over in different
audio daemons (we do have 3 implementations atm: pulseaudio, pipewire &
bluez-alsa)
* prevent people like me from doing ugly hacks to get work done
* improve collaboration between all the different people that care about
the bluetooth stack instead of having them antagonize each other
* avoid the context switching overkill; we should only have 1 process
between bluez and the audio daemon / solution, imho
* potentially allow people to use some components in combination with a
proprietary bluetooth stack instead of bluez (a strong requirement in
the automotive industry at the moment, at least)

I imagine that this component library would include:

* bluetooth audio codecs
* HFP/HSP commands handling
* telephony handling
* exposure of common D-Bus APIs for side-channel things like power
management or phone dialing

... and then every downstream user (pulse, pipewire, bluez-alsa, ...)
could reuse these components and implement the rest of the routing /
management logic in their own daemon.

My two cents...

Regards,
George



  reply	other threads:[~2019-12-09  9:43 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-01 18:57 Proposal for a new API and usage of Bluetooth HSP and HFP profiles on Linux Pali Rohár
2019-12-02 17:01 ` [pulseaudio-discuss] " Tanu Kaskinen
2019-12-02 18:45   ` Pali Rohár
2019-12-04 15:15     ` Arun Raghavan
2019-12-04 17:05       ` Pali Rohár
2019-12-05  9:32     ` Pali Rohár
2019-12-15 22:11       ` Luiz Augusto von Dentz
2019-12-16  9:15         ` Pali Rohár
2019-12-17 23:47           ` Luiz Augusto von Dentz
2019-12-18  8:30             ` Pali Rohár
2019-12-18 17:00           ` Denis Kenzior
2019-12-18 17:28             ` Pali Rohár
2019-12-18 17:36               ` Pali Rohár
2019-12-18 20:53                 ` Denis Kenzior
2019-12-18 21:33                   ` Pali Rohár
2019-12-19  1:03                     ` Denis Kenzior
2019-12-19  9:51                       ` Pali Rohár
2019-12-19 14:53                         ` Denis Kenzior
2019-12-19 15:33                           ` Pali Rohár
2019-12-20 21:19                             ` Denis Kenzior
2019-12-20 22:46                               ` Pali Rohár
2020-01-04 10:51                                 ` Pali Rohár
2020-01-07 17:35                                 ` Denis Kenzior
2020-01-07 19:01                                   ` Pali Rohár
2019-12-02 19:49 ` Sebastian Reichel
2019-12-07 20:09 ` Pali Rohár
2019-12-09  9:43   ` George Kiagiadakis [this message]
2019-12-09 11:07     ` Pali Rohár
2020-03-15 14:17 ` Pali Rohár

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c37951ef-77ff-d5eb-8b35-19bd5725a7c9@collabora.com \
    --to=george.kiagiadakis@collabora.com \
    --cc=arkadiusz.bokowy@gmail.com \
    --cc=arun@arunraghavan.net \
    --cc=denkenz@gmail.com \
    --cc=devkit-devel@lists.freedesktop.org \
    --cc=georg@chini.tk \
    --cc=hadess@hadess.net \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=ofono@ofono.org \
    --cc=pali.rohar@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=pulseaudio-discuss@lists.freedesktop.org \
    --cc=rtreleaven@bunnykick.ca \
    --cc=sre@ring0.de \
    --cc=tanuk@iki.fi \
    --cc=wim.taymans@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).