QTFile_FileControlBlock::~QTFile_FileControlBlock(void) { if( fDataBufferPool != NULL ) delete[] fDataBufferPool; #if DSS_USE_API_CALLBACKS (void)QTSS_CloseFileObject(fDataFD); #endif }
char* QTAccessFile::GetAccessFile_Copy( const char* movieRootDir, const char* dirPath) { OSMutexLocker locker(sAccessFileMutex); char* currentDir= NULL; char* lastSlash = NULL; int movieRootDirLen = ::strlen(movieRootDir); int maxLen = strlen(dirPath)+strlen(sQTAccessFileName) + strlen(kPathDelimiterString) + 1; currentDir = NEW char[maxLen]; ::strcpy(currentDir, dirPath); //strip off filename lastSlash = ::strrchr(currentDir, kPathDelimiterChar); if (lastSlash != NULL) lastSlash[0] = '\0'; //check qtaccess files while ( true ) //walk backward up the dir tree. { int curLen = strlen(currentDir) + strlen(sQTAccessFileName) + strlen(kPathDelimiterString); if ( curLen >= maxLen ) break; ::strcat(currentDir, kPathDelimiterString); ::strcat(currentDir, sQTAccessFileName); QTSS_Object fileObject = NULL; if( QTSS_OpenFileObject(currentDir, qtssOpenFileNoFlags, &fileObject) == QTSS_NoErr) { (void)QTSS_CloseFileObject(fileObject); return currentDir; } //strip off the "/qtaccess" lastSlash = ::strrchr(currentDir, kPathDelimiterChar); lastSlash[0] = '\0'; //strip of the tailing directory lastSlash = ::strrchr(currentDir, kPathDelimiterChar); if (lastSlash == NULL) break; else lastSlash[0] = '\0'; if ( (lastSlash-currentDir) < movieRootDirLen ) //bail if we start eating our way out of fMovieRootDir break; } delete[] currentDir; return NULL; }
RTPFileSession::ErrorCode RTPFile::Initialize(const StrPtrLen& inFilePath) { //OSFileSource theFile(inFilePath.Ptr); QTSS_Object theFile = NULL; QTSS_Error theErr = QTSS_OpenFileObject(inFilePath.Ptr, 0, &theFile); if (theErr != QTSS_NoErr) return RTPFileSession::errFileNotFound; // Copy the path. fFilePath.Ptr = NEW char[inFilePath.Len + 1]; ::memcpy(fFilePath.Ptr, inFilePath.Ptr, inFilePath.Len); fFilePath.Len = inFilePath.Len; // Setup our osref fRef.Set(fFilePath, this); // Read the header //OS_Error theErr = theFile.Read(&fHeader, sizeof(fHeader)); UInt32 theLengthRead = 0; theErr = QTSS_Read(theFile, &fHeader, sizeof(fHeader), &theLengthRead); Assert(theErr == QTSS_NoErr); Assert(theLengthRead == sizeof(fHeader)); // Read the SDP data fSDPData.Len = fHeader.fSDPLen; fSDPData.Ptr = NEW char[fSDPData.Len + 1]; //theErr = theFile.Read(fSDPData.Ptr, fSDPData.Len); theErr = QTSS_Read(theFile, fSDPData.Ptr, fSDPData.Len, &theLengthRead); Assert(theErr == QTSS_NoErr); Assert(theLengthRead == fSDPData.Len); // Parse the SDP Information fSourceInfo.Parse(fSDPData.Ptr, fSDPData.Len); // Read the track info fTrackInfo = NEW RTPFileTrackInfo[fHeader.fNumTracks]; //theErr = theFile.Read(fTrackInfo, sizeof(RTPFileTrackInfo) * fHeader.fNumTracks); theErr = QTSS_Read(theFile, fTrackInfo, sizeof(RTPFileTrackInfo) * fHeader.fNumTracks, &theLengthRead); Assert(theErr == QTSS_NoErr); Assert(theLengthRead == sizeof(RTPFileTrackInfo) * fHeader.fNumTracks); // Create and read the block map fBlockMap = NEW UInt8[fHeader.fBlockMapSize]; //theErr = theFile.Read(fBlockMap, fHeader.fBlockMapSize); theErr = QTSS_Read(theFile, fBlockMap, fHeader.fBlockMapSize, &theLengthRead); Assert(theErr == QTSS_NoErr); Assert(theLengthRead == fHeader.fBlockMapSize); // Calculate bit rate of all the tracks combined Float64 totalBytes = 0; for (UInt32 x = 0; x < fHeader.fNumTracks; x++) totalBytes += (Float64)fTrackInfo[x].fBytesInTrack; totalBytes /= fHeader.fMovieDuration; fBytesPerSecond = (UInt32)totalBytes; //Get the max track number fMaxTrackNumber = 0; for (UInt32 y = 0; y < fHeader.fNumTracks; y++) if (fTrackInfo[y].fID > fMaxTrackNumber) fMaxTrackNumber = fTrackInfo[y].fID; (void)QTSS_CloseFileObject(theFile); return RTPFileSession::errNoError; }
QTSS_Error QTSSModuleUtils::ReadEntireFile(char* inPath, StrPtrLen* outData, QTSS_TimeVal inModDate, QTSS_TimeVal* outModDate) { QTSS_Object theFileObject = NULL; QTSS_Error theErr = QTSS_NoErr; outData->Ptr = NULL; outData->Len = 0; do { // Use the QTSS file system API to read the file theErr = QTSS_OpenFileObject(inPath, 0, &theFileObject); if (theErr != QTSS_NoErr) break; UInt32 theParamLen = 0; QTSS_TimeVal* theModDate = NULL; theErr = QTSS_GetValuePtr(theFileObject, qtssFlObjModDate, 0, (void**)(void*)&theModDate, &theParamLen); Assert(theParamLen == sizeof(QTSS_TimeVal)); if(theParamLen != sizeof(QTSS_TimeVal)) break; if(outModDate != NULL) *outModDate = (QTSS_TimeVal)*theModDate; if(inModDate != -1) { // If file hasn't been modified since inModDate, don't have to read the file if(*theModDate <= inModDate) break; } theParamLen = 0; UInt64* theLength = NULL; theErr = QTSS_GetValuePtr(theFileObject, qtssFlObjLength, 0, (void**)(void*)&theLength, &theParamLen); if (theParamLen != sizeof(UInt64)) break; if (*theLength > kSInt32_Max) break; // Allocate memory for the file data outData->Ptr = NEW char[ (SInt32) (*theLength + 1) ]; outData->Len = (SInt32) *theLength; outData->Ptr[outData->Len] = 0; // Read the data UInt32 recvLen = 0; theErr = QTSS_Read(theFileObject, outData->Ptr, outData->Len, &recvLen); if (theErr != QTSS_NoErr) { outData->Delete(); break; } Assert(outData->Len == recvLen); }while(false); // Close the file if(theFileObject != NULL) { theErr = QTSS_CloseFileObject(theFileObject); } return theErr; }