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