Occasional 1.5-second BASS_ChannelGetData stall on a decoding mixer

Started by Bello,

Bello

Hi Ian,

We are investigating occasional long source reads in our radio automation application on Windows, using .NET Framework 4.8/x86 and a native audio worker. The affected installation uses BASS 2.4.18.3 and BASSmix 2.4.13.

Our AoIP output path is:

File streams (DECODE | FLOAT | ASYNCFILE)
→ decoding mixers
→ native worker calling BASS_ChannelGetData
→ approximately 25 ms PCM FIFO
→ RTP sender

One measured call requested 53 stereo float frames at 48 kHz, or 424 bytes. It returned all 424 bytes, but spent 1525.2398 ms inside BASS_ChannelGetData.

This happened during ongoing playback, about 138 seconds after the last logged track start. We cannot yet exclude concurrent opening, seeking or closing of other streams. Coarse file-buffer observations showed approximately 63 KiB available in overlapping observation windows, but do not establish the buffer level at the exact stalled read.

Interestingly, we have not observed or received reports of comparable second-long outages through our established hardware-output routes. Our standard WDM configuration uses BASS_ATTRIB_BUFFER = 0; ASIO feeds a decoding mixer through BASSASIO. Those routes do not have our additional AoIP PCM FIFO. This is an operational observation rather than a controlled comparison.

We are preparing another duration test using BASS 2.4.18.29 and a 1 MiB asynchronous file buffer instead of 64 KiB. Results are still pending.

Could you advise:

1. Which operations could hold up a decoding-mixer GetData call this long despite asynchronous file reading? Could stream creation, seeking, freeing, or mixtime sync/DSP callbacks introduce contention across streams?
2. Could our small pull blocks or worker-thread context explain different behaviour from the hardware-output path?
3. What diagnostics would best distinguish file-reader waits, internal synchronization, callback work and OS scheduling?

We would prefer to identify the blocking cause before adding substantially more PCM buffering and output latency.

Ian @ un4seen

Quote from: Bello1. Which operations could hold up a decoding-mixer GetData call this long despite asynchronous file reading? Could stream creation, seeking, freeing, or mixtime sync/DSP callbacks introduce contention across streams?

Any slow callback (or async BASS_ChannelLock call) on the mixer or its sources (including sub-mixers) could cause a delay. Function calls or callbacks on other mixers/sources shouldn't affect it.

Regarding asynchronous file reading, if the required amount of file data isn't immediately available (buffered) then a decoder will currently wait for more (or a read error). If a lot of file data is needed each cycle, you can raise the size of a stream's file buffer via BASS_CONFIG_ASYNCFILE_BUFFER (before creating the stream).

Quote from: Bello2. Could our small pull blocks or worker-thread context explain different behaviour from the hardware-output path?
3. What diagnostics would best distinguish file-reader waits, internal synchronization, callback work and OS scheduling?

We would prefer to identify the blocking cause before adding substantially more PCM buffering and output latency.

When the BASS_ChannelGetData call takes a long time, you could immediately (before calling BASS_ChannelGetData  again) check the BASS_ATTRIB_CPU value of the mixer and each of its sources, to narrow down which one caused the delay. Note the delay won't necessarily be caused by the source's decoder; it could be a DSPPROC or SYNCPROC on it. In that case, you could add logging of your callback function entry/exit to find out which it is.

Bello

Hi Ian,

Thanks. We now sample BASS_ATTRIB_CPU for the mixer and its file sources immediately after a slow GetData, before the next call.

Our setup uses BASS 2.4.18.29/x86, six output decoding mixers and six native GetData worker threads (one reader per output mixer). File streams use DECODE | FLOAT | ASYNCFILE with a 4 MiB async buffer.

Two retained examples:
- 584 bytes (73 stereo float frames at 48 kHz): GetData took 26.6686 ms. Immediately afterwards, CPU was 3.2355% for the mixer and 2.9993% for the file source. Encoded buffer fill was 1,668,815 bytes before and 1,660,623 afterwards.
- 608 bytes (76 frames): GetData took 108.9256 ms. Encoded buffer fill was 2,411,495 bytes before and 2,403,344 afterwards.
The buffer readings are sequential snapshots, not proof of availability throughout either call.

We suspect BASS_ATTRIB_CPU is averaged over a wider processing window, so it may hide an isolated long call. Is that correct? What window does it use, and does it include channel/mixer lock waiting?

Normal END/POS syncs use BASS_SYNC_THREAD; application notifications are queued separately. There is no application file-read callback, VST or custom recording DSP on the investigated TX chain. Background ASYNCBUF queries every 100 ms and channel-control/mixer operations can overlap GetData on that chain.

Could those same-chain calls contend with GetData? Which call or callback would you instrument next?

Thanks!