|
1 /* |
|
2 * Copyright (c) 2002-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: RTP Keepalive mechanism |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32math.h> |
|
23 #include "mccrtpkeepalivecontainer.h" |
|
24 #include "mccrtpkeepalive.h" |
|
25 #include "mccdef.h" |
|
26 #include "mccinternaldef.h" |
|
27 #include "mccsubcontrollerlogs.h" |
|
28 #include "mccinternalevents.h" |
|
29 #include "mccrtpinterface.h" |
|
30 |
|
31 |
|
32 // EXTERNAL DATA STRUCTURES |
|
33 |
|
34 // EXTERNAL FUNCTION PROTOTYPES |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 // MACROS |
|
39 |
|
40 // LOCAL CONSTANTS AND MACROS |
|
41 |
|
42 // MODULE DATA STRUCTURES |
|
43 |
|
44 // LOCAL FUNCTION PROTOTYPES |
|
45 |
|
46 // FORWARD DECLARATIONS |
|
47 |
|
48 |
|
49 // ============================= LOCAL FUNCTIONS ============================= |
|
50 |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS ============================= |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CMccRtpKeepaliveContainer::NewL |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CMccRtpKeepaliveContainer* CMccRtpKeepaliveContainer::NewL( |
|
59 MAsyncEventHandler& aEventHandler, |
|
60 CRtpAPI& aRtpAPI, |
|
61 TRtpId aRtpSessionId ) |
|
62 { |
|
63 CMccRtpKeepaliveContainer* self = |
|
64 new ( ELeave ) CMccRtpKeepaliveContainer( aEventHandler, |
|
65 aRtpAPI, |
|
66 aRtpSessionId ); |
|
67 |
|
68 return self; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CMccRtpKeepaliveContainer::~CMccRtpKeepaliveContainer |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CMccRtpKeepaliveContainer::~CMccRtpKeepaliveContainer() |
|
76 { |
|
77 iKeepaliveHandlers.ResetAndDestroy(); |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // CMccRtpKeepaliveContainer::StartKeepaliveL |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 void CMccRtpKeepaliveContainer::StartKeepaliveL( |
|
85 MMccRtpInterface& aUser, |
|
86 TMccCodecInfo& aCodecInfo, |
|
87 CMccRtpMediaClock& aRtpMediaClock ) |
|
88 { |
|
89 __SUBCONTROLLER( "CMccRtpKeepaliveContainer::StartKeepaliveL(), Entry" ) |
|
90 |
|
91 if ( aUser.IsSink() ) |
|
92 { |
|
93 iRtpSinkExist = ETrue; |
|
94 } |
|
95 |
|
96 if ( ( aCodecInfo.iKeepaliveInterval > 0 && !iStopped ) && |
|
97 ( aUser.IsSink() || |
|
98 ( !aUser.IsSink() && EFalse == iRtpSinkExist ) ) ) |
|
99 { |
|
100 __SUBCONTROLLER( "CMccRtpKeepaliveContainer::StartKeepaliveL(),\ |
|
101 interval defined" ) |
|
102 |
|
103 CMccRtpKeepalive* handler = FindKeepaliveHandler( |
|
104 aCodecInfo.iKeepalivePT, aUser ); |
|
105 if ( !handler ) |
|
106 { |
|
107 handler = CMccRtpKeepalive::NewL( iEventHandler, |
|
108 iRtpAPI, |
|
109 iRtpSessionId, |
|
110 aCodecInfo.iKeepalivePT, |
|
111 aCodecInfo.iKeepaliveInterval, |
|
112 aCodecInfo.iKeepaliveData, |
|
113 iRemoteAddressSet ); |
|
114 CleanupStack::PushL( handler ); |
|
115 iKeepaliveHandlers.AppendL( handler ); |
|
116 CleanupStack::Pop( handler ); |
|
117 } |
|
118 handler->StartKeepaliveL( aUser, aRtpMediaClock ); |
|
119 } |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CMccRtpKeepaliveContainer::StopKeepalive |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 TInt CMccRtpKeepaliveContainer::StopKeepalive( |
|
127 MMccRtpInterface& aUser, |
|
128 const TMccCodecInfo& aCodecInfo ) |
|
129 { |
|
130 __SUBCONTROLLER( "CMccRtpKeepaliveContainer::StopKeepalive(), Entry" ) |
|
131 TInt err( KErrNotFound ); |
|
132 CMccRtpKeepalive* handler = FindKeepaliveHandler( |
|
133 aCodecInfo.iKeepalivePT, aUser ); |
|
134 if ( handler ) |
|
135 { |
|
136 TInt refCount( 0 ); |
|
137 err = handler->StopKeepalive( aUser, refCount ); |
|
138 if ( !refCount ) |
|
139 { |
|
140 // No more users, can be removed |
|
141 TInt index = iKeepaliveHandlers.Find( handler ); |
|
142 if ( index != KErrNotFound ) |
|
143 { |
|
144 __SUBCONTROLLER( "CMccRtpKeepaliveContainer::StopKeepalive(),\ |
|
145 delete Handler" ) |
|
146 delete iKeepaliveHandlers[ index ]; |
|
147 iKeepaliveHandlers.Remove( index ); |
|
148 } |
|
149 } |
|
150 if ( iRtpSinkExist ) |
|
151 { |
|
152 iRtpSinkExist = EFalse; |
|
153 TInt count = iKeepaliveHandlers.Count(); |
|
154 for ( TInt i = 0; i < count && !iRtpSinkExist; i++ ) |
|
155 { |
|
156 iRtpSinkExist = iKeepaliveHandlers[ i ]->IsForSink(); |
|
157 } |
|
158 } |
|
159 } |
|
160 return err; |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CMccRtpKeepaliveContainer::ResetKeepAliveTimer |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CMccRtpKeepaliveContainer::ResetKeepaliveTimer() |
|
168 { |
|
169 TInt count = iKeepaliveHandlers.Count(); |
|
170 for ( TInt i = 0; i < count; i++ ) |
|
171 { |
|
172 iKeepaliveHandlers[ i ]->ResetKeepaliveTimer(); |
|
173 } |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // CMccRtpKeepaliveContainer::UpdateParamsL |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CMccRtpKeepaliveContainer::UpdateParamsL( MMccRtpInterface& aUser, |
|
181 const TMccCodecInfo& aCodecInfo ) |
|
182 { |
|
183 __SUBCONTROLLER( "CMccRtpKeepaliveContainer::UpdateParamsL(), Entry" ) |
|
184 |
|
185 CMccRtpKeepalive* handler = |
|
186 FindKeepaliveHandler( aCodecInfo.iKeepalivePT, aUser ); |
|
187 |
|
188 if ( handler ) |
|
189 { |
|
190 // Deactivate handler because update invalidates references to the |
|
191 // previous keep-alive data. |
|
192 handler->Cancel(); |
|
193 handler->UpdateParamsL( aCodecInfo.iKeepalivePT, |
|
194 aCodecInfo.iKeepaliveInterval, aCodecInfo.iKeepaliveData ); |
|
195 |
|
196 if ( aCodecInfo.iKeepaliveInterval > 0 && !handler->IsActive() ) |
|
197 { |
|
198 handler->ResetKeepaliveTimer(); |
|
199 } |
|
200 } |
|
201 |
|
202 __SUBCONTROLLER( "CMccRtpKeepaliveContainer::UpdateParamsL(), exit" ) |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // CMccRtpKeepaliveContainer::StopAll |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 void CMccRtpKeepaliveContainer::StopAll() |
|
210 { |
|
211 iKeepaliveHandlers.ResetAndDestroy(); |
|
212 iStopped = ETrue; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CMccRtpKeepaliveContainer::RemoteAddressSet |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 TInt CMccRtpKeepaliveContainer::RemoteAddressSet() |
|
220 { |
|
221 TInt err( KErrNotReady ); |
|
222 iRemoteAddressSet = ETrue; |
|
223 if ( !iStopped ) |
|
224 { |
|
225 err = KErrNone; |
|
226 for ( TInt i = 0; i < iKeepaliveHandlers.Count(); i++ ) |
|
227 { |
|
228 err |= iKeepaliveHandlers[ i ]->RemoteAddressSet(); |
|
229 } |
|
230 } |
|
231 return err; |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // CMccRtpKeepaliveContainer::FindKeepaliveHandler |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 CMccRtpKeepalive* CMccRtpKeepaliveContainer::FindKeepaliveHandler( |
|
239 TUint8 aKeepAlivePT, MMccRtpInterface& aUser ) |
|
240 { |
|
241 CMccRtpKeepalive* handler = NULL; |
|
242 for ( TInt i = 0; i < iKeepaliveHandlers.Count() && !handler; i++ ) |
|
243 { |
|
244 if ( aUser.IsSink() ) |
|
245 { |
|
246 if ( iKeepaliveHandlers[ i ]->StreamId() == aUser.RtpStreamId() ) |
|
247 { |
|
248 handler = iKeepaliveHandlers[ i ]; |
|
249 } |
|
250 } |
|
251 else |
|
252 { |
|
253 if ( iKeepaliveHandlers[ i ]->PayloadType() == aKeepAlivePT ) |
|
254 { |
|
255 handler = iKeepaliveHandlers[ i ]; |
|
256 } |
|
257 } |
|
258 } |
|
259 return handler; |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CMccRtpKeepaliveContainer::CMccRtpKeepaliveContainer |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 CMccRtpKeepaliveContainer::CMccRtpKeepaliveContainer( |
|
267 MAsyncEventHandler& aEventHandler, |
|
268 CRtpAPI& aRtpAPI, |
|
269 TRtpId aRtpSessionId ) : |
|
270 iEventHandler( aEventHandler ), |
|
271 iRtpAPI( aRtpAPI ), |
|
272 iRtpSessionId( aRtpSessionId ) |
|
273 { |
|
274 } |
|
275 |
|
276 |
|
277 // ========================== OTHER EXPORTED FUNCTIONS ======================= |
|
278 |
|
279 // End of File |