void RTPFileSession::ReadAndAdvise() { if (fReadBuffer == NULL) { // In some situations, callers of this function may not want the fDataBuffer // to be disturbed (see Seek()). If that's the case, the caller will set // fReadBuffer to NULL, and we must allocate it here fReadBuffer = NEW UInt8[fDataBufferSize]; } // Read the next block. There should always be at least one packet // here, as we have a valid block in the block table. #if RTPFILESESSIONDEBUG //qtss_printf("Moving onto next block. File loc: %qd\n",fFileSource.GetCurOffset()); #endif fDataBufferLen = 0; //(void)fFileSource.Read(fDataBuffer, fDataBufferSize, &fDataBufferLen); QTSS_Error theErr = QTSS_Read(fFileSource, fDataBuffer, fDataBufferSize, &fDataBufferLen); Assert(theErr == QTSS_NoErr); Assert(fDataBufferLen > sizeof(RTPFilePacket)); fCurrentPosition += fDataBufferLen; // Now do an advise for the next block, if this block isn't the last. if (fCurrentPosition < fFileLength) { Assert(fDataBufferLen == fDataBufferSize); //fFileSource.Advise(fFileSource.GetCurOffset(), fDataBufferSize); theErr = QTSS_Advise(fFileSource, fCurrentPosition, fDataBufferSize); } fReadBufferOffset = 0; fCurrentPacket = fDataBuffer; }
Bool16 QTFile_FileControlBlock::ReadInternal(FILE_SOURCE *dataFD, UInt64 inPosition, void* inBuffer, UInt32 inLength, UInt32 *inReadLenPtr) { UInt32 readLen = 0; if (NULL != inReadLenPtr) *inReadLenPtr = 0; #if DSS_USE_API_CALLBACKS QTSS_Error theErr = QTSS_Seek(*dataFD, inPosition); if (theErr == QTSS_NoErr) theErr = QTSS_Read(*dataFD, inBuffer, inLength, &readLen); if (theErr != QTSS_NoErr) return false; #else if( dataFD->Read(inPosition, inBuffer, inLength, &readLen) != OS_NoErr ) return false; #endif if (NULL != inReadLenPtr) *inReadLenPtr = readLen; if(inReadLenPtr == NULL && readLen != inLength) //external reads expect false if it fails to read all the requested data. return false; return true; }
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; }