From 25300c48cd1bd134c72f152957f6592c9c10dff2 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 12 Jul 2012 23:33:27 +0200 Subject: [PATCH] player: faster seek termination detection Instead of hanging when the gap between two frames is larger than 100ms, terminate after 5 times of trying. --- src/player.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/player.cpp b/src/player.cpp index 4ba92b2e..84571ef1 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -76,8 +76,10 @@ namespace Player{ DTSC::Stream * tmpStream = new DTSC::Stream(1); unsigned long leftByte = 1, rightByte = fileSize; unsigned int leftMS = 0, rightMS = INT_MAX; + unsigned long foundRange = 0;//leftMS concatenated with rightMS + int lastOccurences = 0;//times that foundRange stayed the same during an iteration /// \todo set last packet as last byte, consider metadata - while (rightMS - leftMS >= 100 && leftMS + 100 <= miliseconds){ + while (lastOccurences < 5){//assume that we have found the position if the boundaries do not in 5 times std::string buffer; // binary search: pick the first packet on the right unsigned long medByte = leftByte + (rightByte - leftByte) / 2; @@ -112,6 +114,9 @@ namespace Player{ leftByte = medByte; leftMS = medMS; } + //concatenate leftMS with rightMS + unsigned long sum = ((unsigned long)leftMS << (CHAR_BIT * sizeof(leftMS))) | rightMS; + if (foundRange == sum){++lastOccurences;}else{foundRange = sum;lastOccurences = 0;} } seekDone: // clear the buffer and adjust file pointer