From 892dfa4e389f71f84b2059fc1a22ebcb03971c0b Mon Sep 17 00:00:00 2001
From: Thulinma <jaron@vietors.com>
Date: Wed, 10 Jul 2013 12:29:18 +0200
Subject: [PATCH] Fixed MistPlayer CPU usage and benchmarking texts.
---
src/buffer/player.cpp | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/buffer/player.cpp b/src/buffer/player.cpp
index 6ed5533d..e6f2297e 100644
--- a/src/buffer/player.cpp
+++ b/src/buffer/player.cpp
@@ -112,7 +112,7 @@ int main(int argc, char** argv){
bool meta_sent = false;
int playUntil = -1;
- long long now = 0; //for timing of sending packets
+ long long now, lastTime = 0; //for timing of sending packets
long long bench = 0; //for benchmarking
std::set<int> newSelect;
Stats sts;
@@ -170,13 +170,16 @@ int main(int argc, char** argv){
case 's': { //second-seek
int ms = JSON::Value(in_out.Received().get().substr(2)).asInt();
bool ret = source.seek_time(ms);
+ lasttime = 0;
break;
}
case 'p': { //play
playing = -1;
+ lasttime = 0;
in_out.setBlocking(false);
if (in_out.Received().get().size() >= 2){
playUntil = atoi(in_out.Received().get().substr(2).c_str());
+ bench = Util::getMS();
}else{
playUntil = 0;
}
@@ -232,7 +235,14 @@ int main(int argc, char** argv){
--playing;
}
}
- if ( playUntil && playUntil <= source.getJSON()["time"].asInt()){
+ if (lastTime == 0){
+ lastTime = now - source.getJSON()["time"].asInt();
+ }
+ if (playing == -1 && playUntil == 0 && source.getJSON()["time"].asInt() > now - lastTime + 2500){
+ std::cerr << (source.getJSON()["time"].asInt() - (now - lastTime)) << " sleepytimes" << std::endl;
+ Util::sleep(source.getJSON()["time"].asInt() - (now - lastTime));
+ }
+ if ( playUntil && playUntil < source.getJSON()["time"].asInt()){
playing = 0;
}
if (playing == 0){