00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CMEDIACLIENTENGINE
00019 #define CMEDIACLIENTENGINE
00020
00021 #include <e32std.h>
00022 #include <f32file.h>
00023 #include <badesca.h>
00024
00025 #include <mdaaudiosampleplayer.h>
00026 #include <mdaaudiotoneplayer.h>
00027 #include <mdaaudiosampleeditor.h>
00028 #include <mdaaudiooutputstream.h>
00029
00030 class MExEngineObserver;
00031
00032
00033 typedef RPointerArray<CMMFMetaDataEntry> RMetaDataArray;
00034
00036 class TFormatOptions
00037 {
00038 public:
00039 TFormatOptions() {Reset();}
00040 virtual void Reset() {i4CCSet = iBitRateSet = iSampleRateSet = iChannelSet = EFalse;}
00041 public:
00042
00043 TFourCC i4CC;
00044 TUint iBitRate;
00045 TUint iSampleRate;
00046 TUint iChannel;
00047
00048 TBool i4CCSet;
00049 TBool iBitRateSet;
00050 TBool iSampleRateSet;
00051 TBool iChannelSet;
00052 };
00053
00056 class TRecordFormatOptions: public TFormatOptions
00057 {
00058 public:
00059 TRecordFormatOptions() {Reset();}
00060 void Reset()
00061 {
00062 TFormatOptions::Reset();
00063 iBalanceSet = iGainSet = EFalse;
00064 }
00065 public:
00066
00067 TInt iBalance;
00068 TInt iGain;
00069
00070 public:
00071
00072 TBool iBalanceSet;
00073 TBool iGainSet;
00074 };
00075
00082 class CMediaClientEngine : public CBase,
00083 public MMdaAudioPlayerCallback,
00084 public MMdaAudioToneObserver,
00085 public MMdaObjectStateChangeObserver,
00086 public MMdaAudioOutputStreamCallback
00087 {
00088 public:
00090 enum TExVolume
00091 {
00093 ELoud=1,
00095 EMedium,
00097 EQuiet
00098 };
00099
00101 enum TExRecordGain
00102 {
00104 EGainMax,
00106 EGainMedium,
00108 EGainLow
00109 };
00110
00112 enum TState
00113 {
00115 EIdle,
00117 ETonePrepare,
00119 ETonePlaying,
00121 EPlayFilePrepare,
00123 EPlayFilePlaying,
00125 ERecordPrepare,
00127 ERecording,
00129 EGetMetaData1,
00131 EGetMetaData2,
00133 EConvert,
00135 EConvertComplete,
00137 EStreamPrepare,
00139 EStreamStarted,
00141 ENextStreamBuf,
00143 EStreamError,
00145 EStreamStopping
00146 };
00147
00148 public:
00151 CMediaClientEngine(RFs& aFs);
00153 ~CMediaClientEngine();
00156 void SetObserver(MExEngineObserver& aObserver);
00160 void PlayL(const TDesC &aFile);
00165 void PlayL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
00168 void PlayL();
00171 void WriteToStreamL(const TDesC8& aData);
00173 CMdaAudioRecorderUtility* NewRecorderL(const TDesC& aTargetType);
00175 void RecordTypesL(CDesCArray& aTypeArray);
00178 void RecordL(const TDesC &aFile, const TRecordFormatOptions& aRecordOptions);
00180 void Stop();
00182 void GetMetaDataL(const TFileName& aFile, RMetaDataArray& aMetaData);
00184 static void DestinationTypesL(const TFileName& aFile, CDesCArray& aExt);
00186 CMdaAudioConvertUtility* NewConverterL(const TFileName& aFile, const TDesC& aTargetType,
00187 TFileName& aTargetFile);
00189 void ConvertL(const TFileName& aFile, const TDesC& aTargetType, const TFormatOptions& aOptions);
00191 TExVolume Volume() const;
00194 void SetVolume(TExVolume aVolume);
00195
00198 TState Status() const;
00199
00200 private:
00202 enum TPanics
00203 {
00205 EInProgress,
00207 ENullObserver,
00209 ENotReady,
00211 ENullTonePlayer,
00213 EWrongState,
00215 ENullPlayerUtility
00216 };
00217
00218 private:
00219
00223 void MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration);
00224
00227 void MapcPlayComplete(TInt aError);
00230 void MatoPrepareComplete(TInt aError);
00233 void MatoPlayComplete(TInt aError);
00234
00235
00241 void MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState,
00242 TInt aCurrentState, TInt aErrorCode);
00243
00246 void MaoscPlayComplete(TInt aError);
00249 void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer);
00252 void MaoscOpenComplete(TInt aError);
00253
00255 void Convert2L();
00257 void Record2L();
00258
00260 void ToneCleanup();
00262 void PlayCleanup();
00264 void RecordCleanup();
00266 void StreamCleanup();
00268 void ConvertCleanup();
00269
00272 void Panic(TPanics aPanic);
00273
00274 private:
00276 TFileName iFileName;
00278 TFileName iTargetFile;
00280 RFs& iFs;
00282 TState iState;
00284 TExVolume iVolume;
00286 TExRecordGain iGain;
00288 MExEngineObserver* iEngineObserver;
00289
00291 CMdaAudioToneUtility* iAudioToneUtility;
00293 CMdaAudioPlayerUtility* iAudioPlayUtility;
00295 CMdaAudioRecorderUtility* iAudioRecorderUtility;
00297 CMdaAudioOutputStream* iAudioStreamPlayer;
00299 CMdaAudioConvertUtility* iConvertUtility;
00300
00302 TMdaAudioDataSettings iSettings;
00304 RMetaDataArray* iMetaData;
00306 const TFormatOptions* iOptions;
00308 const TRecordFormatOptions* iRecordFormatOptions;
00309 };
00310
00312 class MExEngineObserver
00313 {
00314 public:
00318 virtual void HandleEngineState(CMediaClientEngine::TState aState, TInt aError) = 0;
00319 };
00320
00322 class CRecorderCreator: public CActive, public MMdaObjectStateChangeObserver
00323 {
00324 public:
00325 static CMdaAudioRecorderUtility* NewRecorderL(const TDesC& aTargetType);
00326
00327 private:
00328 CRecorderCreator();
00329 CMdaAudioRecorderUtility* ConstructL(const TDesC& aTargetType);
00330 void RunL();
00331 void DoCancel();
00332 void MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode);
00333
00334 private:
00335 CMdaAudioRecorderUtility* iRecorderUtility;
00336 };
00337
00338
00340 class CConverterCreator: public CActive, public MMdaObjectStateChangeObserver
00341 {
00342 public:
00343 static CMdaAudioConvertUtility* NewConverterL(const TFileName& aFile, const TDesC& aTargetType,
00344 TFileName& aTargetFile);
00345
00346 private:
00347 CConverterCreator();
00348 CMdaAudioConvertUtility* ConstructL(const TFileName& aFile, const TDesC& aTargetType,
00349 TFileName& aTargetFile);
00350 void RunL();
00351 void DoCancel();
00352 void MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode);
00353
00354 private:
00355 CMdaAudioConvertUtility* iConvertUtility;
00356 };
00357
00358
00359 #endif // CMEDIACLIENTENGINE