nRF5340 Audio application: broadcast headset: active_stream.stream->ep is NULL after stream switching

Dear DevZone community, 

When testing the pull request mentioned here https://devzone.nordicsemi.com/f/nordic-q-a/96965/nrf5340-audio-application-null-pointer-dereference, I believe, that I've discovered another issue (not caused by that PR).

In nRF5340 Audio application, in le_audio_bis_headset.c, if the streams are switched (button 4 is pressed on the headset), active_stream.stream->ep is NULL despite the fact that the second stream is present and playing. 

The reason is that in this application bt_audio_broadcast_sink_sync always takes only the first stream object into account, because it is used to synchronize to exactly one BIS (i.e. bis_index_bitfields[active_stream_index] has always exactly one bit set). When active_stream.stream points to the second stream object (to audio_stream[1]), it points to a stream object with an uninitialized ep. This can cause issue at places where e.g. ep->status.state is checked for an active stream. 

One possible solution would be to change bis_index_bitfields from array to a single bitfield and set the bit corresponding to all available BISes. Then bt_audio_broadcast_sink_sync to all and the incoming data of interest could be filtered in stream_recv_cb, where only the data originating from currently selected stream (from active_stream.stream) would be passed on to further processing.

If you like this solution, I can gladly prepare a PR.

Thanks!

Lada

Related