00001 // 00002 // CascadeAudioPlaybackDevice.h - header file for class CascadeAudioPlaybackDevice 00003 // 00004 // Copyright (c) 2003, Roku, LLC. All rights reserved. 00005 // 00008 00009 #ifndef _ROKU_INCLUDE_CASCADE_AV_CASCADEAUDIOPLAYBACKDEVICE_H 00010 #define _ROKU_INCLUDE_CASCADE_AV_CASCADEAUDIOPLAYBACKDEVICE_H 00011 00012 #include <cascade/CascadeTypedefs.h> 00013 00025 class CascadeAudioPlaybackDevice 00026 { 00027 public: 00028 CascadeAudioPlaybackDevice() { } 00032 virtual ~CascadeAudioPlaybackDevice() { } 00036 public: 00037 virtual bool GetBufferRequirements(u32 & nMinNumBuffersToSet, u32 & nMaxNumBuffersToSet, u32 & nMinBufferSizeToSet, u32 & nMaxBufferSizeToSet, u32 & nBufferSizeMultipleToSet) = 0; 00038 // GetBufferRequirements() sets the parameters passed in with the buffer requirements of the driver 00039 // These parameters are set as follows: 00040 // nMinNumBuffersToSet - the minimum number of buffers that can be queued by the driver 00041 // nMaxNumBuffersToSet - the maximum number of buffers that can be queued by the driver 00042 // nMinBufferSizeToSet - the minimum size of a buffer that can be queued by the driver 00043 // nMaxBufferSizeToSet - the maximum size of a buffer that can be queued by the driver 00044 // nBufferSizeMultipleToSet - buffer lengths must be a multiple of this number 00045 // call GetBufferRequirements() before opening the driver so you know the legal parameters 00046 // for use with Open() 00047 virtual bool GetDefaultBufferRequirements(u32 & nNumBuffersToSet, u32 & nBufferSizeInBytesToSet) = 0; 00048 // Gets the default number of buffers and buffer size that the driver recommends 00049 // be passed into Open() 00050 virtual bool Open(u32 nNumBuffers, u32 nBufferSizeInBytes, void ** ppBufferLocationsToSet) = 0; 00051 // Open() opens the driver. 00052 // Call GetBufferRequirements() to determine the maximum number of buffers that can be used 00053 // and the buffer size multiple that must be used. 00054 // Set the parameters as follows: 00055 // nNumBuffers - the number of buffers you want for streaming. This number MUST be 00056 // <= to the maximum number of buffers returned by GetBufferRequirements() 00057 // nBufferSizeInBytes - the size of each individual streaming buffer. This size MUST 00058 // a multiple of the size multiple returned by GetBufferRequirements() 00059 // ppBufferLocationsToSet - a pointer to an array of void pointers. This array of void 00060 // pointers must have nNumBuffers elements. The elements will 00061 // be filled with pointers to buffer memory allocated by the driver. 00062 virtual bool Close() = 0; 00063 // Close() closes the driver. Any playing audio stops immediately - 00064 // all pending buffers are flushed. 00065 virtual bool QueueBuffer(s16 * pData, u32 nSamples) = 0; 00066 // QueueBuffer() is used to queue a buffer to the driver. 00067 // pData contains right and left interleaved 16 bit words of PCM audio data 00068 // nSamples is the number of samples of audio data contained in pData 00069 // Note: (nSamples * 2) is the byte size of the buffer 00070 virtual u32 WaitForBuffer() = 0; 00071 // WaitForBuffer() blocks the calling thread until at least 1 00072 // buffer is available for queueing by the driver. WaitForBuffer() 00073 // returns the number of buffers available for queueing or 0, to indicate an 00074 // error. When finished streaming, repeatedly call WaitForBuffer() until it returns 00075 // the same number of buffers you passed into the Open() call. (This means all buffers 00076 // are available for queuing). An easy way to do this is, for example: 00077 // while ((0 != WaitForBuffer()) && (nNumBuffers != WaitForBuffer())); 00078 // Contrast this with Flush() which immediately flushes all buffers without continuing 00079 // playback of queued buffers. WaitForBuffer() will always return all buffers 00080 // if it is preceded by a call to Flush. 00081 virtual bool GetNumBuffersAvailable(u32 & nNumBuffersAvailableToSet) = 0; 00082 // GetNumBufferesAvailable() sets nNumBuffersAvailableToSet with the number of buffers currently 00083 // available for setting. It is like WaitForBuffer() but doesn't ever wait. 00084 virtual bool Pause() = 0; 00085 // Pause() pauses the audio driver. 00086 // NOTE: if you Pause() the audio driver and then call WaitForBuffer() 00087 // you may block indefinitely (if all queued buffers are busy in the driver). 00088 virtual bool Play() = 0; 00089 // Play() resumes playback of the audio driver. The audio driver is initialized 00090 // in Play() state so that playing starts as soon as buffers are queued. 00091 virtual bool Flush() = 0; 00092 // Flush() causes the driver to immediately dequeue all queued buffers. 00093 // After calling Flush() the state of the driver is the same as it was after 00094 // the driver was opened and before the first buffer was queued. 00095 virtual bool SetVolume(u16 nVolume) = 0; 00096 // call SetVolume() to set the output volume of audio playback. Legal values for 00097 // volume are 0 - 0xFFFF which is a linear range of volume 00098 // where 0 is no volume and 0xFFFF is full volume. 00099 virtual bool SetSampleRate(u32 nSampleRate) = 0; 00100 // SetSampleRate() sets the sample rate of the samples that are passed in via 00101 // QueueBuffer(). 00102 // nSampleRate is the sample rate in kHz. For example a value of 44100 means 44.1kHZ. 00103 // The driver is initialized with a default value of 44100 o 44.1kHZ. 00104 virtual u32 GetSampleRate() = 0; 00105 // GetSampleRate() gets the sample rate. The driver must be opened. If not, 00106 // GetSampleRate() returns 0. 00107 virtual bool IsSupportedSampleRate(u32 nSampleRate) = 0; 00108 // IsSupportedSampleRate() returns true if nSampleRate is supported by the device, 00109 // false otherwise. 00110 virtual bool SetOutputFlags(bool bAnalog, bool bSPDIF) = 0; 00111 // SetOutputFlags() specifies which outputs the playback device should 00112 // direct playback to: analog, spdif, both, or none. 00113 virtual void GetOutputFlags(bool & bAnalogToSet, bool & bSPDIFToSet) = 0; 00114 // GetOutputFlags() sets bAnalogToSet and bSPDIFToSet with the current 00115 // values of the output flags. 00116 public: 00117 static CascadeAudioPlaybackDevice * AcquireDefaultAudioPlaybackDevice(); 00118 // AcquireDefaultAudioPlaybackDevice() returns the default CascadeAudioPlaybackDevice 00119 // for this system. Only 1 client may acquire the default audio playback device 00120 // at a time. If AcquireDefaultAudioPlaybackDevice() fails, NULL is returned. 00121 static void ReleaseDefaultAudioPlaybackDevice(CascadeAudioPlaybackDevice * pDevice); 00122 // call ReleaseDefaultAudioPlaybackDevice() when you are done with the device. 00123 // If the device is not closed when ReleaseDefaultAudioPlaybackDevice() is called, 00124 // it will be closed automatically. 00125 }; 00126 00127 #endif // #ifndef _ROKU_INCLUDE_CASCADE_AV_CASCADEAUDIOPLAYBACKDEVICE_H 00128 00130 // LOG 00132 // 08-Aug-03 dwoodward created from AJW's CascadeDevAudioPlay class 00133 // 09-Dec-03 dwoodward added GetNumBuffersAvailable() 00134 // 28-Mar-04 dwoodward added IsSupportedSampleRate() 00135 // 29-Sep-04 dwoodward added SetOutputFlags() and GetOutputFlags() 00136 // 23-Feb-05 dwoodward added GetDefaultBufferRequirements(), AcquireDefaultAudioPlaybackDevice(), ReleaseDefaultAudioPlaybackDevice(), 00137 // and modified parameters to GetBufferRequirements() 00138 // 03-Mar-05 dwoodward added GetSampleRate() 00139