aws-samples / amazon-ivs-player-web-sample

This project contains code samples demonstrating how to build, package, and integrate with the Amazon IVS Player Web SDK.
https://docs.aws.amazon.com/ivs/
MIT No Attribution
81 stars 32 forks source link

Delay / buffer growth issue #25

Closed fsalomon closed 3 years ago

fsalomon commented 3 years ago

I have a use case where low latency is business critical. I literally prefer no video at all over delayed video.

I have received many reports from users (and observed myself) that in some cases, the delay (i.e. buffer duration) grows very high (> 30 seconds). These cases seem to be more frequent on mobile devices and/or when the video is played in the background. I have player.setLiveLowLatencyEnabled(true).

So I came up with a fix:

player.addEventListener(PlayerEventType.BUFFER_UPDATE, function() {
    var bufferlen = player.getBufferDuration();
    if (bufferlen > 3.0) {
        player.seekTo(player.getPosition() + bufferlen - 1.1)
    } else if (bufferlen > 2.0) {
        player.setPlaybackRate(1.5);
    } else if (bufferlen > 1.5) {
        player.setPlaybackRate(1.25);
    } else if (bufferlen > 1.35) {
        player.setPlaybackRate(1.1);
    } else if (bufferlen > 1.1) {
        player.setPlaybackRate(1.05);
    } else {
        player.setPlaybackRate(1);
    }
});

As you can see, the idea is to keep the buffer below 1.1 seconds by speeding up the playback rate. Yes, I'm aware, this can lead to frequent re-buffering on unstable connections, but I'm okay with that.

Now I'm asking: Why is such a feature not part of the library? Is there something I'm getting horribly wrong?

tonyjin commented 3 years ago

Hey @fsalomon thank you for the report and code snippet. Our player has the internal capability to speed-up when the buffer grows large (we play at 1.03x in those situations, slowing down to 1x when the buffer shrinks below a threshold). We decided to not expose this API publicly at launch because it can have some downsides, e.g. audio pitching up and down on some browsers (Chrome and Firefox implement playback rate changes differently).

We're looking at exposing a different API that skips to the live edge after a buffer event in a subsequent player release, which sounds like it'd meet your requirements. Keep an eye on https://docs.aws.amazon.com/ivs/latest/userguide/release-notes.html for updates.