Get available L2CAP CoC credits

41 views
Skip to first unread message

Sherman Perry

unread,
Jul 19, 2024, 6:39:20 AM7/19/24
to btstack-dev
Hi

I haven't been able to find anything in the source, but I just wanted to ask if there is a way to get the outgoing credits from an L2CAP CoC channel?

The context for this is that I am attempting to implement ASHA on a RPi Pico W, which uses the combination of connection interval and credits to time the audio stream. I need to be able to detect overruns and underruns to drop or skip audio packets as required. For context, the project is Pico-ASHA.

If it is not possible, I was thinking of modifying btstack to add this. My idea was to implement something like:

uint8_t l2cap_cbm_available_outgoing_credits(uint16_t local_cid, uint16_t* outgoing_credits);

which would get the l2cap channel and copy the outgoing_credits struct variable.

Is this the right approach to take? And would such an addition be of interest to anybody else?

Thank you.

Regards,
Sherman

Matthias Ringwald

unread,
Jul 22, 2024, 7:15:08 AM7/22/24
to btsta...@googlegroups.com
Hi Sherman

Interesting project! I have seen the public ASHA documentation, but it hadn't been a priority for us.

I've re-read the spec and it's not obvious to me how to properly synchronize the audio streams. If a getter for the number of outgoing packets in an CoC channel is needed/helpful, we can certainly add that one.
What's the latency in ASHA roughly, given that it uses queueing CoC channels?

Could you explain how you (want to) use the outgoing packet count for synchronization?
At the moment, queued packets for CoC cannot be discarded and you'll get an event when there's space in the outgoing queue, which seems to be similar to checking the number of outgoing packets to me.

Cheers
Matthias
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/btstack-dev/d925e05b-57ea-425e-bb57-b0f1b34223c4n%40googlegroups.com.

Sherman Perry

unread,
Jul 22, 2024, 3:24:49 PM7/22/24
to btstack-dev
Hi Matthias

Yeah, you will have noticed in the spec that properly syncing the audio streams between two devices is an exercise left to the reader. Each audio packet is prepended with a sequence number, which the devices are supposed to use for synchronization. I've noticed that this seems to have limited utility, if the difference is too large (as few as 8 packets) the devices will play audio out of sync.

Audio latency depends on how many audio packets you are willing to pre-buffer. It could be as high as 160ms + device processing. That is if you pre-buffer 8 audio packets (which are 20ms each). The less pre-buffer, the lower the latency, but the higher the chance of stream instability.

I am currently not pre-buffering audio, which makes the stream unstable, but minimizes latency and makes syncing audio between devices extremely simple. The biggest trouble is if the buffer on my devices runs empty, my devices tend to disconnect completely.

In the Android source code, the code does flush the L2CAP buffer if required.

So I guess, basically I need to know when the device buffer is about to run empty so I can do something about it. What is the size of the outgoing L2CAP buffer in btstack, and can I influence that?

Apologies if I'm not very clear. I'm still very much still learning about BLE, so part of what I'm doing is trying different stuff to see what works.

I can see why LE Audio (and isochronous streams) was invented. ASHA is quite the hack...

Thanks,
Sherman

Matthias Ringwald

unread,
Aug 14, 2024, 5:30:32 AM8/14/24
to btsta...@googlegroups.com
Hi Sherman

I've added l2cap_cbm_available_credits and l2cap_ecbm_available_credits (for enhanced coc or regular) on the develop branch.
Please let me know if this works for you.

Best
Matthias
> To view this discussion on the web visit https://groups.google.com/d/msgid/btstack-dev/e966b807-fb20-475d-9802-f7b6ec2cf572n%40googlegroups.com.


Sherman Perry

unread,
Aug 17, 2024, 6:11:46 PM8/17/24
to btstack-dev
Hi Matthias

Apologies for the delayed reply, I didn't notice it until yesterday.

This works perfectly, and is proving to be very helpful.

Thank you.

(Note, anything further on this topic I'll post in the Github issue.)

Regards,
Sherman
Reply all
Reply to author
Forward
0 new messages