Made DTSC seeking functions more robust.

This commit is contained in:
Thulinma 2014-04-22 16:15:11 +02:00
parent 8fde3f5851
commit 60929d5014
2 changed files with 18 additions and 5 deletions

View file

@ -748,7 +748,7 @@ bool DTSC::File::reachedEOF(){
/// Reading the packet means the file position is increased to the next packet. /// Reading the packet means the file position is increased to the next packet.
void DTSC::File::seekNext(){ void DTSC::File::seekNext(){
if ( !currentPositions.size()){ if ( !currentPositions.size()){
DEBUG_MSG(DLVL_HIGH, "No seek positions set - returning empty packet."); DEBUG_MSG(DLVL_WARN, "No seek positions set - returning empty packet.");
myPack.null(); myPack.null();
return; return;
} }
@ -947,6 +947,12 @@ bool DTSC::File::seek_time(unsigned int ms, int trackNo, bool forceSeek){
tmpPos.seekTime = 0; tmpPos.seekTime = 0;
tmpPos.bytePos = 0; tmpPos.bytePos = 0;
} }
if (reachedEOF()){
clearerr(F);
seek_bpos(0);
tmpPos.bytePos = 0;
tmpPos.seekTime = 0;
}
DTSC::readOnlyTrack & trackRef = metadata.tracks[trackNo]; DTSC::readOnlyTrack & trackRef = metadata.tracks[trackNo];
for (unsigned int i = 0; i < trackRef.keyLen; i++){ for (unsigned int i = 0; i < trackRef.keyLen; i++){
long keyTime = trackRef.keys[i].getTime(); long keyTime = trackRef.keys[i].getTime();
@ -958,13 +964,11 @@ bool DTSC::File::seek_time(unsigned int ms, int trackNo, bool forceSeek){
tmpPos.bytePos = trackRef.keys[i].getBpos(); tmpPos.bytePos = trackRef.keys[i].getBpos();
} }
} }
if (reachedEOF()){
clearerr(F);
}
bool foundPacket = false; bool foundPacket = false;
while ( !foundPacket){ while ( !foundPacket){
lastreadpos = ftell(F); lastreadpos = ftell(F);
if (reachedEOF()){ if (reachedEOF()){
DEBUG_MSG(DLVL_WARN, "Reached EOF during seek to %u in track %d - aborting @ %lld", ms, trackNo, lastreadpos);
return false; return false;
} }
//Seek to first packet after ms. //Seek to first packet after ms.
@ -976,6 +980,11 @@ bool DTSC::File::seek_time(unsigned 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){
if (memcmp(header,"DT",2) != 0){
DEBUG_MSG(DLVL_WARN, "Invalid header during seek to %u in track %d @ %lld - resetting bytePos from %lld to zero", ms, trackNo, lastreadpos, tmpPos.bytePos);
tmpPos.bytePos = 0;
continue;
}
tmpPos.bytePos += 8 + packSize; tmpPos.bytePos += 8 + packSize;
continue; continue;
} }

View file

@ -65,7 +65,11 @@ namespace DTSC {
if (master && !rhs.master){ if (master && !rhs.master){
null(); null();
} }
if (rhs){
reInit(rhs.data, rhs.dataLen, !rhs.master); reInit(rhs.data, rhs.dataLen, !rhs.master);
}else{
null();
}
} }
/// Returns true if the packet is deemed valid, false otherwise. /// Returns true if the packet is deemed valid, false otherwise.