mmfenh/progressivedownload/ProgressiveDownloadUtility/src/EMCPdProperties.h
changeset 16 43d09473c595
parent 14 80975da52420
child 22 128eb6a32b84
equal deleted inserted replaced
14:80975da52420 16:43d09473c595
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Progressive Download Utility
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __EMCPDPROPERTIES_H__
       
    20 #define __EMCPDPROPERTIES_H__
       
    21 
       
    22 #include <e32std.h>
       
    23 #include <e32base.h>
       
    24 #include <f32file.h>
       
    25 #include "MAudioPlayUtility.h"
       
    26 #include "EMCPdPlayUtility.h"
       
    27 
       
    28 #include "mmfclientutility.h"
       
    29 
       
    30 #include <mmf/common/mmcaf.h>
       
    31 
       
    32 #include <StreamControl.h>
       
    33 #include <ControlObserver.h>
       
    34 #include <Events.h>
       
    35 #include <DataBufferSource.h>
       
    36 #include <DataBuffer.h>
       
    37 #include <MMControlFactory.h>
       
    38 #include <SinkControl.h>
       
    39 #include <MimeTypes.h>
       
    40 #include <VolumeControl.h>
       
    41 #include <StreamControlObserver.h>
       
    42 #include <SourceControlObserver.h>
       
    43 
       
    44 #include "BufferEmptiedEventAO.h"
       
    45 #include "ContentFile.h"
       
    46 
       
    47 using namespace multimedia;
       
    48 
       
    49 using multimedia::MStreamControl;
       
    50 using multimedia::MControlObserver;
       
    51 using multimedia::MDataBufferSource;
       
    52 using multimedia::MDataBuffer;
       
    53 using multimedia::MControl;
       
    54 using multimedia::CMultimediaFactory;
       
    55 using multimedia::MSinkControl;
       
    56 using multimedia::MVolumeControl;
       
    57 using multimedia::MSourceControlObserver;
       
    58 using multimedia::MStreamControlObserver;
       
    59 
       
    60 //static const TUid KUidMmfAudioController = {KMmfUidControllerAudio};
       
    61 
       
    62 
       
    63 /**
       
    64 Mixin class to allow notification that the timed silence has finished.
       
    65 */
       
    66 class MRepeatTrailingSilenceTimerObs
       
    67 	{
       
    68 public:
       
    69 	virtual void RepeatTrailingSilenceTimerComplete() = 0;
       
    70 	};
       
    71 
       
    72 /**
       
    73 CTimer-based active object that waits the requested time before notifying its observer.
       
    74 */
       
    75 class CRepeatTrailingSilenceTimer : public CTimer
       
    76 	{
       
    77 public:
       
    78 	static CRepeatTrailingSilenceTimer* NewL(MRepeatTrailingSilenceTimerObs& aObs);
       
    79 	void RunL();
       
    80 private:
       
    81 	CRepeatTrailingSilenceTimer(MRepeatTrailingSilenceTimerObs& aObs);
       
    82 private:
       
    83 	MRepeatTrailingSilenceTimerObs& iObs;
       
    84 	};
       
    85 
       
    86 /**
       
    87 Active object utility class to allow the callback to be called asynchronously.
       
    88 This should help prevent re-entrant code in clients of the mediaframework.
       
    89 */
       
    90 class CMMFMdaAudioPlayerCallBack : public CActive
       
    91 	{
       
    92 public:
       
    93 	enum TCallbackState {
       
    94 		ECallbackInitComplete,
       
    95 		ECallbackPlayComplete,
       
    96 		ECallbackPlaying,
       
    97 		ECallbackPaused
       
    98 		};
       
    99 
       
   100 
       
   101 public:
       
   102 	static CMMFMdaAudioPlayerCallBack* NewL(MAudioPdPlayUtilityCallback& aCallback);
       
   103 	~CMMFMdaAudioPlayerCallBack();
       
   104 	void InitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration);
       
   105 	void PlayComplete(TInt aError);
       
   106 	void PlayingCallback();
       
   107 	void PausedCallback();
       
   108 private:
       
   109 	CMMFMdaAudioPlayerCallBack(MAudioPdPlayUtilityCallback& aCallback);
       
   110 	void RunL();
       
   111 	void DoCancel();
       
   112 private:
       
   113 	MAudioPdPlayUtilityCallback& iCallback;
       
   114 	TInt iError;
       
   115 	TTimeIntervalMicroSeconds iDuration;
       
   116 	TCallbackState iState;
       
   117 	};
       
   118 
       
   119 
       
   120 
       
   121 /**
       
   122 Concrete implementation of the CAudioPdPlayUtility API.
       
   123 @see CAudioPdPlayUtility
       
   124 */
       
   125 
       
   126 class CAudioPdProperties: public CBase,
       
   127                             public MControlObserver,
       
   128                             public MBufferEmptiedObserver,
       
   129                             public MMMFDRMCustomCommand
       
   130 	{
       
   131 
       
   132 public:
       
   133 
       
   134 	enum TMMFAudioPlayerState
       
   135 		{
       
   136 		EStopped,
       
   137 		EOpening,
       
   138 		EPaused,
       
   139 		EPlaying,
       
   140 		EBuffering,
       
   141 		EPrimed
       
   142 		};
       
   143 
       
   144 	static CAudioPdProperties* NewL(MAudioPdPlayUtilityCallback& aCallback);
       
   145 	static CAudioPdProperties* NewLC(MAudioPdPlayUtilityCallback& aCallback);
       
   146 
       
   147 	~CAudioPdProperties();
       
   148 
       
   149 
       
   150    //For Download Status
       
   151     void HandleDownloadEventL(TUint aTransactionID,
       
   152                               TBrCtlDownloadEvent aEvent,
       
   153                               TUint aValue);
       
   154 
       
   155 
       
   156 	 //For Audio control
       
   157 	void Play();
       
   158 	void Stop();
       
   159 	TInt Pause();
       
   160 	void SetVolume(TInt aVolume);
       
   161 	void SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence);
       
   162 	void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
       
   163 	const TTimeIntervalMicroSeconds& Duration();
       
   164 	TInt MaxVolume();
       
   165 	void Close();
       
   166 	TInt GetPosition(TTimeIntervalMicroSeconds& aPosition);
       
   167 	void SetPosition(const TTimeIntervalMicroSeconds& aPosition);
       
   168 
       
   169 	TInt SetPriority(TInt aPriority, TMdaPriorityPreference aPref);
       
   170 	TInt GetVolume(TInt& aVolume);
       
   171 	TInt GetNumberOfMetaDataEntries(TInt& aNumEntries);
       
   172 	CMMFMetaDataEntry* GetMetaDataEntryL(TInt aMetaDataIndex);
       
   173 	TInt SetPlayWindow(const TTimeIntervalMicroSeconds& aStart,
       
   174 								const TTimeIntervalMicroSeconds& aEnd);
       
   175 	TInt ClearPlayWindow();
       
   176 	TInt SetBalance(TInt aBalance = KMMFBalanceCenter);
       
   177 	TInt GetBalance(TInt& aBalance);
       
   178 	TInt GetBitRate(TUint& aBitRate);
       
   179 
       
   180 	void RegisterForAudioLoadingNotification(MAudioLoadingObserver& aCallback);
       
   181 	void GetAudioLoadingProgressL(TInt& aPercentageProgress);
       
   182 	const CMMFControllerImplementationInformation& ControllerImplementationInformationL();
       
   183 
       
   184 	TInt CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom);
       
   185 	TInt CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2);
       
   186 	void CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus);
       
   187 	void CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus);
       
   188 
       
   189 
       
   190 	MMMFDRMCustomCommand* GetDRMCustomCommand();
       
   191 
       
   192 	void OpenFileL(const TDesC& aFileName);
       
   193 	void OpenFileL(const RFile& aFile);
       
   194 
       
   195     void DlCompleteOpenFileL(const TDesC& aFileName);
       
   196 
       
   197 	TInt GetFilePosition(TInt& aFilePosition);
       
   198 	TInt SetFileSize(TInt aFileSize);
       
   199 	TInt SetBytesDownloaded(TInt aBytesDownloaded, TBool isDownloadComplete);
       
   200 
       
   201 	TInt CheckAudioPlayerState();
       
   202 
       
   203     TInt DisableAutomaticIntent(TBool aDisableAutoIntent);
       
   204     TInt ExecuteIntent(ContentAccess::TIntent aIntent);
       
   205     TInt EvaluateIntent(ContentAccess::TIntent aIntent);
       
   206     TInt SetAgentProperty(ContentAccess::TAgentProperty aProperty, TInt aValue);
       
   207 
       
   208 private:
       
   209 
       
   210     void Event( MControl* aControl, TUint aEventType, TAny* aEventObject );
       
   211     void BufferEmptiedBySource();
       
   212     void FillSourceBuffers();
       
   213     void CreateAudioBuffersL();
       
   214     void DetermineFNMimeType(const TDesC& aFileName, TDes8& aMimeType);
       
   215     void DetermineFHMimeType(const RFile& aFile, TDes8& aMimeType);
       
   216     TInt ReadFromFileAndWriteToStream(TInt aIndex)    ;
       
   217     TInt ExtractDRMRestrictionsL();
       
   218     TInt ReOpenCAF();
       
   219 
       
   220 	CAudioPdProperties(/*MMdaAudioPlayerCallback*/MAudioPdPlayUtilityCallback& aCallback);
       
   221 	void ConstructL(MAudioPdPlayUtilityCallback& aCallback);
       
   222 
       
   223 private:
       
   224 
       
   225 	//MAudioPdPlayUtilityCallback* iAudioPdPlayCallback;
       
   226 
       
   227 	// last play window command
       
   228 	enum TPlayWindowCommand
       
   229 		{
       
   230 		ENone,
       
   231 		ESet,
       
   232 		EClear
       
   233 		};
       
   234 
       
   235 	MAudioPdPlayUtilityCallback& iCallback;
       
   236 	CMMFMdaAudioPlayerCallBack* iAsyncCallBack;
       
   237 
       
   238 	MAudioLoadingObserver* iLoadingObserver;
       
   239 	RMMFController iController;
       
   240 	RMMFController* iControllerPtr;
       
   241 	TMMFAudioPlayerState iState;
       
   242 	TTimeIntervalMicroSeconds iDuration; // Needed because of api "Duration()" that returns a reference
       
   243 	TMMFPrioritySettings iPrioritySettings;
       
   244 
       
   245 	TInt iNumberOfTimesPlayed;
       
   246 	TInt iNumberOfTimesToRepeat;
       
   247 	TTimeIntervalMicroSeconds iTrailingSilence;
       
   248 
       
   249 	// Custom command handlers
       
   250 	RMMFAudioPlayDeviceCustomCommands iAudioPlayDeviceCommands;
       
   251 	RMMFAudioPlayControllerCustomCommands iAudioPlayControllerCommands;
       
   252 	RMMFDRMCustomCommands iDRMCustomCommands;
       
   253 
       
   254 	// Current playback time so we can resume from where we were stopped
       
   255 	TTimeIntervalMicroSeconds iPosition;
       
   256 
       
   257 	// Play window start and end times and whether it has been set
       
   258 	TTimeIntervalMicroSeconds iPlayStart;
       
   259 	TTimeIntervalMicroSeconds iPlayEnd;
       
   260 	TPlayWindowCommand iPlayWindowSet;
       
   261 	//RArray<TUid> iMediaIds;
       
   262 
       
   263 	CMMFControllerImplementationInformation* iControllerImplementationInformation;
       
   264 	TUid iControllerUid;
       
   265 
       
   266 
       
   267     MStreamControl* iStreamControl;
       
   268     MDataBufferSource* iMDataBufferSource;
       
   269     MSinkControl* iMAudioSink;
       
   270     MVolumeControl* iMVolumeControl;
       
   271 
       
   272     RFs             iFs;
       
   273     CContentFile*    iFile;
       
   274     RFile               iFileHandle;
       
   275 
       
   276     RPointerArray<MDataBuffer> iBuffers;
       
   277     RArray<TInt> iAvailable;
       
   278     TBool        iIsEOFReached;
       
   279     TInt         iBytesReadFromFile;
       
   280     TInt         iFileSizeInBytes;
       
   281     CMultimediaFactory* iFactory;
       
   282     HBufC8* iMimeType;
       
   283     MStreamControl::TStreamState iStreamState;
       
   284     CBufferEmptiedEventAO* iBufferEmptiedEventAO;
       
   285     TInt iFileSize;
       
   286     TBool iBuffering;
       
   287     TInt iBytesDownloaded;
       
   288     TBool iStopCalled;
       
   289     HBufC* iFileName;
       
   290     TBool isProtected;
       
   291     TBool iDisableAutoIntent;
       
   292     TBool iMetaDataRead;
       
   293     // Metadata entries, if supported
       
   294     RPointerArray<CMMFMetaDataEntry> iMetaDataEntries;
       
   295     TBool iControllerLoaded;
       
   296     TBool iDownloadComplete;
       
   297 	};
       
   298 
       
   299 #endif