Tweaked buffer/player timings to prevent delays, almost-working smooth support.

This commit is contained in:
Thulinma 2013-07-24 13:25:38 +02:00
parent 4d3a500e66
commit 25c7f6f93d
3 changed files with 45 additions and 7 deletions

View file

@ -212,7 +212,10 @@ namespace Buffer {
}
while (buffer_running){
if (thisStream->getIPInput().connected()){
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){

View file

@ -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;

View file

@ -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();