|
1 /* |
|
2 * Copyright (c) 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: Provides functionality for DTMF digit encoding and sending. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef CDTMFPAYLOADFORMATWRITE_H |
|
22 #define CDTMFPAYLOADFORMATWRITE_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include <mmf/server/mmfformat.h> |
|
27 #include "rtpheader.h" |
|
28 #include "mmccevents.h" |
|
29 #include "dtmfpayloadformatdefs.h" |
|
30 #include "mccinternalcodecs.h" |
|
31 #include "dtmfencstatemachine.h" |
|
32 #include "formatstatemachine.h" |
|
33 |
|
34 // FORWARD DECLARATIONS |
|
35 class CDTMFPayloadEncoder; |
|
36 class MMccRtpDataSink; |
|
37 class CMccRtpMediaClock; |
|
38 class CDtmfHighResTimer; |
|
39 |
|
40 // CLASS DECLARATION |
|
41 |
|
42 /** |
|
43 * Handles DTMF encoding and passing to the RTP data sink. |
|
44 * Supported DTMF payload format is telephone-event payload. |
|
45 * |
|
46 * @lib mmccdtmfplformat.dll |
|
47 * @since Series 60 3.2 |
|
48 */ |
|
49 class CDTMFPayloadFormatWrite : public CPayloadFormatWrite, |
|
50 public MDtmfEncClient |
|
51 { |
|
52 public: // Constructors and destructor |
|
53 |
|
54 /** |
|
55 * Two-phased constructor. |
|
56 */ |
|
57 static CDTMFPayloadFormatWrite* NewL( MDataSink* aSink ); |
|
58 |
|
59 /** |
|
60 * Destructor. |
|
61 */ |
|
62 virtual ~CDTMFPayloadFormatWrite(); |
|
63 |
|
64 public: // New functions |
|
65 |
|
66 /** |
|
67 * Used to dispatch timer events from the timer to the class instance |
|
68 * being interested in receiving them. |
|
69 * |
|
70 * @since Series 60 3.2 |
|
71 * @param aObjectPtr Pointer to object that wants |
|
72 * to receive timer events |
|
73 * @return Non-zero value if current task is ongoing |
|
74 */ |
|
75 static TInt HandleTimerEventL( TAny* aObjectPtr ); |
|
76 |
|
77 /** |
|
78 * Start to packetize DTMF digit to the RTP packets and send them. |
|
79 * |
|
80 * @since Series 60 3.2 |
|
81 * @param aTone Digit user has pressed at UI |
|
82 */ |
|
83 virtual void StartDTMFToneL( const TChar aTone ); |
|
84 |
|
85 /** |
|
86 * Stop DTMF digit packetizing and sending. |
|
87 * |
|
88 * @since Series 60 3.2 |
|
89 */ |
|
90 virtual void StopDTMFToneL(); |
|
91 |
|
92 /** |
|
93 * Starts sending of passed DTMF string incrementally. |
|
94 * |
|
95 * @since Series 60 3.2 |
|
96 * @param aTones DTMF string to send |
|
97 */ |
|
98 virtual void SendDTMFTonesL( const TDesC8& aTones ); |
|
99 |
|
100 /** |
|
101 * Start/Stop notify about stops ('w' char) in a DTMF string. |
|
102 * |
|
103 * @since Series 60 3.2 |
|
104 * @param aFlag ETrue to enable, EFalse to disable notify service |
|
105 */ |
|
106 virtual void NotifyStopInDTMFString( TBool aFlag ); |
|
107 |
|
108 /** |
|
109 * Continue DTMF string sending after stop in a string has been |
|
110 * encountered. |
|
111 * |
|
112 * @since Series 60 3.2 |
|
113 * @param aContinue Whether to continue string sending |
|
114 * @return KErrNone |
|
115 */ |
|
116 virtual TInt ContinueDTMFStringSending( TBool aContinue ); |
|
117 |
|
118 /** |
|
119 * Cancel DTMF string sending. |
|
120 * |
|
121 * @since Series 60 3.2 |
|
122 */ |
|
123 virtual void CancelDTMFStringSending(); |
|
124 |
|
125 /** |
|
126 * Returns payload format used in DTMF encoding. |
|
127 * |
|
128 * @since Series 60 3.2 |
|
129 * @return Payload format used in DTMF encoding |
|
130 */ |
|
131 virtual TDTMFPayloadFormat PayloadFormat() const; |
|
132 |
|
133 /** |
|
134 * Sets payload format to be used in DTMF encoding. |
|
135 * |
|
136 * @since Series 60 3.2 |
|
137 * @param aPayloadFormat Payload format to be used |
|
138 * @return System wide error code |
|
139 */ |
|
140 virtual TInt SetPayloadFormat( TDTMFPayloadFormat aPayloadFormat ); |
|
141 |
|
142 /** |
|
143 * From MDtmfEncClient. Called when it's time to handle next digit |
|
144 * in sequence while sending DTMF string. |
|
145 * |
|
146 * @since Series 60 3.2 |
|
147 */ |
|
148 void EncodeNextDigitL(); |
|
149 |
|
150 /** |
|
151 * From MDtmfEncClient. Does actions belonging to tone on state. |
|
152 * Actions include DTMF event update packets sending. |
|
153 * |
|
154 * @since Series 60 3.2 |
|
155 * @param aEntryToState Indicates is this transition to state |
|
156 */ |
|
157 void DoToneOnActionsL( TBool aEntryToState ); |
|
158 |
|
159 /** |
|
160 * From MDtmfEncClient. Does actions belonging to tone off state. |
|
161 * Actions include DTMF event final packet sending and |
|
162 * retransmissions. During DTMF string sending this state implements |
|
163 * wait activity before proceeding to send next digit in a string. |
|
164 * |
|
165 * @since Series 60 3.2 |
|
166 * @param aEntryToState Indicates is this transition to state |
|
167 * @return void |
|
168 */ |
|
169 void DoToneOffActionsL( TBool aEntryToState ); |
|
170 |
|
171 public: // Functions from CMMFFormatEncode |
|
172 |
|
173 /** |
|
174 * From CMMFFormatEncode. Gets the time interval for one frame. |
|
175 * |
|
176 * @since Series 60 3.2 |
|
177 * @param aMediaType The media type ID |
|
178 * @return The time interval for one frame, in microseconds. |
|
179 */ |
|
180 TTimeIntervalMicroSeconds FrameTimeInterval( |
|
181 TMediaId aMediaType ) const; |
|
182 |
|
183 /** |
|
184 * From CMMFFormatEncode. Gets the duration of the sink clip for the |
|
185 * specified media ID. |
|
186 * |
|
187 * @since Series 60 3.2 |
|
188 * @param aMediaType The media type ID |
|
189 * @return Duration of the sink clip |
|
190 */ |
|
191 TTimeIntervalMicroSeconds Duration( TMediaId aMediaType ) const; |
|
192 |
|
193 /** |
|
194 * From CMMFFormatEncode. Empty the given source buffer. |
|
195 * |
|
196 * @since Series 60 3.2 |
|
197 * @param aBuffer data buffer containing DTMF payload |
|
198 * @param aSupplier data source pointer |
|
199 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
200 * KUidMediaTypeVideo |
|
201 */ |
|
202 void EmptyBufferL( CMMFBuffer* aBuffer, MDataSource* aSupplier, |
|
203 TMediaId aMediaId ); |
|
204 |
|
205 /** |
|
206 * From CMMFFormatEncode. Called by the clip to indicate data has been |
|
207 * processed. |
|
208 * |
|
209 * @since Series 60 3.2 |
|
210 * @param aBuffer The emptied buffer. |
|
211 */ |
|
212 void BufferEmptiedL( CMMFBuffer* aBuffer ); |
|
213 |
|
214 /** |
|
215 * From CMMFFormatEncode. DTMF payload format write doesn't support |
|
216 * sink buffer creation. |
|
217 * |
|
218 * @since Series 60 3.2 |
|
219 * @return EFalse |
|
220 */ |
|
221 TBool CanCreateSinkBuffer(); |
|
222 |
|
223 /** |
|
224 * From CMMFFormatEncode. DTMF payload format write doesn't support |
|
225 * sink buffer creation. |
|
226 * |
|
227 * @since Series 60 3.2 |
|
228 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
229 * KUidMediaTypeVideo |
|
230 * @param aReference value of False is returned to caller if sink |
|
231 * buffer is created |
|
232 * @return NULL |
|
233 */ |
|
234 CMMFBuffer* CreateSinkBufferL( TMediaId aMediaId, TBool &aReference ); |
|
235 |
|
236 public: // Functions from MDataSink |
|
237 |
|
238 /** |
|
239 * From MDataSink. Passes prime transition to the RTP data sink. |
|
240 * |
|
241 * @since Series 60 3.2 |
|
242 */ |
|
243 void SinkPrimeL(); |
|
244 |
|
245 /** |
|
246 * From MDataSink. Passes play transition to the RTP data sink. |
|
247 * |
|
248 * @since Series 60 3.2 |
|
249 */ |
|
250 void SinkPlayL(); |
|
251 |
|
252 /** |
|
253 * From MDataSink. Passes pause transition to the RTP data sink. |
|
254 * |
|
255 * @since Series 60 3.2 |
|
256 */ |
|
257 void SinkPauseL(); |
|
258 |
|
259 /** |
|
260 * From MDataSink. Passes stop transition to the RTP data sink. |
|
261 * |
|
262 * @since Series 60 3.2 |
|
263 */ |
|
264 void SinkStopL(); |
|
265 |
|
266 /** |
|
267 * Log in to the sink thread - this funtion merely passes the |
|
268 * command to its sink clip data source object. The sink clip |
|
269 * object will handle the thread log on procedures. |
|
270 * |
|
271 * @since Series 60 3.2 |
|
272 * @param aEventHandler address of event handler |
|
273 * @return error code returned by source clip |
|
274 */ |
|
275 TInt SinkThreadLogon( MAsyncEventHandler& aEventHandler ); |
|
276 |
|
277 /** |
|
278 * Log out of the sink thread - this funtion merely passes the command |
|
279 * to its sink clip data source object. The sink clip object will |
|
280 * handle the thread log off procedures. |
|
281 * |
|
282 * @since Series 60 3.2 |
|
283 */ |
|
284 void SinkThreadLogoff(); |
|
285 |
|
286 /** |
|
287 * Return the sink four CC code for the given media |
|
288 * |
|
289 * @since Series 60 3.2 |
|
290 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
291 * KUidMediaTypeVideo |
|
292 * @return FourCC code for the mediaId |
|
293 */ |
|
294 TFourCC SinkDataTypeCode( TMediaId aMediaId ); |
|
295 |
|
296 /** |
|
297 * Set the sink data type to given four CC code for the given media |
|
298 * |
|
299 * @since Series 60 3.2 |
|
300 * @param aSinkFourCC fourCC code |
|
301 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
302 * KUidMediaTypeVideo |
|
303 * @return error code KErrNotSupported if invalid media ID, else |
|
304 * return KErrNone |
|
305 */ |
|
306 TInt SetSinkDataTypeCode( TFourCC aSinkFourCC, TMediaId aMediaId ); |
|
307 |
|
308 /** |
|
309 * Sets the sink's priority settings. |
|
310 * |
|
311 * @since Series 60 3.2 |
|
312 * @param aPrioritySettings Sink priority settings. |
|
313 */ |
|
314 void SetSinkPrioritySettings( const TMMFPrioritySettings& |
|
315 aPrioritySettings ); |
|
316 |
|
317 public: |
|
318 |
|
319 /** |
|
320 * Configures payload format with format spesific parameters and |
|
321 * sets RTP Media clock with which to synchronize DTMF sending. |
|
322 * Leaves with KErrArgument if parameters are invalid. |
|
323 * |
|
324 * @since Series 60 3.2 |
|
325 * @param aConfigParams Configuration parameters |
|
326 * @param aRtpMediaClock RTP media clock |
|
327 */ |
|
328 virtual void ConfigurePayloadFormatL( const TDesC8& aConfigParams, |
|
329 CMccRtpMediaClock& aClock ); |
|
330 |
|
331 protected: |
|
332 |
|
333 /** |
|
334 * Called when specified time interval has elapsed. |
|
335 * |
|
336 * @since Series 60 3.2 |
|
337 * @return Non-zero value if current task is ongoing |
|
338 */ |
|
339 TInt DoHandleTimerEventL(); |
|
340 |
|
341 private: |
|
342 |
|
343 /** |
|
344 * C++ default constructor. |
|
345 */ |
|
346 CDTMFPayloadFormatWrite(); |
|
347 |
|
348 /** |
|
349 * By default Symbian 2nd phase constructor is private. |
|
350 */ |
|
351 void ConstructL( MDataSink* aSink ); |
|
352 |
|
353 /** |
|
354 * Prepare packet header and deliver the packet to the datasink. |
|
355 * |
|
356 * @since Series 60 3.2 |
|
357 * @param aPayload Payload to deliver to the datasink. |
|
358 * @param aMarkerBit Marker bit on/off status |
|
359 */ |
|
360 void DeliverPacketL( CMMFDataBuffer& aPayload, TBool aMarkerBit ); |
|
361 |
|
362 /** |
|
363 * Check that digits are valid DTMF. |
|
364 * |
|
365 * @since Series 60 3.2 |
|
366 * @param aDigits DTMF string to be checked |
|
367 * @return ETrue if valid, otherwise EFalse |
|
368 */ |
|
369 TBool IsValidDigits( const TDesC8& aDigits ) const; |
|
370 |
|
371 /** |
|
372 * Takes care of handling 'p' and 'w' chars in a DTMF string. |
|
373 * |
|
374 * @since Series 60 3.2 |
|
375 * @param aChar Control char to handle |
|
376 */ |
|
377 void HandleControlChar( const TChar& aChar ); |
|
378 |
|
379 /** |
|
380 * Signaling about events to the client. |
|
381 * |
|
382 * @since Series 60 3.2 |
|
383 * @param aEventType Type of the event to send to a client |
|
384 */ |
|
385 void SendEventSignalToClient( TMccDtmfEventType aEventType ) const; |
|
386 |
|
387 /** |
|
388 * Checks that digit is valid DTMF. |
|
389 * |
|
390 * @since Series 60 3.2 |
|
391 * @param aDigit Digit to check |
|
392 * @return ETrue if valid, otherwise EFalse |
|
393 */ |
|
394 TBool IsValidDigit( const TChar& aDigit ) const; |
|
395 |
|
396 private: // Data |
|
397 |
|
398 class TSendBufferElement |
|
399 { |
|
400 |
|
401 public: |
|
402 |
|
403 TSendBufferElement( const TChar& aDtmfTone, TUint32 aStartTime ) |
|
404 : |
|
405 iTone( aDtmfTone ), |
|
406 iStartTimeInMs( aStartTime ), |
|
407 iStopTimeInMs( 0 ) |
|
408 { |
|
409 |
|
410 } |
|
411 |
|
412 const TChar& Tone() const |
|
413 { |
|
414 return iTone; |
|
415 } |
|
416 |
|
417 TUint32 StartTime() const |
|
418 { |
|
419 return iStartTimeInMs; |
|
420 } |
|
421 |
|
422 TUint32 StopTime() const |
|
423 { |
|
424 return iStopTimeInMs; |
|
425 } |
|
426 |
|
427 void SetStopTime( TUint32 aStopTime ) |
|
428 { |
|
429 iStopTimeInMs = aStopTime; |
|
430 } |
|
431 |
|
432 TUint Duration() const |
|
433 { |
|
434 if ( iStopTimeInMs < iStartTimeInMs ) |
|
435 { |
|
436 // wrap around situation |
|
437 const TUint32 KMaxUintValue( 0xFFFFFFFF ); |
|
438 return ( ( KMaxUintValue - iStartTimeInMs ) + iStopTimeInMs ); |
|
439 } |
|
440 else |
|
441 { |
|
442 return ( iStopTimeInMs - iStartTimeInMs ); |
|
443 } |
|
444 } |
|
445 |
|
446 private: |
|
447 |
|
448 TChar iTone; |
|
449 TUint32 iStartTimeInMs; |
|
450 TUint32 iStopTimeInMs; |
|
451 }; |
|
452 |
|
453 enum TDTMFSendingMode |
|
454 { |
|
455 EModeNotDefined = 0, |
|
456 EModeManual = 1, |
|
457 EModeAutomatic = 2 |
|
458 }; |
|
459 |
|
460 /** |
|
461 * The FourCC code for DTMF PayloadFormatWrite |
|
462 */ |
|
463 TFourCC iFourCC; |
|
464 |
|
465 /** |
|
466 * Pointer to sink buffer that holds encoded DTMF / RTP payload |
|
467 * Own. |
|
468 */ |
|
469 CMMFDataBuffer* iSinkBuffer; |
|
470 |
|
471 /** |
|
472 * Pointer to formatter class for encoding of RTP payload |
|
473 * Own. |
|
474 */ |
|
475 CDTMFPayloadEncoder* iPayloadEncoder; |
|
476 |
|
477 /** |
|
478 * Timer used for event updates and incremental DTMF string send. |
|
479 * Own. |
|
480 */ |
|
481 CDtmfHighResTimer* iSendTimer; |
|
482 |
|
483 /** |
|
484 * RTP header used for sending RTP packet |
|
485 */ |
|
486 TRtpSendHeader iRtpSendHeader; |
|
487 |
|
488 /** |
|
489 * Contains current duration of tone |
|
490 */ |
|
491 TUint16 iToneDuration; |
|
492 |
|
493 /** |
|
494 * Payload format used for encoding |
|
495 */ |
|
496 TDTMFPayloadFormat iPayloadFormat; |
|
497 |
|
498 /** |
|
499 * Send buffer for timed DTMF sending |
|
500 */ |
|
501 RArray<TSendBufferElement> iSendBuffer; |
|
502 |
|
503 /** |
|
504 * Indicates is DTMF generated inbandly or outbandly |
|
505 */ |
|
506 TInt iGenerationMode; |
|
507 |
|
508 /** |
|
509 * Pointer to asynchronous event handler |
|
510 * Not own. |
|
511 */ |
|
512 MAsyncEventHandler* iEventHandler; |
|
513 |
|
514 /** |
|
515 * Boolean indicating is NotifyStopInDTMFString() request in force |
|
516 */ |
|
517 TBool iNotifyStopReq; |
|
518 |
|
519 /** |
|
520 * Contains valid DTMF digits |
|
521 */ |
|
522 RArray<TChar> iValidDigits; |
|
523 |
|
524 /** |
|
525 * Parameters relating to RTP data encoding |
|
526 */ |
|
527 TMccCodecInfo iCInfo; |
|
528 |
|
529 /** |
|
530 * Used to keep track on how many final packets is |
|
531 * sent with current tone |
|
532 */ |
|
533 TInt iFinalPacketCtr; |
|
534 |
|
535 /** |
|
536 * Sending mode |
|
537 */ |
|
538 TDTMFSendingMode iSendingMode; |
|
539 |
|
540 /** |
|
541 * Pointer to state machine for DTMF encoding and sending |
|
542 * Own. |
|
543 */ |
|
544 CDtmfEncStateMachine* iStateMachine; |
|
545 |
|
546 /** |
|
547 * Pointer to data sink capable to receive RTP data. |
|
548 * Not own. |
|
549 */ |
|
550 MMccRtpDataSink* iRtpDataSink; |
|
551 |
|
552 /** |
|
553 * Key for Rtp media clock |
|
554 */ |
|
555 TUint32 iKey; |
|
556 |
|
557 /** |
|
558 * Pointer to RTP media clock used to synchronize |
|
559 * DTMF sending with audio |
|
560 * Not own. |
|
561 */ |
|
562 CMccRtpMediaClock* iRtpMediaClock; |
|
563 |
|
564 /** |
|
565 * Sampling rate used. |
|
566 */ |
|
567 TUint iSampleRate; |
|
568 |
|
569 /** |
|
570 * Nanokernel tick period in milliseconds. |
|
571 */ |
|
572 TInt iTickPeriod; |
|
573 |
|
574 private: // Friend classes |
|
575 |
|
576 #ifdef TEST_EUNIT |
|
577 friend class UT_CDTMFPayloadFormatWrite; |
|
578 #endif |
|
579 }; |
|
580 |
|
581 #endif // CDTMFPAYLOADFORMATWRITE_H |
|
582 |
|
583 // End of File |