-
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
Adding mSBC mode into HFP #29
Comments
Hi, First of all, I'm glad, that you find this software useful. Currently, there is no HFP support what so ever. The RFCOMM and SCO IO threads are tailored for HSP profile. I thought for a while about actual HFP support, however I don't know how to accomplish that and keep bluealsa simple (bluealsa should be only for audio management). I thought about forwarding AT command to some external "server", which will handle all HFP-related actions (there is much more in the HFP specification, than simple audio transfer). There is a project called nohands, however is seems that integrating it with bluealsa might not be so simple. So basically, this issue is an open question. What I would not want to do, is to make yet another bloatware, which will be impossible to maintain :) I'm scarred a little bit right now, to be honest, because the code is getting out of control in few places - scheduled for future refactoring. My first thought about HFP, is that, the support for this profile should be separated from the HSP one - even though the HFP is a successor of the HSP and the HSP can be handled (?) with the HFP implementation. But I'm open to any suggestions - maintainability is a very strong argument. As for communication problem between the RFCOMM and SCO threads.... Yes, that's a nightmare. The eventfd is used only because there was no need for anything fancy, not yet. So, if there is a need for some logic within the communication channel, FIFO seems to be OK. To answer to your question more thoroughly, I will have to read once more the HFP specification. I will try to share some constructive thoughts in a next few days. |
I should explain. We are looking to use HFP over HSP only because it supports mSBC and therefore offers better audio quality compared to HSP. If we could do A2DP full duplex that would be awesome but no devices support it. I have no need to implement any of the cellular-specific functionality, outside of what little handshaking is required to complete the control channel establishment and codec negotiation. I like that bluez-alsa is audio only and I would like to keep it that way. Just make it a little better by using mSBC. Based on what you write, would you like to see both the rfcomm and io threads separated into hsp&hfp models? I.e. separate transports types? While cleaner, it would lead to some code multiplication though some could probably be shared. |
I'm just after a brief reading of the "Hands-Free Profile 1.7.1" :) So, it seems, that indeed there is no need to separate RFCOMM transports. It should be possible to handle both HFP and HSP with a single logic. It is more complicated with the SCO IO thread, but I'm leaving it up to you. I do not know how the eSCO link is implemented in the bluez. If it is transparent to the user (encoding/decoding is performed in the bluez), the sco thread can be shared. If the encoding/decoding process is simple enough, that there is no need for lots of "ifs" in the current IO thread, this process can be incorporated in the io_thread_sco. However, if the eSCO link is somehow different from the current SCO link implementation, I would rather make it as a separate IO thread function.
That's fine. However, keep in mind, that in the future I would like to make such a support, but I would like to implement it as an "external" functionality.
I think, that the thread can be created, but the SCO acquisition should be delayed. I might be wrong, though. Like I said before, I don't know how the eSCO link should be handled :| |
Indeed it is possible to handle both with same logic, I am doing that currently. The eSCO is a detail the kernel takes care of, if it detects that the link supports it, eSCO will be used. There is one socket option (BT_VOICE) that needs to be passed to change the SCO socket to transparent mode but that's it. The problem is not the SCO thread creation per se but the transport creation. After the transport is created (currently it happens immediately when the profile is connected to) an application can try to use it. With mSBC this can lead to trouble since the sample rate differs from CVSD, the application can grab the transport at a point where we don't know yet whether it is CVSD or mSBC. |
OK, so right now I'm fully aware of the problem you've got. Thanks for this explanation. If you think, that it will be "cleaner" to postpone SCO transport creation, that's OK. In my current design, the SCO and RFCOMM transports are tightly coupled - in order to make sure that there will be no dangling pointer, everything is initialized in the transport_new_rfcomm function. What I would do (I think), it will be a "flag"/enum in the sco structure (in the ba_transport structure) which will be indicating selected codec type (SBC, mSBC, CVSD and "undefined"). It will be required anyway, in order to determine the sampling rate (for the transport_get_sampling function). So, if the codec is undefined, the transport will not be exposed in the ctl list_transports request. What do you think? |
Hey guys, It looks like bluetoothd eventually receives a connection reset event on the rfcomm socket, leading to bluealsa closing the RFCOMM/HFP thread(s). I've read the current thread, juha's pull request and his different work branches, and was wondering if any of you guys succeeded with this? Note I fully understand HFP in bluez-alsa is not exactly ready for production, but I wouldn't mind helping with debugging it if possible :-) |
Hi, Currently I'm not involved with the HFP support (It's sad to say, by I haven't tested kukika's PR yet - regarding HFP). I'm still working on PCM ALSA plugin.... |
Add support for the mSBC codec for HFP into the SCO IO thread. This support is optional, and is controlled by the --enable-msbc configuration flag. The receiving part of this mSBC support has been tested with Jabra MOVE v2.3.0 headset and seems to work flawlessly. However, playback does not work... Maybe it will work with some other BT device. Note: This commit is a rework of a pull request submitted by Juha Kuikka. Fixes #29 and closes #37
Hi, After a long battle with other issues, I've finally started to work with this feature. I've managed to "merge" your mSBC code with the master branch (it's rather far from the original code, however the logic is still there, I hope). It's not pushed to the master branch yet, because I've got one problem... I've got Jabra MOVE v2.3.0 headset, which I'm using for testing. Fortunately, it supports mSBC codec, so it seems to be a nice test-case for this feature. I'm able to receive and decode signal from the microphone (yeah!), however sending data to the headset does not produce any audio... If writing MTU is set to 24 bytes, then some glitches are audible, however I wouldn't say that I can hear sound. I've tried to use your code (checkout onto the PR commit), however it's the same issue. Microphone works, speaker is silent. So, I've got a question: have you been able to send mSBC signal to BT headset (or some other device) using the code from the PR? Because, maybe my headset is broken and the code itself is OK. @kuikka (or anyone who stumbles upon this issue :)) could you test msbc branch and provide some info whether it works for you or not? Side note:
|
Hi, I'd love to record wideband audio with my BT headsets, so I built @arkq's msbc branch, and tested it with my LG HBS-780 (healthy) and Jabra Halo Smart (speakers broken). Following
... but similar During recording,
|
@asari-fd many thank for your testing and reply! So it seems, that the playback part is not working after all... The problem might be on my side, however it's hard to tell. I will try to tinker a little bit more.
Yeap, I've seen something similar. The problem is definitely in bluealsa code. However, this part (recording) sometimes works, so the game is not lost completely :). |
Hi, I got another Jabra Halo Smart (healthy) from Amazon, so I tried @arkq's msbc branch again. Headsets: Tried commands:
Machine 1:
Machine 2:
Unfortunately, for now I can't reproduce the situation of my last post, for I have upgraded "Machine 2" from Ubuntu 17.10 beta to 17.10 (release) and rebuilt bluez-alsa. I'm sorry if I bothered you by my post based on the beta release. ( By the way, I have difficulty in making "Machine 1" connect to multiple headsets simultaneously. Perhaps newer bluez will do, so I'll try to upgrade it later. ) |
Hi @asari-fd, So, you are saying that playing using the mSBC codec works for you? Because using |
Add support for the mSBC codec for HFP into the SCO IO thread. This support is optional, and is controlled by the --enable-msbc configuration flag. The receiving part of this mSBC support has been tested with Jabra MOVE v2.3.0 headset and seems to work flawlessly. However, playback does not work... Maybe it will work with some other BT device. Note: This commit is a rework of a pull request submitted by Juha Kuikka. Fixes #29 and closes #37
Add support for the mSBC codec for HFP into the SCO IO thread. This support is optional, and is controlled by the --enable-msbc configuration flag. The receiving part of this mSBC support has been tested with Jabra MOVE v2.3.0 headset and seems to work flawlessly. However, playback does not work... Maybe it will work with some other BT device. Note: This commit is a rework of a pull request submitted by Juha Kuikka. Fixes #29 and closes #37
Add support for the mSBC codec for HFP into the SCO IO thread. This support is optional, and is controlled by the --enable-msbc configuration flag. The receiving part of this mSBC support has been tested with Jabra MOVE v2.3.0 headset and seems to work flawlessly. However, playback does not work... Maybe it will work with some other BT device. Note: This commit is a rework of a pull request submitted by Juha Kuikka. Fixes #29 and closes #37
Add support for the mSBC codec for HFP into the SCO IO thread. This support is optional, and is controlled by the --enable-msbc configuration flag. The receiving part of this mSBC support has been tested with Jabra MOVE v2.3.0 headset and seems to work flawlessly. However, playback does not work... Maybe it will work with some other BT device. Note: This commit is a rework of a pull request submitted by Juha Kuikka. Fixes #29 and closes #37
Add support for the mSBC codec for HFP into the SCO IO thread. This support is optional, and is controlled by the --enable-msbc configuration flag. The receiving part of this mSBC support has been tested with Jabra MOVE v2.3.0 headset and seems to work flawlessly. However, playback does not work... Maybe it will work with some other BT device. Note: This commit is a rework of a pull request submitted by Juha Kuikka. Fixes #29 and closes #37
Great piece of software! I am currently working on integrating this into our product in lieu of pulseaudio due to former's excessive CPU usage with BT audio.
I am enhancing the HFP support by adding more AT command handling (some headsets drop the connection if the standard handshake is not followed) and by adding mSBC support.
Before I dive in to the mSBC I wanted to ask if you have thought about how to best implement it? The problematic detail is that the codec negotiation happens in the RFCOMM thread but the information needs to go to both the SCO IO thread and into the control thread since the sampling rates differ between CVSD and mSBC.
I could either delay the creation of the accompanying SCO transport until the codec has been decided upon, or add a more complex logic, maybe a fifo instead of the eventfd to pass more complex communications between the threads.
There is also a race condition where the plugin may attempt to grab the SCO transport before the AT negotiation has finished, this leads me to prefer delaying the creation of the SCO IO thread.
Thoughts?
The text was updated successfully, but these errors were encountered: