|
1 /* |
|
2 * Copyright (c) 2004-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * |
|
14 * Description: Reads RTP payload format containing ILBC data. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef ILBCPAYLOADFORMATREAD_H |
|
21 #define ILBCPAYLOADFORMATREAD_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <mmf/server/mmfformat.h> |
|
26 #include "rtpheader.h" |
|
27 #include "formatstatemachine.h" |
|
28 #include "mccinternalcodecs.h" |
|
29 |
|
30 // CLASS DECLARATION |
|
31 /** |
|
32 * Depacketizes RTP payload containing ILBC data. |
|
33 * |
|
34 * @lib MMCCIlbcPlFormat.dll |
|
35 * @since Series 60 3.0 |
|
36 */ |
|
37 class CIlbcPayloadFormatRead : public CPayloadFormatRead, |
|
38 public MAsyncEventHandler, |
|
39 public MPayloadFormatRead |
|
40 { |
|
41 public: |
|
42 /** |
|
43 * Two-phased constructor. |
|
44 * @param aSource Data source configuration parameters |
|
45 */ |
|
46 static CIlbcPayloadFormatRead* NewL ( MDataSource* aSource ); |
|
47 |
|
48 /** |
|
49 * Destructor. |
|
50 */ |
|
51 virtual ~CIlbcPayloadFormatRead(); |
|
52 |
|
53 public: // New functions |
|
54 |
|
55 /** |
|
56 * Configures payload format with format spesific parameters. |
|
57 * Leaves with KErrArgument if parameters are invalid. |
|
58 * |
|
59 * @since Series 60 3.0 |
|
60 * @param aConfigParams Configuration parameters |
|
61 * @return void |
|
62 */ |
|
63 virtual void ConfigurePayloadFormatL( const TDesC8& aConfigParams ); |
|
64 |
|
65 public: // From CMMFFormatDecode |
|
66 |
|
67 /** |
|
68 * Return number of audio streams for the given media |
|
69 * Raw audio files can only have 1 audio stream |
|
70 * @since Series 60 3.0 |
|
71 * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo |
|
72 * @return Number of audio streams |
|
73 */ |
|
74 TUint Streams( TUid aMediaType ) const; |
|
75 |
|
76 /** |
|
77 * Return the frame time interval for the given media |
|
78 * |
|
79 * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo |
|
80 * |
|
81 * @return Time interval in micro seconds |
|
82 */ |
|
83 TTimeIntervalMicroSeconds FrameTimeInterval( TMediaId aMediaType ) const; |
|
84 |
|
85 /** *** NOT SUPPORTED *** |
|
86 * Return the clip duration for the given media |
|
87 * |
|
88 * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo |
|
89 * |
|
90 * @return Clip duration in micro seconds |
|
91 */ |
|
92 TTimeIntervalMicroSeconds Duration( TMediaId aMediaType ) const; |
|
93 |
|
94 /** |
|
95 * Accessor funtion to return the number of channels |
|
96 * |
|
97 * @param |
|
98 * |
|
99 * @return Number of channels |
|
100 */ |
|
101 TUint NumChannels(); |
|
102 |
|
103 /** |
|
104 * Accessor funtion to return the sampling rate |
|
105 * |
|
106 * @param |
|
107 * |
|
108 * @return Sampling rate |
|
109 */ |
|
110 TUint SampleRate(); |
|
111 |
|
112 /** |
|
113 * Set the samplerate to the given value. |
|
114 * |
|
115 * @param aSampleRate |
|
116 * |
|
117 * @return error code KErrNotSupported if invalid samplerate, else |
|
118 * return KErrNone |
|
119 */ |
|
120 TInt SetSampleRate( TUint aSampleRate ); |
|
121 |
|
122 public: // From MDataSource |
|
123 |
|
124 /** |
|
125 * Return the four CC code for the given media |
|
126 * |
|
127 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
128 * KUidMediaTypeVideo |
|
129 * |
|
130 * @return FourCC code |
|
131 */ |
|
132 TFourCC SourceDataTypeCode( TMediaId aMediaId ); |
|
133 |
|
134 /** |
|
135 * Set the source data type to the given four CC code for the given |
|
136 * media |
|
137 * |
|
138 * @param aSourceFourCC fourCC code |
|
139 * @param aMediaId contains the media type KUidMediaTypeAudio |
|
140 * or KUidMediaTypeVideo |
|
141 * |
|
142 * @return error code KErrNotSupported if invalid |
|
143 * media ID, else return KErrNone |
|
144 */ |
|
145 TInt SetSourceDataTypeCode( TFourCC aSourceFourCC, |
|
146 TMediaId aMediaId ); |
|
147 |
|
148 /** |
|
149 * Create a source buffer for the given media |
|
150 * |
|
151 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
152 * KUidMediaTypeVideo |
|
153 * @param aReference value of False is returned to caller if source |
|
154 * buffer is created |
|
155 * |
|
156 * @return Pointer to source buffer created |
|
157 */ |
|
158 CMMFBuffer* CreateSourceBufferL( TMediaId aMediaId, |
|
159 TBool &aReference ); |
|
160 |
|
161 /** |
|
162 * Create a source buffer for the given media, setting frame size |
|
163 * to match the given sink buffer |
|
164 * |
|
165 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
166 * KUidMediaTypeVideo |
|
167 * @param aSinkBuffer address of sink buffer |
|
168 * @param aReference value of False is returned to caller if source |
|
169 * buffer is created |
|
170 * |
|
171 * @return Pointer to source buffer created |
|
172 */ |
|
173 CMMFBuffer* CreateSourceBufferL( TMediaId aMediaId, |
|
174 CMMFBuffer& aSinkBuffer, |
|
175 TBool &aReference ); |
|
176 |
|
177 /** |
|
178 * Read the next block of data from file into the given buffer |
|
179 * |
|
180 * @param aBuffer source data buffer for the AMR-NB data read |
|
181 * @param aConsumer data sink pointer |
|
182 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
183 * KUidMediaTypeVideo |
|
184 * |
|
185 * @return |
|
186 */ |
|
187 void FillBufferL( CMMFBuffer* aBuffer, |
|
188 MDataSink* aConsumer, |
|
189 TMediaId aMediaId ); |
|
190 |
|
191 /** |
|
192 * Log in to the source thread - this funtion merely passes the |
|
193 * command to its source clip data source object. The source clip |
|
194 * object will handle the thread log on procedures. |
|
195 * |
|
196 * @param aEventHandler address of event handler |
|
197 * |
|
198 * @return error code returned by source clip |
|
199 */ |
|
200 TInt SourceThreadLogon( MAsyncEventHandler& aEventHandler ); |
|
201 |
|
202 /** |
|
203 * Log out of the source thread - this funtion merely passes the |
|
204 * command to its source clip data source object. The source clip |
|
205 * object will handle the thread log off procedures. |
|
206 * |
|
207 * @param |
|
208 * @return |
|
209 */ |
|
210 void SourceThreadLogoff(); |
|
211 |
|
212 /** |
|
213 * Negotiate source settings (buffer size) to match |
|
214 * given source object |
|
215 * |
|
216 * @param aDataSink address of sink object |
|
217 * |
|
218 * @return |
|
219 */ |
|
220 void NegotiateSourceL( MDataSink& aDataSink ); |
|
221 |
|
222 /** |
|
223 * From MDataSource Primes the source. |
|
224 * @since |
|
225 * @param None |
|
226 */ |
|
227 void SourcePrimeL(); |
|
228 |
|
229 /** |
|
230 * From MDataSource Plays the source. |
|
231 * @since |
|
232 * @param None |
|
233 */ |
|
234 void SourcePlayL(); |
|
235 |
|
236 /** |
|
237 * From MDataSource Pauses the source. |
|
238 * @since |
|
239 * @param None |
|
240 */ |
|
241 void SourcePauseL(); |
|
242 |
|
243 /** |
|
244 * From MDataSource Stops the source. |
|
245 * @since |
|
246 * @param None |
|
247 */ |
|
248 void SourceStopL(); |
|
249 |
|
250 public: // From MDataSink |
|
251 |
|
252 /** |
|
253 * Called after the data buffer is filled. Update the number of bytes |
|
254 * read and the current read position for the next read operation. |
|
255 * |
|
256 * @param aBuffer data buffer filled |
|
257 * |
|
258 * @return |
|
259 */ |
|
260 virtual void DataBufferFilledL( CMMFBuffer* aBuffer, |
|
261 const TRtpRecvHeader& aRecvHeader ); |
|
262 |
|
263 /** |
|
264 * Gets the data type code for the sink specified by the media ID. |
|
265 * Format decode may act in role of MDataSink. |
|
266 * |
|
267 * @param aMediaId Media ID |
|
268 * @return The data sink type code |
|
269 */ |
|
270 TFourCC SinkDataTypeCode( TMediaId aMediaId ); |
|
271 |
|
272 public: // From MAsyncEventHandler |
|
273 virtual TInt SendEventToClient(const TMMFEvent& /*aEvent*/) |
|
274 {return KErrNone;} |
|
275 |
|
276 public: // From MPayloadFormatRead |
|
277 |
|
278 /** |
|
279 * Send full sink buffer with iLBC frames to data path. |
|
280 * Sink buffer is decided on one of the two frame buffers |
|
281 * Called by the state machine. |
|
282 * @since Series 60 3.0 |
|
283 * @param None |
|
284 */ |
|
285 void SendDataToSinkL(); |
|
286 |
|
287 /** |
|
288 * Fill the sink buffer by decoding the RTP payload into iLBC frames |
|
289 * Sink buffer is decided on one of the two frame buffers |
|
290 * Called by the state machine. |
|
291 * @since Series 60 3.0 |
|
292 * @param None |
|
293 */ |
|
294 void FillSinkBufferL(); |
|
295 |
|
296 /** |
|
297 * Request the RTPSource to fill the source buffer with RTP payload |
|
298 * Source buffer is decided by the RTPSource. |
|
299 * Called by the state machine. |
|
300 * @since Series 60 3.0 |
|
301 * @param None |
|
302 */ |
|
303 void FillSourceBufferL(); |
|
304 |
|
305 protected: // New functions |
|
306 |
|
307 protected: // Functions from base classes |
|
308 |
|
309 private: // New functions |
|
310 |
|
311 /** |
|
312 * Decode audio frames from RTP payload to the audio frame array. |
|
313 * Next decoded frame may be requested by GetNextFrameL(). |
|
314 * |
|
315 * @since Series 60 3.0 |
|
316 * @param aSourceBuffer RTP payload to be decoded |
|
317 * @return Number of decoded frames |
|
318 */ |
|
319 TInt DecodePayload( const TDesC8& aSourceBuffer ); |
|
320 |
|
321 /** |
|
322 * Return next decoded audio frame. |
|
323 * @since Series 60 3.0 |
|
324 * @param aToBuffer - [output] Buffer to place decoded frame |
|
325 * @return Boolean indicating whether decoded frames are remaining. |
|
326 */ |
|
327 TBool GetNextFrame( TDes8& aToBuffer ); |
|
328 |
|
329 /** |
|
330 * Update payload format with format spesific parameters. |
|
331 * |
|
332 * @since Series 60 3.0 |
|
333 * @param aCodecInfo Codec info |
|
334 * @return void |
|
335 */ |
|
336 void UpdateConfigurationL( const TMccCodecInfo& aCodecInfo ); |
|
337 |
|
338 /** |
|
339 * Configures the formatter based on input parameters. |
|
340 * |
|
341 * @since Series 60 3.0 |
|
342 * @param aCodecInfo Codec info |
|
343 * @return void |
|
344 */ |
|
345 void DoConfigurePayloadFormatL( const TMccCodecInfo& aCodecInfo ); |
|
346 |
|
347 private: |
|
348 |
|
349 /** |
|
350 * C++ default constructor. |
|
351 */ |
|
352 CIlbcPayloadFormatRead (); |
|
353 |
|
354 /** |
|
355 * By default Symbian 2nd phase constructor is private. |
|
356 * |
|
357 * @param aConf Decoder Configuration params |
|
358 */ |
|
359 void ConstructL ( MDataSource* aSource ); |
|
360 |
|
361 /** |
|
362 * Creates a buffer used in data transfer between format read and |
|
363 * its datasource. |
|
364 * |
|
365 * @since Series 60 3.2 |
|
366 * @param aSize Suggested buffer size |
|
367 * @param aIsOwnBuffer Indicates ownership of the buffer |
|
368 * @return Created buffer |
|
369 */ |
|
370 CMMFDataBuffer* CreateClipBufferL( TUint aSize, TBool& aIsOwnBuffer ); |
|
371 |
|
372 private: // Data |
|
373 |
|
374 enum TCurrentBuffer |
|
375 { |
|
376 EBufferOne = 0, |
|
377 EBufferTwo |
|
378 }; |
|
379 |
|
380 // the fourCC |
|
381 TFourCC iFourCC; |
|
382 |
|
383 // Format decoding state machine |
|
384 CFormatDecodeStateMachine* iStateMachine; |
|
385 |
|
386 // ETrue if decoded frames are remaining |
|
387 TBool iBufferToReadExists; |
|
388 |
|
389 // Number of frames decoded from received RTP payload |
|
390 TInt iNumOfFrames; |
|
391 // Data sink that requested "FillBuffer". |
|
392 MDataSink* iSink; |
|
393 |
|
394 // Frame time interval in micro seconds |
|
395 TTimeIntervalMicroSeconds iFrameTimeInterval; |
|
396 |
|
397 // Buffer to store depacketized Ilbc frames |
|
398 CMMFDataBuffer* iFrameBufferOne; |
|
399 |
|
400 // Alternative buffer to store depacketized Ilbc frames |
|
401 CMMFDataBuffer* iFrameBufferTwo; |
|
402 |
|
403 // Flag to indicate which buffer is in use |
|
404 TCurrentBuffer iCurrentBuffer; |
|
405 |
|
406 // Buffer to hold payload got from data source; |
|
407 CMMFDataBuffer* iSourceBuffer; |
|
408 |
|
409 // Indicates whether payload read has ownership of source buffer |
|
410 TBool iSourceBufOwnership; |
|
411 |
|
412 TMediaId iMediaId; |
|
413 |
|
414 // Flag to indicate that received frame was comfort noise |
|
415 TBool iCnFrame; |
|
416 |
|
417 // Current index in set of audio frames decoded from last payload |
|
418 TInt iFrameIndex; |
|
419 |
|
420 // Contains pointers to audio frames in received payload |
|
421 RArray<TPtr8> iFrameArray; |
|
422 |
|
423 // RTP Header |
|
424 TRtpRecvHeader iRecvHeader; |
|
425 |
|
426 // Parameters relating to RTP data encoding |
|
427 TMccCodecInfo iCInfo; |
|
428 |
|
429 // Friend class for testing |
|
430 #ifdef TEST_EUNIT |
|
431 friend class UT_CIlbcPayloadFormatRead; |
|
432 #endif |
|
433 }; |
|
434 |
|
435 #endif /* ILBCPAYLOADFORMATREAD_H */ |
|
436 |
|
437 // End of File |