Commit f4df35b9 authored by Sam Lantinga's avatar Sam Lantinga

Max has been reworking this code so it works on MacOS X 10.1

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40769
parent 86ec9803
...@@ -2430,11 +2430,9 @@ case "$target" in ...@@ -2430,11 +2430,9 @@ case "$target" in
# Set up files for the cdrom library # Set up files for the cdrom library
if test x$enable_cdrom = xyes; then if test x$enable_cdrom = xyes; then
# The CD-ROM code won't work on old versions of MacOS X yet... # The CD-ROM code won't work on old versions of MacOS X yet...
#CDROM_SUBDIRS="$CDROM_SUBDIRS macosx" CDROM_SUBDIRS="$CDROM_SUBDIRS macosx"
#CDROM_DRIVERS="$CDROM_DRIVERS macosx/libcdrom_macosx.la" CDROM_DRIVERS="$CDROM_DRIVERS macosx/libcdrom_macosx.la"
#SYSTEM_LIBS="$SYSTEM_LIBS -framework AudioToolbox -framework AudioUnit -lstdc++" SYSTEM_LIBS="$SYSTEM_LIBS -framework AudioToolbox -framework AudioUnit -lstdc++"
CDROM_SUBDIRS="$CDROM_SUBDIRS dummy"
CDROM_DRIVERS="$CDROM_DRIVERS dummy/libcdrom_dummy.la"
fi fi
# Set up files for the thread library # Set up files for the thread library
if test x$enable_threads = xyes; then if test x$enable_threads = xyes; then
......
This diff is collapsed.
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#include <AudioToolbox/AudioToolbox.h> #include <AudioToolbox/AudioConverter.h>
#include <AudioUnit/AudioUnit.h> #include <AudioUnit/AudioUnit.h>
#include "SDL_error.h" #include "SDL_error.h"
...@@ -97,12 +97,9 @@ public: ...@@ -97,12 +97,9 @@ public:
#if DEBUG #if DEBUG
void Print() const void Print() const
{ {
CAShow (mAudioFileID);
printf ("Destination Bus:%ld\n", GetBusNumber()); printf ("Destination Bus:%ld\n", GetBusNumber());
printf ("Is 'aunt' unit:%s\n", (mIsAUNTUnit ? "true" : "false"));
printf ("Is Connected:%s\n", (IsConnected() ? "true" : "false")); printf ("Is Connected:%s\n", (IsConnected() ? "true" : "false"));
if (mConverter) CAShow (mConverter); printf ("- - - - - - - - - - - - - - \n");
printf ("- - - - - - - - - - - - - - \n");
} }
#endif #endif
...@@ -111,14 +108,13 @@ public: ...@@ -111,14 +108,13 @@ public:
private: private:
AudioUnit mPlayUnit; AudioUnit mPlayUnit;
UInt32 mBusNumber; UInt32 mBusNumber;
AudioFileID mAudioFileID; SInt16 mForkRefNum;
AudioUnitInputCallback mInputCallback; AudioUnitInputCallback mInputCallback;
AudioStreamBasicDescription mFileDescription; AudioStreamBasicDescription mFileDescription;
bool mConnected; bool mConnected;
bool mIsAUNTUnit;
AudioFileManager* mAudioFileManager; AudioFileManager* mAudioFileManager;
AudioConverterRef mConverter; AudioConverterRef mConverter;
...@@ -137,14 +133,12 @@ private: ...@@ -137,14 +133,12 @@ private:
class AudioFileManager class AudioFileManager
{ {
public: public:
AudioFileManager (AudioFilePlayer& inParent, AudioFileID inFile) AudioFileManager (AudioFilePlayer &inParent,
: mParent (inParent), SInt16 inForkRefNum,
mAudioFileID (inFile), SInt64 inFileLength,
mFileBuffer (0), UInt32 inChunkSize);
mByteCounter (0)
{}
virtual ~AudioFileManager(); ~AudioFileManager();
void Connect (AudioConverterRef inConverter) void Connect (AudioConverterRef inConverter)
...@@ -155,36 +149,51 @@ public: ...@@ -155,36 +149,51 @@ public:
// this method should NOT be called by an object of this class // this method should NOT be called by an object of this class
// as it is called by the parent's Disconnect() method // as it is called by the parent's Disconnect() method
virtual void Disconnect () {} void Disconnect ();
const AudioFileID& GetFileID() const { return mAudioFileID; } OSStatus Read(char *buffer, UInt32 *len);
const char* GetFileBuffer () { return mFileBuffer; } const char* GetFileBuffer () { return mFileBuffer; }
const AudioFilePlayer& GetParent () const { return mParent; } const AudioFilePlayer& GetParent () const { return mParent; }
virtual void SetPosition (SInt64 pos) = 0; // seek/rewind in the file void SetPosition (SInt64 pos); // seek/rewind in the file
virtual int GetByteCounter () { return mByteCounter; } // return actual bytes streamed to audio hardware int GetByteCounter () { return mByteCounter; } // return actual bytes streamed to audio hardware
virtual void SetEndOfFile (SInt64 pos) = 0; // set the "EOF" (will behave just like it reached eof) void SetEndOfFile (SInt64 pos); // set the "EOF" (will behave just like it reached eof)
protected: protected:
AudioFilePlayer& mParent; AudioFilePlayer& mParent;
AudioConverterRef mParentConverter; AudioConverterRef mParentConverter;
const AudioFileID mAudioFileID; SInt16 mForkRefNum;
SInt64 mAudioDataOffset;
char* mFileBuffer; char* mFileBuffer;
OSStatus Render (AudioBuffer &ioData); int mByteCounter;
bool mReadFromFirstBuffer;
bool mLockUnsuccessful;
bool mIsEngaged;
int mNumTimesAskedSinceFinished;
int mByteCounter; public:
const UInt32 mChunkSize;
SInt64 mFileLength;
SInt64 mReadFilePosition;
bool mWriteToFirstBuffer;
bool mFinishedReadingData;
protected:
OSStatus Render (AudioBuffer &ioData);
virtual OSStatus GetFileData (void** inOutData, UInt32 *inOutDataSize) = 0; OSStatus GetFileData (void** inOutData, UInt32 *inOutDataSize);
virtual void DoConnect () = 0; void DoConnect ();
virtual void AfterRender () = 0; void AfterRender ();
public: public:
static OSStatus FileInputProc (void *inRefCon, static OSStatus FileInputProc (void *inRefCon,
...@@ -199,42 +208,4 @@ public: ...@@ -199,42 +208,4 @@ public:
}; };
#pragma mark __________ AudioFileReaderThread
class AudioFileReaderThread
: public AudioFileManager
{
public:
const UInt32 mChunkSize;
SInt64 mFileLength;
SInt64 mReadFilePosition;
bool mWriteToFirstBuffer;
bool mFinishedReadingData;
AudioFileReaderThread (AudioFilePlayer &inParent,
AudioFileID &inFile,
SInt64 inFileLength,
UInt32 inChunkSize);
virtual void Disconnect ();
virtual void SetPosition (SInt64 pos); // seek/rewind in the file
virtual void SetEndOfFile (SInt64 pos); // set the "EOF" (will behave just like it reached eof)
protected:
virtual void DoConnect ();
virtual OSStatus GetFileData (void** inOutData, UInt32 *inOutDataSize);
virtual void AfterRender ();
private:
bool mReadFromFirstBuffer;
bool mLockUnsuccessful;
bool mIsEngaged;
int mNumTimesAskedSinceFinished;
};
#endif #endif
This diff is collapsed.
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
#include <stdio.h> #include <stdio.h>
#define NDEBUG 1 //#define NDEBUG 1
#include <assert.h> #include <assert.h>
......
...@@ -114,9 +114,7 @@ int DetectAudioCDVolumes(FSVolumeRefNum *volumes, int numVolumes) ...@@ -114,9 +114,7 @@ int DetectAudioCDVolumes(FSVolumeRefNum *volumes, int numVolumes)
for (volumeIndex = 1; result == noErr || result != nsvErr; volumeIndex++) for (volumeIndex = 1; result == noErr || result != nsvErr; volumeIndex++)
{ {
FSVolumeRefNum actualVolume; FSVolumeRefNum actualVolume;
HFSUniStr255 volumeName;
FSVolumeInfo volumeInfo; FSVolumeInfo volumeInfo;
FSRef rootDirectory;
memset (&volumeInfo, 0, sizeof(volumeInfo)); memset (&volumeInfo, 0, sizeof(volumeInfo));
...@@ -125,13 +123,13 @@ int DetectAudioCDVolumes(FSVolumeRefNum *volumes, int numVolumes) ...@@ -125,13 +123,13 @@ int DetectAudioCDVolumes(FSVolumeRefNum *volumes, int numVolumes)
&actualVolume, &actualVolume,
kFSVolInfoFSInfo, kFSVolInfoFSInfo,
&volumeInfo, &volumeInfo,
&volumeName, NULL,
&rootDirectory); NULL);
if (result == noErr) if (result == noErr)
{ {
if (volumeInfo.filesystemID == kAudioCDFilesystemID) // It's an audio CD if (volumeInfo.filesystemID == kAudioCDFilesystemID) // It's an audio CD
{ {
if (volumes != NULL && cdVolumeCount < numVolumes) if (volumes != NULL && cdVolumeCount < numVolumes)
volumes[cdVolumeCount] = actualVolume; volumes[cdVolumeCount] = actualVolume;
......
...@@ -25,9 +25,8 @@ ...@@ -25,9 +25,8 @@
#include <string.h> #include <string.h>
#include <CoreFoundation/CoreFoundation.h>
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include <CoreFoundation/CoreFoundation.h>
#include <AudioUnit/AudioUnit.h> #include <AudioUnit/AudioUnit.h>
#include "SDL.h" #include "SDL.h"
......
...@@ -265,19 +265,25 @@ void SDL_SYS_CDQuit(void) ...@@ -265,19 +265,25 @@ void SDL_SYS_CDQuit(void)
/* Get the Unix disk name of the volume */ /* Get the Unix disk name of the volume */
static const char *SDL_SYS_CDName (int drive) static const char *SDL_SYS_CDName (int drive)
{ {
CFStringRef diskID;
OSStatus err = noErr; OSStatus err = noErr;
HParamBlockRec pb;
GetVolParmsInfoBuffer volParmsInfo;
if (fakeCD) if (fakeCD)
return "Fake CD-ROM Device"; return "Fake CD-ROM Device";
err = FSCopyDiskIDForVolume (volumes[drive], &diskID); pb.ioParam.ioNamePtr = NULL;
pb.ioParam.ioVRefNum = volumes[drive];
pb.ioParam.ioBuffer = (Ptr)&volParmsInfo;
pb.ioParam.ioReqCount = (SInt32)sizeof(volParmsInfo);
err = PBHGetVolParmsSync(&pb);
if (err != noErr) { if (err != noErr) {
SDL_SetError ("FSCopyDiskIDForVolume returned %d", err); SDL_SetError ("PBHGetVolParmsSync returned %d", err);
return NULL; return NULL;
} }
return CFStringGetCStringPtr (diskID, 0); return volParmsInfo.vMDeviceID;
} }
/* Open the "device" */ /* Open the "device" */
...@@ -318,14 +324,15 @@ static int SDL_SYS_CDGetTOC (SDL_CD *cdrom) ...@@ -318,14 +324,15 @@ static int SDL_SYS_CDGetTOC (SDL_CD *cdrom)
/* Get CD-ROM status */ /* Get CD-ROM status */
static CDstatus SDL_SYS_CDStatus (SDL_CD *cdrom, int *position) static CDstatus SDL_SYS_CDStatus (SDL_CD *cdrom, int *position)
{ {
int trackFrame; if (position) {
int trackFrame;
Lock ();
trackFrame = GetCurrentFrame (); Lock ();
Unlock (); trackFrame = GetCurrentFrame ();
Unlock ();
if (position) *position = cdrom->track[currentTrack].offset + trackFrame;
*position = cdrom->track[currentTrack].offset + trackFrame; }
return status; return status;
} }
...@@ -383,8 +390,10 @@ static int SDL_SYS_CDPause(SDL_CD *cdrom) ...@@ -383,8 +390,10 @@ static int SDL_SYS_CDPause(SDL_CD *cdrom)
Lock (); Lock ();
if (PauseFile () < 0) if (PauseFile () < 0) {
Unlock ();
return -2; return -2;
}
status = CD_PAUSED; status = CD_PAUSED;
...@@ -403,8 +412,10 @@ static int SDL_SYS_CDResume(SDL_CD *cdrom) ...@@ -403,8 +412,10 @@ static int SDL_SYS_CDResume(SDL_CD *cdrom)
Lock (); Lock ();
if (PlayFile () < 0) if (PauseFile () < 0) {
Unlock ();
return -2; return -2;
}
status = CD_PLAYING; status = CD_PLAYING;
...@@ -423,11 +434,15 @@ static int SDL_SYS_CDStop(SDL_CD *cdrom) ...@@ -423,11 +434,15 @@ static int SDL_SYS_CDStop(SDL_CD *cdrom)
Lock (); Lock ();
if (PauseFile () < 0) if (PauseFile () < 0) {
Unlock ();
return -2; return -2;
}
if (ReleaseFile () < 0) if (ReleaseFile () < 0) {
Unlock ();
return -3; return -3;
}
status = CD_STOPPED; status = CD_STOPPED;
...@@ -440,6 +455,7 @@ static int SDL_SYS_CDStop(SDL_CD *cdrom) ...@@ -440,6 +455,7 @@ static int SDL_SYS_CDStop(SDL_CD *cdrom)
static int SDL_SYS_CDEject(SDL_CD *cdrom) static int SDL_SYS_CDEject(SDL_CD *cdrom)
{ {
OSStatus err; OSStatus err;
HParamBlockRec pb;
if (fakeCD) { if (fakeCD) {
SDL_SetError (kErrorFakeDevice); SDL_SetError (kErrorFakeDevice);
...@@ -448,20 +464,28 @@ static int SDL_SYS_CDEject(SDL_CD *cdrom) ...@@ -448,20 +464,28 @@ static int SDL_SYS_CDEject(SDL_CD *cdrom)
Lock (); Lock ();
if (PauseFile () < 0) if (PauseFile () < 0) {
Unlock ();
return -2; return -2;
}
if (ReleaseFile () < 0) if (ReleaseFile () < 0) {
Unlock ();
return -3; return -3;
}
status = CD_STOPPED; status = CD_STOPPED;
err = FSEjectVolumeSync (volumes[cdrom->id], 0, NULL); // Eject the volume
pb.ioParam.ioNamePtr = NULL;
if (err != noErr) { pb.ioParam.ioVRefNum = volumes[cdrom->id];
SDL_SetError ("FSEjectVolumeSync returned %d", err); err = PBUnmountVol((ParamBlockRec *) &pb);
return -4;
} if (err != noErr) {
Unlock ();
SDL_SetError ("PBUnmountVol returned %d", err);
return -4;
}
status = CD_TRAYEMPTY; status = CD_TRAYEMPTY;
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
slouken@libsdl.org slouken@libsdl.org
*/ */
/* This is the Mac OS X / CoreAudio specific header for the SDL CD-ROM API
Contributed by Darrell Walisser and Max Horn
*/
/*********************************************************************************** /***********************************************************************************
Implementation Notes Implementation Notes
......
...@@ -1365,7 +1365,7 @@ static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) { ...@@ -1365,7 +1365,7 @@ static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
SDL_RWops *rw; SDL_RWops *rw;
SDL_Surface *tmp; SDL_Surface *tmp;
rw = SDL_RWFromMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon)); rw = SDL_RWFromConstMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
tmp = SDL_LoadBMP_RW (rw, SDL_TRUE); tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY); resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment