mmfenh/progressivedownload/ProgressiveDownloadSource/src/ProgressiveDownloadSource.h
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     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 
       
    20 #ifndef __PROGRESSIVEDOWNLOADSOURCE_H_
       
    21 #define __PROGRESSIVEDOWNLOADSOURCE_H_
       
    22 
       
    23 #include <f32file.h>
       
    24 
       
    25 #include <mmf/server/mmfclip.h>
       
    26 #include <mmf/server/mmfdatabuffer.h>
       
    27 #include <mmf/common/mmcaf.h>
       
    28 
       
    29 #include "ProgressiveDownloadSourceUIDs.hrh"
       
    30 
       
    31 class CReadWriteRequest;
       
    32 class CTransferBufferCopy;
       
    33 class MGenericFile;
       
    34 
       
    35 /**
       
    36 @publishedAll
       
    37 @released
       
    38 
       
    39 Provides the filename and path of file.
       
    40 
       
    41 Used by CMMFFile::ConstructL().
       
    42 */
       
    43 class TMMFFileParams
       
    44 	{
       
    45 public:
       
    46 	/**
       
    47 	Filename and path of file.
       
    48 	*/
       
    49 	TFileName iPath ; // Filename and path of file.
       
    50 private:
       
    51 	/**
       
    52 	This member is internal and not intended for use.
       
    53 	*/
       
    54 	TInt iReserved1;
       
    55 	};
       
    56 
       
    57 /**
       
    58 @internalTechnology
       
    59 */
       
    60 const TUid KFileHandleUid = {0x101FFA19};
       
    61 const TUid KMMFileSourceUid = {0x101F7DA9};
       
    62 const TUid KMMFileHandleSourceUid = {0x101F7DAA};
       
    63 /**
       
    64 @publishedAll
       
    65 @released
       
    66 
       
    67 Provides a pointer to the file handle
       
    68 
       
    69 Used by CMMFFile::ConstructL().
       
    70 */
       
    71 class TMMFFileHandleParams
       
    72 	{
       
    73 public:
       
    74 	TMMFFileHandleParams(RFile* aFile) : iUid(KFileHandleUid), iFile(aFile) {}
       
    75 	TMMFFileHandleParams() : iUid(KFileHandleUid) {}
       
    76 
       
    77 	TUid iUid;
       
    78 	/**
       
    79 	Handle of file
       
    80 	*/
       
    81 	RFile* iFile;
       
    82 private:
       
    83 	/**
       
    84 	This member is internal and not intended for use.
       
    85 	*/
       
    86 	TInt iReserved1;
       
    87 	};
       
    88 
       
    89 
       
    90 
       
    91 
       
    92 /**
       
    93 @publishedAll
       
    94 @released
       
    95 */
       
    96 typedef TPckgBuf<TMMFFileParams>  TMMFFileConfig ;
       
    97 
       
    98 /**
       
    99 @publishedAll
       
   100 @released
       
   101 */
       
   102 typedef TPckgBuf<TMMFFileHandleParams>  TMMFFileHandleConfig ;
       
   103 
       
   104 
       
   105 /**
       
   106 @publishedAll
       
   107 @released
       
   108 
       
   109 This details how big the iTransferBufferCopies array of CMMFFile may
       
   110 become before we start looking to free entries.
       
   111 */
       
   112 const TInt KAcceptableTransferBufferCopiesSize = 5;
       
   113 
       
   114 /**
       
   115 @publishedAll
       
   116 @released
       
   117 
       
   118 This details how big the iTransferBufferCopies array of CMMFFile may
       
   119 become before we start looking to free entries.
       
   120 */
       
   121 const TInt KMaximumTransferBufferCopiesSize = 100;
       
   122 
       
   123 
       
   124 /**
       
   125 @publishedAll
       
   126 @released
       
   127 
       
   128 MultiMedia framework class.  Represents a physical file.
       
   129 
       
   130 This may be source file from which data is read or destination to which data is written.
       
   131 
       
   132 Intended to be used by controller plugin developers for source and sink plugins.
       
   133 */
       
   134 class CProgressiveDownloadSource : public CMMFClip
       
   135 	{
       
   136 public:
       
   137 	// From MDataSource
       
   138 	virtual TFourCC SourceDataTypeCode(TMediaId aMediaId) ;
       
   139 	virtual void FillBufferL( CMMFBuffer* aBuffer, MDataSink* aConsumer, TMediaId aMediaId ) ;
       
   140 	virtual void BufferEmptiedL( CMMFBuffer* aBuffer ) ;
       
   141 	virtual TBool CanCreateSourceBuffer() ;
       
   142 	virtual CMMFBuffer* CreateSourceBufferL( TMediaId aMediaId, TBool &aReference ) ;
       
   143 	virtual TInt SourceThreadLogon(MAsyncEventHandler& aEventHandler) ;
       
   144 	virtual void SourceThreadLogoff();
       
   145 	virtual void SourcePrimeL();
       
   146 	virtual void SourceStopL();
       
   147 
       
   148 	// From MDataSink
       
   149 	virtual TFourCC SinkDataTypeCode(TMediaId aMediaId) ; //used by data path MDataSource/Sink for codec matching
       
   150 	virtual void EmptyBufferL( CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId ) ;
       
   151 	virtual void BufferFilledL( CMMFBuffer* aBuffer ) ;
       
   152 	virtual TBool CanCreateSinkBuffer() ;
       
   153 	virtual CMMFBuffer* CreateSinkBufferL( TMediaId aMediaId , TBool &aReference) ;
       
   154 	virtual TInt SinkThreadLogon(MAsyncEventHandler& aEventHandler) ;
       
   155 	virtual void SinkThreadLogoff();
       
   156 	virtual void SinkPrimeL();
       
   157 	virtual void SinkStopL();
       
   158 
       
   159 	// From CMMFClip
       
   160 	virtual void ReadBufferL( TInt aLength, CMMFBuffer* aBuffer, TInt aPosition, MDataSink* aConsumer);
       
   161 	virtual void WriteBufferL( TInt aLength, CMMFBuffer* aBuffer, TInt aPosition, MDataSource* aSupplier);
       
   162 	virtual void ReadBufferL( CMMFBuffer* aBuffer, TInt aPosition, MDataSink* aConsumer) ;
       
   163 	virtual void WriteBufferL( CMMFBuffer* aBuffer, TInt aPosition, MDataSource* aSupplier) ;
       
   164 	virtual void ReadBufferL( CMMFBuffer* aBuffer, TInt aPosition ) ;
       
   165 	virtual void WriteBufferL( CMMFBuffer* aBuffer, TInt aPosition ) ;
       
   166 	virtual TInt64 BytesFree() ;  // amount of space available for the clip
       
   167 	virtual TInt Size() ;
       
   168 	virtual TInt Delete();
       
   169 	virtual TInt SetSize(TInt aSize);
       
   170 
       
   171 	// New Functions
       
   172 	virtual const TDesC& FileName() const ;
       
   173 	virtual const TDesC& Extension() const ;
       
   174 	virtual const TDesC& FilePath() const ;
       
   175 	virtual const TDesC& FileDrive() const ;
       
   176 	virtual const TFileName FullName() const;
       
   177 	virtual RFile& FileL() ;
       
   178 
       
   179 	virtual void SourceCustomCommand(TMMFMessage& aMessage);
       
   180 
       
   181 
       
   182 public :
       
   183 	virtual ~CProgressiveDownloadSource() ;
       
   184 	static MDataSource* NewSourceL() ;
       
   185 	static MDataSink* NewSinkL() ;
       
   186 
       
   187 	void SetTransferBuffer (TBool aTBuffer) ;
       
   188 	TBool CanUseTransferBuffer () ;
       
   189 	virtual TBool SinkStopped();
       
   190 
       
   191 protected :
       
   192 	/**
       
   193 	Indicates for which purpose the object instance is being created
       
   194 	*/
       
   195 	enum TMMFileMode
       
   196 		{
       
   197 		/** The object is created for being a source */
       
   198 		ESourceMode,
       
   199 		/** The object is created for being a sink */
       
   200 		ESinkMode
       
   201 		};
       
   202 	virtual void ConstructSourceL( const TDesC8& aInitData ) ;
       
   203 	virtual void ConstructSinkL( const TDesC8& aInitData ) ;
       
   204 	void ConstructL(const TDesC8& aInitData, TMMFileMode aFileMode) ;
       
   205 	CProgressiveDownloadSource() ;
       
   206 
       
   207 	void StoreRequestL( CReadWriteRequest* aRequest ) ;
       
   208 	void CancelRequests();
       
   209 
       
   210 
       
   211 	CTransferBufferCopy* ObtainCopyOfTransferBufferL(TInt aMaxLength);
       
   212 
       
   213 public:
       
   214 	// Additional virtuals for DRM Intent
       
   215 	virtual TInt ExecuteIntent(ContentAccess::TIntent aIntent);
       
   216 	virtual TInt EvaluateIntent(ContentAccess::TIntent aIntent) const;
       
   217 	virtual TBool IsProtectedL() const;
       
   218 
       
   219 
       
   220 	virtual TInt SetAgentProperty(ContentAccess::TAgentProperty aProperty, TInt aValue);
       
   221 	virtual const TDesC& UniqueId() const;
       
   222 
       
   223 
       
   224 private:
       
   225 	class CMMFFileAsyncEventHandler : public MAsyncEventHandler
       
   226 		{
       
   227 		public:
       
   228 			CMMFFileAsyncEventHandler(CProgressiveDownloadSource* aParent);
       
   229 			virtual ~CMMFFileAsyncEventHandler();
       
   230 		public:
       
   231 			virtual TInt SendEventToClient(const TMMFEvent& aEvent);
       
   232 		private:
       
   233 			CProgressiveDownloadSource* iParent;
       
   234 		};
       
   235 private:
       
   236 	MGenericFile* iFile;
       
   237 	RFs iFsSession;
       
   238 
       
   239 	TBool iFileHandle;
       
   240 	RFile iHandle;
       
   241 	TBool iFileOpen; // "virtual" open, makes sure that certain accesses are between Prime and Stop
       
   242 
       
   243 	TBool iSinkNotStopped;
       
   244 
       
   245 	TFileName iFullFileName ;
       
   246 	HBufC* iFileName ;
       
   247 	HBufC* iFileExt ;
       
   248 	HBufC* iFilePath ;
       
   249 	HBufC* iFileDrive ;
       
   250 
       
   251 	HBufC* iUniqueId;
       
   252 
       
   253 	TInt iFileSize; //holds the cached file size
       
   254 
       
   255 	TInt iFix;
       
   256 
       
   257 	//Keeps track of the read position within the file. Needed in order to enable passing of the
       
   258 	//read position to the CReadRequest to manage the LastBuffer flag.
       
   259 	//NB: Continuous reads once EOF has been reached will result in iPosition going > iFileSize,
       
   260 	//but this causes no ill effects
       
   261 	TUint iPosition;
       
   262 
       
   263 	TFourCC  iSinkFourCC ;
       
   264 	TFourCC  iSourceFourCC ;
       
   265 
       
   266 
       
   267 	RPointerArray<CReadWriteRequest> iRequests;
       
   268 
       
   269 	MAsyncEventHandler *iEventHandler;
       
   270 	CMMFFileAsyncEventHandler* iMmfFileEventHandler;
       
   271 
       
   272 	RPointerArray<CTransferBufferCopy> iTransferBufferCopies;
       
   273 	friend class CMMFFileAsyncEventHandler;
       
   274 	TInt iBytesDownloaded;
       
   275 	};
       
   276 
       
   277 
       
   278 
       
   279 
       
   280 #endif