symbian-qemu-0.9.1-12/libsdl-trunk/src/cdrom/macosx/AudioFilePlayer.h
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 /*
       
     2     SDL - Simple DirectMedia Layer
       
     3     Copyright (C) 1997-2004 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 #ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
       
    37 #include <AudioUnit/AUNTComponent.h>
       
    38 #endif
       
    39 
       
    40 #include "SDL_error.h"
       
    41 
       
    42 const char* AudioFilePlayerErrorStr (OSStatus error);
       
    43 
       
    44 /*
       
    45 void ThrowResult (OSStatus result, const char *str);
       
    46 
       
    47 #define THROW_RESULT(str)                                       \
       
    48     if (result) {                                               \
       
    49         ThrowResult (result, str);                              \
       
    50     }
       
    51 */
       
    52 
       
    53 typedef void (*AudioFilePlayNotifier)(void          *inRefCon,
       
    54                                     OSStatus        inStatus);
       
    55 
       
    56 enum {
       
    57     kAudioFilePlayErr_FilePlayUnderrun = -10000,
       
    58     kAudioFilePlay_FileIsFinished = -10001,
       
    59     kAudioFilePlay_PlayerIsUninitialized = -10002
       
    60 };
       
    61 
       
    62 
       
    63 struct S_AudioFileManager;
       
    64 
       
    65 #pragma mark __________ AudioFilePlayer
       
    66 typedef struct S_AudioFilePlayer
       
    67 {
       
    68 /*public:*/
       
    69     int             (*SetDestination)(struct S_AudioFilePlayer *afp, AudioUnit *inDestUnit);
       
    70     void            (*SetNotifier)(struct S_AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon);
       
    71     void            (*SetStartFrame)(struct S_AudioFilePlayer *afp, int frame); /* seek in the file */
       
    72     int             (*GetCurrentFrame)(struct S_AudioFilePlayer *afp); /* get the current frame position */
       
    73     void            (*SetStopFrame)(struct S_AudioFilePlayer *afp, int frame);   /* set limit in the file */
       
    74     int             (*Connect)(struct S_AudioFilePlayer *afp);
       
    75     void            (*Disconnect)(struct S_AudioFilePlayer *afp);
       
    76     void            (*DoNotification)(struct S_AudioFilePlayer *afp, OSStatus inError);
       
    77     int             (*IsConnected)(struct S_AudioFilePlayer *afp);
       
    78     AudioUnit       (*GetDestUnit)(struct S_AudioFilePlayer *afp);
       
    79     void            (*Print)(struct S_AudioFilePlayer *afp);
       
    80 
       
    81 /*private:*/
       
    82     AudioUnit                       mPlayUnit;
       
    83     SInt16                          mForkRefNum;
       
    84     
       
    85     AudioUnitInputCallback          mInputCallback;
       
    86 
       
    87     AudioStreamBasicDescription     mFileDescription;
       
    88     
       
    89     int                             mConnected;
       
    90     
       
    91     struct S_AudioFileManager*      mAudioFileManager;
       
    92     
       
    93     AudioFilePlayNotifier           mNotifier;
       
    94     void*                           mRefCon;
       
    95     
       
    96     int                             mStartFrame;
       
    97     
       
    98 #pragma mark __________ Private_Methods
       
    99     
       
   100     int          (*OpenFile)(struct S_AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileSize);
       
   101 } AudioFilePlayer;
       
   102 
       
   103 
       
   104 AudioFilePlayer *new_AudioFilePlayer(const FSRef    *inFileRef);
       
   105 void delete_AudioFilePlayer(AudioFilePlayer *afp);
       
   106 
       
   107 
       
   108 
       
   109 #pragma mark __________ AudioFileManager
       
   110 typedef struct S_AudioFileManager
       
   111 {
       
   112 /*public:*/
       
   113         /* this method should NOT be called by an object of this class
       
   114            as it is called by the parent's Disconnect() method */
       
   115     void                (*Disconnect)(struct S_AudioFileManager *afm);
       
   116     int                 (*DoConnect)(struct S_AudioFileManager *afm);
       
   117     OSStatus            (*Read)(struct S_AudioFileManager *afm, char *buffer, UInt32 *len);
       
   118     const char*         (*GetFileBuffer)(struct S_AudioFileManager *afm);
       
   119     const AudioFilePlayer *(*GetParent)(struct S_AudioFileManager *afm);
       
   120     void                (*SetPosition)(struct S_AudioFileManager *afm, SInt64 pos);  /* seek/rewind in the file */
       
   121     int                 (*GetByteCounter)(struct S_AudioFileManager *afm);  /* return actual bytes streamed to audio hardware */
       
   122     void                (*SetEndOfFile)(struct S_AudioFileManager *afm, SInt64 pos);  /* set the "EOF" (will behave just like it reached eof) */
       
   123    
       
   124 /*protected:*/
       
   125     AudioFilePlayer*    mParent;
       
   126     SInt16              mForkRefNum;
       
   127     SInt64              mAudioDataOffset;
       
   128     
       
   129     char*               mFileBuffer;
       
   130 
       
   131     int                 mByteCounter;
       
   132 
       
   133     int                mReadFromFirstBuffer;
       
   134     int                mLockUnsuccessful;
       
   135     int                mIsEngaged;
       
   136     
       
   137     int                 mNumTimesAskedSinceFinished;
       
   138 
       
   139 
       
   140 	void*               mTmpBuffer;
       
   141 	UInt32              mBufferSize;
       
   142 	UInt32              mBufferOffset;
       
   143 /*public:*/
       
   144     UInt32              mChunkSize;
       
   145     SInt64              mFileLength;
       
   146     SInt64              mReadFilePosition;
       
   147     int                 mWriteToFirstBuffer;
       
   148     int                 mFinishedReadingData;
       
   149 
       
   150 /*protected:*/
       
   151     OSStatus            (*Render)(struct S_AudioFileManager *afm, AudioBuffer *ioData);
       
   152     OSStatus            (*GetFileData)(struct S_AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize);
       
   153     void                (*AfterRender)(struct S_AudioFileManager *afm);
       
   154 
       
   155 /*public:*/
       
   156     /*static*/
       
   157     OSStatus            (*FileInputProc)(void                             *inRefCon,
       
   158                                          AudioUnitRenderActionFlags      inActionFlags,
       
   159                                          const AudioTimeStamp            *inTimeStamp,
       
   160                                          UInt32                          inBusNumber,
       
   161                                          AudioBuffer                     *ioData);
       
   162 } AudioFileManager;
       
   163 
       
   164 
       
   165 AudioFileManager *new_AudioFileManager (AudioFilePlayer *inParent,
       
   166                       SInt16          inForkRefNum, 
       
   167                       SInt64          inFileLength,
       
   168                       UInt32          inChunkSize);
       
   169     
       
   170 void delete_AudioFileManager(AudioFileManager *afm);
       
   171 
       
   172 #endif
       
   173