os/mm/mmplugins/lib3gp/impl/inc/filewriter.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __FILEWRITER_H
    17 #define __FILEWRITER_H
    18 
    19 //  INCLUDES
    20 #include <e32base.h>
    21 #include "mp4atom.h"
    22 
    23 // CONSTANTS
    24 const TInt KFileWriterBufferSizeSmall = 65536;
    25 const TInt KFileWriterBufferSizeLarge = (4*65536);  
    26 const TInt KFileWriterSoftBufLimit = 12;
    27 const TInt KFileWriterHardBufLimit = 16;
    28 const TInt KFileWriterMinBufferCount = 4; // shouldn't be less than 4
    29 
    30 // FORWARD DECLARATIONS
    31 class RFile64;
    32 
    33 // CLASS DECLARATION
    34 
    35 /**
    36 *  Async buffering file writer.
    37 */
    38 NONSHARABLE_CLASS(CFileWriter) : public CActive
    39     {
    40     public:
    41         enum TOutputBufferSize
    42             {   
    43                 EBufferSizeSmall = 0,
    44                 EBufferSizeLarge, 
    45                 EBufferSizeCustom
    46             };
    47 
    48     public: // Constructors and destructor
    49 
    50         /**
    51         * Two-phased constructor.
    52         */
    53         static CFileWriter* NewL( RFile64& aFile, TInt aInitSetSize = 0, TInt aOutputBufferSizeSmall = KFileWriterBufferSizeSmall, TInt aOutputBufferSizeLarge = KFileWriterBufferSizeLarge );
    54 
    55         /**
    56         * Destructor.
    57         */
    58         ~CFileWriter();
    59     
    60     public: // New functions
    61 
    62         /**
    63         * Writes incoming buffer data to internal buffers for writing to disk.
    64         * @since 2.1
    65         * @param aBuf Data to be written
    66         * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
    67         */
    68         TInt Write( const TDesC8& aBuf );
    69 
    70         /**
    71         * Flush internal buffers to disk.
    72         * @since 2.1
    73         * @param aBuf Additional data to be written before flush.
    74         * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
    75         */
    76         TInt Flush( const TDesC8& aBuf );
    77 
    78         /**
    79         * Set file output buffer size
    80         * @since 2.6
    81         * @param aBufferSize Size of buffer.
    82         * @param aHandle MP4Handle.
    83         * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
    84         */
    85         TInt SetOutputBufferSize( TOutputBufferSize aBufferSize, MP4Handle aHandle );
    86         
    87         /**
    88         * Set file output buffer count
    89         * @since 3.0
    90         * @param aHandle MP4Handle.
    91         */
    92         void SetOutputBufferCount( MP4Handle aHandle ); 
    93 
    94         inline TInt64 OutputFileSize() const
    95 			{
    96 			return iOutputFileSize;
    97 			}    
    98 
    99     protected: // Functions from base classes
   100         
   101         /**
   102         * From CActive Cancels async request.
   103         */
   104         void DoCancel();
   105 
   106         /**
   107         * From CActive Called when async request completes.
   108         */
   109 	    void RunL();
   110 
   111 private:
   112 
   113         /**
   114         * C++ default constructor.
   115         */
   116         CFileWriter( TInt aInitSetSize, TInt aOutputBufferSizeSmall, TInt aOutputBufferSizeLarge );
   117 
   118         /**
   119         * By default Symbian 2nd phase constructor is private.
   120         */
   121         void ConstructL( RFile64& aFile );
   122 
   123         /**
   124         * Writes incoming data to internal buffers and buffer queues..
   125         * @since 2.1
   126         * @param aBuf Data to be added to buffers..
   127         * @return Error code, KErrNone if no errors, otherwise one of the system wide error codes.
   128         */
   129         TInt AddDataToBuffer( const TDesC8& aBuf );
   130 
   131         /**
   132         * Allocates input and output buffers.
   133         * @since 2.6
   134         */
   135         void AllocateBuffersL();
   136 		
   137 		/**
   138 		* Updates output file size and reserves extra space for following writing if iSetSize is set.
   139 		* Takes into account if the position in the file was changed.
   140 		*/
   141         void UpdateOutputFileSize();
   142 
   143 private:
   144         // Whether we are flushing after async write.
   145     	TBool iFlush;
   146 		// Flag whether there is async writing going.
   147 	    TBool iAsyncWritingOngoing;
   148 		// Flag whether we have received any data.
   149         TBool iWritingStarted;
   150         // Flag whether init has been done
   151         TBool iMemReadyForWriting;
   152 
   153         // Write error code.
   154         TInt iError;
   155         
   156         // Current set file size
   157         TInt64 iSetSize;
   158         // Current output file size
   159 	    TInt64 iOutputFileSize;		
   160 
   161         TInt iOutputBufferSizeSmall;
   162         TInt iOutputBufferSizeLarge;
   163         
   164         // Output buffer size.
   165         TInt iOutputBufferSize;
   166         // Hard limit for max output buffers
   167         TInt iMaxOutputBufHardLimit;
   168         // Soft limit for max output buffers
   169         TInt iMaxOutputBufSoftLimit;
   170 
   171 
   172         // Output file for writes.
   173         RFile64* iOutputFile;
   174         // Queue of empty write buffers.
   175         RPointerArray<HBufC8> iEmptyBufferQueue;
   176         // Queue of full write buffers.
   177         RPointerArray<HBufC8> iFullBufferQueue;
   178 
   179         // Current input buffers for incoming data.
   180         HBufC8* iInputBuf;
   181 };
   182 
   183 #endif  //__FILEWRITER_H
   184 // End of File