mirror of
https://github.com/yawut/SDL.git
synced 2026-10-02 05:06:46 -05:00
Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
--HG-- branch : SDL-1.2
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
so if you want to see the original search for it on apple.com/developer
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
#include "SDL_endian.h"
|
||||
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
AudioFilePlayer.cpp
|
||||
@@ -78,7 +79,7 @@ static int AudioFilePlayer_SetDestination (AudioFilePlayer *afp, AudioUnit *inD
|
||||
/* we're going to use this to know which convert routine to call
|
||||
a v1 audio unit will have a type of 'aunt'
|
||||
a v2 audio unit will have one of several different types. */
|
||||
if (desc.componentType != kAudioUnitComponentType) {
|
||||
if (desc.componentType != kAudioUnitType_Output) {
|
||||
result = badComponentInstance;
|
||||
/*THROW_RESULT("BAD COMPONENT")*/
|
||||
if (result) return 0;
|
||||
@@ -175,7 +176,7 @@ static int AudioFilePlayer_Connect(AudioFilePlayer *afp)
|
||||
afp->mInputCallback.inputProcRefCon = afp->mAudioFileManager;
|
||||
|
||||
OSStatus result = AudioUnitSetProperty (afp->mPlayUnit,
|
||||
kAudioUnitProperty_SetInputCallback,
|
||||
kAudioUnitProperty_SetRenderCallback,
|
||||
kAudioUnitScope_Input,
|
||||
0,
|
||||
&afp->mInputCallback,
|
||||
@@ -215,7 +216,7 @@ static void AudioFilePlayer_Disconnect (AudioFilePlayer *afp)
|
||||
afp->mInputCallback.inputProc = 0;
|
||||
afp->mInputCallback.inputProcRefCon = 0;
|
||||
OSStatus result = AudioUnitSetProperty (afp->mPlayUnit,
|
||||
kAudioUnitProperty_SetInputCallback,
|
||||
kAudioUnitProperty_SetRenderCallback,
|
||||
kAudioUnitScope_Input,
|
||||
0,
|
||||
&afp->mInputCallback,
|
||||
@@ -254,12 +255,12 @@ static int AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef
|
||||
result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(chunkHeader), &chunkHeader, &actual);
|
||||
if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
|
||||
|
||||
if (chunkHeader.ckID != 'FORM') {
|
||||
if (SDL_SwapBE32(chunkHeader.ckID) != 'FORM') {
|
||||
result = -1;
|
||||
if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'");*/
|
||||
}
|
||||
|
||||
if (chunkHeader.formType != 'AIFC') {
|
||||
if (SDL_SwapBE32(chunkHeader.formType) != 'AIFC') {
|
||||
result = -1;
|
||||
if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'");*/
|
||||
}
|
||||
@@ -272,8 +273,11 @@ static int AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef
|
||||
offset = 0;
|
||||
do {
|
||||
result = FSReadFork(afp->mForkRefNum, fsFromMark, offset, sizeof(chunk), &chunk, &actual);
|
||||
if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
|
||||
|
||||
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');
|
||||
@@ -281,10 +285,12 @@ static int AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef
|
||||
/* 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")*/
|
||||
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")*/
|
||||
if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition")*/
|
||||
|
||||
/* Data size */
|
||||
*outFileDataSize = chunk.ckSize - ssndData.offset - 8;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
||||
#include <AudioUnit/AudioUnit.h>
|
||||
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
|
||||
#include <AudioUnit/AUNTComponent.h>
|
||||
#endif
|
||||
|
||||
@@ -82,7 +82,7 @@ typedef struct S_AudioFilePlayer
|
||||
AudioUnit mPlayUnit;
|
||||
SInt16 mForkRefNum;
|
||||
|
||||
AudioUnitInputCallback mInputCallback;
|
||||
AURenderCallbackStruct mInputCallback;
|
||||
|
||||
AudioStreamBasicDescription mFileDescription;
|
||||
|
||||
@@ -114,7 +114,7 @@ typedef struct S_AudioFileManager
|
||||
as it is called by the parent's Disconnect() method */
|
||||
void (*Disconnect)(struct S_AudioFileManager *afm);
|
||||
int (*DoConnect)(struct S_AudioFileManager *afm);
|
||||
OSStatus (*Read)(struct S_AudioFileManager *afm, char *buffer, UInt32 *len);
|
||||
OSStatus (*Read)(struct S_AudioFileManager *afm, char *buffer, ByteCount *len);
|
||||
const char* (*GetFileBuffer)(struct S_AudioFileManager *afm);
|
||||
const AudioFilePlayer *(*GetParent)(struct S_AudioFileManager *afm);
|
||||
void (*SetPosition)(struct S_AudioFileManager *afm, SInt64 pos); /* seek/rewind in the file */
|
||||
@@ -148,17 +148,18 @@ typedef struct S_AudioFileManager
|
||||
int mFinishedReadingData;
|
||||
|
||||
/*protected:*/
|
||||
OSStatus (*Render)(struct S_AudioFileManager *afm, AudioBuffer *ioData);
|
||||
OSStatus (*Render)(struct S_AudioFileManager *afm, AudioBufferList *ioData);
|
||||
OSStatus (*GetFileData)(struct S_AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize);
|
||||
void (*AfterRender)(struct S_AudioFileManager *afm);
|
||||
|
||||
/*public:*/
|
||||
/*static*/
|
||||
OSStatus (*FileInputProc)(void *inRefCon,
|
||||
AudioUnitRenderActionFlags inActionFlags,
|
||||
OSStatus (*FileInputProc)(void *inRefCon,
|
||||
AudioUnitRenderActionFlags *ioActionFlags,
|
||||
const AudioTimeStamp *inTimeStamp,
|
||||
UInt32 inBusNumber,
|
||||
AudioBuffer *ioData);
|
||||
UInt32 inNumberFrames,
|
||||
AudioBufferList *ioData);
|
||||
} AudioFileManager;
|
||||
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ static void *FileReaderThread_DiskReaderEntry (void *inRefCon)
|
||||
static void FileReaderThread_ReadNextChunk (FileReaderThread *frt)
|
||||
{
|
||||
OSStatus result;
|
||||
UInt32 dataChunkSize;
|
||||
ByteCount dataChunkSize;
|
||||
AudioFileManager* theItem = 0;
|
||||
|
||||
for (;;)
|
||||
@@ -380,7 +380,7 @@ static int AudioFileManager_DoConnect (AudioFileManager *afm)
|
||||
afm->mNumTimesAskedSinceFinished = 0;
|
||||
afm->mLockUnsuccessful = 0;
|
||||
|
||||
UInt32 dataChunkSize;
|
||||
ByteCount dataChunkSize;
|
||||
|
||||
if ((afm->mFileLength - afm->mReadFilePosition) < afm->mChunkSize)
|
||||
dataChunkSize = afm->mFileLength - afm->mReadFilePosition;
|
||||
@@ -415,7 +415,7 @@ static void AudioFileManager_Disconnect (AudioFileManager *afm)
|
||||
}
|
||||
}
|
||||
|
||||
static OSStatus AudioFileManager_Read(AudioFileManager *afm, char *buffer, UInt32 *len)
|
||||
static OSStatus AudioFileManager_Read(AudioFileManager *afm, char *buffer, ByteCount *len)
|
||||
{
|
||||
return FSReadFork (afm->mForkRefNum,
|
||||
fsFromStart,
|
||||
@@ -508,39 +508,44 @@ static int AudioFileManager_GetByteCounter(AudioFileManager *afm)
|
||||
return afm->mByteCounter;
|
||||
}
|
||||
|
||||
|
||||
static OSStatus AudioFileManager_FileInputProc (void *inRefCon,
|
||||
AudioUnitRenderActionFlags inActionFlags,
|
||||
const AudioTimeStamp *inTimeStamp,
|
||||
UInt32 inBusNumber,
|
||||
AudioBuffer *ioData)
|
||||
static OSStatus AudioFileManager_FileInputProc (void *inRefCon,
|
||||
AudioUnitRenderActionFlags *ioActionFlags,
|
||||
const AudioTimeStamp *inTimeStamp,
|
||||
UInt32 inBusNumber,
|
||||
UInt32 inNumberFrames,
|
||||
AudioBufferList *ioData)
|
||||
{
|
||||
AudioFileManager* afm = (AudioFileManager*)inRefCon;
|
||||
return afm->Render(afm, ioData);
|
||||
}
|
||||
|
||||
static OSStatus AudioFileManager_Render (AudioFileManager *afm, AudioBuffer *ioData)
|
||||
static OSStatus AudioFileManager_Render (AudioFileManager *afm, AudioBufferList *ioData)
|
||||
{
|
||||
OSStatus result = noErr;
|
||||
|
||||
if (afm->mBufferOffset >= afm->mBufferSize) {
|
||||
result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize);
|
||||
if (result) {
|
||||
SDL_SetError ("AudioConverterFillBuffer:%ld\n", result);
|
||||
afm->mParent->DoNotification(afm->mParent, result);
|
||||
return result;
|
||||
}
|
||||
AudioBuffer *abuf;
|
||||
UInt32 i;
|
||||
|
||||
afm->mBufferOffset = 0;
|
||||
}
|
||||
|
||||
if (ioData->mDataByteSize > afm->mBufferSize - afm->mBufferOffset)
|
||||
ioData->mDataByteSize = afm->mBufferSize - afm->mBufferOffset;
|
||||
ioData->mData = (char *)afm->mTmpBuffer + afm->mBufferOffset;
|
||||
afm->mBufferOffset += ioData->mDataByteSize;
|
||||
for (i = 0; i < ioData->mNumberBuffers; i++) {
|
||||
abuf = &ioData->mBuffers[i];
|
||||
if (afm->mBufferOffset >= afm->mBufferSize) {
|
||||
result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize);
|
||||
if (result) {
|
||||
SDL_SetError ("AudioConverterFillBuffer:%ld\n", result);
|
||||
afm->mParent->DoNotification(afm->mParent, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
afm->mBufferOffset = 0;
|
||||
}
|
||||
|
||||
if (abuf->mDataByteSize > afm->mBufferSize - afm->mBufferOffset)
|
||||
abuf->mDataByteSize = afm->mBufferSize - afm->mBufferOffset;
|
||||
abuf->mData = (char *)afm->mTmpBuffer + afm->mBufferOffset;
|
||||
afm->mBufferOffset += abuf->mDataByteSize;
|
||||
|
||||
afm->mByteCounter += ioData->mDataByteSize;
|
||||
afm->AfterRender(afm);
|
||||
afm->mByteCounter += abuf->mDataByteSize;
|
||||
afm->AfterRender(afm);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,28 +134,37 @@ int ReadTOCData (FSVolumeRefNum theVolume, SDL_CD *theCD)
|
||||
{
|
||||
HFSUniStr255 dataForkName;
|
||||
OSStatus theErr;
|
||||
SInt16 forkRefNum;
|
||||
FSIORefNum forkRefNum;
|
||||
SInt64 forkSize;
|
||||
Ptr forkData = 0;
|
||||
ByteCount actualRead;
|
||||
CFDataRef dataRef = 0;
|
||||
CFPropertyListRef propertyListRef = 0;
|
||||
|
||||
int i;
|
||||
FSRefParam fsRefPB;
|
||||
FSRef tocPlistFSRef;
|
||||
|
||||
FSRef rootRef;
|
||||
const char* error = "Unspecified Error";
|
||||
|
||||
/* get stuff from .TOC.plist */
|
||||
fsRefPB.ioCompletion = NULL;
|
||||
fsRefPB.ioNamePtr = "\p.TOC.plist";
|
||||
fsRefPB.ioVRefNum = theVolume;
|
||||
fsRefPB.ioDirID = 0;
|
||||
fsRefPB.newRef = &tocPlistFSRef;
|
||||
|
||||
theErr = PBMakeFSRefSync (&fsRefPB);
|
||||
const UniChar uniName[] = { '.','T','O','C','.','p','l','i','s','t' };
|
||||
|
||||
theErr = FSGetVolumeInfo(theVolume, 0, 0, kFSVolInfoNone, 0, 0, &rootRef);
|
||||
if(theErr != noErr) {
|
||||
error = "PBMakeFSRefSync";
|
||||
error = "FSGetVolumeInfo";
|
||||
goto bail;
|
||||
}
|
||||
|
||||
SDL_memset(&fsRefPB, '\0', sizeof (fsRefPB));
|
||||
|
||||
/* get stuff from .TOC.plist */
|
||||
fsRefPB.ref = &rootRef;
|
||||
fsRefPB.newRef = &tocPlistFSRef;
|
||||
fsRefPB.nameLength = sizeof (uniName) / sizeof (uniName[0]);
|
||||
fsRefPB.name = uniName;
|
||||
fsRefPB.textEncodingHint = kTextEncodingUnknown;
|
||||
|
||||
theErr = PBMakeFSRefUnicodeSync (&fsRefPB);
|
||||
if(theErr != noErr) {
|
||||
error = "PBMakeFSRefUnicodeSync";
|
||||
goto bail;
|
||||
}
|
||||
|
||||
@@ -551,9 +560,9 @@ static OSStatus CheckInit ()
|
||||
{ /*try {*/
|
||||
ComponentDescription desc;
|
||||
|
||||
desc.componentType = kAudioUnitComponentType;
|
||||
desc.componentSubType = kAudioUnitSubType_Output;
|
||||
desc.componentManufacturer = kAudioUnitID_DefaultOutput;
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
|
||||
|
||||
@@ -263,6 +263,14 @@ void SDL_SYS_CDQuit(void)
|
||||
/* Get the Unix disk name of the volume */
|
||||
static const char *SDL_SYS_CDName (int drive)
|
||||
{
|
||||
/*
|
||||
* !!! FIXME: PBHGetVolParmsSync() is gone in 10.6,
|
||||
* !!! FIXME: replaced with FSGetVolumeParms(), which
|
||||
* !!! FIXME: isn't available before 10.5. :/
|
||||
*/
|
||||
return "Mac OS X CD-ROM Device";
|
||||
|
||||
#if 0
|
||||
OSStatus err = noErr;
|
||||
HParamBlockRec pb;
|
||||
GetVolParmsInfoBuffer volParmsInfo;
|
||||
@@ -282,6 +290,7 @@ static const char *SDL_SYS_CDName (int drive)
|
||||
}
|
||||
|
||||
return volParmsInfo.vMDeviceID;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Open the "device" */
|
||||
|
||||
Reference in New Issue
Block a user