Fixed a potential bug in DTSC::seekPos

This commit is contained in:
Erik Zandvliet 2013-08-27 16:00:07 +02:00
parent 6cf42561a6
commit 86a745dbfb
2 changed files with 12 additions and 12 deletions

View file

@ -731,7 +731,7 @@ void DTSC::File::seekNext(){
jsonbuffer.null(); jsonbuffer.null();
return; return;
} }
fseek(F,currentPositions.begin()->seekPos, SEEK_SET); fseek(F,currentPositions.begin()->bytePos, SEEK_SET);
if ( reachedEOF()){ if ( reachedEOF()){
strbuffer = ""; strbuffer = "";
jsonbuffer.null(); jsonbuffer.null();
@ -741,7 +741,7 @@ void DTSC::File::seekNext(){
if ( !metadata.isMember("merged") || !metadata["merged"]){ if ( !metadata.isMember("merged") || !metadata["merged"]){
seek_time(currentPositions.begin()->seekTime + 1, currentPositions.begin()->trackID); seek_time(currentPositions.begin()->seekTime + 1, currentPositions.begin()->trackID);
} }
fseek(F,currentPositions.begin()->seekPos, SEEK_SET); fseek(F,currentPositions.begin()->bytePos, SEEK_SET);
currentPositions.erase(currentPositions.begin()); currentPositions.erase(currentPositions.begin());
lastreadpos = ftell(F); lastreadpos = ftell(F);
if (fread(buffer, 4, 1, F) != 1){ if (fread(buffer, 4, 1, F) != 1){
@ -800,7 +800,7 @@ void DTSC::File::seekNext(){
if (fread((void*)newHeader, 20, 1, F) == 1){ if (fread((void*)newHeader, 20, 1, F) == 1){
if (memcmp(newHeader, DTSC::Magic_Packet2, 4) == 0){ if (memcmp(newHeader, DTSC::Magic_Packet2, 4) == 0){
seekPos tmpPos; seekPos tmpPos;
tmpPos.seekPos = tempLoc; tmpPos.bytePos = tempLoc;
tmpPos.trackID = ntohl(((int*)newHeader)[2]); tmpPos.trackID = ntohl(((int*)newHeader)[2]);
if (selectedTracks.find(tmpPos.trackID) != selectedTracks.end()){ if (selectedTracks.find(tmpPos.trackID) != selectedTracks.end()){
tmpPos.seekTime = ((long long unsigned int)ntohl(((int*)newHeader)[3])) << 32; tmpPos.seekTime = ((long long unsigned int)ntohl(((int*)newHeader)[3])) << 32;
@ -810,7 +810,7 @@ void DTSC::File::seekNext(){
for (JSON::ArrIter it = getTrackById(jsonbuffer["trackid"].asInt())["keys"].ArrBegin(); it != getTrackById(jsonbuffer["trackid"].asInt())["keys"].ArrEnd(); it++){ for (JSON::ArrIter it = getTrackById(jsonbuffer["trackid"].asInt())["keys"].ArrBegin(); it != getTrackById(jsonbuffer["trackid"].asInt())["keys"].ArrEnd(); it++){
if ((*it)["time"].asInt() > jsonbuffer["time"].asInt()){ if ((*it)["time"].asInt() > jsonbuffer["time"].asInt()){
tmpPos.seekTime = (*it)["time"].asInt(); tmpPos.seekTime = (*it)["time"].asInt();
tmpPos.seekPos = (*it)["bpos"].asInt(); tmpPos.bytePos = (*it)["bpos"].asInt();
tmpPos.trackID = jsonbuffer["trackid"].asInt(); tmpPos.trackID = jsonbuffer["trackid"].asInt();
break; break;
} }
@ -919,10 +919,10 @@ bool DTSC::File::seek_time(int ms, int trackNo, bool forceSeek){
tmpPos.trackID = trackNo; tmpPos.trackID = trackNo;
if (!forceSeek && jsonbuffer && ms > jsonbuffer["time"].asInt() && trackNo >= jsonbuffer["trackid"].asInt()){ if (!forceSeek && jsonbuffer && ms > jsonbuffer["time"].asInt() && trackNo >= jsonbuffer["trackid"].asInt()){
tmpPos.seekTime = jsonbuffer["time"].asInt(); tmpPos.seekTime = jsonbuffer["time"].asInt();
tmpPos.seekPos = getBytePos(); tmpPos.bytePos = getBytePos();
}else{ }else{
tmpPos.seekTime = 0; tmpPos.seekTime = 0;
tmpPos.seekPos = 0; tmpPos.bytePos = 0;
} }
for (JSON::ArrIter keyIt = metadata["tracks"][trackMapping[trackNo]]["keys"].ArrBegin(); keyIt != metadata["tracks"][trackMapping[trackNo]]["keys"].ArrEnd(); keyIt++){ for (JSON::ArrIter keyIt = metadata["tracks"][trackMapping[trackNo]]["keys"].ArrBegin(); keyIt != metadata["tracks"][trackMapping[trackNo]]["keys"].ArrEnd(); keyIt++){
if ((*keyIt)["time"].asInt() > ms){ if ((*keyIt)["time"].asInt() > ms){
@ -930,7 +930,7 @@ bool DTSC::File::seek_time(int ms, int trackNo, bool forceSeek){
} }
if ((*keyIt)["time"].asInt() > tmpPos.seekTime){ if ((*keyIt)["time"].asInt() > tmpPos.seekTime){
tmpPos.seekTime = (*keyIt)["time"].asInt(); tmpPos.seekTime = (*keyIt)["time"].asInt();
tmpPos.seekPos = (*keyIt)["bpos"].asInt(); tmpPos.bytePos = (*keyIt)["bpos"].asInt();
} }
} }
bool foundPacket = false; bool foundPacket = false;
@ -940,7 +940,7 @@ bool DTSC::File::seek_time(int ms, int trackNo, bool forceSeek){
return false; return false;
} }
//Seek to first packet after ms. //Seek to first packet after ms.
seek_bpos(tmpPos.seekPos); seek_bpos(tmpPos.bytePos);
//read the header //read the header
char header[20]; char header[20];
fread((void*)header, 20, 1, F); fread((void*)header, 20, 1, F);
@ -948,7 +948,7 @@ bool DTSC::File::seek_time(int ms, int trackNo, bool forceSeek){
int packSize = ntohl(((int*)header)[1]); int packSize = ntohl(((int*)header)[1]);
int packID = ntohl(((int*)header)[2]); int packID = ntohl(((int*)header)[2]);
if (memcmp(header,Magic_Packet2,4) != 0 || packID != trackNo){ if (memcmp(header,Magic_Packet2,4) != 0 || packID != trackNo){
tmpPos.seekPos += 8 + packSize; tmpPos.bytePos += 8 + packSize;
continue; continue;
} }
//get timestamp of packet, if too large, break, if not, skip size bytes. //get timestamp of packet, if too large, break, if not, skip size bytes.
@ -958,7 +958,7 @@ bool DTSC::File::seek_time(int ms, int trackNo, bool forceSeek){
if (myTime >= ms){ if (myTime >= ms){
foundPacket = true; foundPacket = true;
}else{ }else{
tmpPos.seekPos += 8 + packSize; tmpPos.bytePos += 8 + packSize;
continue; continue;
} }
} }

View file

@ -72,7 +72,7 @@ namespace DTSC {
return true; return true;
}else{ }else{
if (seekTime == rhs.seekTime){ if (seekTime == rhs.seekTime){
if (seekPos < rhs.seekPos){ if (bytePos < rhs.bytePos){
return true; return true;
}else{ }else{
if (trackID < rhs.trackID){ if (trackID < rhs.trackID){
@ -84,7 +84,7 @@ namespace DTSC {
return false; return false;
} }
long long unsigned int seekTime; long long unsigned int seekTime;
long long unsigned int seekPos; long long unsigned int bytePos;
unsigned int trackID; unsigned int trackID;
}; };