-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for HFP from Ofono #172
Conversation
Many tanks for this PR. It indeed looks promising. I'll try to review it during this weekend, however right now I can say few things:
Extra thing to keep in mind: |
Adds support for HFP-HF & HFP-AG over Ofono. Namely, when Ofono is running, it registers as HFP profile to bluez, preventing bluez-alsa to do so. Fortunately, it has a DBus interface to get the connections events and the audio file descriptor. To enable Ofono support, bluez-alsa must be compiled with --enable-ofono Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Hi Arkq,
I have taken all your remarks into account and repushed.
The usage of a is_ofono boolean is indeed better than
TRANSPORT_TYPE_OFONO_SCO
Also I could removed the TRANSPORT_FETCH trick, it only had a sense in
my early dev, sorry.
Thanks !
…On 11/22/2018 11:32 PM, Arkadiusz Bokowy wrote:
Many tanks for this PR. It indeed looks promising. I'll try to review
it during this weekend, however right now I can say few things:
1. The usage of |__func__| in debug() calls. If the name of debugged
function is desired, it should be added to the debug() macro
definition, not to the call site. It generates a lot of
boilerplate code.
2. Help message (in the main.c) lacks ofono version number (if it was
desired, and I'm not saying that it should be), so the argument
list is shifted.
3. The introduction of TRANSPORT_TYPE_OFONO_SCO. I do not know
exactly why, but it seems too much for me (in almost every place
it equals to TRANSPORT_TYPE_SCO) :D Maybe after thorough review it
will make sense.
Extra thing to keep in mind:
I'd like the ofono code to be conditional (via preprocessor), however
I will talk about this later, because I'm not sure yet whether ofono
code or everything related to HFP/HSP.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#172 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACRrzsLzB_ExJlZBKp-DxMSgKRl4kn8bks5uxyYOgaJpZM4YvDpG>.
|
Sorry for the delay, however I'm rather busy lately. I will try to make a proper review in the next few days. I hope you don't mind. |
Hi Arkq,
no problem, I wish it could be possibly get merged by next week, in
order to simply bump the sha1 in our yocto meta.
While reviewing, you will notice that handsfree volume control is not
supported yet.
For some reason, Ofono has a separate dbus interface to do so, that uses
modems IDs instead of "cards" (phones),
and I have to figure out how to do the matching between them.
That is something that I could submit later in another pull request.
Cheers
Thierry
…On 11/27/2018 08:25 PM, Arkadiusz Bokowy wrote:
Sorry for the delay, however I'm rather busy lately. I will try to
make a proper review in the next few days. I hope you don't mind.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#172 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACRrzqHfFDNMXKwRSYew0P3XKyONueC7ks5uzZG7gaJpZM4YvDpG>.
|
Hi, I've took the liberty to make same changes by myself within this PR in order to speed up merging process (otherwise it would take many ping-pong-like conversations). In general this PR was OK, however there was some things to be fixed:
I hope you don't mind :) Unfortunately, I was not able to test whether HFP-AG works... It seems, that it is required to configure modem within oFono in order to get AG profile. If you've got setup with AG configured, please test whether it works after my changes. Also, I've removed Once again may thanks for your work and making bluez-alsa better software! |
Many thanks !
I do not mind you corrected it yourself, it was faster this way.
I had very little experience on dbus and glib before this work, I will
pay more attention next time. I am happy to have succeeded in
doing something far more readable and simple than the old-style in pulse
audio plugin.
I am just curious why you removed the ofono_unregister()
For information, I am currently working on having bluez-alsa build
generate a bluealsa shared library.
All the functions in ctl_client.h are of interest for an application
wanting to monitor the available transports (of both SCO and A2DP),
in order to start or stop PCM loops. I hope this kind of thing would
also be of interest to you, the work is basically
most a matter of Makefile.am rather than C code, but I will have to
change some include paths in order to have the packaging (make install)
work as expected. If you like the idea of that shared library, both the
alsa plugins and bluealsa-aplay could rely on it in the future, instead of
being statically linked with the object files as they are today.
Cheers
Thierry
…On 12/02/2018 04:37 PM, Arkadiusz Bokowy wrote:
Hi,
I've took the liberty to make same changes by myself within this PR in
order to speed up merging process (otherwise it would take many
ping-pong-like conversations). In general this PR was OK, however
there was some things to be fixed:
* general code cleanup (it has looked more like PoC, than
merge-ready commit - badly formatted docstrings, mixed
indentation, function names taken from other places without
renaming, etc.)
* function reorganization within the ofono.c file in order to remove
forward declarations
* I've placed all oFono DBus related strings and values in the
iface.h file
* fixed many memory leakages (not freed glib error structs, not
unrefed DBus replies, not initialized char* causing segfault, etc.)
* fixed SCO file descriptor leakage when there is no PCM client
connected
* I've also prepared some generic framework for acquire/release
handlers (in other commit), so this PR could be simplified
I hope you don't mind :)
Unfortunately, I was not able to test whether HFP-AG works... It
seems, that it is required to configure modem within oFono in order to
get AG profile. If you've got setup with AG configured, please test
whether it works after my changes. Also, I've removed
|connect_pending| flag, so right now there are warning messages that
the operation is already in progress. I will think about some more
elegant way of deciding whether to call "Connect" method, so for now
I'm OK with this warning.
Once again may thanks for your work and making bluez-alsa better software!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#172 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACRrztgujGu3TY5FWLjCiCQKavV6SVdGks5u0_PBgaJpZM4YvDpG>.
|
General idea is very simple. When DBus connection is terminated, every object registered in DBus is dropped as well (or should be dropped). That's exactly the case for
Yes, this kind of work is desired :) See this PR: #95 However, I'm not very eager to merge such PR right now, because providing library adds some extra responsibility. There will be some API and ABI which should be maintained then. I will merge such a feature when the ctl-proto.h and ctl-client.h will be mature enough. Also keep in mind that there is a possibility for #160 to be merged in the near future. |
Hi again,
I am sorry but with the latest code on master, I am not able to get any
SCO sound output.
What is your test case ?
My is as such:
Have a mobile phone always connected, launch bluealsa in command line
/usr/bin/bluealsa -p a2dp-sink -p hfp-ofono
In a separate shell,
bluealsa-aplay -v --profile-sco 00:00:00:00:00:00
Then start a phone call.
This works on my PR branch, I am investigating what is missing. I wonder
if there is a chicken-and-egg or race condition around the "release" logic.
Namely, when the NewConnection event occurs, then it immediately
releases the ofono fd, because
t->sco.spk_pcm.fd and t->sco.spk_pcm.fd are not initialized yet, and it
removes the transport, letting no chance to bluealsa-aplay to have it
enumerated.
Thierry
…On 12/02/2018 11:12 PM, Arkadiusz Bokowy wrote:
I am just curious why you removed the ofono_unregister()
General idea is very simple. When DBus connection is terminated, every
object registered in DBus is dropped as well (or should be dropped).
That's exactly the case for |pkill ofonod| you've implemented. One
cannot rely on others for cleanup procedures. This forces "us" (e.g.
DBus, kernel itself, glibc) to implement cleanup actions upon e.g.
connection lost or process termination (file descriptors are closed,
heap memory is freed, mutexes are unlocked, etc.). So, most the time
I'm exploiting this requirement by intentionally omitting cleanup upon
main() return. One exception is filesystem, where cleanup is required
(temporary files, named sockets are not unlinked). This eliminates
code redundancy, hence saves some bytes.
All the functions in ctl_client.h are of interest for an
application wanting to monitor the available transports (of both
SCO and A2DP), in order to start or stop PCM loops. I hope this
kind of thing would also be of interest to you.
Yes, this kind of work is desired :) See this PR: #95
<#95> However, I'm not very
eager to merge such PR right now, because providing library adds some
extra responsibility. There will be some API and ABI which should be
maintained then. I will merge such a feature when the ctl-proto.h and
ctl-client.h will be mature enough. Also keep in mind that there is a
possibility for #160 <#160> to
be merged in the near future.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#172 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACRrzvnk9YgRBxZ-D7FwmSyVM3ZL86Nfks5u1FBKgaJpZM4YvDpG>.
|
Commenting out
/* transport_send_signal(t, TRANSPORT_PCM_OPEN); */
at ofono.c line 326 fixes the issue.
…On 12/03/2018 04:12 PM, Thierry Bultel wrote:
Hi again,
I am sorry but with the latest code on master, I am not able to get
any SCO sound output.
What is your test case ?
My is as such:
Have a mobile phone always connected, launch bluealsa in command line
/usr/bin/bluealsa -p a2dp-sink -p hfp-ofono
In a separate shell,
bluealsa-aplay -v --profile-sco 00:00:00:00:00:00
Then start a phone call.
This works on my PR branch, I am investigating what is missing. I
wonder if there is a chicken-and-egg or race condition around the
"release" logic.
Namely, when the NewConnection event occurs, then it immediately
releases the ofono fd, because
t->sco.spk_pcm.fd and t->sco.spk_pcm.fd are not initialized yet, and
it removes the transport, letting no chance to bluealsa-aplay to have
it enumerated.
Thierry
On 12/02/2018 11:12 PM, Arkadiusz Bokowy wrote:
>
> I am just curious why you removed the ofono_unregister()
>
> General idea is very simple. When DBus connection is terminated,
> every object registered in DBus is dropped as well (or should be
> dropped). That's exactly the case for |pkill ofonod| you've
> implemented. One cannot rely on others for cleanup procedures. This
> forces "us" (e.g. DBus, kernel itself, glibc) to implement cleanup
> actions upon e.g. connection lost or process termination (file
> descriptors are closed, heap memory is freed, mutexes are unlocked,
> etc.). So, most the time I'm exploiting this requirement by
> intentionally omitting cleanup upon main() return. One exception is
> filesystem, where cleanup is required (temporary files, named sockets
> are not unlinked). This eliminates code redundancy, hence saves some
> bytes.
>
> All the functions in ctl_client.h are of interest for an
> application wanting to monitor the available transports (of both
> SCO and A2DP), in order to start or stop PCM loops. I hope this
> kind of thing would also be of interest to you.
>
> Yes, this kind of work is desired :) See this PR: #95
> <#95> However, I'm not very
> eager to merge such PR right now, because providing library adds some
> extra responsibility. There will be some API and ABI which should be
> maintained then. I will merge such a feature when the ctl-proto.h and
> ctl-client.h will be mature enough. Also keep in mind that there is a
> possibility for #160 <#160> to
> be merged in the near future.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#172 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ACRrzvnk9YgRBxZ-D7FwmSyVM3ZL86Nfks5u1FBKgaJpZM4YvDpG>.
>
|
My test approach is similar to yours. What architecture you are using? Because there indeed might be a problem related to memory barrier.As a quick test you might add volatile to bt_fd and remove compiler optimizations -O0 (still processor might rearrange instructions, however, it should suffice). I will try to adopt transport mutex lock to this part of code, because I've omitted sco thread while I was adding lock for transport critical sections.
|
Yeap, however it is required :)
|
I do not understand why, if you wakeup the io thread it will immediately
close and forget the SCO transport. There is maybe something I am
missing in the logic.
Do reply to your last question: I am running it on an UpBoard (x86_64)
…On 12/03/2018 05:00 PM, Arkadiusz Bokowy wrote:
Yeap, however it is required :)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#172 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACRrzti5WFJTkhIxBHMnp-VK7VIp72Cfks5u1UqKgaJpZM4YvDpG>.
|
The only place where the SCO file descriptor can be closed is Sooo, finally the problem is, that when And now the question is, how bluealsa should behave when there is no client for reading SCO data, and why in your case, thread_sco sees Regarding the case where there is indeed PCM client, how bluealsa should act when new SCO connection arrives. I think that the most appropriate way is to let oFono know, that we are not able to handle audio, so it could release SCO connection - phone will not forward audio to the bluetooth. Or maybe it is OK to grab phone audio even though it will go straight to /dev/null so to speak. What do you think? |
Hmmm... indeed it does not work.... It seems, that I had to break it just before making commit :| EDIT: EDIT2: |
In order to properly handle SCO socket file descriptor obtained from the oFono, it is required to omit our internal acquire/release actions executed during event handling. Also, it is not possible not to read data from the socket when there is no PCM client connected, because it will be not possible to release SCO (we have to read from it in order to detect hangup). Fixes #172
I think, that I've fixed this premature SCO release caused by the introduction of the |
Many thanks,
this works now (I tested the speaker only) and I the code is far more
readable.
…On 12/04/2018 10:29 PM, Arkadiusz Bokowy wrote:
I think, that I've fixed this premature SCO release caused by the
introduction of the |transport_send_signal()|. Please, check if it
will work for you (I've checked it with my phone, and I was able to
send/receive audio to/from connected phone). Sorry, for the trouble
caused by this bug.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#172 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACRrznB7uRVzV65oOhhFWO-Lp--RdFQSks5u1ukhgaJpZM4YvDpG>.
|
@arkq, do you happen to have any ofono/bluealsa/asound configuration files/commands that could help me solve my issue ? |
yes, some more info woul be nice. I could use both streams like this: sudo su and in another terminal: and in another terminal: works, but huge delay 20s :-( cat ~/.asoundrc |
This brings HFP support over Ofono, using its DBus interface.
HFP-HF has been tested and both source and sink work. HFP-AG has not been tested yet.
The "transport" code has been slightly modified, in order to be able to have SCO without RFCOMM
The backend is robust to bluez-alsa restarts, in regard to Ofono, and is also robust to Ofono restarts.