Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CascadeAudioPlayer.h

Go to the documentation of this file.
00001 //
00002 // CascadeAudioPlayer.h - header file for class CascadeAudioPlayer
00003 //
00004 // Copyright (c) 2004, Roku, LLC.  All rights reserved.
00005 //
00008 
00009 #ifndef _ROKU_INCLUDE_CASCADE_AV_CASCADEAUDIOPLAYER_H
00010 #define _ROKU_INCLUDE_CASCADE_AV_CASCADEAUDIOPLAYER_H
00011 
00012 #include <cascade/av/CascadeAudioCodec.h>
00013 #include <cascade/av/CascadeAudioPlaybackDevice.h>
00014 #include <cascade/util/CascadeStream.h>
00015 
00016 #ifndef DOXY_SKIP
00017     namespace CascadePrivate { class CascadeAudioPlayerInitializer; };
00018 #endif
00019 
00035 class CascadeAudioPlayer : public CascadeObject
00036 {
00037 public: class Client;   // forward declaration
00038 public:
00039         CascadeAudioPlayer();
00043         virtual ~CascadeAudioPlayer();
00047 public:
00048     virtual bool Open(Client * pClient = NULL);
00057     virtual void Close();
00062     virtual bool IsOpen();
00069     enum { kOutputFlagAnalog = (1 << 0), kOutputFlagSPDIF = (1 << 1) };    
00070     virtual bool QueueStream(CascadeStream & stream, const char * pType = NULL, u32 nOutputFlags = (kOutputFlagAnalog|kOutputFlagSPDIF));
00101         //   "PCM:samplerate:numchannels:bitspersample:polarity:endianness:order:durationinmilliseconds"
00119     virtual bool Stop();
00125     virtual bool Pause();
00130     virtual bool Resume();
00135         virtual bool SetVolume(u16 nVolume);
00143         virtual bool SetVolumePercent(u8 nVolume);
00152     virtual bool IsPlaying();
00157     virtual bool IsStopped();
00162     virtual bool IsPaused();
00167     virtual bool AttachDevice(CascadeAudioPlaybackDevice & device);
00180     virtual bool DetachDevice();
00189 public:    
00190     class SampleSet
00191     {
00192     public:
00193         u32  m_nStreamID;               
00194         u32  m_nSequenceNumber;         
00195         u32  m_nNumSamples;             
00196         u8 * m_pSamples;                
00197         u32  m_nTimestampMilliseconds;  
00198         u32  m_nDurationMilliseconds;   
00199         u32  m_nSampleBytes;            
00200     public:
00201         u32 m_nNumChannels;             
00202         u32 m_nSampleRate;              
00203         u32 m_nBitsPerSample;           
00204     };
00212 
00213     enum PlaybackResult
00214     { 
00215         kNormalCompletion = 0,              
00216         kPlaybackStopped,                   
00217         kErrorUnknown,                      
00218         kErrorOutOfMemory,                  
00219         kErrorUnsupportedSampleRate,        
00220         kErrorUnsupportedBitsPerSample,     
00221         kErrorUnsupportedNumChannels,       
00222         kErrorUnsupportedSamplePolarity,    
00223         kErrorUnsupportedSampleEndianness,  
00224         kErrorUnsupportedSampleOrder,       
00225         kErrorUnknownAudioType,             
00226         kErrorCodecInputFailure,            
00227         kErrorStreamReadFailure,            
00228         kErrorDeviceNonexistant,            
00229         kErrorDeviceFailure,                
00230         kErrorDeviceUnavailable,            
00231         kErrorUnsupportedOutputFlags,       
00232     };
00240     
00241     static const char * PlaybackResultToString(PlaybackResult result);
00242 
00243     class Client
00244     {
00245     public:
00246         virtual void OnAudioDecodeBegin(u32 nStreamID, CascadeStream * pStream, u32 nDurationInMilliseconds);
00247             // called when decoding of the stream begins
00248             // NOTE the nStreamID which is assigned to the stream indicated by pStream.
00249             // You'll need to NOTE it because that is what subsequent notifications use to uniquely identify the stream.
00250         virtual void OnAudioBuffering(u32 nStreamID, u32 nBuffersFilled, u32 nBuffersToFill);
00251             // Indicates that buffering is occurring either becuase of an initial pre-load or because
00252             // an underflow occurred.  nBuffersFilled / nBuffersToFill * 100 is the percent complete
00253             // of the buffering phase.  OnAudioBuffering gets called throughout the buffering
00254             // phase until nBuffersFilled == nBuffersToFill.
00255         virtual void OnAudioPlaybackBegin(u32 nStreamID);
00256             // Indicates audio has started to come out.  This function is called after pre-loading of buffers
00257             // is complete and audio starts actually playing, and also after an underflow when audio-buffering
00258             // has been re-engaged and finished, and audio is again flowing.
00259         virtual void OnAudioDecodeEnd(u32 nStreamID, CascadeStream * pStream, PlaybackResult result, u32 nPlaybackResultData);
00260             // Indicates that the player has finished decoding (and using) pStream.
00261             // pStream is now owned by the client again (CascadeAudioPlayer assumed ownership when QueueStream() was
00262             // called).  The client may feel free to delete pStream if they wish.
00263             // Note that OnAudioDecodeEnd() may be called significantly in advance of the end of the actual
00264             // audio playback.
00265         virtual void OnAudioPlaybackEnd(u32 nStreamID, PlaybackResult result);
00266             // Called when audio has finished playing.
00267 
00268         virtual void OnVisualizePrepare(u32 nStreamID, const SampleSet & samples);
00284         virtual void OnVisualizeExecute(u32 nStreamID, u32 nSequenceNumber, u32 nTimestampMilliseconds, u32 nBuffersQueued, u32 nTotalBuffers);
00308         virtual void OnPlaybackPause();
00309         virtual void OnPlaybackResume();
00310         virtual void OnPlaybackStop();
00311     };
00312 #ifndef DOXY_SKIP
00313     private:
00314         friend class CascadePrivate::CascadeAudioPlayerInitializer;
00315 #endif
00316 private:
00317     class Player;
00318     Player * m_pPlayer;
00319 };
00320 
00321 #endif // #ifndef _ROKU_INCLUDE_CASCADE_AV_CASCADEAUDIOPLAYER_H
00322 
00324 //  LOG
00326 //  07-Mar-04   dwoodward       created from CascadeMP3Player
00327 //  29-Mar-04   dwoodward   added codec registration
00328 //  25-May-04   mjkobb      Updated a comment
00329 //  16-Jun-04   dsletten    added nStreamUniqueID to SampleSet and OnVisualizeExecute()
00330 //  23-Jun-04   dwoodward   added Open() and Close()
00331 //  29-Sep-04   dwoodward   Added nOutputFlags parameter to QueueStream()
00332 //  09-Dec-04   mjkobb      Added SetVolumePercent
00333 //  28-Mar-05   dwoodward   got rid of RegisterCodec
00334 //  15-Apr-05   dwoodward   added OnPlaybackPause(), OnPlaybackResume(), OnPlaybackStop(), PlaybackResultToString()

Generated on Sun Jul 24 14:27:17 2005 for Cascade Library by  doxygen 1.4.1