1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmplugins/lib3gp/impl/inc/filewriter.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,184 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#ifndef __FILEWRITER_H
1.20 +#define __FILEWRITER_H
1.21 +
1.22 +// INCLUDES
1.23 +#include <e32base.h>
1.24 +#include "mp4atom.h"
1.25 +
1.26 +// CONSTANTS
1.27 +const TInt KFileWriterBufferSizeSmall = 65536;
1.28 +const TInt KFileWriterBufferSizeLarge = (4*65536);
1.29 +const TInt KFileWriterSoftBufLimit = 12;
1.30 +const TInt KFileWriterHardBufLimit = 16;
1.31 +const TInt KFileWriterMinBufferCount = 4; // shouldn't be less than 4
1.32 +
1.33 +// FORWARD DECLARATIONS
1.34 +class RFile64;
1.35 +
1.36 +// CLASS DECLARATION
1.37 +
1.38 +/**
1.39 +* Async buffering file writer.
1.40 +*/
1.41 +NONSHARABLE_CLASS(CFileWriter) : public CActive
1.42 + {
1.43 + public:
1.44 + enum TOutputBufferSize
1.45 + {
1.46 + EBufferSizeSmall = 0,
1.47 + EBufferSizeLarge,
1.48 + EBufferSizeCustom
1.49 + };
1.50 +
1.51 + public: // Constructors and destructor
1.52 +
1.53 + /**
1.54 + * Two-phased constructor.
1.55 + */
1.56 + static CFileWriter* NewL( RFile64& aFile, TInt aInitSetSize = 0, TInt aOutputBufferSizeSmall = KFileWriterBufferSizeSmall, TInt aOutputBufferSizeLarge = KFileWriterBufferSizeLarge );
1.57 +
1.58 + /**
1.59 + * Destructor.
1.60 + */
1.61 + ~CFileWriter();
1.62 +
1.63 + public: // New functions
1.64 +
1.65 + /**
1.66 + * Writes incoming buffer data to internal buffers for writing to disk.
1.67 + * @since 2.1
1.68 + * @param aBuf Data to be written
1.69 + * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
1.70 + */
1.71 + TInt Write( const TDesC8& aBuf );
1.72 +
1.73 + /**
1.74 + * Flush internal buffers to disk.
1.75 + * @since 2.1
1.76 + * @param aBuf Additional data to be written before flush.
1.77 + * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
1.78 + */
1.79 + TInt Flush( const TDesC8& aBuf );
1.80 +
1.81 + /**
1.82 + * Set file output buffer size
1.83 + * @since 2.6
1.84 + * @param aBufferSize Size of buffer.
1.85 + * @param aHandle MP4Handle.
1.86 + * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
1.87 + */
1.88 + TInt SetOutputBufferSize( TOutputBufferSize aBufferSize, MP4Handle aHandle );
1.89 +
1.90 + /**
1.91 + * Set file output buffer count
1.92 + * @since 3.0
1.93 + * @param aHandle MP4Handle.
1.94 + */
1.95 + void SetOutputBufferCount( MP4Handle aHandle );
1.96 +
1.97 + inline TInt64 OutputFileSize() const
1.98 + {
1.99 + return iOutputFileSize;
1.100 + }
1.101 +
1.102 + protected: // Functions from base classes
1.103 +
1.104 + /**
1.105 + * From CActive Cancels async request.
1.106 + */
1.107 + void DoCancel();
1.108 +
1.109 + /**
1.110 + * From CActive Called when async request completes.
1.111 + */
1.112 + void RunL();
1.113 +
1.114 +private:
1.115 +
1.116 + /**
1.117 + * C++ default constructor.
1.118 + */
1.119 + CFileWriter( TInt aInitSetSize, TInt aOutputBufferSizeSmall, TInt aOutputBufferSizeLarge );
1.120 +
1.121 + /**
1.122 + * By default Symbian 2nd phase constructor is private.
1.123 + */
1.124 + void ConstructL( RFile64& aFile );
1.125 +
1.126 + /**
1.127 + * Writes incoming data to internal buffers and buffer queues..
1.128 + * @since 2.1
1.129 + * @param aBuf Data to be added to buffers..
1.130 + * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
1.131 + */
1.132 + TInt AddDataToBuffer( const TDesC8& aBuf );
1.133 +
1.134 + /**
1.135 + * Allocates input and output buffers.
1.136 + * @since 2.6
1.137 + */
1.138 + void AllocateBuffersL();
1.139 +
1.140 + /**
1.141 + * Updates output file size and reserves extra space for following writing if iSetSize is set.
1.142 + * Takes into account if the position in the file was changed.
1.143 + */
1.144 + void UpdateOutputFileSize();
1.145 +
1.146 +private:
1.147 + // Whether we are flushing after async write.
1.148 + TBool iFlush;
1.149 + // Flag whether there is async writing going.
1.150 + TBool iAsyncWritingOngoing;
1.151 + // Flag whether we have received any data.
1.152 + TBool iWritingStarted;
1.153 + // Flag whether init has been done
1.154 + TBool iMemReadyForWriting;
1.155 +
1.156 + // Write error code.
1.157 + TInt iError;
1.158 +
1.159 + // Current set file size
1.160 + TInt64 iSetSize;
1.161 + // Current output file size
1.162 + TInt64 iOutputFileSize;
1.163 +
1.164 + TInt iOutputBufferSizeSmall;
1.165 + TInt iOutputBufferSizeLarge;
1.166 +
1.167 + // Output buffer size.
1.168 + TInt iOutputBufferSize;
1.169 + // Hard limit for max output buffers
1.170 + TInt iMaxOutputBufHardLimit;
1.171 + // Soft limit for max output buffers
1.172 + TInt iMaxOutputBufSoftLimit;
1.173 +
1.174 +
1.175 + // Output file for writes.
1.176 + RFile64* iOutputFile;
1.177 + // Queue of empty write buffers.
1.178 + RPointerArray<HBufC8> iEmptyBufferQueue;
1.179 + // Queue of full write buffers.
1.180 + RPointerArray<HBufC8> iFullBufferQueue;
1.181 +
1.182 + // Current input buffers for incoming data.
1.183 + HBufC8* iInputBuf;
1.184 +};
1.185 +
1.186 +#endif //__FILEWRITER_H
1.187 +// End of File