14 * Description: Telephony Multimedia Service |
14 * Description: Telephony Multimedia Service |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <AudioPreference.h> |
18 #include <AudioPreference.h> |
19 #include <glib.h> |
19 #include <tms.h> |
20 #include <S60FourCC.h> |
20 #include <S60FourCC.h> |
|
21 #include "tmsutility.h" |
21 #include "tmscsdevsound.h" |
22 #include "tmscsdevsound.h" |
22 #include "tmscsdevsoundobserver.h" |
23 #include "tmscsdevsoundobserver.h" |
23 |
24 |
24 using namespace TMS; |
25 using namespace TMS; |
25 |
26 |
26 // ----------------------------------------------------------------------------- |
27 // CONSTANTS |
27 // TMSCSPDevSound |
28 const gint KTimeoutInitial = 200000; // 200 ms initial timeout |
28 // ----------------------------------------------------------------------------- |
29 const gint KTimeoutMultiplier = 2; // Double the timeout for each retry |
29 // |
30 const gint KMicroSecMultiply = 1000000; //1 sec |
30 TMSCSPDevSound::TMSCSPDevSound(TMSCSPDevSoundObserver& aObserver) : |
31 |
31 iObserver(aObserver) |
32 // ----------------------------------------------------------------------------- |
32 { |
33 // TMSCSDevSound |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 TMSCSDevSound::TMSCSDevSound(TMSCSDevSoundObserver& observer) : |
|
37 iObserver(observer) |
|
38 { |
|
39 iTimer = NULL; |
|
40 iTimeout = KTimeoutInitial; |
|
41 iInitRetryTime = 0; |
|
42 iStartRetryTime = 0; |
33 } |
43 } |
34 |
44 |
35 // ----------------------------------------------------------------------------- |
45 // ----------------------------------------------------------------------------- |
36 // ConstructL |
46 // ConstructL |
37 // ----------------------------------------------------------------------------- |
47 // ----------------------------------------------------------------------------- |
38 // |
48 // |
39 void TMSCSPDevSound::ConstructL(TMMFState aMode, gint aAudioPreference, |
49 void TMSCSDevSound::ConstructL(const TMSStreamType strmtype, |
40 gint aAudioPriority) |
50 const gint retrytime) |
41 { |
51 { |
|
52 TRACE_PRN_FN_ENT; |
|
53 iInitRetryTime = retrytime; |
|
54 iStreamType = strmtype; |
|
55 |
|
56 if (strmtype == TMS_STREAM_UPLINK) |
|
57 { |
|
58 iMode = EMMFStateRecording; |
|
59 iPriority = KAudioPriorityCSCallUplink; |
|
60 iPreference = KAudioPrefCSCallUplink; |
|
61 } |
|
62 else if (strmtype == TMS_STREAM_DOWNLINK) |
|
63 { |
|
64 iMode = EMMFStatePlaying; |
|
65 iPriority = KAudioPriorityCSCallDownlink; |
|
66 iPreference = KAudioPrefCSCallDownlink; |
|
67 } |
|
68 |
|
69 if (iInitRetryTime != 0) |
|
70 { |
|
71 iTimer = TMSTimer::NewL(); |
|
72 } |
|
73 |
|
74 InitializeL(); |
|
75 TRACE_PRN_FN_EXT; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // InitializeL |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void TMSCSDevSound::InitializeL() |
|
83 { |
|
84 TRACE_PRN_FN_ENT; |
42 TMMFPrioritySettings audioPriority; |
85 TMMFPrioritySettings audioPriority; |
43 TFourCC modemFourCC; |
86 TFourCC modemFourCC; |
44 modemFourCC.Set(KS60FourCCCodeModem); |
87 modemFourCC.Set(KS60FourCCCodeModem); |
|
88 |
|
89 delete iDevSound; |
|
90 iDevSound = NULL; |
45 iDevSound = CMMFDevSound::NewL(); |
91 iDevSound = CMMFDevSound::NewL(); |
46 if (iDevSound) |
92 if (iDevSound) |
47 { |
93 { |
48 #ifndef __WINSCW__ |
94 #ifndef __WINSCW__ |
49 iDevSound->InitializeL(*this, modemFourCC, aMode); |
95 iDevSound->InitializeL(*this, modemFourCC, iMode); |
50 #else //For testing TMS in WINSCW |
96 #else |
51 iDevSound->InitializeL(*this, KMMFFourCCCodePCM16, aMode); |
97 //For testing TMS in WINSCW |
|
98 iDevSound->InitializeL(*this, KMMFFourCCCodePCM16, iMode); |
52 #endif |
99 #endif |
53 iStreamType = aAudioPreference; |
100 audioPriority.iPriority = iPriority; |
54 audioPriority.iPriority = aAudioPriority; |
101 audioPriority.iPref = iPreference; |
55 audioPriority.iPref = aAudioPreference; |
102 audioPriority.iState = iMode; |
56 audioPriority.iState = aMode; |
|
57 iDevSound->SetPrioritySettings(audioPriority); |
103 iDevSound->SetPrioritySettings(audioPriority); |
58 } |
104 } |
|
105 TRACE_PRN_FN_EXT; |
59 } |
106 } |
60 |
107 |
61 // ----------------------------------------------------------------------------- |
108 // ----------------------------------------------------------------------------- |
62 // From class MDevSoundObserver |
109 // From class MDevSoundObserver |
63 // Not implemented |
110 // Not implemented |
64 // ----------------------------------------------------------------------------- |
111 // ----------------------------------------------------------------------------- |
65 // |
112 // |
66 TMSCSPDevSound::~TMSCSPDevSound() |
113 TMSCSDevSound::~TMSCSDevSound() |
67 { |
114 { |
|
115 TRACE_PRN_FN_ENT; |
|
116 CancelTimer(); |
|
117 delete iTimer; |
68 delete iDevSound; |
118 delete iDevSound; |
|
119 TRACE_PRN_FN_EXT; |
69 } |
120 } |
70 |
121 |
71 // ----------------------------------------------------------------------------- |
122 // ----------------------------------------------------------------------------- |
72 // Tries to activate the audio stream if not active or activating |
123 // Tries to activate the audio stream if not active or activating |
73 // ----------------------------------------------------------------------------- |
124 // ----------------------------------------------------------------------------- |
74 // |
125 // |
75 void TMSCSPDevSound::Activate() |
126 void TMSCSDevSound::Activate(const gint retrytime) |
76 { |
127 { |
77 if (!IsActive() && !IsActivationOngoing()) |
128 iStartRetryTime = retrytime; |
|
129 |
|
130 if (!iActive && !iActivationOngoing) |
78 { |
131 { |
79 iActivationOngoing = ETrue; |
132 iActivationOngoing = ETrue; |
80 TRAP_IGNORE(DoActivateL()); |
133 TRAP_IGNORE(DoActivateL()); |
81 } |
134 } |
82 } |
135 } |
83 |
136 |
84 // ----------------------------------------------------------------------------- |
137 // ----------------------------------------------------------------------------- |
85 // Deactivates the audio device. |
138 // Deactivates the audio device. |
86 // ----------------------------------------------------------------------------- |
139 // ----------------------------------------------------------------------------- |
87 // |
140 // |
88 void TMSCSPDevSound::Deactivate() |
141 void TMSCSDevSound::Deactivate(gboolean reset) |
89 { |
142 { |
90 if (iDevSound && (IsActive() || IsActivationOngoing())) |
143 TRACE_PRN_FN_ENT; |
|
144 if (reset) |
|
145 { |
|
146 iTimeout = KTimeoutInitial; |
|
147 } |
|
148 CancelTimer(); |
|
149 if (iDevSound && (iActive || iActivationOngoing)) |
91 { |
150 { |
92 iDevSound->Stop(); |
151 iDevSound->Stop(); |
93 iActive = EFalse; |
152 iActive = EFalse; |
94 iActivationOngoing = EFalse; |
153 iActivationOngoing = EFalse; |
95 } |
154 } |
96 } |
155 TRACE_PRN_FN_EXT; |
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // ActivationOngoing |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 TBool TMSCSPDevSound::IsActivationOngoing() const |
|
103 { |
|
104 return iActivationOngoing; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // IsActive |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 TBool TMSCSPDevSound::IsActive() const |
|
112 { |
|
113 return iActive; |
|
114 } |
156 } |
115 |
157 |
116 // ----------------------------------------------------------------------------- |
158 // ----------------------------------------------------------------------------- |
117 // DevSound |
159 // DevSound |
118 // ----------------------------------------------------------------------------- |
160 // ----------------------------------------------------------------------------- |
119 // |
161 // |
120 CMMFDevSound& TMSCSPDevSound::DevSound() |
162 CMMFDevSound& TMSCSDevSound::DevSound() |
121 { |
163 { |
122 return *iDevSound; |
164 return *iDevSound; |
123 } |
165 } |
124 |
166 |
125 // ----------------------------------------------------------------------------- |
167 // ----------------------------------------------------------------------------- |
126 // From class MDevSoundObserver |
168 // From class MDevSoundObserver |
127 // Not implemented |
169 // ----------------------------------------------------------------------------- |
128 // ----------------------------------------------------------------------------- |
170 // |
129 // |
171 void TMSCSDevSound::InitializeComplete(TInt aError) |
130 void TMSCSPDevSound::InitializeComplete(TInt aError) |
172 { |
131 { |
173 TRACE_PRN_FN_ENT; |
132 if (iStreamType == KAudioPrefCSCallDownlink) |
174 if (aError != TMS_RESULT_SUCCESS && iInitRetryTime != 0) |
133 { |
175 { |
134 iObserver.DownlinkInitCompleted(aError); |
176 StartTimer(); |
135 } |
177 } |
136 else |
178 else |
137 { |
179 { |
138 iObserver.UplinkInitCompleted(aError); |
180 iTimeout = KTimeoutInitial; |
139 } |
181 CancelTimer(); |
140 } |
182 NotifyEvent(aError); |
141 |
183 } |
142 // ----------------------------------------------------------------------------- |
184 TRACE_PRN_FN_EXT; |
143 // From class MDevSoundObserver |
185 } |
144 // Not implemented |
186 |
145 // ----------------------------------------------------------------------------- |
187 |
146 // |
188 // ----------------------------------------------------------------------------- |
147 void TMSCSPDevSound::BufferToBeFilled(CMMFBuffer* /*aBuffer*/) |
189 // TMSCSDevSound::NotifyEvent |
148 { |
190 // ----------------------------------------------------------------------------- |
149 } |
191 // |
150 |
192 void TMSCSDevSound::NotifyEvent(gint error) |
151 // ----------------------------------------------------------------------------- |
193 { |
152 // From class MDevSoundObserver |
194 if (iStreamType == TMS_STREAM_DOWNLINK) |
153 // Not implemented |
195 { |
154 // ----------------------------------------------------------------------------- |
196 iObserver.DownlinkInitCompleted(error); |
155 // |
197 } |
156 void TMSCSPDevSound::PlayError(TInt /*aError*/) |
198 else if (iStreamType == TMS_STREAM_UPLINK) |
157 { |
199 { |
158 } |
200 iObserver.UplinkInitCompleted(error); |
159 |
201 } |
160 // ----------------------------------------------------------------------------- |
202 } |
161 // From class MDevSoundObserver |
203 |
162 // Not implemented |
204 // ----------------------------------------------------------------------------- |
163 // ----------------------------------------------------------------------------- |
205 // TMSCSDevSound::CancelTimer |
164 // |
206 // Resets timer |
165 void TMSCSPDevSound::ToneFinished(TInt /*aError*/) |
207 // ----------------------------------------------------------------------------- |
166 { |
208 // |
167 } |
209 void TMSCSDevSound::CancelTimer() |
168 |
210 { |
169 // ----------------------------------------------------------------------------- |
211 iInitRetryTime = 0; |
170 // From class MDevSoundObserver |
212 if (iTimer) |
171 // Not implemented |
213 { |
172 // ----------------------------------------------------------------------------- |
214 if (iTimer->IsRunning()) |
173 // |
215 { |
174 void TMSCSPDevSound::BufferToBeEmptied(CMMFBuffer* /*aBuffer*/) |
216 iTimer->CancelNotify(); |
175 { |
217 } |
176 } |
218 } |
177 |
219 } |
178 // ----------------------------------------------------------------------------- |
220 |
179 // From class MDevSoundObserver |
221 // ----------------------------------------------------------------------------- |
180 // Not implemented |
222 // TMSCSDevSound::StartTimer |
181 // ----------------------------------------------------------------------------- |
223 // Activates timer |
182 // |
224 // ----------------------------------------------------------------------------- |
183 void TMSCSPDevSound::RecordError(TInt /*aError*/) |
225 // |
184 { |
226 void TMSCSDevSound::StartTimer() |
185 } |
227 { |
186 |
228 if (iTimer && (iInitRetryTime != 0 || iStartRetryTime != 0)) |
187 // ----------------------------------------------------------------------------- |
229 { |
188 // From class MDevSoundObserver |
230 iTimer->NotifyAfter(iTimeout, *this); |
189 // Not implemented |
231 } |
190 // ----------------------------------------------------------------------------- |
232 } |
191 // |
233 |
192 void TMSCSPDevSound::ConvertError(TInt /*aError*/) |
234 // ----------------------------------------------------------------------------- |
193 { |
235 // From TMSTimerObserver |
194 } |
236 // Notification upon TMSTimer timeout. |
195 |
237 // ----------------------------------------------------------------------------- |
196 // ----------------------------------------------------------------------------- |
238 // |
197 // From class MDevSoundObserver |
239 void TMSCSDevSound::TimerEvent() |
198 // Not implemented |
240 { |
199 // ----------------------------------------------------------------------------- |
241 iTimeout *= KTimeoutMultiplier; |
200 // |
242 |
201 void TMSCSPDevSound::DeviceMessage(TUid /*aMessageType*/, |
243 if (!iActivationOngoing) //Initializing |
202 const TDesC8& /*aMsg*/) |
244 { |
203 { |
245 if (iTimeout > (iInitRetryTime * KMicroSecMultiply)) |
|
246 { |
|
247 iInitRetryTime = 0; |
|
248 } |
|
249 TRAPD(status, InitializeL()); |
|
250 if (status != TMS_RESULT_SUCCESS) |
|
251 { |
|
252 NotifyEvent(status); |
|
253 } |
|
254 } |
|
255 else //Activating |
|
256 { |
|
257 if (iTimeout > (iStartRetryTime * KMicroSecMultiply)) |
|
258 { |
|
259 iStartRetryTime = 0; |
|
260 } |
|
261 Deactivate(FALSE); |
|
262 Activate(iStartRetryTime); |
|
263 } |
204 } |
264 } |
205 |
265 |
206 // End of File |
266 // End of File |