sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __FILEWRITER_H sl@0: #define __FILEWRITER_H sl@0: sl@0: // INCLUDES sl@0: #include sl@0: #include "mp4atom.h" sl@0: sl@0: // CONSTANTS sl@0: const TInt KFileWriterBufferSizeSmall = 65536; sl@0: const TInt KFileWriterBufferSizeLarge = (4*65536); sl@0: const TInt KFileWriterSoftBufLimit = 12; sl@0: const TInt KFileWriterHardBufLimit = 16; sl@0: const TInt KFileWriterMinBufferCount = 4; // shouldn't be less than 4 sl@0: sl@0: // FORWARD DECLARATIONS sl@0: class RFile64; sl@0: sl@0: // CLASS DECLARATION sl@0: sl@0: /** sl@0: * Async buffering file writer. sl@0: */ sl@0: NONSHARABLE_CLASS(CFileWriter) : public CActive sl@0: { sl@0: public: sl@0: enum TOutputBufferSize sl@0: { sl@0: EBufferSizeSmall = 0, sl@0: EBufferSizeLarge, sl@0: EBufferSizeCustom sl@0: }; sl@0: sl@0: public: // Constructors and destructor sl@0: sl@0: /** sl@0: * Two-phased constructor. sl@0: */ sl@0: static CFileWriter* NewL( RFile64& aFile, TInt aInitSetSize = 0, TInt aOutputBufferSizeSmall = KFileWriterBufferSizeSmall, TInt aOutputBufferSizeLarge = KFileWriterBufferSizeLarge ); sl@0: sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: ~CFileWriter(); sl@0: sl@0: public: // New functions sl@0: sl@0: /** sl@0: * Writes incoming buffer data to internal buffers for writing to disk. sl@0: * @since 2.1 sl@0: * @param aBuf Data to be written sl@0: * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes. sl@0: */ sl@0: TInt Write( const TDesC8& aBuf ); sl@0: sl@0: /** sl@0: * Flush internal buffers to disk. sl@0: * @since 2.1 sl@0: * @param aBuf Additional data to be written before flush. sl@0: * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes. sl@0: */ sl@0: TInt Flush( const TDesC8& aBuf ); sl@0: sl@0: /** sl@0: * Set file output buffer size sl@0: * @since 2.6 sl@0: * @param aBufferSize Size of buffer. sl@0: * @param aHandle MP4Handle. sl@0: * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes. sl@0: */ sl@0: TInt SetOutputBufferSize( TOutputBufferSize aBufferSize, MP4Handle aHandle ); sl@0: sl@0: /** sl@0: * Set file output buffer count sl@0: * @since 3.0 sl@0: * @param aHandle MP4Handle. sl@0: */ sl@0: void SetOutputBufferCount( MP4Handle aHandle ); sl@0: sl@0: inline TInt64 OutputFileSize() const sl@0: { sl@0: return iOutputFileSize; sl@0: } sl@0: sl@0: protected: // Functions from base classes sl@0: sl@0: /** sl@0: * From CActive Cancels async request. sl@0: */ sl@0: void DoCancel(); sl@0: sl@0: /** sl@0: * From CActive Called when async request completes. sl@0: */ sl@0: void RunL(); sl@0: sl@0: private: sl@0: sl@0: /** sl@0: * C++ default constructor. sl@0: */ sl@0: CFileWriter( TInt aInitSetSize, TInt aOutputBufferSizeSmall, TInt aOutputBufferSizeLarge ); sl@0: sl@0: /** sl@0: * By default Symbian 2nd phase constructor is private. sl@0: */ sl@0: void ConstructL( RFile64& aFile ); sl@0: sl@0: /** sl@0: * Writes incoming data to internal buffers and buffer queues.. sl@0: * @since 2.1 sl@0: * @param aBuf Data to be added to buffers.. sl@0: * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes. sl@0: */ sl@0: TInt AddDataToBuffer( const TDesC8& aBuf ); sl@0: sl@0: /** sl@0: * Allocates input and output buffers. sl@0: * @since 2.6 sl@0: */ sl@0: void AllocateBuffersL(); sl@0: sl@0: /** sl@0: * Updates output file size and reserves extra space for following writing if iSetSize is set. sl@0: * Takes into account if the position in the file was changed. sl@0: */ sl@0: void UpdateOutputFileSize(); sl@0: sl@0: private: sl@0: // Whether we are flushing after async write. sl@0: TBool iFlush; sl@0: // Flag whether there is async writing going. sl@0: TBool iAsyncWritingOngoing; sl@0: // Flag whether we have received any data. sl@0: TBool iWritingStarted; sl@0: // Flag whether init has been done sl@0: TBool iMemReadyForWriting; sl@0: sl@0: // Write error code. sl@0: TInt iError; sl@0: sl@0: // Current set file size sl@0: TInt64 iSetSize; sl@0: // Current output file size sl@0: TInt64 iOutputFileSize; sl@0: sl@0: TInt iOutputBufferSizeSmall; sl@0: TInt iOutputBufferSizeLarge; sl@0: sl@0: // Output buffer size. sl@0: TInt iOutputBufferSize; sl@0: // Hard limit for max output buffers sl@0: TInt iMaxOutputBufHardLimit; sl@0: // Soft limit for max output buffers sl@0: TInt iMaxOutputBufSoftLimit; sl@0: sl@0: sl@0: // Output file for writes. sl@0: RFile64* iOutputFile; sl@0: // Queue of empty write buffers. sl@0: RPointerArray iEmptyBufferQueue; sl@0: // Queue of full write buffers. sl@0: RPointerArray iFullBufferQueue; sl@0: sl@0: // Current input buffers for incoming data. sl@0: HBufC8* iInputBuf; sl@0: }; sl@0: sl@0: #endif //__FILEWRITER_H sl@0: // End of File