sedmelluq / lavaplayer

Audio player library for Discord
Apache License 2.0
959 stars 247 forks source link

Http audio player changes speed #628

Open sleepy-evelyn opened 3 years ago

sleepy-evelyn commented 3 years ago

On a rare occasion (maybe 1/100 times) when starting / restarting the player from a http audio stream it can change speed. Typically when limiting the internet connection speed it will cause the player to glitch but it wont slow the actual stream down. This seems to be completely separate to that although I could be wrong 🤷

I collected a bunch of information on the stream when it's in this state and when it isn't, available here: https://gist.github.com/profjb58/3b06685f560d637b9bd6311a1d5fecc7 the radio player is called Hive365 and is linked to the stream http://stream.hive365.co.uk:8088/live

I've fixed the audio format info so it should be impossible to grab an in-correct sample rate, bit rate, chunk size etc...

The execution loop is as follows:

private void execute() throws IOException {
        playing.set(true);
        byte[] buffer = new byte[COMMON_PCM_S16_BE.maximumChunkSize()];
        int chunkSize;
        while ((chunkSize = stream.read(buffer)) > 0) { // Process input stream
            line.write(buffer, 0, chunkSize);
            if(stopPlayer.get()) { // Exit condition
                break;
            }
        }
        destroy();
    }

It's I think a slight modification of the original but with an atomic flag which allows it to safely escape the audio processing loop if it's triggered for a restart. If for some reason this doesn't fire the thread gets interrupted on restarting and everything resets anyway. The player, line output etc.. are all locked using a re-entrant lock when setting up so I doubt it's a multithreading issue

sleepy-evelyn commented 3 years ago

The first 100 values of the buffer output for the stream are available at the bottom of the gist file. I may be wrong on this but the problem stream seems to call the 0 value more often which might explain the issue at least, idk :P