examples/ForumNokia/AudioStreamExample/inc/AudioStreamEngine.h

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 #ifndef AUDIOSTREAMENGINE_H
00031 #define AUDIOSTREAMENGINE_H
00032 
00033 // INCLUDES
00034 #include <e32base.h>
00035 #include <aknviewappui.h> 
00036 
00037 #include <mda/common/audio.h>
00038 #include <MdaAudioInputStream.h>    // audio input stream
00039 #include <MdaAudioOutputStream.h>   // audio output stream
00040 
00041 #include "AudioStream.hrh"
00042 #include "AudioStreamView.h"    
00043 #include "AudioStreamAppUi.h"   
00044 
00045 // FORWARD DECLARATIONS
00046 class CAudioStreamView;
00047 
00048 // CLASS DECLARATION
00049 
00054 class CAudioStreamEngine : public CBase, MMdaAudioInputStreamCallback, 
00055     MMdaAudioOutputStreamCallback
00056 {
00057 public:
00064     static CAudioStreamEngine* NewL(CAudioStreamAppUi* /* aAppUi */);
00065 
00073     static CAudioStreamEngine* NewLC(CAudioStreamAppUi* /* aAppUi */);
00074 
00075 
00081     ~CAudioStreamEngine();
00082         
00083 
00084 public: // New functions
00085     
00091     void Play();
00097     void Record();
00103     void Stop();
00104     
00110     void LoadAudioFileL();
00116     void SaveAudioFileL();
00117 
00125     void SetEncodingL(TBool aAmr);
00126     
00127 private: // in-class methods
00128 
00138     TPtr8& CAudioStreamEngine::GetFrame(TUint aFrameIdx);
00148     TPtr8& CAudioStreamEngine::GetPlaybackFrames(TUint aLastFrame);
00149 
00159     void ShowMessage(const TDesC& /* aMsg */, TBool /* aReset=false */);
00160     
00171     virtual void MaiscOpenComplete(TInt aError);
00182     virtual void MaiscBufferCopied(TInt aError, const TDesC8& aBuffer);
00192     virtual void MaiscRecordComplete(TInt aError);
00193 
00204     virtual void MaoscOpenComplete(TInt aError);
00219     virtual void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer);
00220     
00230     virtual void MaoscPlayComplete(TInt aError);
00231 
00232     static TInt BackgroundStop( TAny *aStream );
00233     
00234 public: // Functions from base classes
00235 
00236 private: // Basic two-phase EPOC constructors
00237 
00244     void ConstructL();
00245  
00251     CAudioStreamEngine(CAudioStreamAppUi* /* aAppUi */);
00252 
00253 private:    
00254 
00255     // enumeration of input/output stream status
00256     enum TStatus
00257         {
00258         ENotReady,
00259         EOpen
00260         };
00261 
00262         
00263 private:    // data members
00264 
00265     // application UI object reference
00266     CAudioStreamAppUi* iAppUi;
00267     // audio input stream object reference
00268     CMdaAudioInputStream* iInputStream;
00269     // audio output stream object reference
00270     CMdaAudioOutputStream* iOutputStream;
00271 
00272     // Handle to CCoeEnv's file server
00273     RFs iFs;
00274 
00275     // Do we use AMR-NB encoding?
00276     TBool iUseAMR;
00277     // The path to the sample audio file (sample.aud or sample.amr)
00278     TFileName iAudioFilePath;
00279     // The audio file to be used (sample.aud or sample.amr)
00280     TFileName iAudioFile;   
00281     // The frame size for the current encoding
00282     TUint iFrameSize;
00283     // The number of frames to be buffered
00284     TUint iFrameCount;
00285 
00286     // A buffer containing the audio frames
00287     HBufC8* iStreamBuffer;  
00288     // Modifiable pointer used to reference a single frame in iStreamBuffer 
00289     // while recording, and all the valid frames in iStreamBuffer while playback (the
00290     // iStreamBuffer might not always be fully recorded in this example).
00291     TPtr8 iFramePtr;
00292     // Buffer status (does it contain valid audio data)
00293     TBool iBufferOK;
00294     // The default encoding used by the platform
00295     TFourCC iDefaultEncoding;
00296     // The encoding we are currently using
00297     TFourCC iCurrentEncoding;
00298 
00299     // Audio data stream settings for input and output streams
00300     TMdaAudioDataSettings iStreamSettings;
00301     // Status enumeration of input stream
00302     TStatus iInputStatus;
00303     // Status enumeration of output stream  
00304     TStatus iOutputStatus;
00305     // Index of audio data block currently being played/recorded on the buffer
00306     TUint iStreamIdx;
00307     // Application status message displayed to user
00308     TBuf<255> iMsg;
00309     // Stream start (first audio block in buffer) and end index
00310     TUint iStreamStart;
00311     TUint iStreamEnd;
00312     
00313     CIdle* iStop;
00314     
00315 };
00316 
00317 #endif // AUDIOSTREAMENGINE_H
00318 
00319 

Generated by  doxygen 1.6.2