Buffer indication fluctuation while playing HLS internet audio strem

Started by TBacker,

TBacker

My audio stream player has buffer level monitoring for alarms and a UI bargraph and time graph.

It works as expected, but when in block mode with HLS, the calculated buffer level (%) drops to zero for a moment every time BASS has to download the next block from the server. This results in my metering and logging alerting to an empty buffer every few seconds.

Is there a way to prevent this, or is it just the nature of the HLS beast?

Here is my buffer calculation code:

        If (BASSLib_ChannelInfo.flags And BASSFlag.BASS_STREAM_BLOCK) <> BASSFlag.BASS_DEFAULT Then

            'Stream is block mode
            NewBufferPercent = (Bass.BASS_StreamGetFilePosition(BASSLib_ChannelHandle, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD) - Bass.BASS_StreamGetFilePosition(BASSLib_ChannelHandle, BASSStreamFilePosition.BASS_FILEPOS_CURRENT)) * 100.0F / Bass.BASS_StreamGetFilePosition(BASSLib_ChannelHandle, BASSStreamFilePosition.BASS_FILEPOS_END)

            If NewBufferPercent > 100 Then
                NewBufferPercent = 100
            End If

            Return NewBufferPercent

        Else

            'Stream is continuous mode
            NewBufferPercent = Bass.BASS_StreamGetFilePosition(BASSLib_ChannelHandle, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD) * 100.0F / Bass.BASS_StreamGetFilePosition(BASSLib_ChannelHandle, BASSStreamFilePosition.BASS_FILEPOS_END)

            Return NewBufferPercent

        End If

Here is what it looks like on my UI:



TBacker

I believe I've resolved this. Still testing.

Before creating the channel, I'm downloading the HLS playlist data with a HTTP request and getting the maximum segment size (usually all equal). Then I'm setting the network buffer to slightly longer than that. That bridges the download gap between segments where the buffer could have momentarily dropped to zero.

It can make for some big buffers, but I can set curbs on that if necessary.

Ian @ un4seen

I don't seem to be able to reproduce that here (with default BASS_CONFIG_NET_BUFFER). Is it affecting all HLS streams or only some? Please provide an affected one to investigate. It seems the most likely cause of what you describe is that there's some delay in fetching the next segment, so please also try pinging the server to see what the network latency is.

Are you hearing any breaks/stalls in playback? The decoded data in the playback buffer would hopefully prevent that. Also some decoders (notably Media Foundation) will have internal buffers that are unaccounted for, so even when BASS shows an empty file buffer there may actually be some buffered data.