1 /* |
|
2 * Copyright (c) 2009 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: Telephony Multimedia Service |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "tmsutility.h" |
|
20 #include "tmsdtmftoneplayer.h" |
|
21 |
|
22 // CONSTANTS |
|
23 const gint KDTMFMaxBufSize = 64; |
|
24 const gint KMaxVolumeLevel = 10; |
|
25 |
|
26 _LIT(KPhoneTone_Asterisk, "*+w"); |
|
27 |
|
28 //from voip |
|
29 const guint KDTMFToneLengthOn = 250000; |
|
30 const guint KDTMFToneLengthOff = 50000; |
|
31 const guint KDTMFToneLengthPause = 2500000; |
|
32 |
|
33 using namespace TMS; |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // TMSAudioDtmfTonePlayer::NewL |
|
37 // Two-phased constructor. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 TMSAudioDtmfTonePlayer* TMSAudioDtmfTonePlayer::NewL( |
|
41 TMSDTMFTonePlayerObserver& obsrvr, guint audioPreference, |
|
42 guint audioPriority) |
|
43 { |
|
44 TMSAudioDtmfTonePlayer* self = new (ELeave) TMSAudioDtmfTonePlayer(obsrvr, |
|
45 audioPreference, audioPriority); |
|
46 |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 //Destructor |
|
54 TMSAudioDtmfTonePlayer::~TMSAudioDtmfTonePlayer() |
|
55 { |
|
56 TRACE_PRN_FN_ENT; |
|
57 Cancel(); |
|
58 delete iDTMFPlayer; |
|
59 TRACE_PRN_FN_EXT; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // TMSAudioDtmfTonePlayer::TMSAudioDtmfTonePlayer |
|
64 // C++ default constructor can NOT contain any code, that |
|
65 // might leave. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 TMSAudioDtmfTonePlayer::TMSAudioDtmfTonePlayer( |
|
69 TMSDTMFTonePlayerObserver& obsrvr, guint audioPreference, |
|
70 guint audioPriority) : |
|
71 iObserver(obsrvr), |
|
72 iPref(audioPreference), |
|
73 iPrior(audioPriority) |
|
74 { |
|
75 TRACE_PRN_FN_ENT; |
|
76 TRACE_PRN_FN_EXT; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // TMSAudioDtmfTonePlayer::ConstructL |
|
81 // Symbian 2nd phase constructor can leave. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void TMSAudioDtmfTonePlayer::ConstructL() |
|
85 { |
|
86 TRACE_PRN_FN_ENT; |
|
87 |
|
88 TMMFPrioritySettings dtmfClickPlayerPrioritySettings; |
|
89 iDTMFPlayer = CMMFDevSound::NewL(); |
|
90 iDTMFPlayer->InitializeL(*this, EMMFStateTonePlaying); |
|
91 |
|
92 TRACE_PRN_FN_EXT; |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // TMSAudioDtmfTonePlayer::SetVolume |
|
97 // Sets the volume level that is used when the dtmf tone is played. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void TMSAudioDtmfTonePlayer::SetVolume(gint volume) |
|
101 { |
|
102 TRACE_PRN_FN_ENT; |
|
103 gint vol = ConvertVolumeLevel(volume); |
|
104 |
|
105 if (vol != iVolume) |
|
106 { |
|
107 iVolume = vol; |
|
108 iDTMFPlayer->SetVolume(iVolume); |
|
109 } |
|
110 TRACE_PRN_FN_EXT; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // TMSAudioDtmfTonePlayer::PlayDtmfTone |
|
115 // Searches the given DTMF tone from iToneArray and calls PlayCurrentTone |
|
116 // member function. |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 void TMSAudioDtmfTonePlayer::PlayDtmfTone(TDes& tone) |
|
120 { |
|
121 TRACE_PRN_FN_ENT; |
|
122 Cancel(); |
|
123 |
|
124 // DTMF signaling. |
|
125 if (iDTMFPlayer) |
|
126 { |
|
127 TBuf<KDTMFMaxBufSize> key; |
|
128 key.Append(tone); |
|
129 TRAP_IGNORE(iDTMFPlayer->PlayDTMFStringL(tone)); |
|
130 } |
|
131 TRACE_PRN_FN_EXT; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // TMSAudioDtmfTonePlayer::Cancel |
|
136 // Cancels the currently playing tone. |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void TMSAudioDtmfTonePlayer::Cancel() |
|
140 { |
|
141 TRACE_PRN_FN_ENT; |
|
142 iDTMFPlayer->Stop(); |
|
143 TRACE_PRN_FN_EXT; |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // TMSAudioDtmfTonePlayer::Normalize |
|
148 // Lowers case for chars and if its '*','+', or 'w' sets it to asterisk |
|
149 // char ('*'). |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void TMSAudioDtmfTonePlayer::Normalize(TChar& tone) |
|
153 { |
|
154 TRACE_PRN_FN_ENT; |
|
155 tone.LowerCase(); |
|
156 TPtrC ast(KPhoneTone_Asterisk); |
|
157 |
|
158 if (ast.Locate(tone) != KErrNotFound) |
|
159 { |
|
160 tone = ast[0]; |
|
161 } |
|
162 TRACE_PRN_FN_EXT; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // TMSAudioDtmfTonePlayer::InitializeComplete |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void TMSAudioDtmfTonePlayer::InitializeComplete(TInt aError) |
|
170 { |
|
171 TRACE_PRN_FN_ENT; |
|
172 |
|
173 if (aError == KErrNone) |
|
174 { |
|
175 TMMFPrioritySettings dtmfPlayerSettings; |
|
176 dtmfPlayerSettings.iPref = iPref; |
|
177 dtmfPlayerSettings.iPriority = iPrior; |
|
178 dtmfPlayerSettings.iState = EMMFStateTonePlaying; |
|
179 iDTMFPlayer->SetPrioritySettings(dtmfPlayerSettings); |
|
180 |
|
181 TTimeIntervalMicroSeconds32 length(KDTMFToneLengthOn); |
|
182 TTimeIntervalMicroSeconds32 pause(KDTMFToneLengthOff); |
|
183 TTimeIntervalMicroSeconds32 zero(KDTMFToneLengthPause); |
|
184 iDTMFPlayer->SetDTMFLengths(length, pause, zero); |
|
185 iDTMFPlayer->SetVolume(iDTMFPlayer->MaxVolume()); |
|
186 } |
|
187 |
|
188 iObserver.DTMFInitCompleted(aError); |
|
189 TRACE_PRN_IF_ERR(aError); |
|
190 TRACE_PRN_FN_EXT; |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // TMSAudioDtmfTonePlayer::ToneFinished |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void TMSAudioDtmfTonePlayer::ToneFinished(TInt aError) |
|
198 { |
|
199 TRACE_PRN_FN_ENT; |
|
200 iObserver.DTMFToneFinished(aError); |
|
201 TRACE_PRN_IF_ERR(aError); |
|
202 TRACE_PRN_FN_EXT; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // TMSAudioDtmfTonePlayer::ConvertVolumeLevel |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 gint TMSAudioDtmfTonePlayer::ConvertVolumeLevel(gint volume) |
|
210 { |
|
211 TRACE_PRN_FN_ENT; |
|
212 gint result = iDTMFPlayer->MaxVolume() * volume / KMaxVolumeLevel; |
|
213 TRACE_PRN_FN_EXT; |
|
214 return result; |
|
215 } |
|
216 |
|