From 25c7f6f93d2c5c945c0f41483d165e809b4a65e0 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 24 Jul 2013 13:25:38 +0200 Subject: [PATCH] Tweaked buffer/player timings to prevent delays, almost-working smooth support. --- src/buffer/buffer.cpp | 11 +++++---- src/buffer/player.cpp | 4 ++-- src/connectors/conn_http_smooth.cpp | 37 ++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/buffer/buffer.cpp b/src/buffer/buffer.cpp index b37936af..ddbfb4f7 100644 --- a/src/buffer/buffer.cpp +++ b/src/buffer/buffer.cpp @@ -212,7 +212,10 @@ namespace Buffer { } while (buffer_running){ if (thisStream->getIPInput().connected()){ - connected = true; + if (!connected){ + connected = true; + thisStream->getIPInput().setBlocking(false); + } if (thisStream->getIPInput().spool()){ while (true){ thisStream->getWriteLock(); @@ -225,12 +228,12 @@ namespace Buffer { thisStream->dropWriteLock(true); }else{ thisStream->dropWriteLock(false); - Util::sleep(25); //10ms wait + //Util::sleep(10); //10ms wait break; } } - }else{ - Util::sleep(1000); //10ms wait + //}else{ + //Util::sleep(500); //500ms wait } }else{ if (connected){ diff --git a/src/buffer/player.cpp b/src/buffer/player.cpp index 5188f4f4..cf47bd15 100644 --- a/src/buffer/player.cpp +++ b/src/buffer/player.cpp @@ -239,8 +239,8 @@ int main(int argc, char** argv){ if (lastTime == 0){ lastTime = now - source.getJSON()["time"].asInt(); } - if (playing == -1 && playUntil == 0 && source.getJSON()["time"].asInt() > now - lastTime + 1000){ - Util::sleep(source.getJSON()["time"].asInt() - (now - lastTime)); + if (playing == -1 && playUntil == 0 && source.getJSON()["time"].asInt() > now - lastTime + 7500){ + Util::sleep(source.getJSON()["time"].asInt() - (now - lastTime + 5000)); } if ( playUntil && playUntil < source.getJSON()["time"].asInt()){ playing = 0; diff --git a/src/connectors/conn_http_smooth.cpp b/src/connectors/conn_http_smooth.cpp index b7a13ddd..3624bf44 100644 --- a/src/connectors/conn_http_smooth.cpp +++ b/src/connectors/conn_http_smooth.cpp @@ -296,8 +296,43 @@ namespace Connector_HTTP { } } } + + long long mstime = 0; + long long mslen = 0; + if (myRef.isMember("keys")){ + for (JSON::ArrIter it = myRef["keys"].ArrBegin(); it != myRef["keys"].ArrEnd(); it++){ + if ((*it)["time"].asInt() >= (requestedTime / 10000)){ + mstime = (*it)["time"].asInt(); + mslen = (*it)["len"].asInt(); + if (Strm.metadata.isMember("live")){ + if (it == myRef["keys"].ArrEnd() - 2){ + HTTP_S.Clean(); + HTTP_S.SetBody("Proxy, re-request this in a second or two.\n"); + conn.SendNow(HTTP_S.BuildResponse("208", "Ask again later")); + HTTP_R.Clean(); //clean for any possible next requests + std::cout << "Fragment after fragment @ " << (requestedTime / 10000) << " not available yet" << std::endl; + } + } + break; + } + } + } + if (HTTP_R.url == "/"){continue;}//Don't continue, but continue instead. + if (Strm.metadata.isMember("live")){ + if (mstime == 0 && (requestedTime / 10000) > 1){ + HTTP_S.Clean(); + HTTP_S.SetBody("The requested fragment is no longer kept in memory on the server and cannot be served.\n"); + conn.SendNow(HTTP_S.BuildResponse("412", "Fragment out of range")); + HTTP_R.Clean(); //clean for any possible next requests + std::cout << "Fragment @ " << (requestedTime / 10000) << " too old" << std::endl; + continue; + } + } + + sstream << "t " << myRef["trackid"].asInt() << "\n"; - sstream << "s " << (requestedTime / 10000) << "\no \n"; + sstream << "s " << (requestedTime / 10000) << "\np " << (mstime + mslen) <<"\n"; + std::cout << "Sending: " << sstream.str() << std::endl; ss.SendNow(sstream.str().c_str()); HTTP_S.Clean();