--- a/receiver/recplayer.cpp +++ b/receiver/recplayer.cpp @@ -97,13 +97,14 @@ int cRecordingPlayer::seek(off_t offset, } // finally, we can seek // TODO: binary search - for(index = 1; this->mLastOffsets[index]; index++){ + for(index = 1; index <= this->mLastFileNumber; index++){ if(this->mLastOffsets[index-1] <= offset && offset <= this->mLastOffsets[index]){ relativeOffset = offset - this->mLastOffsets[index-1]; break; } } - if(!(this->mCurrentFile = this->mRecordingFile->SetOffset(index, relativeOffset))){ + if(index > this->mLastFileNumber || + !(this->mCurrentFile = this->mRecordingFile->SetOffset(index, relativeOffset))){ // seeking failed!!! should never happen. this->mCurrentFile = this->mRecordingFile->SetOffset(1); return -1; @@ -115,9 +116,12 @@ int cRecordingPlayer::seek(off_t offset, void cRecordingPlayer::scanLastOffsets(){ // rewind this->mCurrentFile = this->mRecordingFile->SetOffset(1); - for(int i = 1; (this->mCurrentFile = this->mRecordingFile->NextFile()); i++){ + this->mLastOffsets[0] = 0; + this->mLastFileNumber = 1; + for(int i = 1; this->mCurrentFile; i++){ this->mLastOffsets[i] = this->mLastOffsets[i-1] + this->mCurrentFile->Seek(0, SEEK_END); this->mLastFileNumber = this->mRecordingFile->Number(); + this->mCurrentFile = this->mRecordingFile->NextFile(); } }