changeset 4190:386181851388 SDL-1.2

Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 12 Sep 2009 15:06:16 +0000
parents 95213cf5efcc
children caaa3cbf7b13
files src/cdrom/macosx/AudioFilePlayer.c src/cdrom/macosx/AudioFilePlayer.h src/cdrom/macosx/AudioFileReaderThread.c src/cdrom/macosx/CDPlayer.c src/cdrom/macosx/SDL_syscdrom.c
diffstat 5 files changed, 87 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/cdrom/macosx/AudioFilePlayer.c	Sat Sep 12 15:04:32 2009 +0000
+++ b/src/cdrom/macosx/AudioFilePlayer.c	Sat Sep 12 15:06:16 2009 +0000
@@ -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 @@
         /* 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 @@
         afp->mInputCallback.inputProcRefCon = afp->mAudioFileManager;
 
         OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, 
-                            kAudioUnitProperty_SetInputCallback, 
+                            kAudioUnitProperty_SetRenderCallback,
                             kAudioUnitScope_Input, 
                             0,
                             &afp->mInputCallback, 
@@ -215,7 +216,7 @@
         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 @@
     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 @@
     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 @@
     /* 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;
--- a/src/cdrom/macosx/AudioFilePlayer.h	Sat Sep 12 15:04:32 2009 +0000
+++ b/src/cdrom/macosx/AudioFilePlayer.h	Sat Sep 12 15:06:16 2009 +0000
@@ -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 @@
     AudioUnit                       mPlayUnit;
     SInt16                          mForkRefNum;
     
-    AudioUnitInputCallback          mInputCallback;
+    AURenderCallbackStruct          mInputCallback;
 
     AudioStreamBasicDescription     mFileDescription;
     
@@ -114,7 +114,7 @@
            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 @@
     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;
 
 
--- a/src/cdrom/macosx/AudioFileReaderThread.c	Sat Sep 12 15:04:32 2009 +0000
+++ b/src/cdrom/macosx/AudioFileReaderThread.c	Sat Sep 12 15:06:16 2009 +0000
@@ -245,7 +245,7 @@
 static void    FileReaderThread_ReadNextChunk (FileReaderThread *frt)
 {
     OSStatus result;
-    UInt32  dataChunkSize;
+    ByteCount dataChunkSize;
     AudioFileManager* theItem = 0;
 
     for (;;) 
@@ -380,7 +380,7 @@
         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 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 @@
     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;
 }
 
--- a/src/cdrom/macosx/CDPlayer.c	Sat Sep 12 15:04:32 2009 +0000
+++ b/src/cdrom/macosx/CDPlayer.c	Sat Sep 12 15:06:16 2009 +0000
@@ -134,28 +134,37 @@
 {
     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";
-    
+    const UniChar uniName[] = { '.','T','O','C','.','p','l','i','s','t' };
+
+    theErr = FSGetVolumeInfo(theVolume, 0, 0, kFSVolInfoNone, 0, 0, &rootRef);
+    if(theErr != noErr) {
+        error = "FSGetVolumeInfo";
+        goto bail;
+    }
+
+    SDL_memset(&fsRefPB, '\0', sizeof (fsRefPB));
+
     /* get stuff from .TOC.plist */
-    fsRefPB.ioCompletion = NULL;
-    fsRefPB.ioNamePtr = "\p.TOC.plist";
-    fsRefPB.ioVRefNum = theVolume;
-    fsRefPB.ioDirID = 0;
+    fsRefPB.ref = &rootRef;
     fsRefPB.newRef = &tocPlistFSRef;
-    
-    theErr = PBMakeFSRefSync (&fsRefPB);
+    fsRefPB.nameLength = sizeof (uniName) / sizeof (uniName[0]);
+    fsRefPB.name = uniName;
+    fsRefPB.textEncodingHint = kTextEncodingUnknown;
+
+    theErr = PBMakeFSRefUnicodeSync (&fsRefPB);
     if(theErr != noErr) {
-        error = "PBMakeFSRefSync";
+        error = "PBMakeFSRefUnicodeSync";
         goto bail;
     }
     
@@ -551,9 +560,9 @@
     { /*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;
         
--- a/src/cdrom/macosx/SDL_syscdrom.c	Sat Sep 12 15:04:32 2009 +0000
+++ b/src/cdrom/macosx/SDL_syscdrom.c	Sat Sep 12 15:06:16 2009 +0000
@@ -263,6 +263,14 @@
 /* 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 @@
     }
 
     return volParmsInfo.vMDeviceID;
+#endif
 }
 
 /* Open the "device" */