From 942ca0c1d17f28e1d80d02cae7f6a5c94e0f4200 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 2 Oct 2020 21:54:42 +0200 Subject: [PATCH] Fixed input buffering for pages ending in a key > 20s long, added debug message when output reconnects to input during prepareNext. --- src/input/input.cpp | 7 +++++++ src/output/output.cpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/input/input.cpp b/src/input/input.cpp index a7b8f08c..fd39e160 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -27,10 +27,17 @@ namespace Mist{ WARN_MSG("Player is inside invalid track: %zu", track); return; } + //This is a bit tricky: + //We want to make sure the next page is buffered before we need it, during playback. + //To do so, we grab the current key's time and make sure current key and everything 20 seconds after it, is loaded. size_t key = users.getKeyNum(id); uint64_t time = M.getTimeForKeyIndex(track, key); size_t endKey = M.getKeyIndexForTime(track, time + 20000); + //But! What if our current key is 20+ seconds long? HAVE YOU THOUGHT OF THAT?! + //Exactly! I thought not! So, if the end key number == the first, we increase by one. + if (endKey == key){++endKey;} for (size_t i = key; i <= endKey; i++){bufferFrame(track, i);} + //Now, we can rest assured that the next ~20 seconds or so is pre-buffered in RAM. } void Input::userOnDisconnect(size_t id){} void Input::userLeadOut(){} diff --git a/src/output/output.cpp b/src/output/output.cpp index d1f39308..3ab5214c 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -1564,6 +1564,7 @@ namespace Mist{ } //every ~16 seconds, reconnect to metadata if (emptyCount % 1600 == 0){ + INFO_MSG("Reconnecting to input; track %" PRIu64 " key %zu is on page %zu and we're currently serving %zu from %zu", nxt.tid, thisKey+1, nextKeyPage, thisKey, currentPage[nxt.tid]); reconnect(); if (!meta){ onFail("Could not connect to stream data", true);