src/cdrom/macosx/CDPlayer.c
changeset 1487 dc6b59e925a2
parent 1402 d910939febfa
child 1662 782fd950bd46
child 1895 c121d94672cb
child 4159 a1b03ba2fcd0
equal deleted inserted replaced
1486:9d77fc9d0ace 1487:dc6b59e925a2
    23 
    23 
    24 #include "CDPlayer.h"
    24 #include "CDPlayer.h"
    25 #include "AudioFilePlayer.h"
    25 #include "AudioFilePlayer.h"
    26 #include "SDLOSXCAGuard.h"
    26 #include "SDLOSXCAGuard.h"
    27 
    27 
    28 // we're exporting these functions into C land for SDL_syscdrom.c
    28 /* we're exporting these functions into C land for SDL_syscdrom.c */
    29 //extern "C" {
    29 /*extern "C" {*/
    30 
    30 
    31 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
    31 /*///////////////////////////////////////////////////////////////////////////
    32 //  Constants
    32     Constants
    33 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
    33   //////////////////////////////////////////////////////////////////////////*/
    34 
    34 
    35 #define kAudioCDFilesystemID   (UInt16)(('J' << 8) | 'H') // 'JH'; this avoids compiler warning
    35 #define kAudioCDFilesystemID   (UInt16)(('J' << 8) | 'H') /* 'JH'; this avoids compiler warning */
    36 
    36 
    37 // XML PList keys
    37 /* XML PList keys */
    38 #define kRawTOCDataString           "Format 0x02 TOC Data"
    38 #define kRawTOCDataString           "Format 0x02 TOC Data"
    39 #define kSessionsString             "Sessions"
    39 #define kSessionsString             "Sessions"
    40 #define kSessionTypeString          "Session Type"
    40 #define kSessionTypeString          "Session Type"
    41 #define kTrackArrayString           "Track Array"
    41 #define kTrackArrayString           "Track Array"
    42 #define kFirstTrackInSessionString      "First Track"
    42 #define kFirstTrackInSessionString      "First Track"
    45 #define kDataKeyString              "Data"
    45 #define kDataKeyString              "Data"
    46 #define kPointKeyString             "Point"
    46 #define kPointKeyString             "Point"
    47 #define kSessionNumberKeyString         "Session Number"
    47 #define kSessionNumberKeyString         "Session Number"
    48 #define kStartBlockKeyString            "Start Block"   
    48 #define kStartBlockKeyString            "Start Block"   
    49     
    49     
    50 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
    50 /*///////////////////////////////////////////////////////////////////////////
    51 //  Globals
    51     Globals
    52 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
    52   //////////////////////////////////////////////////////////////////////////*/
    53 
    53 
    54 #pragma mark -- Globals --
    54 #pragma mark -- Globals --
    55 
    55 
    56 static int             playBackWasInit = 0;
    56 static int             playBackWasInit = 0;
    57 static AudioUnit        theUnit;
    57 static AudioUnit        theUnit;
    59 static CDPlayerCompletionProc   completionProc = NULL;
    59 static CDPlayerCompletionProc   completionProc = NULL;
    60 static SDL_mutex       *apiMutex = NULL;
    60 static SDL_mutex       *apiMutex = NULL;
    61 static SDL_sem         *callbackSem;
    61 static SDL_sem         *callbackSem;
    62 static SDL_CD*          theCDROM;
    62 static SDL_CD*          theCDROM;
    63 
    63 
    64 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
    64 /*///////////////////////////////////////////////////////////////////////////
    65 //  Prototypes
    65     Prototypes
    66 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
    66   //////////////////////////////////////////////////////////////////////////*/
    67 
    67 
    68 #pragma mark -- Prototypes --
    68 #pragma mark -- Prototypes --
    69 
    69 
    70 static OSStatus CheckInit ();
    70 static OSStatus CheckInit ();
    71 
    71 
    86 
    86 
    87 void     Unlock ()
    87 void     Unlock ()
    88 {
    88 {
    89     SDL_mutexV(apiMutex);
    89     SDL_mutexV(apiMutex);
    90 }
    90 }
    91 
       
    92 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
    93 //  DetectAudioCDVolumes
       
    94 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
    95 
    91 
    96 int DetectAudioCDVolumes(FSVolumeRefNum *volumes, int numVolumes)
    92 int DetectAudioCDVolumes(FSVolumeRefNum *volumes, int numVolumes)
    97 {
    93 {
    98     int volumeIndex;
    94     int volumeIndex;
    99     int cdVolumeCount = 0;
    95     int cdVolumeCount = 0;
   114                                   NULL,
   110                                   NULL,
   115                                   NULL); 
   111                                   NULL); 
   116          
   112          
   117         if (result == noErr)
   113         if (result == noErr)
   118         {
   114         {
   119             if (volumeInfo.filesystemID == kAudioCDFilesystemID) // It's an audio CD
   115             if (volumeInfo.filesystemID == kAudioCDFilesystemID) /* It's an audio CD */
   120             {
   116             {
   121                 if (volumes != NULL && cdVolumeCount < numVolumes)
   117                 if (volumes != NULL && cdVolumeCount < numVolumes)
   122                     volumes[cdVolumeCount] = actualVolume;
   118                     volumes[cdVolumeCount] = actualVolume;
   123             
   119             
   124                 cdVolumeCount++;
   120                 cdVolumeCount++;
   125             }
   121             }
   126         }
   122         }
   127         else 
   123         else 
   128         {
   124         {
   129             // I'm commenting this out because it seems to be harmless
   125             /* I'm commenting this out because it seems to be harmless */
   130             //SDL_SetError ("DetectAudioCDVolumes: FSGetVolumeInfo returned %d", result);
   126             /*SDL_SetError ("DetectAudioCDVolumes: FSGetVolumeInfo returned %d", result);*/
   131         }
   127         }
   132     }
   128     }
   133         
   129         
   134     return cdVolumeCount;
   130     return cdVolumeCount;
   135 }
   131 }
   136 
       
   137 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   138 //  ReadTOCData
       
   139 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   140 
   132 
   141 int ReadTOCData (FSVolumeRefNum theVolume, SDL_CD *theCD)
   133 int ReadTOCData (FSVolumeRefNum theVolume, SDL_CD *theCD)
   142 {
   134 {
   143     HFSUniStr255      dataForkName;
   135     HFSUniStr255      dataForkName;
   144     OSStatus          theErr;
   136     OSStatus          theErr;
   152     FSRefParam      fsRefPB;
   144     FSRefParam      fsRefPB;
   153     FSRef           tocPlistFSRef;
   145     FSRef           tocPlistFSRef;
   154     
   146     
   155     const char* error = "Unspecified Error";
   147     const char* error = "Unspecified Error";
   156     
   148     
   157     // get stuff from .TOC.plist                                                   
   149     /* get stuff from .TOC.plist */
   158     fsRefPB.ioCompletion = NULL;
   150     fsRefPB.ioCompletion = NULL;
   159     fsRefPB.ioNamePtr = "\p.TOC.plist";
   151     fsRefPB.ioNamePtr = "\p.TOC.plist";
   160     fsRefPB.ioVRefNum = theVolume;
   152     fsRefPB.ioVRefNum = theVolume;
   161     fsRefPB.ioDirID = 0;
   153     fsRefPB.ioDirID = 0;
   162     fsRefPB.newRef = &tocPlistFSRef;
   154     fsRefPB.newRef = &tocPlistFSRef;
   165     if(theErr != noErr) {
   157     if(theErr != noErr) {
   166         error = "PBMakeFSRefSync";
   158         error = "PBMakeFSRefSync";
   167         goto bail;
   159         goto bail;
   168     }
   160     }
   169     
   161     
   170     // Load and parse the TOC XML data
   162     /* Load and parse the TOC XML data */
   171 
   163 
   172     theErr = FSGetDataForkName (&dataForkName);
   164     theErr = FSGetDataForkName (&dataForkName);
   173     if (theErr != noErr) {
   165     if (theErr != noErr) {
   174         error = "FSGetDataForkName";
   166         error = "FSGetDataForkName";
   175         goto bail;
   167         goto bail;
   185     if (theErr != noErr) {
   177     if (theErr != noErr) {
   186         error = "FSGetForkSize";
   178         error = "FSGetForkSize";
   187         goto bail;
   179         goto bail;
   188     }
   180     }
   189     
   181     
   190     // Allocate some memory for the XML data
   182     /* Allocate some memory for the XML data */
   191     forkData = NewPtr (forkSize);
   183     forkData = NewPtr (forkSize);
   192     if(forkData == NULL) {
   184     if(forkData == NULL) {
   193         error = "NewPtr";
   185         error = "NewPtr";
   194         goto bail;
   186         goto bail;
   195     }
   187     }
   213     if (propertyListRef == NULL) {
   205     if (propertyListRef == NULL) {
   214         error = "CFPropertyListCreateFromXMLData";
   206         error = "CFPropertyListCreateFromXMLData";
   215         goto bail;
   207         goto bail;
   216     }
   208     }
   217 
   209 
   218     // Now we got the Property List in memory. Parse it.
   210     /* Now we got the Property List in memory. Parse it. */
   219     
   211     
   220     // First, make sure the root item is a CFDictionary. If not, release and bail.
   212     /* First, make sure the root item is a CFDictionary. If not, release and bail. */
   221     if(CFGetTypeID(propertyListRef)== CFDictionaryGetTypeID())
   213     if(CFGetTypeID(propertyListRef)== CFDictionaryGetTypeID())
   222     {
   214     {
   223         CFDictionaryRef dictRef = (CFDictionaryRef)propertyListRef;
   215         CFDictionaryRef dictRef = (CFDictionaryRef)propertyListRef;
   224         
   216         
   225         CFDataRef   theRawTOCDataRef;
   217         CFDataRef   theRawTOCDataRef;
   226         CFArrayRef  theSessionArrayRef;
   218         CFArrayRef  theSessionArrayRef;
   227         CFIndex     numSessions;
   219         CFIndex     numSessions;
   228         CFIndex     index;
   220         CFIndex     index;
   229         
   221         
   230         // This is how we get the Raw TOC Data
   222         /* This is how we get the Raw TOC Data */
   231         theRawTOCDataRef = (CFDataRef)CFDictionaryGetValue (dictRef, CFSTR(kRawTOCDataString));
   223         theRawTOCDataRef = (CFDataRef)CFDictionaryGetValue (dictRef, CFSTR(kRawTOCDataString));
   232         
   224         
   233         // Get the session array info.
   225         /* Get the session array info. */
   234         theSessionArrayRef = (CFArrayRef)CFDictionaryGetValue (dictRef, CFSTR(kSessionsString));
   226         theSessionArrayRef = (CFArrayRef)CFDictionaryGetValue (dictRef, CFSTR(kSessionsString));
   235         
   227         
   236         // Find out how many sessions there are.
   228         /* Find out how many sessions there are. */
   237         numSessions = CFArrayGetCount (theSessionArrayRef);
   229         numSessions = CFArrayGetCount (theSessionArrayRef);
   238         
   230         
   239         // Initialize the total number of tracks to 0
   231         /* Initialize the total number of tracks to 0 */
   240         theCD->numtracks = 0;
   232         theCD->numtracks = 0;
   241         
   233         
   242         // Iterate over all sessions, collecting the track data
   234         /* Iterate over all sessions, collecting the track data */
   243         for(index = 0; index < numSessions; index++)
   235         for(index = 0; index < numSessions; index++)
   244         {
   236         {
   245             CFDictionaryRef theSessionDict;
   237             CFDictionaryRef theSessionDict;
   246             CFNumberRef     leadoutBlock;
   238             CFNumberRef     leadoutBlock;
   247             CFArrayRef      trackArray;
   239             CFArrayRef      trackArray;
   270                 trackNumber   = (CFNumberRef)  CFDictionaryGetValue (theTrackDict, CFSTR(kPointKeyString));
   262                 trackNumber   = (CFNumberRef)  CFDictionaryGetValue (theTrackDict, CFSTR(kPointKeyString));
   271                 sessionNumber = (CFNumberRef)  CFDictionaryGetValue (theTrackDict, CFSTR(kSessionNumberKeyString));
   263                 sessionNumber = (CFNumberRef)  CFDictionaryGetValue (theTrackDict, CFSTR(kSessionNumberKeyString));
   272                 startBlock    = (CFNumberRef)  CFDictionaryGetValue (theTrackDict, CFSTR(kStartBlockKeyString));
   264                 startBlock    = (CFNumberRef)  CFDictionaryGetValue (theTrackDict, CFSTR(kStartBlockKeyString));
   273                 isDataTrack   = (CFBooleanRef) CFDictionaryGetValue (theTrackDict, CFSTR(kDataKeyString));
   265                 isDataTrack   = (CFBooleanRef) CFDictionaryGetValue (theTrackDict, CFSTR(kDataKeyString));
   274                                                         
   266                                                         
   275                 // Fill in the SDL_CD struct
   267                 /* Fill in the SDL_CD struct */
   276                 int idx = theCD->numtracks++;
   268                 int idx = theCD->numtracks++;
   277 
   269 
   278                 CFNumberGetValue (trackNumber, kCFNumberSInt32Type, &value);
   270                 CFNumberGetValue (trackNumber, kCFNumberSInt32Type, &value);
   279                 theCD->track[idx].id = value;
   271                 theCD->track[idx].id = value;
   280                 
   272                 
   281                 CFNumberGetValue (startBlock, kCFNumberSInt32Type, &value);
   273                 CFNumberGetValue (startBlock, kCFNumberSInt32Type, &value);
   282                 theCD->track[idx].offset = value;
   274                 theCD->track[idx].offset = value;
   283 
   275 
   284                 theCD->track[idx].type = (isDataTrack == kCFBooleanTrue) ? SDL_DATA_TRACK : SDL_AUDIO_TRACK;
   276                 theCD->track[idx].type = (isDataTrack == kCFBooleanTrue) ? SDL_DATA_TRACK : SDL_AUDIO_TRACK;
   285 
   277 
   286                 // Since the track lengths are not stored in .TOC.plist we compute them.
   278                 /* Since the track lengths are not stored in .TOC.plist we compute them. */
   287                 if (trackIndex > 0) {
   279                 if (trackIndex > 0) {
   288                     theCD->track[idx-1].length = theCD->track[idx].offset - theCD->track[idx-1].offset;
   280                     theCD->track[idx-1].length = theCD->track[idx].offset - theCD->track[idx-1].offset;
   289                 }
   281                 }
   290             }
   282             }
   291             
   283             
   292             // Compute the length of the last track
   284             /* Compute the length of the last track */
   293             CFNumberGetValue (leadoutBlock, kCFNumberSInt32Type, &value);
   285             CFNumberGetValue (leadoutBlock, kCFNumberSInt32Type, &value);
   294             
   286             
   295             theCD->track[theCD->numtracks-1].length = 
   287             theCD->track[theCD->numtracks-1].length = 
   296                 value - theCD->track[theCD->numtracks-1].offset;
   288                 value - theCD->track[theCD->numtracks-1].offset;
   297 
   289 
   298             // Set offset to leadout track
   290             /* Set offset to leadout track */
   299             theCD->track[theCD->numtracks].offset = value;
   291             theCD->track[theCD->numtracks].offset = value;
   300         }
   292         }
   301     
   293     
   302     }
   294     }
   303 
   295 
   317         
   309         
   318     FSCloseFork (forkRefNum);
   310     FSCloseFork (forkRefNum);
   319 
   311 
   320     return theErr;
   312     return theErr;
   321 }
   313 }
   322 
       
   323 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   324 //  ListTrackFiles
       
   325 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   326 
   314 
   327 int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks)
   315 int ListTrackFiles (FSVolumeRefNum theVolume, FSRef *trackFiles, int numTracks)
   328 {
   316 {
   329     OSStatus        result = -1;
   317     OSStatus        result = -1;
   330     FSIterator      iterator;
   318     FSIterator      iterator;
   355             if (result == noErr) {
   343             if (result == noErr) {
   356                 
   344                 
   357                 CFStringRef  name;
   345                 CFStringRef  name;
   358                 name = CFStringCreateWithCharacters (NULL, nameStr.unicode, nameStr.length);
   346                 name = CFStringCreateWithCharacters (NULL, nameStr.unicode, nameStr.length);
   359                 
   347                 
   360                 // Look for .aiff extension
   348                 /* Look for .aiff extension */
   361                 if (CFStringHasSuffix (name, CFSTR(".aiff")) ||
   349                 if (CFStringHasSuffix (name, CFSTR(".aiff")) ||
   362                     CFStringHasSuffix (name, CFSTR(".cdda"))) {
   350                     CFStringHasSuffix (name, CFSTR(".cdda"))) {
   363                     
   351                     
   364                     // Extract the track id from the filename
   352                     /* Extract the track id from the filename */
   365                     int trackID = 0, i = 0;
   353                     int trackID = 0, i = 0;
   366                     while (i < nameStr.length && !isdigit(nameStr.unicode[i])) {
   354                     while (i < nameStr.length && !isdigit(nameStr.unicode[i])) {
   367                         ++i;
   355                         ++i;
   368                     }
   356                     }
   369                     while (i < nameStr.length && isdigit(nameStr.unicode[i])) {
   357                     while (i < nameStr.length && isdigit(nameStr.unicode[i])) {
   374                     #if DEBUG_CDROM
   362                     #if DEBUG_CDROM
   375                     printf("Found AIFF for track %d: '%s'\n", trackID, 
   363                     printf("Found AIFF for track %d: '%s'\n", trackID, 
   376                     CFStringGetCStringPtr (name, CFStringGetSystemEncoding()));
   364                     CFStringGetCStringPtr (name, CFStringGetSystemEncoding()));
   377                     #endif
   365                     #endif
   378                     
   366                     
   379                     // Track ID's start at 1, but we want to start at 0
   367                     /* Track ID's start at 1, but we want to start at 0 */
   380                     trackID--;
   368                     trackID--;
   381                     
   369                     
   382                     assert(0 <= trackID && trackID <= SDL_MAX_TRACKS);
   370                     assert(0 <= trackID && trackID <= SDL_MAX_TRACKS);
   383                     
   371                     
   384                     if (trackID < numTracks)
   372                     if (trackID < numTracks)
   391     }
   379     }
   392     
   380     
   393     return 0;
   381     return 0;
   394 }
   382 }
   395 
   383 
   396 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   397 //  LoadFile
       
   398 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   399 
       
   400 int LoadFile (const FSRef *ref, int startFrame, int stopFrame)
   384 int LoadFile (const FSRef *ref, int startFrame, int stopFrame)
   401 {
   385 {
   402     int error = -1;
   386     int error = -1;
   403     
   387     
   404     if (CheckInit () < 0)
   388     if (CheckInit () < 0)
   405         goto bail;
   389         goto bail;
   406     
   390     
   407     // release any currently playing file
   391     /* release any currently playing file */
   408     if (ReleaseFile () < 0)
   392     if (ReleaseFile () < 0)
   409         goto bail;
   393         goto bail;
   410     
   394     
   411     #if DEBUG_CDROM
   395     #if DEBUG_CDROM
   412     printf ("LoadFile: %d %d\n", startFrame, stopFrame);
   396     printf ("LoadFile: %d %d\n", startFrame, stopFrame);
   413     #endif
   397     #endif
   414     
   398     
   415     //try {
   399     /*try {*/
   416     
   400     
   417         // create a new player, and attach to the audio unit
   401         /* create a new player, and attach to the audio unit */
   418         
   402         
   419         thePlayer = new_AudioFilePlayer(ref);
   403         thePlayer = new_AudioFilePlayer(ref);
   420         if (thePlayer == NULL) {
   404         if (thePlayer == NULL) {
   421             SDL_SetError ("LoadFile: Could not create player");
   405             SDL_SetError ("LoadFile: Could not create player");
   422             return -3; //throw (-3);
   406             return -3; /*throw (-3);*/
   423         }
   407         }
   424             
   408             
   425         if (!thePlayer->SetDestination(thePlayer, &theUnit))
   409         if (!thePlayer->SetDestination(thePlayer, &theUnit))
   426             goto bail;
   410             goto bail;
   427         
   411         
   429             thePlayer->SetStartFrame (thePlayer, startFrame);
   413             thePlayer->SetStartFrame (thePlayer, startFrame);
   430         
   414         
   431         if (stopFrame >= 0 && stopFrame > startFrame)
   415         if (stopFrame >= 0 && stopFrame > startFrame)
   432             thePlayer->SetStopFrame (thePlayer, stopFrame);
   416             thePlayer->SetStopFrame (thePlayer, stopFrame);
   433         
   417         
   434         // we set the notifier later
   418         /* we set the notifier later */
   435         //thePlayer->SetNotifier(thePlayer, FilePlayNotificationHandler, NULL);
   419         /*thePlayer->SetNotifier(thePlayer, FilePlayNotificationHandler, NULL);*/
   436             
   420             
   437         if (!thePlayer->Connect(thePlayer))
   421         if (!thePlayer->Connect(thePlayer))
   438             goto bail;
   422             goto bail;
   439     
   423     
   440         #if DEBUG_CDROM
   424         #if DEBUG_CDROM
   441         thePlayer->Print(thePlayer);
   425         thePlayer->Print(thePlayer);
   442         fflush (stdout);
   426         fflush (stdout);
   443         #endif
   427         #endif
   444     //}
   428     /*}
   445     //catch (...)
   429       catch (...)
   446     //{
   430       {
   447     //    goto bail;
   431           goto bail;
   448     //}
   432       }*/
   449         
   433         
   450     error = 0;
   434     error = 0;
   451 
   435 
   452     bail:
   436     bail:
   453     return error;
   437     return error;
   454 }
   438 }
   455 
   439 
   456 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   457 //  ReleaseFile
       
   458 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   459 
       
   460 int ReleaseFile ()
   440 int ReleaseFile ()
   461 {
   441 {
   462     int error = -1;
   442     int error = -1;
   463         
   443         
   464     // (Don't see any way that the original C++ code could throw here.) --ryan.
   444     /* (Don't see any way that the original C++ code could throw here.) --ryan. */
   465     //try {
   445     /*try {*/
   466         if (thePlayer != NULL) {
   446         if (thePlayer != NULL) {
   467             
   447             
   468             thePlayer->Disconnect(thePlayer);
   448             thePlayer->Disconnect(thePlayer);
   469             
   449             
   470             delete_AudioFilePlayer(thePlayer);
   450             delete_AudioFilePlayer(thePlayer);
   471             
   451             
   472             thePlayer = NULL;
   452             thePlayer = NULL;
   473         }
   453         }
   474     //}
   454     /*}
   475     //catch (...)
   455       catch (...)
   476     //{
   456       {
   477     //    goto bail;
   457           goto bail;
   478     //}
   458       }*/
   479     
   459     
   480     error = 0;
   460     error = 0;
   481     
   461     
   482 //  bail:
   462 /*  bail: */
   483     return error;
   463     return error;
   484 }
   464 }
   485 
   465 
   486 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   487 //  PlayFile
       
   488 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   489 
       
   490 int PlayFile ()
   466 int PlayFile ()
   491 {
   467 {
   492     OSStatus result = -1;
   468     OSStatus result = -1;
   493     
   469     
   494     if (CheckInit () < 0)
   470     if (CheckInit () < 0)
   495         goto bail;
   471         goto bail;
   496         
   472         
   497 //    try {
   473     /*try {*/
   498     
   474     
   499         // start processing of the audio unit
   475         // start processing of the audio unit
   500         result = AudioOutputUnitStart (theUnit);
   476         result = AudioOutputUnitStart (theUnit);
   501             if (result) goto bail; //THROW_RESULT("PlayFile: AudioOutputUnitStart")
   477             if (result) goto bail; //THROW_RESULT("PlayFile: AudioOutputUnitStart")
   502         
   478         
   503 //    }
   479     /*}
   504 //    catch (...)
   480     catch (...)
   505 //    {
   481     {
   506 //        goto bail;
   482         goto bail;
   507 //    }
   483     }*/
   508     
   484     
   509     result = 0;
   485     result = 0;
   510     
   486     
   511 bail:
   487 bail:
   512     return result;
   488     return result;
   513 }
   489 }
   514 
   490 
   515 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   516 //  PauseFile
       
   517 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   518 
       
   519 int PauseFile ()
   491 int PauseFile ()
   520 {
   492 {
   521     OSStatus result = -1;
   493     OSStatus result = -1;
   522     
   494     
   523     if (CheckInit () < 0)
   495     if (CheckInit () < 0)
   524         goto bail;
   496         goto bail;
   525             
   497             
   526     //try {
   498     /*try {*/
   527     
   499     
   528         // stop processing the audio unit
   500         /* stop processing the audio unit */
   529         result = AudioOutputUnitStop (theUnit);
   501         result = AudioOutputUnitStop (theUnit);
   530             if (result) goto bail;  //THROW_RESULT("PauseFile: AudioOutputUnitStop")
   502             if (result) goto bail;  /*THROW_RESULT("PauseFile: AudioOutputUnitStop")*/
   531     //}
   503     /*}
   532     //catch (...)
   504       catch (...)
   533     //{
   505       {
   534     //    goto bail;
   506           goto bail;
   535     //}
   507       }*/
   536     
   508     
   537     result = 0;
   509     result = 0;
   538 bail:
   510 bail:
   539     return result;
   511     return result;
   540 }
   512 }
   541 
   513 
   542 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   543 //  SetCompletionProc
       
   544 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   545 
       
   546 void SetCompletionProc (CDPlayerCompletionProc proc, SDL_CD *cdrom)
   514 void SetCompletionProc (CDPlayerCompletionProc proc, SDL_CD *cdrom)
   547 {
   515 {
   548     assert(thePlayer != NULL);
   516     assert(thePlayer != NULL);
   549 
   517 
   550     theCDROM = cdrom;
   518     theCDROM = cdrom;
   551     completionProc = proc;
   519     completionProc = proc;
   552     thePlayer->SetNotifier (thePlayer, FilePlayNotificationHandler, cdrom);
   520     thePlayer->SetNotifier (thePlayer, FilePlayNotificationHandler, cdrom);
   553 }
   521 }
   554 
       
   555 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   556 //  GetCurrentFrame
       
   557 //ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ
       
   558 
   522 
   559 int GetCurrentFrame ()
   523 int GetCurrentFrame ()
   560 {    
   524 {    
   561     int frame;
   525     int frame;
   562     
   526     
   576     if (playBackWasInit)
   540     if (playBackWasInit)
   577         return 0;
   541         return 0;
   578     
   542     
   579     OSStatus result = noErr;
   543     OSStatus result = noErr;
   580     
   544     
   581     // Create the callback semaphore
   545     /* Create the callback semaphore */
   582     callbackSem = SDL_CreateSemaphore(0);
   546     callbackSem = SDL_CreateSemaphore(0);
   583 
   547 
   584     // Start callback thread
   548     /* Start callback thread */
   585     SDL_CreateThread(RunCallBackThread, NULL);
   549     SDL_CreateThread(RunCallBackThread, NULL);
   586 
   550 
   587     { //try {
   551     { /*try {*/
   588         ComponentDescription desc;
   552         ComponentDescription desc;
   589     
   553     
   590         desc.componentType = kAudioUnitComponentType;
   554         desc.componentType = kAudioUnitComponentType;
   591         desc.componentSubType = kAudioUnitSubType_Output;
   555         desc.componentSubType = kAudioUnitSubType_Output;
   592         desc.componentManufacturer = kAudioUnitID_DefaultOutput;
   556         desc.componentManufacturer = kAudioUnitID_DefaultOutput;
   607             if (result) return -1; //THROW_RESULT("CheckInit: AudioUnitInitialize")
   571             if (result) return -1; //THROW_RESULT("CheckInit: AudioUnitInitialize")
   608         
   572         
   609                     
   573                     
   610         playBackWasInit = true;
   574         playBackWasInit = true;
   611     }
   575     }
   612     //catch (...)
   576     /*catch (...)
   613     //{
   577       {
   614     //    return -1;
   578           return -1;
   615     //}
   579       }*/
   616     
   580     
   617     return 0;
   581     return 0;
   618 }
   582 }
   619 
   583 
   620 static void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus)
   584 static void FilePlayNotificationHandler(void * inRefCon, OSStatus inStatus)
   621 {
   585 {
   622     if (inStatus == kAudioFilePlay_FileIsFinished) {
   586     if (inStatus == kAudioFilePlay_FileIsFinished) {
   623     
   587     
   624         // notify non-CA thread to perform the callback
   588         /* notify non-CA thread to perform the callback */
   625         SDL_SemPost(callbackSem);
   589         SDL_SemPost(callbackSem);
   626         
   590         
   627     } else if (inStatus == kAudioFilePlayErr_FilePlayUnderrun) {
   591     } else if (inStatus == kAudioFilePlayErr_FilePlayUnderrun) {
   628     
   592     
   629         SDL_SetError ("CDPlayer Notification: buffer underrun");
   593         SDL_SetError ("CDPlayer Notification: buffer underrun");
   659     #endif
   623     #endif
   660     
   624     
   661     return 0;
   625     return 0;
   662 }
   626 }
   663 
   627 
   664 //}; // extern "C"
   628 /*}; // extern "C" */