|
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: Class definition for the AMR/RTP payload format plugin |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef AMRPAYLOADFORMATREAD_H |
|
22 #define AMRPAYLOADFORMATREAD_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include <e32std.h> |
|
27 #include <mmf/server/mmfformat.h> |
|
28 #include "rtpheader.h" |
|
29 #include "formatstatemachine.h" |
|
30 #include "amrpayloadformatter.h" |
|
31 #include "streamformatter.h" |
|
32 #include "mccinternalcodecs.h" |
|
33 #include "mccinternalevents.h" |
|
34 |
|
35 #ifdef FTD_ENABLED |
|
36 #include <e32msgqueue.h> |
|
37 #include "MccJBufferStats.h" |
|
38 #endif |
|
39 |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 class CAmrPayloadEncoder; |
|
43 class CAmrPayloadDecoder; |
|
44 |
|
45 // CLASS DECLARATION |
|
46 |
|
47 /** |
|
48 * The CAmrPayloadFormatRead class implements the MMF format plugin for decoding |
|
49 * of RTP payloadformat for AMR codec. Refer to IETF RFC3267. |
|
50 * This class receives AMR payload data from an RTP packet and converts it into |
|
51 * one or more AMR frames. |
|
52 * |
|
53 * @lib MMccamrplformat.dll |
|
54 * @since Series 60 3.0 |
|
55 */ |
|
56 class CAmrPayloadFormatRead : public CPayloadFormatRead, public MPayloadFormatRead |
|
57 { |
|
58 public: // Constructors and destructor |
|
59 /** |
|
60 * Two-phased constructor. |
|
61 * @param aSource Source of the data for the payload format plugin |
|
62 */ |
|
63 static CAmrPayloadFormatRead* NewL ( MDataSource* aSource ); |
|
64 |
|
65 /** |
|
66 * Destructor. |
|
67 */ |
|
68 virtual ~CAmrPayloadFormatRead ( ); |
|
69 |
|
70 public: // New functions |
|
71 |
|
72 /** |
|
73 * Cancel any requests from DataPath and Stop state machine also |
|
74 * @since Series-60 2.1 |
|
75 * @return None |
|
76 */ |
|
77 virtual void CancelDlRequest( ); |
|
78 |
|
79 /** |
|
80 * Send full sink buffer with AMR frames to data path. |
|
81 * Sink buffer is decided on one of the two frame buffers |
|
82 * Called by the state machine. |
|
83 * @since Series-60 2.1 |
|
84 * @return None |
|
85 */ |
|
86 void SendDataToSinkL( ); |
|
87 |
|
88 /* |
|
89 * Fill the sink buffer by decoding the RTP payload into AMR frames |
|
90 * Sink buffer is decided on one of the two frame buffers |
|
91 * Called by the state machine. |
|
92 * @since Series-60 2.1 |
|
93 * @return None |
|
94 */ |
|
95 void FillSinkBufferL( ); |
|
96 |
|
97 /** |
|
98 * Request the RTPSource to fill the source buffer with RTP payload |
|
99 * Source buffer is decided by the RTPSource. |
|
100 * Called by the state machine. |
|
101 * @since Series-60 2.1 |
|
102 * @return None |
|
103 */ |
|
104 void FillSourceBufferL( ); |
|
105 |
|
106 public: // From CMMFFormatDecode |
|
107 |
|
108 /** |
|
109 * From CMMFFormatDecode. Return number of audio streams for the given |
|
110 * media Raw audio files can only have 1 audio stream. |
|
111 * |
|
112 * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo |
|
113 * @return Number of audio streams |
|
114 */ |
|
115 TUint Streams( TUid aMediaType ) const; |
|
116 |
|
117 /** |
|
118 * Return the frame time interval for the given media |
|
119 * |
|
120 * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo |
|
121 * |
|
122 * @return Time interval in micro seconds |
|
123 */ |
|
124 TTimeIntervalMicroSeconds FrameTimeInterval( TMediaId aMediaType ) const; |
|
125 |
|
126 /** *** NOT SUPPORTED *** |
|
127 * Return the clip duration for the given media |
|
128 * |
|
129 * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo |
|
130 * |
|
131 * @return Clip duration in micro seconds |
|
132 */ |
|
133 TTimeIntervalMicroSeconds Duration( TMediaId aMediaType ) const; |
|
134 |
|
135 /** |
|
136 * Accessor funtion to return the number of channels |
|
137 * |
|
138 * @return Number of channels |
|
139 */ |
|
140 TUint NumChannels( ); |
|
141 |
|
142 /** |
|
143 * Accessor funtion to return the sampling rate |
|
144 * |
|
145 * |
|
146 * @return Sampling rate |
|
147 */ |
|
148 TUint SampleRate( ); |
|
149 |
|
150 /** |
|
151 * Set the packetizationrate to the given value. |
|
152 * |
|
153 * @param aPacketizationRate - [input] Number of AMR frame blocks per RTP packet |
|
154 * |
|
155 * @return error code KErrNotSupported if invalid packetizationrate, else return KErrNone |
|
156 */ |
|
157 TInt SetSampleRate( TUint aSampleRate ); |
|
158 |
|
159 /** |
|
160 * From CMMFFormatDecode |
|
161 */ |
|
162 TFourCC SinkDataTypeCode( TMediaId aMediaId ); |
|
163 |
|
164 public: // From MDataSource. CAmrPayloadFormatRead is data source to the data path and AMR codec. |
|
165 |
|
166 /** |
|
167 * From MDataSource. Read the next block of data from file into the |
|
168 * given buffer. |
|
169 * |
|
170 * @param aBuffer source data buffer for the AMR-NB data read |
|
171 * @param aConsumer data sink pointer |
|
172 * @param aMediaId contains the media type KUidMediaTypeAudio or KUidMediaTypeVideo |
|
173 * |
|
174 * @return |
|
175 */ |
|
176 void FillBufferL( CMMFBuffer* aBuffer, |
|
177 MDataSink* aConsumer, |
|
178 TMediaId aMediaId ); |
|
179 |
|
180 /** |
|
181 * From MDataSource. Primes the source. |
|
182 * @since Series 60 3.0 |
|
183 * @return None |
|
184 */ |
|
185 void SourcePrimeL( ); |
|
186 |
|
187 /** |
|
188 * From MDataSource. Plays the source. |
|
189 * @since Series 60 3.0 |
|
190 * @return None |
|
191 */ |
|
192 void SourcePlayL( ); |
|
193 |
|
194 /** |
|
195 * From MDataSource. Pauses the source. |
|
196 * @since Series 60 3.0 |
|
197 * @return None |
|
198 */ |
|
199 void SourcePauseL( ); |
|
200 |
|
201 /** |
|
202 * From MDataSource. Stops the source. |
|
203 * @since Series 60 3.0 |
|
204 * @return None |
|
205 */ |
|
206 void SourceStopL( ); |
|
207 |
|
208 /** |
|
209 * Create a source buffer for the given media |
|
210 * |
|
211 * @param aMediaId contains the media type KUidMediaTypeAudio or KUidMediaTypeVideo |
|
212 * @param aReference value of False is returned to caller if source buffer is created |
|
213 * |
|
214 * @return Pointer to source buffer created |
|
215 */ |
|
216 CMMFBuffer* CreateSourceBufferL( TMediaId aMediaId, |
|
217 TBool &aReference ); |
|
218 |
|
219 /** |
|
220 * Create a source buffer for the given media, setting frame size to match |
|
221 * the given sink buffer |
|
222 * |
|
223 * @param aMediaId contains the media type KUidMediaTypeAudio or KUidMediaTypeVideo |
|
224 * @param aSinkBuffer address of sink buffer |
|
225 * @param aReference value of False is returned to caller if source buffer is created |
|
226 * |
|
227 * @return Pointer to source buffer created |
|
228 */ |
|
229 CMMFBuffer* CreateSourceBufferL( TMediaId aMediaId, |
|
230 CMMFBuffer& aSinkBuffer, |
|
231 TBool &aReference ); |
|
232 |
|
233 /** |
|
234 * Return the four CC code for the given media |
|
235 * |
|
236 * @param aMediaId contains the media type KUidMediaTypeAudio or KUidMediaTypeVideo |
|
237 * |
|
238 * @return FourCC code |
|
239 */ |
|
240 TFourCC SourceDataTypeCode( TMediaId aMediaId ); |
|
241 |
|
242 /** |
|
243 * Set the source data type to the given four CC code for the given media |
|
244 * |
|
245 * @param aSourceFourCC fourCC code |
|
246 * @param aMediaId contains the media type KUidMediaTypeAudio or KUidMediaTypeVideo |
|
247 * |
|
248 * @return error code KErrNotSupported if invalid media ID, else return KErrNone |
|
249 */ |
|
250 TInt SetSourceDataTypeCode( TFourCC aSourceFourCC, |
|
251 TMediaId aMediaId ); |
|
252 |
|
253 /** |
|
254 * Log in to the source thread - this funtion merely passes the command to |
|
255 * its source clip data source object. The source clip object will handle |
|
256 * the thread log on procedures. |
|
257 * |
|
258 * @param aEventHandler address of event handler |
|
259 * |
|
260 * @return error code returned by source clip |
|
261 */ |
|
262 TInt SourceThreadLogon( MAsyncEventHandler& aEventHandler ); |
|
263 |
|
264 /** |
|
265 * Log out of the source thread - this funtion merely passes the command to |
|
266 * its source clip data source object. The source clip object will handle |
|
267 * the thread log off procedures. |
|
268 * |
|
269 * @return None |
|
270 */ |
|
271 void SourceThreadLogoff( ); |
|
272 |
|
273 /** |
|
274 * Negotiate source settings ( buffer size ) to match |
|
275 * given source object |
|
276 * |
|
277 * @param aDataSink address of sink object |
|
278 * |
|
279 * @return None |
|
280 */ |
|
281 void NegotiateSourceL( MDataSink& aDataSink ); |
|
282 |
|
283 |
|
284 public: // From MDataSink. CAmrPayloadFormatRead is data sink to the RTP data source. |
|
285 |
|
286 /** |
|
287 * Called after the data buffer is filled. Update the number of bytes read |
|
288 * and the current read position for the next read operation. |
|
289 * |
|
290 * @param aBuffer data buffer filled |
|
291 * @param aHeaderInfo RTP packet header information |
|
292 * @return None |
|
293 */ |
|
294 virtual void DataBufferFilledL( CMMFBuffer* aBuffer, |
|
295 const TRtpRecvHeader& aHeaderInfo ); |
|
296 |
|
297 public: |
|
298 |
|
299 /** |
|
300 * Configures payload format with format spesific parameters. |
|
301 * Leaves with KErrArgument if parameters are invalid. |
|
302 * |
|
303 * @since Series 60 3.0 |
|
304 * @param aConfigParams Configuration parameters |
|
305 * @return void |
|
306 */ |
|
307 virtual void ConfigurePayloadFormatL( const TDesC8& aConfigParams ); |
|
308 |
|
309 /** |
|
310 * Update payload format with format spesific parameters. |
|
311 * Leaves with KErrArgument if parameters are invalid. |
|
312 * |
|
313 * @since Series 60 3.0 |
|
314 * @param aCodecInfo Configuration parameters |
|
315 * @return void |
|
316 */ |
|
317 virtual void UpdateConfigurationL( const TMccCodecInfo& aCodecInfo ); |
|
318 |
|
319 private: |
|
320 /** |
|
321 * C++ default constructor. |
|
322 */ |
|
323 CAmrPayloadFormatRead( ); |
|
324 |
|
325 /** |
|
326 * By default Symbian 2nd phase constructor is private. |
|
327 * |
|
328 * @param aSource Source of the data for the payload format plugin |
|
329 */ |
|
330 void ConstructL( MDataSource* aSource ); |
|
331 |
|
332 /** |
|
333 * Reads data starting from the given position into the source buffer |
|
334 * |
|
335 * @param aBuffer RTP payload buffer |
|
336 * |
|
337 * @return TBool indication of finish decoding RTP payload |
|
338 */ |
|
339 TBool DoRead( CMMFBuffer* aBuffer ); |
|
340 |
|
341 /** |
|
342 * Send Amr event to the client . |
|
343 * |
|
344 * @param aEventType |
|
345 */ |
|
346 void SendAmrEventToClient( TMccInternalEventType aEventType ); |
|
347 |
|
348 /** |
|
349 * Creates a buffer used in data transfer between format read and |
|
350 * its datasource. |
|
351 * |
|
352 * @since Series 60 3.2 |
|
353 * @param aSize Suggested buffer size |
|
354 * @param aIsOwnBuffer Indicates ownership of the buffer |
|
355 * @return Created buffer |
|
356 */ |
|
357 CMMFDataBuffer* CreateClipBufferL( TUint aSize, TBool& aIsOwnBuffer ); |
|
358 |
|
359 /** |
|
360 * Gives corresponding bitrate for mode request |
|
361 * @param aModeRequest |
|
362 * @return bitrate |
|
363 */ |
|
364 TInt ConvertModeToBitrate( TAmrModeRequest aModeRequest ); |
|
365 |
|
366 private: // data |
|
367 |
|
368 // True if this AMR narrow band read, False if wideband |
|
369 TBool iIsNb; |
|
370 |
|
371 // Data source providing RTP data |
|
372 MDataSource* iRtpDataSource; |
|
373 |
|
374 // The fourCC for AMR-NB |
|
375 TFourCC iFourCC; |
|
376 |
|
377 // Flag used to determine which buffer is currently used as a sink buffer |
|
378 enum TCurrentBuffer |
|
379 { |
|
380 EBufferOne = 0, |
|
381 EBufferTwo |
|
382 }; |
|
383 |
|
384 // Sampling rate from clip header |
|
385 TInt iSamplingRate; |
|
386 |
|
387 // Number of channels from clip header |
|
388 TUint iChannels; |
|
389 |
|
390 // Mode from clip header |
|
391 TInt iMode; |
|
392 |
|
393 // Payload decoder |
|
394 CAmrPayloadDecoder* iPayloadDecoder; |
|
395 |
|
396 TMediaId iMediaId; |
|
397 |
|
398 // Data buffer passed from RtpSource |
|
399 CMMFBuffer* iBufferToRead; |
|
400 |
|
401 // Indicates are there frames not decoded remaining |
|
402 TBool iBufferToReadExists; |
|
403 |
|
404 // Number of frames decoded from RTP packet |
|
405 TInt iNumOfFrames; |
|
406 |
|
407 // Frame index indicating are all frames decoded passed to datapath |
|
408 TInt iCurrentFrame; |
|
409 |
|
410 // Maximum number of frames expected to receive in one RTP packet |
|
411 TInt iFramesPerPacket; |
|
412 |
|
413 // AMR mode request, used to construct RTP AMR payload header |
|
414 TAmrModeRequest iCmr; |
|
415 |
|
416 // Format decoding state machine |
|
417 CFormatDecodeStateMachine* iStateMachine; |
|
418 |
|
419 // Buffer to store depacketized AMR frames |
|
420 CMMFDataBuffer* iFrameBufferOne; |
|
421 |
|
422 // Alternate buffer to store depacketized AMR frames |
|
423 CMMFDataBuffer* iFrameBufferTwo; |
|
424 |
|
425 // Flag to indicate which buffer is in use |
|
426 TCurrentBuffer iCurrentBuffer; |
|
427 |
|
428 // Buffer to hold payload got from data source |
|
429 CMMFDataBuffer* iSourceBuffer; |
|
430 |
|
431 // Indicates whether payload read has ownership of source buffer |
|
432 TBool iSourceBufOwnership; |
|
433 |
|
434 // Flag to indicate the outstanding request from data path |
|
435 TBool iFillRequested; |
|
436 |
|
437 // Encoder |
|
438 TStreamEncoder iStreamEncoder; |
|
439 |
|
440 // RTP Header |
|
441 TRtpRecvHeader iRecvHeader; |
|
442 |
|
443 // Parameters relating to RTP data decoding |
|
444 TMccCodecInfo iCInfo; |
|
445 |
|
446 // MMF AsyncEventHandler |
|
447 MAsyncEventHandler* iEventHandler; |
|
448 |
|
449 #ifdef FTD_ENABLED |
|
450 // Message queue carrying jitter buffer statistics |
|
451 RMsgQueue<TMccJBufferStats> iJBufStatsQueue; |
|
452 |
|
453 // For RTP packet loss detection |
|
454 TUint32 iLatestSeqNum; |
|
455 |
|
456 // Number of frames decoded after starting |
|
457 TUint32 iTotalFrames; |
|
458 |
|
459 // Number of frames lost due to packet loss |
|
460 TUint32 iLostFrames; |
|
461 #endif |
|
462 |
|
463 private: // Friend classes |
|
464 |
|
465 #ifdef TEST_EUNIT |
|
466 friend class UT_CAmrPayloadFormatRead; |
|
467 #endif |
|
468 |
|
469 }; |
|
470 |
|
471 #endif //AMRPAYLOADFORMATREAD_H |