src/cdrom/macosx/AudioFilePlayer.h
author Ryan C. Gordon
Sun, 18 Sep 2011 02:00:39 -0400
branchSDL-1.2
changeset 5952 c838b121901e
parent 4369 f14cf9d71233
child 5955 0ade820b8f5f
permissions -rw-r--r--
Fixed building with a newer Mac OS X SDK and -mmacosx-version-min=10.4.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 
    22     This file based on Apple sample code. We haven't changed the file name, 
    23     so if you want to see the original search for it on apple.com/developer
    24 */
    25 #include "SDL_config.h"
    26 
    27 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    28     AudioFilePlayer.h
    29 */
    30 #ifndef __AudioFilePlayer_H__
    31 #define __AudioFilePlayer_H__
    32 
    33 #include <CoreServices/CoreServices.h>
    34 
    35 #include <AudioUnit/AudioUnit.h>
    36 #if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
    37 #include <AudioUnit/AUNTComponent.h>
    38 #endif
    39 
    40 /* This typedef is included in the 10.5+ SDK headers. */
    41 #ifndef MAC_OS_X_VERSION_10_5
    42 typedef SInt16 FSIORefNum;
    43 #endif
    44 
    45 #include "SDL_error.h"
    46 
    47 const char* AudioFilePlayerErrorStr (OSStatus error);
    48 
    49 /*
    50 void ThrowResult (OSStatus result, const char *str);
    51 
    52 #define THROW_RESULT(str)                                       \
    53     if (result) {                                               \
    54         ThrowResult (result, str);                              \
    55     }
    56 */
    57 
    58 typedef void (*AudioFilePlayNotifier)(void          *inRefCon,
    59                                     OSStatus        inStatus);
    60 
    61 enum {
    62     kAudioFilePlayErr_FilePlayUnderrun = -10000,
    63     kAudioFilePlay_FileIsFinished = -10001,
    64     kAudioFilePlay_PlayerIsUninitialized = -10002
    65 };
    66 
    67 
    68 struct S_AudioFileManager;
    69 
    70 #pragma mark __________ AudioFilePlayer
    71 typedef struct S_AudioFilePlayer
    72 {
    73 /*public:*/
    74     int             (*SetDestination)(struct S_AudioFilePlayer *afp, AudioUnit *inDestUnit);
    75     void            (*SetNotifier)(struct S_AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon);
    76     void            (*SetStartFrame)(struct S_AudioFilePlayer *afp, int frame); /* seek in the file */
    77     int             (*GetCurrentFrame)(struct S_AudioFilePlayer *afp); /* get the current frame position */
    78     void            (*SetStopFrame)(struct S_AudioFilePlayer *afp, int frame);   /* set limit in the file */
    79     int             (*Connect)(struct S_AudioFilePlayer *afp);
    80     void            (*Disconnect)(struct S_AudioFilePlayer *afp);
    81     void            (*DoNotification)(struct S_AudioFilePlayer *afp, OSStatus inError);
    82     int             (*IsConnected)(struct S_AudioFilePlayer *afp);
    83     AudioUnit       (*GetDestUnit)(struct S_AudioFilePlayer *afp);
    84     void            (*Print)(struct S_AudioFilePlayer *afp);
    85 
    86 /*private:*/
    87     AudioUnit                       mPlayUnit;
    88     FSIORefNum                      mForkRefNum;
    89     
    90     AURenderCallbackStruct          mInputCallback;
    91 
    92     AudioStreamBasicDescription     mFileDescription;
    93     
    94     int                             mConnected;
    95     
    96     struct S_AudioFileManager*      mAudioFileManager;
    97     
    98     AudioFilePlayNotifier           mNotifier;
    99     void*                           mRefCon;
   100     
   101     int                             mStartFrame;
   102     
   103 #pragma mark __________ Private_Methods
   104     
   105     int          (*OpenFile)(struct S_AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileSize);
   106 } AudioFilePlayer;
   107 
   108 
   109 AudioFilePlayer *new_AudioFilePlayer(const FSRef    *inFileRef);
   110 void delete_AudioFilePlayer(AudioFilePlayer *afp);
   111 
   112 
   113 
   114 #pragma mark __________ AudioFileManager
   115 typedef struct S_AudioFileManager
   116 {
   117 /*public:*/
   118         /* this method should NOT be called by an object of this class
   119            as it is called by the parent's Disconnect() method */
   120     void                (*Disconnect)(struct S_AudioFileManager *afm);
   121     int                 (*DoConnect)(struct S_AudioFileManager *afm);
   122     OSStatus            (*Read)(struct S_AudioFileManager *afm, char *buffer, ByteCount *len);
   123     const char*         (*GetFileBuffer)(struct S_AudioFileManager *afm);
   124     const AudioFilePlayer *(*GetParent)(struct S_AudioFileManager *afm);
   125     void                (*SetPosition)(struct S_AudioFileManager *afm, SInt64 pos);  /* seek/rewind in the file */
   126     int                 (*GetByteCounter)(struct S_AudioFileManager *afm);  /* return actual bytes streamed to audio hardware */
   127     void                (*SetEndOfFile)(struct S_AudioFileManager *afm, SInt64 pos);  /* set the "EOF" (will behave just like it reached eof) */
   128    
   129 /*protected:*/
   130     AudioFilePlayer*    mParent;
   131     SInt16              mForkRefNum;
   132     SInt64              mAudioDataOffset;
   133     
   134     char*               mFileBuffer;
   135 
   136     int                 mByteCounter;
   137 
   138     int                mReadFromFirstBuffer;
   139     int                mLockUnsuccessful;
   140     int                mIsEngaged;
   141     
   142     int                 mNumTimesAskedSinceFinished;
   143 
   144 
   145 	void*               mTmpBuffer;
   146 	UInt32              mBufferSize;
   147 	UInt32              mBufferOffset;
   148 /*public:*/
   149     UInt32              mChunkSize;
   150     SInt64              mFileLength;
   151     SInt64              mReadFilePosition;
   152     int                 mWriteToFirstBuffer;
   153     int                 mFinishedReadingData;
   154 
   155 /*protected:*/
   156     OSStatus            (*Render)(struct S_AudioFileManager *afm, AudioBufferList *ioData);
   157     OSStatus            (*GetFileData)(struct S_AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize);
   158     void                (*AfterRender)(struct S_AudioFileManager *afm);
   159 
   160 /*public:*/
   161     /*static*/
   162     OSStatus            (*FileInputProc)(void                            *inRefCon,
   163                                          AudioUnitRenderActionFlags      *ioActionFlags,
   164                                          const AudioTimeStamp            *inTimeStamp,
   165                                          UInt32                          inBusNumber,
   166                                          UInt32                          inNumberFrames,
   167                                          AudioBufferList                 *ioData);
   168 } AudioFileManager;
   169 
   170 
   171 AudioFileManager *new_AudioFileManager (AudioFilePlayer *inParent,
   172                       SInt16          inForkRefNum, 
   173                       SInt64          inFileLength,
   174                       UInt32          inChunkSize);
   175     
   176 void delete_AudioFileManager(AudioFileManager *afm);
   177 
   178 #endif
   179