|
1 /* |
|
2 * Copyright (c) 2002-2003 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "rtpsessionsrtp.h" |
|
23 |
|
24 // ================= MEMBER FUNCTIONS ======================= |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // C++ default constructor can NOT contain any code, that |
|
28 // might leave. |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CRtpSessionSrtp::CRtpSessionSrtp( const TRtpId aSessionId, |
|
32 const TUint32* aProfileRTPTimeRates, |
|
33 const TBool aStandardRtp, |
|
34 MRtpErrNotify& aErrNotify, |
|
35 const CRtpSDES* aSdesInfo , |
|
36 MRtpAsignUniqueID& aAssignUniqueID, |
|
37 CSRTPSession& aSRTPSession) |
|
38 :CRtpSession( aSessionId, |
|
39 aProfileRTPTimeRates, |
|
40 aStandardRtp, aErrNotify, |
|
41 aSdesInfo, aAssignUniqueID), |
|
42 iSRTPSession( aSRTPSession ), |
|
43 iSndPacket(NULL), |
|
44 iSndRtcpPacket(NULL) |
|
45 { |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Symbian 2nd phase constructor can leave. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 void CRtpSessionSrtp::ConstructL( const TCreateSessionParams& aParams, |
|
53 TUint& aPort, |
|
54 TBool aEnableRtcp, |
|
55 const TRtcpParams* aRtcpParams, |
|
56 RSocketServ& aSocketServ, |
|
57 RConnection& aRConn, |
|
58 const RLibrary& aLibrary, |
|
59 MRtpErrNotify& aErrNotify ) |
|
60 { |
|
61 CRtpSession::ConstructL( aParams, aPort, aEnableRtcp, aRtcpParams, aSocketServ, |
|
62 aRConn, aLibrary, aErrNotify ); |
|
63 iIsSrtp=ETrue; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Two-phased constructor. |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CRtpSessionSrtp* CRtpSessionSrtp::NewL( const TCreateSessionParams& aParams, |
|
71 TUint& aPort, |
|
72 TBool aEnableRtcp, |
|
73 const TRtcpParams* aRtcpParams, |
|
74 RSocketServ& aSocketServ, |
|
75 RConnection& aRConn, |
|
76 const TRtpId aSessionId, |
|
77 const CRtpSDES* aSdes, // application's SDES |
|
78 const TUint32* aProfileRTPTimeRates, |
|
79 const TBool aStandardRtp, |
|
80 const RLibrary& aLibrary, |
|
81 MRtpErrNotify& aErrNotify, |
|
82 MRtpAsignUniqueID& aAssignUniqueID, |
|
83 CSRTPSession& aSRTPSession ) |
|
84 { |
|
85 CRtpSessionSrtp* self = new ( ELeave ) CRtpSessionSrtp( aSessionId, |
|
86 aProfileRTPTimeRates, |
|
87 aStandardRtp, aErrNotify, |
|
88 aSdes,aAssignUniqueID, |
|
89 aSRTPSession); |
|
90 CleanupStack::PushL( self ); |
|
91 self->ConstructL( aParams, aPort, aEnableRtcp, aRtcpParams, aSocketServ, |
|
92 aRConn, aLibrary, aErrNotify ); |
|
93 CleanupStack::Pop(); // self |
|
94 return self; |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Destructor |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 CRtpSessionSrtp::~CRtpSessionSrtp() |
|
102 { |
|
103 |
|
104 delete iSndPacket; iSndPacket=NULL; |
|
105 delete iRecvPacket; iRecvPacket=NULL; |
|
106 if(iSndRtcpPacket) |
|
107 delete iSndRtcpPacket; iSndRtcpPacket=NULL; |
|
108 if(iRecvRtcpPacket) |
|
109 delete iRecvRtcpPacket;iRecvRtcpPacket=NULL; |
|
110 } |
|
111 |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CRtpSessionSrtp::SendRtpPacket |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 |
|
118 TInt CRtpSessionSrtp::SendRtpPacket( TRtpId aTranStreamId, |
|
119 const TRtpSendHeader& aHeaderInfo, |
|
120 const TDesC8& aPayloadData ) |
|
121 { |
|
122 if ( static_cast<TUint> (aPayloadData.Size()) > iCommNet->MaxSocketSize() ) |
|
123 { |
|
124 return KErrOverflow; |
|
125 } |
|
126 |
|
127 // find stream |
|
128 TUint streamAddress = 0; |
|
129 TInt ret( FindStream( aTranStreamId, streamAddress ) ); |
|
130 |
|
131 if ( ret == KErrNone ) |
|
132 { |
|
133 CRtpTranStream* tempStream = ( CRtpTranStream* ) streamAddress; |
|
134 tempStream->BuildRtpPacket( aHeaderInfo, aPayloadData, 0, EFalse, |
|
135 iPktSnd ); |
|
136 |
|
137 if(iSndPacket) |
|
138 { |
|
139 delete iSndPacket; |
|
140 iSndPacket=NULL; |
|
141 } |
|
142 TRAPD( error, iSndPacket =iSRTPSession.ProtectRTPL(tempStream->GetLocalSSRC(), iPktSnd->Des())); |
|
143 if(error==KErrNone) |
|
144 { |
|
145 return error = iCommNet->Send( ERTPPort, *iSndPacket); |
|
146 } |
|
147 return error; |
|
148 } |
|
149 return ret; |
|
150 |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CRtpSessionSrtp::SendRtpPacket |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 |
|
158 |
|
159 TInt CRtpSessionSrtp::SendRtpPacket( TRtpId aTranStreamId, |
|
160 const TRtpSendHeader& aHeaderInfo, |
|
161 const TDesC8& aPayloadData, |
|
162 TRequestStatus& aStatus ) |
|
163 { |
|
164 if ( static_cast<TUint> (aPayloadData.Size()) > iCommNet->MaxSocketSize() ) |
|
165 { |
|
166 return KErrOverflow; |
|
167 } |
|
168 |
|
169 // find stream |
|
170 TUint streamAddress = 0; |
|
171 TInt ret( FindStream( aTranStreamId, streamAddress ) ); |
|
172 |
|
173 if ( ret == KErrNone ) |
|
174 { |
|
175 CRtpTranStream* tempStream = ( CRtpTranStream* ) streamAddress; |
|
176 tempStream->BuildRtpPacket( aHeaderInfo, aPayloadData, 0, EFalse, |
|
177 iPktSnd ); |
|
178 if(iSndPacket) |
|
179 { |
|
180 delete iSndPacket; |
|
181 iSndPacket=NULL; |
|
182 } |
|
183 |
|
184 TRAPD(error, iSndPacket =iSRTPSession.ProtectRTPL(tempStream->GetLocalSSRC(), iPktSnd->Des())); |
|
185 if(error==KErrNone) |
|
186 { |
|
187 iCommNet->Send( ERTPPort, *iSndPacket, aStatus ); |
|
188 } |
|
189 return error; |
|
190 } |
|
191 return ret; |
|
192 } |
|
193 |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CRtpSessionSrtp::SendRtpPacket |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 |
|
200 |
|
201 TInt CRtpSessionSrtp::SendRtpPacket( TRtpId aTranStreamId, |
|
202 TRtpSequence aSequenceNum, |
|
203 const TRtpSendHeader& aHeaderInfo, |
|
204 const TDesC8& aPayloadData, |
|
205 TRequestStatus& aStatus ) |
|
206 { |
|
207 if ( static_cast<TUint>( aPayloadData.Size() ) > iCommNet->MaxSocketSize() ) |
|
208 { |
|
209 return KErrOverflow; |
|
210 } |
|
211 |
|
212 // find stream |
|
213 TUint streamAddress = 0; |
|
214 TInt ret( FindStream( aTranStreamId, streamAddress ) ); |
|
215 |
|
216 if ( ret == KErrNone ) |
|
217 { |
|
218 CRtpTranStream* tempStream = |
|
219 reinterpret_cast<CRtpTranStream*>( streamAddress ); |
|
220 tempStream->BuildRtpPacket( aHeaderInfo, aPayloadData, aSequenceNum, |
|
221 ETrue, iPktSnd ); |
|
222 if(iSndPacket) |
|
223 { |
|
224 delete iSndPacket; |
|
225 iSndPacket=NULL; |
|
226 } |
|
227 TRAPD( error, iSndPacket =iSRTPSession.ProtectRTPL(tempStream->GetLocalSSRC(), iPktSnd->Des())); |
|
228 if(error==KErrNone) |
|
229 { |
|
230 iCommNet->Send( ERTPPort, *iSndPacket, aStatus ); |
|
231 } |
|
232 return error; |
|
233 } |
|
234 return ret; |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // CRtpSessionSrtp::OnRtpReceivedL |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 |
|
242 void CRtpSessionSrtp::OnRtpReceivedL() |
|
243 { |
|
244 RTP_DEBUG_DETAIL( "CRtpSessionSrtp::OnRtpReceivedL Entry" ); |
|
245 |
|
246 TRtpSSRC ssrc(0); |
|
247 FindRtpRxStreamSSRC(ssrc); |
|
248 if( ssrc!=0 ) |
|
249 { |
|
250 //should always has one recv to match it so ssrc should not be zero |
|
251 if( UnprotectRtp(ssrc)==KErrNone ) |
|
252 { |
|
253 RTP_DEBUG_DETAIL( "Decrypted RTP data succeed" ); |
|
254 CRtpSession::OnRtpReceivedL(); |
|
255 } |
|
256 else //packet is not successful decrypted |
|
257 { |
|
258 RTP_DEBUG_DETAIL( "Decrypted RTP data failed" ); |
|
259 //pass as non-rtp data to application instead of droping msg IssueRtpRecv(); |
|
260 //including STUN and FC messages |
|
261 if (iNonRTPDataObserver) |
|
262 { |
|
263 // notify user |
|
264 RTP_DEBUG_DETAIL( "Notify decrypted failed RTP data as non rtp data" ); |
|
265 iNonRTPDataObserver->NonRTPDataReceived(GetRtpSocket()->LocalPort(), |
|
266 ETrue, iRtpRecvBuf); |
|
267 } |
|
268 IssueRtpRecv(); |
|
269 } |
|
270 |
|
271 } |
|
272 else |
|
273 { |
|
274 //pass as non-rtp data to application |
|
275 //including STUN and FC messages |
|
276 RTP_DEBUG_DETAIL( "Encrypted incoming Packet SSRC is not found from RX streams" ); |
|
277 |
|
278 if (iNonRTPDataObserver) |
|
279 { |
|
280 // notify user |
|
281 RTP_DEBUG_DETAIL( "Notify non rtp data" ); |
|
282 |
|
283 iNonRTPDataObserver->NonRTPDataReceived(GetRtpSocket()->LocalPort(), |
|
284 ETrue, iRtpRecvBuf); |
|
285 } |
|
286 IssueRtpRecv(); |
|
287 } |
|
288 RTP_DEBUG_DETAIL( "CRtpSessionSrtp::OnRtpReceivedL Exit" ); |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // CRtpSessionSrtp::OnRtpReceived |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 |
|
296 TInt CRtpSessionSrtp::UnprotectRtp(TRtpSSRC ssrc) |
|
297 { |
|
298 //should always has one recv to match it so ssrc should not be zero |
|
299 if(iRecvPacket) |
|
300 { |
|
301 delete iRecvPacket; |
|
302 iRecvPacket = NULL; |
|
303 } |
|
304 TRAPD( err, iRecvPacket= iSRTPSession.UnprotectRTPL(ssrc, iRtpRecvBuf); ); |
|
305 if(err==KErrNone) |
|
306 { |
|
307 iRtpRecvBuf=*iRecvPacket/*iRecvPacket->Des()*/; |
|
308 } |
|
309 |
|
310 return err; |
|
311 |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // CRtpSessionSrtp::SendRTCPReport() |
|
316 // |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 void CRtpSessionSrtp::SendSRTCPReportL(TRtpSSRC aSSRC) |
|
320 { |
|
321 TInt err= KErrNone; |
|
322 if ( !iRtcpEnabled ) |
|
323 { |
|
324 return; |
|
325 } |
|
326 if (iSndRtcpPacket) |
|
327 { |
|
328 delete iSndRtcpPacket; |
|
329 iSndRtcpPacket=NULL; |
|
330 } |
|
331 TRAPD( error, |
|
332 iSndRtcpPacket =iSRTPSession.ProtectRTCPL(aSSRC, iPktRtcpSnd->Des())); |
|
333 |
|
334 if ( error==KErrNone && iSndRtcpPacket ) |
|
335 { |
|
336 err =iCommNet->Send( ERTCPPort, *iSndRtcpPacket ); |
|
337 if (err == KErrDisconnected) |
|
338 ( void ) StopRtcpSending(); |
|
339 AverageRtcpSize( iSndRtcpPacket->Size() ); |
|
340 |
|
341 } |
|
342 // update RTCP average packet size |
|
343 |
|
344 iPktRtcpSnd->RtpPacketReset(); |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 // CRtpSessionSrtp::OnRtcpReceived |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 void CRtpSessionSrtp::OnRtcpReceivedL() |
|
352 { |
|
353 RTP_DEBUG_DETAIL( "CRtpSessionSrtp::OnRtcpReceivedL Entry" ); |
|
354 |
|
355 if ( !iRtcpEnabled ) |
|
356 { |
|
357 RTP_DEBUG_DETAIL( "No RTCP obs" ); |
|
358 return; |
|
359 } |
|
360 TRtpSSRC sourceSSRC( NULL ); |
|
361 iPktRtcpRcv->SetSize( iRtcpRecvBuf.Size() ); |
|
362 |
|
363 // set packet pointer to the beginning |
|
364 iPktRtcpRcv->RtpPacketResetPtr(); |
|
365 |
|
366 // parse RTCP packet header |
|
367 iPktRtcpRcv->SetType( ERTCP_HEADER ); |
|
368 // Get SSRC of packet sender for this report |
|
369 // (This operation does not move the packet pointer) |
|
370 sourceSSRC = iPktRtcpRcv->RtpPacketGetSSRC(); |
|
371 if( sourceSSRC!=0 ) |
|
372 { |
|
373 //should always has one recv to match it so ssrc should not be zero |
|
374 if( UnprotectRtcp(sourceSSRC) == KErrNone ) |
|
375 { |
|
376 RTP_DEBUG_DETAIL( "Decrypted RTCP successful" ); |
|
377 |
|
378 CRtpSession::OnRtcpReceivedL(); |
|
379 } |
|
380 else //packet is not successful decrypted |
|
381 { |
|
382 if (iNonRTPDataObserver ) |
|
383 { |
|
384 RTP_DEBUG_DETAIL( "Notify decrypted failed RTP data as non rtp data" ); |
|
385 |
|
386 iNonRTPDataObserver->NonRTPDataReceived(GetRtcpSocket()->LocalPort(), |
|
387 EFalse, |
|
388 iRtcpRecvBuf); |
|
389 } |
|
390 IssueRtcpRecv(); |
|
391 } |
|
392 |
|
393 } |
|
394 else |
|
395 { |
|
396 RTP_DEBUG_DETAIL( "Encrypted incoming Packet SSRC is not found from RX streams" ); |
|
397 if (iNonRTPDataObserver ) |
|
398 { |
|
399 iNonRTPDataObserver->NonRTPDataReceived(GetRtcpSocket()->LocalPort(), |
|
400 EFalse, |
|
401 iRtcpRecvBuf); |
|
402 } |
|
403 IssueRtcpRecv(); |
|
404 } |
|
405 |
|
406 } |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // CRtpSessionSrtp::UnprotectRtcp |
|
410 // --------------------------------------------------------------------------- |
|
411 // |
|
412 |
|
413 TInt CRtpSessionSrtp::UnprotectRtcp(TRtpSSRC ssrc) |
|
414 { |
|
415 //should always has one recv to match it so ssrc should not be zero |
|
416 |
|
417 if(iRecvRtcpPacket) |
|
418 { |
|
419 delete iRecvRtcpPacket; iRecvRtcpPacket=NULL; |
|
420 } |
|
421 TRAPD( err, iRecvRtcpPacket= iSRTPSession.UnprotectRTCPL(ssrc, *(iPktRtcpRcv->GetHBuf())); ); |
|
422 if(err==KErrNone) |
|
423 { |
|
424 iRtcpRecvBuf=*iRecvRtcpPacket; |
|
425 } |
|
426 |
|
427 return err; |
|
428 |
|
429 } |
|
430 |