|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __CPROCINFILEHANDLER_H__ |
|
22 #define __CPROCINFILEHANDLER_H__ |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 #include "ProcFrameHandler.h" |
|
27 #include "ProcWAVFrameHandler.h" |
|
28 |
|
29 #include "AudCommon.h" |
|
30 #include "ProcConstants.h" |
|
31 #include "AudClip.h" |
|
32 #include "ProcDecoder.h" |
|
33 |
|
34 class CProcInFileHandler : public CBase |
|
35 { |
|
36 |
|
37 public: |
|
38 |
|
39 /* |
|
40 * Destructor |
|
41 */ |
|
42 virtual ~CProcInFileHandler(); |
|
43 |
|
44 |
|
45 /** |
|
46 * Gets properties of this input clip |
|
47 * |
|
48 * @param aProperties audio clip properties. Needs to be allocated by the caller |
|
49 * and is filled in by this function |
|
50 * |
|
51 */ |
|
52 virtual void GetPropertiesL(TAudFileProperties* aProperties) = 0; |
|
53 |
|
54 /* |
|
55 * |
|
56 * Is decoding required? |
|
57 */ |
|
58 |
|
59 TBool DecodingRequired(); |
|
60 |
|
61 /* |
|
62 * |
|
63 * Returns the size of a decoded frame |
|
64 */ |
|
65 TInt GetDecodedFrameSize(); |
|
66 |
|
67 /* |
|
68 * |
|
69 * Sets whether decoding is required? |
|
70 */ |
|
71 |
|
72 void SetDecodingRequired(TBool aDecodingRequired); |
|
73 |
|
74 /** |
|
75 * Reads the next audio frame |
|
76 * This function allocates memory and |
|
77 * the caller is responsible for releasing it |
|
78 * |
|
79 * Possible leave codes: |
|
80 * |
|
81 * |
|
82 * @param aFrame audio frame |
|
83 * @param aSize size of the retrieved audio frame |
|
84 * @param aTime duration of the returned frame in milliseconds |
|
85 * @return ETrue if a frame was read |
|
86 * EFalse if frame was not read (EOF) |
|
87 */ |
|
88 TBool GetAudioFrameL(HBufC8*& aFrame, TInt& aSize, TInt32& aTime, TBool& aRawFrame); |
|
89 |
|
90 TBool GetRawAudioFrameL(HBufC8*& aFrame, TInt& aSize, TInt32& aTime); |
|
91 |
|
92 |
|
93 /** |
|
94 * Sets properties of this in file handler |
|
95 * |
|
96 * @param aProperties audio clip properties |
|
97 * |
|
98 */ |
|
99 |
|
100 TBool SetPropertiesL(TAudFileProperties aProperties); |
|
101 |
|
102 /* |
|
103 * Set the size of raw audio frames |
|
104 * |
|
105 * @param aSize audio size |
|
106 * |
|
107 * @return ETrue if successful, EFalse otherwise |
|
108 */ |
|
109 |
|
110 TBool SetRawAudioFrameSize(TInt aSize); |
|
111 |
|
112 |
|
113 /** |
|
114 * Seeks a certain audio frame for reading |
|
115 * |
|
116 * Possible leave codes: |
|
117 * |
|
118 * @param aTime time from the beginning of file in milliseconds |
|
119 * |
|
120 * @return ETrue if successful |
|
121 * EFalse if beyond the file |
|
122 */ |
|
123 virtual TBool SeekAudioFrame(TInt32 aTime) = 0; |
|
124 |
|
125 |
|
126 /** |
|
127 * Seeks a cut in audio frame for reading |
|
128 * |
|
129 * Possible leave codes: |
|
130 * |
|
131 * |
|
132 * @return ETrue if successful |
|
133 * |
|
134 */ |
|
135 virtual TBool SeekCutInFrame() = 0; |
|
136 |
|
137 |
|
138 //virtual TBool GetAudioFrameL(HBufC8*& aFrame, TInt& aSize, TInt32& aTime, TBool& aRawFrame) = 0; |
|
139 |
|
140 |
|
141 /** |
|
142 * Generates and returns a silent audio frame |
|
143 * This function allocates memory and |
|
144 * the caller is responsible for releasing it. |
|
145 * The silent frame is generated according to audio |
|
146 * properties of this input clip |
|
147 * (e.g. sampling rate, channel configuration, bitrate etc) |
|
148 * |
|
149 * Possible leave codes: , at least <code>KErrNotMemory</code> |
|
150 * |
|
151 * |
|
152 * @param aFrame audio frame |
|
153 * @param aSize size of the silent audio frame |
|
154 * @param aDuration duration of the returned silent frame in milliseconds |
|
155 * @return ETrue if a frame was generated |
|
156 * EFalse if frame was not generated (EOF, no need to release aFrame) |
|
157 */ |
|
158 virtual TBool GetSilentAudioFrameL(HBufC8*& aFrame, TInt& aSize, TInt32& aDuration, TBool& aRawFrame); |
|
159 |
|
160 |
|
161 |
|
162 /** |
|
163 * Gets the priority of this clip |
|
164 * |
|
165 * @return priority of this clip |
|
166 * |
|
167 */ |
|
168 TInt Priority() const; |
|
169 |
|
170 /** |
|
171 * Gets the current time of the frame reading |
|
172 * |
|
173 * @return current time in milliseconds |
|
174 * |
|
175 */ |
|
176 TInt32 GetCurrentTimeMilliseconds(); |
|
177 |
|
178 /** |
|
179 * Gets the normalizing margin of this clip |
|
180 * |
|
181 * @return normalizing margin |
|
182 * |
|
183 */ |
|
184 TInt8 NormalizingMargin() const; |
|
185 |
|
186 /** |
|
187 * |
|
188 * Set priority of this clip |
|
189 * |
|
190 * @param aPriority priority >= 0 |
|
191 * |
|
192 * @return ETrue if priority >= 0 |
|
193 * EFalse otherwise, priority not set |
|
194 */ |
|
195 TBool SetPriority(TInt aPriority); |
|
196 |
|
197 /* |
|
198 * Sets the normalizing gain of this clip |
|
199 * |
|
200 * @param aFrameHandler frame handler |
|
201 * |
|
202 * @return ETrue if successful |
|
203 */ |
|
204 virtual TBool SetNormalizingGainL(const CProcFrameHandler* aFrameHandler) = 0; |
|
205 |
|
206 /** |
|
207 * Gets ReadAudioDecoderSpecificInfo from file (if any) |
|
208 * |
|
209 * @param aBytes buffer |
|
210 * @param aBufferSize maximum size of buffer |
|
211 * |
|
212 * @return ETrue if bytes were read (The caller must release aBytes!!) |
|
213 * |
|
214 * EFalse if no bytes were read (no memory releasing needed) |
|
215 * |
|
216 */ |
|
217 |
|
218 virtual TBool ReadAudioDecoderSpecificInfoL(HBufC8*& aBytes, TInt aBufferSize); |
|
219 |
|
220 |
|
221 protected: |
|
222 |
|
223 // constructL |
|
224 void ConstructL(const TDesC& aFileName); |
|
225 |
|
226 // c++ constructor |
|
227 CProcInFileHandler(); |
|
228 |
|
229 |
|
230 /** |
|
231 * Reads the next raw frame |
|
232 * This function allocates memory and |
|
233 * the caller is responsible for releasing it |
|
234 * |
|
235 * Possible leave codes: |
|
236 * |
|
237 * |
|
238 * @param aFrame audio frame |
|
239 * @param aSize size of the retrieved audio frame |
|
240 * @param aTime duration of the returned frame in milliseconds |
|
241 * @return ETrue if a frame was read |
|
242 * EFalse if frame was not read (EOF) |
|
243 */ |
|
244 |
|
245 virtual TBool GetRawSilentAudioFrameL(HBufC8*& aFrame, TInt& aSize, TInt32& aDuration); |
|
246 |
|
247 virtual TBool GetEncAudioFrameL(HBufC8*& aFrame, TInt& aSize, TInt32& aTime) = 0; |
|
248 |
|
249 virtual TBool GetEncSilentAudioFrameL(HBufC8*& aFrame, TInt& aSize, TInt32& aDuration); |
|
250 |
|
251 TBool GetOneRawAudioFrameL(HBufC8*& aFrame, TInt& aSize, TInt32& aDuration); |
|
252 |
|
253 |
|
254 /** |
|
255 * Performs all the necessary initializations and memory allocations needed. |
|
256 * Should be always called by classes inherited from <code>CProcInFileHander</code> |
|
257 * |
|
258 * @param aFileName name of the file |
|
259 * @param aCutInTime cut in time in milliseconds |
|
260 * @param aReadBufferSize read buffer size |
|
261 * |
|
262 * @return ETrue if successful |
|
263 * |
|
264 */ |
|
265 TBool InitAndOpenFileL(const TDesC& aFileName, RFile* aFileHandle, TInt aReadBufferSize); |
|
266 |
|
267 |
|
268 /** |
|
269 * Performs all the necessary resource releasing and file closing |
|
270 * |
|
271 * should be called if <code>InitAndOpenFileL</code> has been called |
|
272 * |
|
273 * @return ETrue if successful |
|
274 * |
|
275 */ |
|
276 void ResetAndCloseFile(); |
|
277 |
|
278 // opens a file for readind |
|
279 TBool OpenFileForReadingL(); |
|
280 |
|
281 // closes the file if open |
|
282 TBool CloseFile(); |
|
283 |
|
284 |
|
285 // File reading methods------------------> |
|
286 TInt BufferedFileRead(TDes8& aDes,TInt aLength); |
|
287 TInt BufferedFileSetFilePos(TInt aPos); |
|
288 TInt BufferedFileGetFilePos(); |
|
289 TInt BufferedFileGetSize(); |
|
290 TInt BufferedFileRead(TInt aPos,TDes8& aDes); |
|
291 TInt BufferedFileRead(TDes8& aDes); |
|
292 TInt BufferedFileReadChar(TInt aPos, TUint8& aChar); |
|
293 // <------------------ File reading methods |
|
294 |
|
295 |
|
296 TBool ManipulateGainL(HBufC8*& aFrameIn); |
|
297 |
|
298 // function for gain manipulation |
|
299 TInt8 GetGainNow(); |
|
300 |
|
301 TBool WriteDataToInputBufferL(const TDesC8& aData); |
|
302 |
|
303 protected: |
|
304 |
|
305 // is inputfile open? |
|
306 TBool iFileOpen; |
|
307 |
|
308 // file name |
|
309 HBufC* iFileName; |
|
310 |
|
311 // RFile |
|
312 RFile iFile; |
|
313 |
|
314 // file server session |
|
315 RFs iFs; |
|
316 |
|
317 // read buffer |
|
318 HBufC8* iReadBuffer; |
|
319 |
|
320 // size of the read buffer |
|
321 TInt iReadBufferSize; |
|
322 |
|
323 // start offset of the read buffer |
|
324 TInt iBufferStartOffset; |
|
325 |
|
326 // end offset of the read buffer |
|
327 TInt iBufferEndOffset; |
|
328 |
|
329 // current file position |
|
330 TInt iFilePos; |
|
331 |
|
332 // cut in time in milliseconds |
|
333 TInt32 iCutInTime; |
|
334 |
|
335 // current read time in milliseconds |
|
336 TInt32 iCurrentTimeMilliseconds; |
|
337 |
|
338 // priority of the clip |
|
339 TInt iPriority; |
|
340 |
|
341 // normalizing margin in dB/2 |
|
342 TInt8 iNormalizingMargin; |
|
343 |
|
344 // audio file properties |
|
345 TAudFileProperties* iProperties; |
|
346 |
|
347 // silent frame |
|
348 HBufC8* iSilentFrame; |
|
349 |
|
350 // duration of the silent frame |
|
351 TInt32 iSilentFrameDuration; |
|
352 |
|
353 // raw silent frame |
|
354 HBufC8* iRawSilentFrame; |
|
355 |
|
356 // duration of the raw silent frame |
|
357 TInt iRawSilentFrameDuration; |
|
358 |
|
359 // if true, this object opens and closes the input file |
|
360 TBool iOwnsFile; |
|
361 |
|
362 TInt iTargetSampleRate; |
|
363 |
|
364 TChannelMode iChannelMode; |
|
365 |
|
366 CProcFrameHandler* iFrameHandler; |
|
367 |
|
368 CAudClip* iClip; |
|
369 |
|
370 TBool iDecodingRequired; |
|
371 |
|
372 CProcDecoder* iDecoder; |
|
373 |
|
374 TBool iDecodingPossible; |
|
375 |
|
376 // We need a temporary storage for extra bytes |
|
377 // when retrieving raw frames af equal length |
|
378 HBufC8* iInputBuffer; |
|
379 |
|
380 TInt iRawFrameLength; |
|
381 |
|
382 // wav frame handler for time domain gain manipulation |
|
383 CProcWAVFrameHandler* iWavFrameHandler; |
|
384 |
|
385 // remainder if audio duration can't be handled accurately in TInt milliseconds, depends on sampling rate |
|
386 TReal iFrameLenRemainderMilli; |
|
387 |
|
388 // Counter for decoder errors. Try to continue after one error, but if there are more, stop decoding. |
|
389 TInt iDecoderErrors; |
|
390 }; |
|
391 |
|
392 #endif |