Exemplo n.º 1
0
static int ogg_seek_func(void *datasource, ogg_int64_t offset, int whence)
{
	imFileRef fp = static_cast<imFileRef>(datasource);
	
#ifdef PRWIN_ENV
	LARGE_INTEGER lpos;

	lpos.QuadPart = offset;

	DWORD method = ( whence == SEEK_SET ? FILE_BEGIN :
						whence == SEEK_CUR ? FILE_CURRENT :
						whence == SEEK_END ? FILE_END :
						FILE_CURRENT );

#if _MSC_VER < 1300
	DWORD pos = SetFilePointer(fp, lpos.u.LowPart, &lpos.u.HighPart, method);

	BOOL result = (pos != 0xFFFFFFFF || NO_ERROR == GetLastError());
#else
	BOOL result = SetFilePointerEx(fp, lpos, NULL, method);
#endif

	return (result ? OV_OK : OV_FALSE);
#else
	UInt16 positionMode = ( whence == SEEK_SET ? fsFromStart :
							whence == SEEK_CUR ? fsFromMark :
							whence == SEEK_END ? fsFromLEOF :
							fsFromMark );
	
	OSErr result = FSSetForkPosition(CAST_REFNUM(fp), positionMode, offset);

	return (result == noErr ? OV_OK : OV_FALSE);
#endif
}
Exemplo n.º 2
0
	XMP_Int64 LFA_Seek ( LFA_FileRef file, XMP_Int64 offset, int mode, bool * okPtr )
	{
		long refNum = (long)file;	// ! Use long to avoid size warnings for SInt16 cast.

		UInt16 posMode;
		switch ( mode ) {
			case SEEK_SET :
				posMode = fsFromStart;
				break;
			case SEEK_CUR :
				posMode = fsFromMark;
				break;
			case SEEK_END :
				posMode = fsFromLEOF;
				break;
			default :
				LFA_Throw ( "LFA_Seek: Invalid seek mode", kLFAErr_InternalFailure );
				break;
		}

		OSErr err;
		XMP_Int64 newPos;

		err = FSSetForkPosition ( refNum, posMode, offset );

		if ( err == eofErr ) {
			// FSSetForkPosition does not implicitly grow the file. Grow then seek to the new EOF.
			err = FSSetForkSize ( refNum, posMode, offset );
			if ( err == noErr ) err = FSSetForkPosition ( refNum, fsFromLEOF, 0 );
		}

		if ( err == noErr ) err = FSGetForkPosition ( refNum, &newPos );

		if ( okPtr != 0 ) {
			*okPtr = (err == noErr);
		} else {
			if ( err != noErr ) LFA_Throw ( "LFA_Seek: FSSetForkPosition failure", kLFAErr_ExternalFailure );
		}

		return newPos;

	}	// LFA_Seek
Exemplo n.º 3
0
void setPointerToAudioStart(
    ImporterLocalRec8H		ldataH,
    const PrAudioSample		startAudioPosition,
    imFileRef				SDKfileRef)
{
    csSDK_uint32		totalVideoFramesLu	= 0;
    csSDK_int64			bytesPerFrameLL		= 0,
                           videoOffsetLL		= 0;
    PrAudioSample		audioOffset			= 0;

#ifdef PRWIN_ENV
    csSDK_int32			tempErrorS			= 0;
    LARGE_INTEGER		distanceToMoveLI;
#else
    SInt64				distanceToMove;
#endif

    totalVideoFramesLu	= (*ldataH)->theFile.numFrames;
    if ((*ldataH)->theFile.hasVideo && totalVideoFramesLu > 0)
    {
        bytesPerFrameLL		= (*ldataH)->theFile.width * (*ldataH)->theFile.height *
                              GetPixelFormatSize((*ldataH)->theFile.videoSubtype);

        videoOffsetLL += totalVideoFramesLu * bytesPerFrameLL;

        // Take the extra bytes at the end of each frame into account
        videoOffsetLL += (PLUS_LINE_LENGTH * (totalVideoFramesLu));
    }

    audioOffset = startAudioPosition * AUDIO_SAMPLE_SIZE;

#ifdef PRWIN_ENV
    distanceToMoveLI.QuadPart = sizeof(SDK_File) + videoOffsetLL + audioOffset;
    tempErrorS = SetFilePointerEx(SDKfileRef,
                                  distanceToMoveLI,
                                  NULL,
                                  FILE_BEGIN);

    if (tempErrorS == INVALID_SET_FILE_POINTER)
    {
        GetLastError ();
    }
#else
    distanceToMove = sizeof(SDK_File) + videoOffsetLL + audioOffset;
    FSSetForkPosition (	reinterpret_cast<intptr_t>(SDKfileRef),
                        fsFromStart,
                        distanceToMove);
#endif
}
Exemplo n.º 4
0
void
XMLMacCarbonFile::reset()
{
    OSErr err = noErr;

    if (!mFileValid)
        ThrowXML(XMLPlatformUtilsException, XMLExcepts::File_CouldNotResetFile);

    if (gHasHFSPlusAPIs)
        err = FSSetForkPosition(mFileRefNum, fsFromStart, 0);
    else
        err = SetFPos(mFileRefNum, fsFromStart, 0);

    if (err != noErr)
        ThrowXML(XMLPlatformUtilsException, XMLExcepts::File_CouldNotResetFile);
}
void
IStreamPr::seekg(Imf::Int64 pos)
{
#ifdef __APPLE__
	OSErr result = FSSetForkPosition(reinterpret_cast<intptr_t>(_fileRef), fsFromStart, pos);

	if(result != noErr)
		throw Iex::IoExc("Error calling FSSetForkPosition().");
#else
	LARGE_INTEGER lpos, out;

	lpos.QuadPart = pos;

	BOOL result = SetFilePointerEx(_fileRef, lpos, &out, FILE_BEGIN);

	if(!result || lpos.QuadPart != out.QuadPart)
		throw Iex::IoExc("Error calling SetFilePointerEx().");
#endif
}
static PyObject *
rf_seek(rfobject *self, PyObject *args)
{
    long amount;
    int whence = SEEK_SET;
    int mode;
    OSErr err;

    if (self->isclosed) {
        PyErr_SetString(PyExc_ValueError, "Operation on closed file");
        return NULL;
    }
    if (!PyArg_ParseTuple(args, "l|i", &amount, &whence)) {
        return NULL;
    }

    switch (whence) {
    case SEEK_CUR:
        mode = fsFromMark;
        break;
    case SEEK_END:
        mode = fsFromLEOF;
        break;
    case SEEK_SET:
        mode = fsFromStart;
        break;
    default:
        PyErr_BadArgument();
        return NULL;
    }

    err = FSSetForkPosition(self->fRefNum, mode, amount);
    if (err != noErr) {
        PyMac_Error(err);
        return NULL;
    }
    Py_INCREF(Py_None);
    return Py_None;
}
Exemplo n.º 7
0
AP4_Result
My_ByteStream::Seek(AP4_Position position)
{
#ifdef PRWIN_ENV
	LARGE_INTEGER lpos;

	lpos.QuadPart = position;

#if _MSC_VER < 1300
	DWORD pos = SetFilePointer(_fp, lpos.u.LowPart, &lpos.u.HighPart, FILE_BEGIN);

	BOOL result = (pos != 0xFFFFFFFF || NO_ERROR == GetLastError());
#else
	BOOL result = SetFilePointerEx(_fp, lpos, NULL, FILE_BEGIN);
#endif

	return (result ? AP4_SUCCESS : AP4_FAILURE);
#else
	OSErr result = FSSetForkPosition(CAST_REFNUM(_fp), fsFromStart, position);

	return (result == noErr ? AP4_SUCCESS : AP4_FAILURE);
#endif
}
Exemplo n.º 8
0
OSErr PSSDKSetFPos(int32 refNum, short posMode, long posOff)
{
	OSErr err = FSSetForkPosition(refNum, posMode, posOff);
	return err;
}
Exemplo n.º 9
0
static int    AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileDataSize)
{
    ContainerChunk chunkHeader;
    ChunkHeader chunk;
    SSNDData ssndData;

    OSErr result;
    HFSUniStr255 dfName;
    ByteCount actual;
    SInt64 offset;

    /* Open the data fork of the input file */
    result = FSGetDataForkName(&dfName);
       if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSGetDataForkName")*/

    result = FSOpenFork(inRef, dfName.length, dfName.unicode, fsRdPerm, &afp->mForkRefNum);
       if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSOpenFork")*/
 
    /* Read the file header, and check if it's indeed an AIFC file */
    result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(chunkHeader), &chunkHeader, &actual);
       if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/

    if (SDL_SwapBE32(chunkHeader.ckID) != 'FORM') {
        result = -1;
        if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'");*/
    }

    if (SDL_SwapBE32(chunkHeader.formType) != 'AIFC') {
        result = -1;
        if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'");*/
    }

    /* Search for the SSND chunk. We ignore all compression etc. information
       in other chunks. Of course that is kind of evil, but for now we are lazy
       and rely on the cdfs to always give us the same fixed format.
       TODO: Parse the COMM chunk we currently skip to fill in mFileDescription.
    */
    offset = 0;
    do {
        result = FSReadFork(afp->mForkRefNum, fsFromMark, offset, sizeof(chunk), &chunk, &actual);
        if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/

        chunk.ckID = SDL_SwapBE32(chunk.ckID);
        chunk.ckSize = SDL_SwapBE32(chunk.ckSize);

        /* Skip the chunk data */
        offset = chunk.ckSize;
    } while (chunk.ckID != 'SSND');

    /* Read the header of the SSND chunk. After this, we are positioned right
       at the start of the audio data. */
    result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(ssndData), &ssndData, &actual);
    if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/

    ssndData.offset = SDL_SwapBE32(ssndData.offset);

    result = FSSetForkPosition(afp->mForkRefNum, fsFromMark, ssndData.offset);
    if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition")*/

    /* Data size */
    *outFileDataSize = chunk.ckSize - ssndData.offset - 8;

    /* File format */
    afp->mFileDescription.mSampleRate = 44100;
    afp->mFileDescription.mFormatID = kAudioFormatLinearPCM;
    afp->mFileDescription.mFormatFlags = kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger;
    afp->mFileDescription.mBytesPerPacket = 4;
    afp->mFileDescription.mFramesPerPacket = 1;
    afp->mFileDescription.mBytesPerFrame = 4;
    afp->mFileDescription.mChannelsPerFrame = 2;
    afp->mFileDescription.mBitsPerChannel = 16;

    return 1;
}
Exemplo n.º 10
0
prMALError readAudioToBuffer (	const PrAudioSample	numAudioFrames,
                                const PrAudioSample	totalSampleFrames,
                                const csSDK_int32	numAudioChannels,
                                imFileRef			SDKfileRef,
                                float **			audioBuffer)
{
    prMALError			result				= malNoError;
    csSDK_uint32		bytesReadLu			= 0;

#ifdef PRWIN_ENV
    csSDK_int32			didReadL			= 0;
    csSDK_int32			tempErrorS			= 0;
    LARGE_INTEGER		distanceToMoveLI;
#else
    SInt64				distanceToMove;
#endif

    // Read all channels into their respective buffers
    for (csSDK_int32 bufferIndexL = 0; bufferIndexL < numAudioChannels; bufferIndexL++)
    {
#ifdef PRWIN_ENV
        didReadL = ReadFile(SDKfileRef,
                            audioBuffer[bufferIndexL],
                            static_cast<csSDK_int32>(numAudioFrames) * AUDIO_SAMPLE_SIZE,
                            reinterpret_cast<LPDWORD>(&bytesReadLu),
                            NULL);
        if (!didReadL)
        {
            return imBadFile;
        }

#else
        result = FSReadFork(reinterpret_cast<intptr_t>(SDKfileRef),
                            fsAtMark,
                            0,
                            numAudioFrames * AUDIO_SAMPLE_SIZE,
                            audioBuffer[bufferIndexL],
                            reinterpret_cast<ByteCount*>(&bytesReadLu));
        if (result)
        {
            return imBadFile;
        }
#endif

        // Move file pointer to next audio channel
#ifdef PRWIN_ENV
        distanceToMoveLI.QuadPart = (totalSampleFrames - numAudioFrames) * AUDIO_SAMPLE_SIZE;
        tempErrorS = SetFilePointerEx(	SDKfileRef,
                                        distanceToMoveLI,
                                        NULL,
                                        FILE_CURRENT);

        if (tempErrorS == INVALID_SET_FILE_POINTER)
        {
            GetLastError ();
        }
#else
        distanceToMove = (totalSampleFrames - numAudioFrames) * AUDIO_SAMPLE_SIZE;
        result = FSSetForkPosition(	reinterpret_cast<intptr_t>(SDKfileRef),
                                    fsFromMark,
                                    distanceToMove);
#endif
    }

    return result;
}