|
1 /* |
|
2 * Copyright (c) 2008 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 RTP observation class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mcemediastream.h> |
|
20 #include <mceaudiostream.h> |
|
21 #include <mceaudiocodec.h> |
|
22 #include "svprtpobserverrequest.h" |
|
23 #include "svpsessionbase.h" |
|
24 #include "svptimer.h" |
|
25 #include "svpconsts.h" |
|
26 #include "mccpcallobserver.h" |
|
27 #include "svplogger.h" |
|
28 #include "svpholdcontroller.h" |
|
29 |
|
30 // LOCAL CONSTANTS |
|
31 // RTCP timeout interval, 30 seconds. |
|
32 const TInt KSVPRtcpTimeout = 30000; |
|
33 // Drift 5 seconds, added to actual timeout allowing some randomness in |
|
34 // actual timeout. |
|
35 const TInt KSVPRtcpTimeoutDrift = 5000; |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // CSVPRtpObserverRequest::CSVPRtpObserverRequest |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CSVPRtpObserverRequest::CSVPRtpObserverRequest( |
|
42 CSVPSessionBase& aSession ) : iSession( aSession ) |
|
43 { |
|
44 // No implementation required |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CSVPRtpObserverRequest::~CSVPRtpObserverRequest |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CSVPRtpObserverRequest::~CSVPRtpObserverRequest() |
|
52 { |
|
53 delete iTimer; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CSVPRtpObserverRequest::NewLC |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CSVPRtpObserverRequest* CSVPRtpObserverRequest::NewLC( |
|
61 CSVPSessionBase& aSession ) |
|
62 { |
|
63 CSVPRtpObserverRequest* self = |
|
64 new ( ELeave ) CSVPRtpObserverRequest( aSession ); |
|
65 |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CSVPRtpObserverRequest::NewL |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CSVPRtpObserverRequest* CSVPRtpObserverRequest::NewL( |
|
76 CSVPSessionBase& aSession ) |
|
77 { |
|
78 CSVPRtpObserverRequest* self = CSVPRtpObserverRequest::NewLC( aSession ); |
|
79 CleanupStack::Pop( self ); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CSVPRtpObserverRequest::ConstructL |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CSVPRtpObserverRequest::ConstructL() |
|
88 { |
|
89 // NB, no need for a special timer ID. |
|
90 iTimer = CSVPTimer::NewL( *this, KErrNone ); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CSVPRtpObserverRequest::SvpSession |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 const CSVPSessionBase* CSVPRtpObserverRequest::SvpSession() const |
|
98 { |
|
99 return &iSession; |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CSVPRtpObserverRequest::MceSession |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 const CMceSession* CSVPRtpObserverRequest::MceSession() const |
|
107 { |
|
108 return &( iSession.Session() ); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CSVPRtpObserverRequest::RtcpPacketReceived |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CSVPRtpObserverRequest::RtcpPacketReceived( |
|
116 TReceivedRtcpPacket /*aPacket*/, |
|
117 CMceSession& aSession, |
|
118 CMceMediaStream& aStream ) |
|
119 { |
|
120 SVPDEBUG2( "CSVPRtpObserverRequest::RtcpPacketReceived aStream.IsEnabled: %d", |
|
121 aStream.IsEnabled() ) |
|
122 SVPDEBUG2( "CSVPRtpObserverRequest::RtcpPacketReceived aSession: 0x%x", |
|
123 &aSession ) |
|
124 SVPDEBUG2( "CSVPRtpObserverRequest::RtcpPacketReceived iSession: 0x%x", |
|
125 &( iSession.Session() ) ) |
|
126 |
|
127 // Check that the given session matches ours |
|
128 if ( &aSession == &( iSession.Session() ) ) |
|
129 { |
|
130 SVPDEBUG1( "CSVPRtpObserverRequest::RtcpPacketReceived, (re)start timer" ) |
|
131 |
|
132 // For the sake of "just to be sure", stop the timer first |
|
133 const TInt timeout( DetermineTimeoutValue( aStream ) ); |
|
134 iTimer->Stop(); |
|
135 iTimer->SetTime( timeout ); |
|
136 iDisconnectSent = EFalse; |
|
137 } |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CSVPRtpObserverRequest::Reset |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CSVPRtpObserverRequest::Reset() |
|
145 { |
|
146 SVPDEBUG1( "CSVPRtpObserverRequest::Reset" ) |
|
147 |
|
148 iTimer->Stop(); |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // CSVPRtpObserverRequest::TimedOut |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 void CSVPRtpObserverRequest::TimedOut( TInt /*aTimerId*/ ) |
|
156 { |
|
157 // For the sake of "just to be sure", stop the timer first |
|
158 iTimer->Stop(); |
|
159 |
|
160 if ( IsSessionInHoldState() ) |
|
161 { |
|
162 SVPDEBUG1( "CSVPRtpObserverRequest::TimedOut, (re)start timer because Session is on HOLD" ) |
|
163 iTimer->SetTime( KSVPRtcpTimeout ); |
|
164 iDisconnectSent = EFalse; |
|
165 } |
|
166 else |
|
167 { |
|
168 SVPDEBUG2( "CSVPRtpObserverRequest::TimedOut iDisconnectSent: %d", |
|
169 iDisconnectSent ) |
|
170 |
|
171 // First CCE must be notified about 'disconnecting', state. Then timer is |
|
172 // re-started so that CCE & UI can handle the events with time (i.e user |
|
173 // has actually time to see the UI notifications). |
|
174 // After timer has fired second time, then send 'idle' event to the |
|
175 // CCE. |
|
176 |
|
177 |
|
178 if ( !iDisconnectSent ) |
|
179 { |
|
180 iSession.GetCCPSessionObserver().CallStateChanged( |
|
181 MCCPCallObserver::ECCPStateDisconnecting, &iSession ); |
|
182 |
|
183 iTimer->SetTime( KSVPTerminatingTime ); |
|
184 iDisconnectSent = ETrue; |
|
185 } |
|
186 else |
|
187 { |
|
188 iSession.GetCCPSessionObserver().CallStateChanged( |
|
189 MCCPCallObserver::ECCPStateIdle, &iSession ); |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CSVPRtpObserverRequest::DetermineTimeoutValue |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 TInt CSVPRtpObserverRequest::DetermineTimeoutValue( |
|
199 CMceMediaStream& aStream ) const |
|
200 { |
|
201 // NB: aStream is not const because call to Codecs() is not const => this |
|
202 // saves a const_cast and keeps some sanity in casting. Though, we do not |
|
203 // modify anything in given aStream... |
|
204 |
|
205 TInt timeout( KSVPRtcpTimeout ); |
|
206 if ( KMceAudio == aStream.Type() ) |
|
207 { |
|
208 CMceAudioStream& audio( static_cast<CMceAudioStream&>( aStream ) ); |
|
209 |
|
210 const RPointerArray<CMceAudioCodec>& codecs( audio.Codecs() ); |
|
211 const TInt count = codecs.Count(); |
|
212 for( TInt k = 0; k < count; k++ ) |
|
213 { |
|
214 // MCE API talks about ms' but returns somethings that look awfully |
|
215 // close to seconds... Oh, well... |
|
216 const TInt kpval( |
|
217 codecs[k]->KeepAliveTimer() * KSVPMilliSecondCoefficient ); |
|
218 if ( kpval > timeout ) |
|
219 { |
|
220 timeout = kpval; |
|
221 } |
|
222 |
|
223 SVPDEBUG2( "CSVPRtpObserverRequest::DetermineTimeoutValue k: %d", k ) |
|
224 SVPDEBUG2( "CSVPRtpObserverRequest::DetermineTimeoutValue kpval: %d", kpval ) |
|
225 } |
|
226 |
|
227 SVPDEBUG2( "CSVPRtpObserverRequest::DetermineTimeoutValue count: %d", count ) |
|
228 } |
|
229 |
|
230 // Now add the drifting to the timeout. |
|
231 timeout += KSVPRtcpTimeoutDrift; |
|
232 |
|
233 SVPDEBUG2( "CSVPRtpObserverRequest::DetermineTimeoutValue timeout: %d", timeout ) |
|
234 |
|
235 return timeout; |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // CSVPRtpObserverRequest::IsSessionInHoldState |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 TBool CSVPRtpObserverRequest::IsSessionInHoldState() |
|
243 { |
|
244 if ( SvpSession()->HasHoldController() && |
|
245 ESVPOnHold == (SvpSession()->HoldController()).HoldState() ) |
|
246 { |
|
247 SVPDEBUG1( "CSVPRtpObserverRequest::IsSessionInHoldState ETrue" ) |
|
248 return ETrue; |
|
249 } |
|
250 else |
|
251 { |
|
252 SVPDEBUG1( "CSVPRtpObserverRequest::IsSessionInHoldState EFalse" ) |
|
253 return EFalse; |
|
254 } |
|
255 } |