|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "MCEConstants.h" |
|
21 #include "TCmdSendStreamDtmf.h" |
|
22 #include "CTcMCEContext.h" |
|
23 |
|
24 #include <MCESession.h> |
|
25 #include <MceMediaStream.h> |
|
26 #include <MceMediaSource.h> |
|
27 #include <MceRtpSource.h> |
|
28 #include <MceAudioStream.h> |
|
29 |
|
30 #include <MCEAudioCodec.h> |
|
31 #include <MceDtmfCodec.h> |
|
32 |
|
33 const TUint KDtmfAudioPriority = 45; |
|
34 const TUint KDtmfAudioPref = 0x00150001; |
|
35 |
|
36 _LIT( KTestSequence, "0123456789abcd*#"); |
|
37 |
|
38 void TCmdSendStreamDtmf::ExecuteL() |
|
39 { |
|
40 // ---------- Setup -------------------------------------------------------- |
|
41 |
|
42 // DTMF out-of-band means DTMF tones are sent as the numerical value in a packet |
|
43 // (RTP type telephone-event, refer RFC2833). |
|
44 |
|
45 const TInt KDefaultDuration = 0; |
|
46 |
|
47 // Get session |
|
48 CMceSession* session = |
|
49 reinterpret_cast<CMceSession*>(GetObjectForIdL(KSessionId, ETrue)); |
|
50 |
|
51 TPtrC8 dtmfTones = ExtractTextL( KParamDtmfTones, EFalse ); |
|
52 TInt dtmfDuration = ExtractIntegerL( KParamDtmfDuration, KDefaultDuration, EFalse ); |
|
53 TBool isSingleTone = ExtractBooleanL( KParamDtmfIsSingleTone, EFalse ); |
|
54 |
|
55 const RPointerArray<CMceMediaStream>& streams = session->Streams(); |
|
56 |
|
57 for ( TInt i = 0; i < streams.Count(); ++i ) |
|
58 { |
|
59 CMceMediaStream* mediaStream; |
|
60 mediaStream = streams[i]; |
|
61 |
|
62 if ( mediaStream->Type() == KMceAudio && mediaStream->Source()->Type() == KMceRTPSource ) |
|
63 { |
|
64 CMceAudioStream* audioStream = dynamic_cast<CMceAudioStream*>(mediaStream); |
|
65 |
|
66 const RPointerArray<CMceAudioCodec>& codecsMain = audioStream->Codecs(); |
|
67 |
|
68 TBool dtmfFound = EFalse; |
|
69 for (TInt i = codecsMain.Count()-1; dtmfFound == EFalse && i >= 0; i --) |
|
70 { |
|
71 if ( codecsMain[i]->SdpName().Compare(KValueCodecDtmf())) |
|
72 { |
|
73 //TODO modify dtmf codec |
|
74 codecsMain[i]->SetMMFPriorityL( KDtmfAudioPriority ); |
|
75 codecsMain[i]->SetMMFPriorityPreferenceL( KDtmfAudioPref ); |
|
76 codecsMain[i]->SetPreferenceL(0); |
|
77 dtmfFound = ETrue; |
|
78 |
|
79 } |
|
80 } |
|
81 //getting the media source pointer from the audio stream; |
|
82 CMceMediaSource* dtmfSource = audioStream->Source(); |
|
83 //checking if dtmf is available |
|
84 if(dtmfSource->DtmfAvailable() && (!dtmfSource->DtmfActive()) ) |
|
85 { |
|
86 //sending dtmf tones |
|
87 if( dtmfTones.Compare( KNullDesC8 ) != 0 ) |
|
88 { |
|
89 HBufC* buf = HBufC::NewLC(dtmfTones.Length()); |
|
90 buf->Des().Copy(dtmfTones); |
|
91 |
|
92 if( isSingleTone && dtmfDuration > 0) |
|
93 { |
|
94 TLex lexer( *buf ); |
|
95 TChar tone = lexer.Get(); |
|
96 //starts sending the tone |
|
97 dtmfSource->StartDtmfToneL( tone ); |
|
98 |
|
99 iDtmfTimer = NULL; |
|
100 //create instance of timer to stop sending the tone after given duration |
|
101 iDtmfTimer = CDelayedProcess::NewL(dtmfSource); |
|
102 |
|
103 if(iDtmfTimer) |
|
104 { |
|
105 TTimeIntervalMicroSeconds32 delay = dtmfDuration * 1000; |
|
106 iDtmfTimer->StartProcess(delay); |
|
107 } |
|
108 } |
|
109 else if( !isSingleTone ) |
|
110 { |
|
111 iDtmfTimer = NULL; |
|
112 dtmfSource->SendDtmfToneSequenceL(*buf); |
|
113 } |
|
114 |
|
115 iaudioStream = audioStream; |
|
116 CleanupStack::PopAndDestroy(buf); |
|
117 buf = NULL; |
|
118 } |
|
119 else |
|
120 { |
|
121 //send default sequence if not present in the params |
|
122 dtmfSource->SendDtmfToneSequenceL(KTestSequence); |
|
123 iaudioStream = audioStream; |
|
124 } |
|
125 |
|
126 } |
|
127 //stop sending dtmf |
|
128 if( dtmfSource->DtmfActive() && ( !isSingleTone ) ) |
|
129 { |
|
130 dtmfSource->CancelDtmfToneSequenceL(); |
|
131 } |
|
132 } |
|
133 } |
|
134 |
|
135 |
|
136 |
|
137 // ---------- Response creation -------------------------------------------- |
|
138 if(iaudioStream) |
|
139 { |
|
140 AddIdResponseL( KStreamId, *iaudioStream ); |
|
141 AddTextResponseL( KParamDtmfTones, dtmfTones ); |
|
142 AddIntegerResponseL( KResponseLocalMediaPort, |
|
143 iaudioStream->LocalMediaPort() ); |
|
144 } |
|
145 else |
|
146 { |
|
147 AddIntegerResponseL(KResponseActionReturnCode, KErrArgument); |
|
148 } |
|
149 } |
|
150 |
|
151 TBool TCmdSendStreamDtmf::Match( const TTcIdentifier& aId ) |
|
152 { |
|
153 return TTcMceCommandBase::Match( aId, _L8("SendStreamDtmf") ); |
|
154 } |
|
155 |
|
156 TTcCommandBase* TCmdSendStreamDtmf::CreateL( MTcTestContext& aContext ) |
|
157 { |
|
158 return new( ELeave ) TCmdSendStreamDtmf( aContext ); |
|
159 } |