|
1 /* |
|
2 * Copyright (c) 2004 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: Represents an SRTP stream. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "srtpstreamout.h" |
|
23 #include "tsrtpstreamoutstatebase.h" |
|
24 #include "tsrtpstreamoutstateuninit.h" |
|
25 #include "tsrtpstreamoutstatenormal.h" |
|
26 #include "srtpsession.h" |
|
27 #include "srtpcryptohandler.h" |
|
28 #include "srtpcryptohandlersrtp.h" |
|
29 #include "srtpcryptohandlersrtcp.h" |
|
30 #include "srtputils.h" |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // Two-phased constructor. Used when stream uses default cryptographic context |
|
34 // |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 EXPORT_C CSRTPStreamOut* CSRTPStreamOut::NewL( CSRTPSession& aSession, TUint aSSRC ) |
|
38 { |
|
39 CSRTPStreamOut* self = new( ELeave )CSRTPStreamOut( aSession, aSSRC); |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // Used when stream uses its own cryptographic context |
|
48 // |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C CSRTPStreamOut* CSRTPStreamOut::NewL( CSRTPSession& aSession, |
|
52 TUint aSSRC, |
|
53 CSRTPCryptoContext* aCon, |
|
54 MSRTPReKeyingObserver& aObs ) |
|
55 { |
|
56 CSRTPStreamOut* self = new( ELeave )CSRTPStreamOut( aSession, aSSRC, |
|
57 aCon, aObs); |
|
58 CleanupStack::PushL( self ); |
|
59 TRAPD( err, self->ConstructL() ); |
|
60 if ( err ) |
|
61 { |
|
62 self->iStrmSpecificCrypto = EFalse; // Cannot take ownership |
|
63 User::Leave( err ); |
|
64 } |
|
65 CleanupStack::Pop( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Used when crypto context will be set later to this stream |
|
71 // |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C CSRTPStreamOut* CSRTPStreamOut::NewL( CSRTPSession& aSession, |
|
75 TUint aSSRC, |
|
76 MSRTPReKeyingObserver& aObs ) |
|
77 { |
|
78 CSRTPStreamOut* self = new( ELeave )CSRTPStreamOut( aSession, aSSRC, |
|
79 aObs); |
|
80 |
|
81 return self; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CSRTPStreamOut::CSRTPStreamOut |
|
86 // |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CSRTPStreamOut::CSRTPStreamOut( CSRTPSession& aSession, |
|
90 TUint aSSRC) |
|
91 : CSRTPStream(aSession, aSSRC, EFalse), |
|
92 iStates(MSRTPStreamOutContext::EMaxStates), |
|
93 iCurrentRTPState(ESRTPStreamOutUninitialized), |
|
94 iCurrentRTCPState(ESRTPStreamOutUninitialized) |
|
95 { |
|
96 |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CSRTPStreamOut::CSRTPStreamOut |
|
101 // |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 CSRTPStreamOut::CSRTPStreamOut( CSRTPSession& aSession, |
|
105 TUint aSSRC, |
|
106 CSRTPCryptoContext* aCon, |
|
107 MSRTPReKeyingObserver& aObs ) |
|
108 : CSRTPStream(aSession, aSSRC, aCon, aObs, EFalse), |
|
109 iStates(MSRTPStreamOutContext::EMaxStates), |
|
110 iCurrentRTPState(ESRTPStreamOutUninitialized), |
|
111 iCurrentRTCPState(ESRTPStreamOutUninitialized) |
|
112 { |
|
113 |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CSRTPStreamOut::CSRTPStreamOut |
|
118 // |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 CSRTPStreamOut::CSRTPStreamOut( CSRTPSession& aSession, |
|
122 TUint aSSRC, |
|
123 MSRTPReKeyingObserver& aObs ) |
|
124 : CSRTPStream(aSession, aSSRC, aObs, EFalse), |
|
125 iStates(MSRTPStreamOutContext::EMaxStates), |
|
126 iCurrentRTPState(ESRTPStreamOutUninitialized), |
|
127 iCurrentRTCPState(ESRTPStreamOutUninitialized) |
|
128 { |
|
129 |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CSRTPStreamOut::ConstructL |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CSRTPStreamOut::ConstructL() |
|
137 { |
|
138 CreateCryptoHandlerSRTPL(); |
|
139 CreateCryptoHandlerSRTCPL(); |
|
140 InitializeStatesL(); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CSRTPStreamOut::SetCryptoOutL() |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C void CSRTPStreamOut::SetCryptoOutL(CSRTPCryptoContext* aCon) |
|
148 { |
|
149 //checking if there is one crytpocontext existed |
|
150 //construct only when stream has its own cryto handler |
|
151 if( !aCon) |
|
152 { |
|
153 User::Leave( KErrArgument ); |
|
154 } |
|
155 if (!iRekey ) |
|
156 { |
|
157 delete iHandlerRTP; iHandlerRTP=NULL; |
|
158 delete iHandlerRTCP;iHandlerRTCP=NULL; |
|
159 delete iContext; iContext=NULL; |
|
160 iContext= aCon; |
|
161 iStrmSpecificCrypto= ETrue; |
|
162 iStates.Reset(); |
|
163 //should create handler and initial state |
|
164 TRAPD( err, |
|
165 { |
|
166 CreateCryptoHandlerSRTPL(); |
|
167 CreateCryptoHandlerSRTCPL(); |
|
168 InitializeStatesL(); |
|
169 } ); |
|
170 if ( err ) |
|
171 { |
|
172 iContext = NULL; // Cannot take ownership if leave occurs |
|
173 User::Leave( err ); |
|
174 } |
|
175 ChangeRTPState(MSRTPStreamOutContext::ESRTPStreamOutUninitialized); |
|
176 ChangeRTCPState(MSRTPStreamOutContext::ESRTPStreamOutUninitialized); |
|
177 } |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CSRTPStreamOut::ReInitialOutStates |
|
182 // |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CSRTPStreamOut::UpdateCryptoAndStatesL() |
|
186 { |
|
187 if( !iStrmSpecificCrypto) |
|
188 { |
|
189 UpdateCryptoHandlerL(); |
|
190 iStates.Reset(); |
|
191 InitializeStatesL(); |
|
192 ChangeRTPState(MSRTPStreamOutContext::ESRTPStreamOutUninitialized); |
|
193 ChangeRTCPState(MSRTPStreamOutContext::ESRTPStreamOutUninitialized); |
|
194 } |
|
195 } |
|
196 // --------------------------------------------------------------------------- |
|
197 // HBufC8* CSRTPStreamOut::ProtectRtpL( |
|
198 // |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 EXPORT_C HBufC8* CSRTPStreamOut::ProtectRtpL( const TDesC8& aPacket ) |
|
202 { |
|
203 if (IsContextSet()) |
|
204 return (CurrentRTPState().DoProtectRtpL(aPacket)); |
|
205 //it is using session crypto but the crypto handler is not been generated yet |
|
206 //it is stream specific crypto but handler is not set yet |
|
207 User::Leave (KErrArgument); |
|
208 return NULL; |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // HBufC8* CSRTPStreamOut::ProtectRtcpL( |
|
213 // |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C HBufC8* CSRTPStreamOut::ProtectRtcpL( const TDesC8& aPacket ) |
|
217 { |
|
218 if (IsContextSet()) |
|
219 return (CurrentRTCPState().DoProtectRtcpL(aPacket)); |
|
220 User::Leave (KErrArgument); |
|
221 return NULL; |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CSRTPStreamOut::InitializeStatesL |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 void CSRTPStreamOut::InitializeStatesL() |
|
229 { |
|
230 iStates.AppendL(TSRTPStreamOutStateUninit(*this, *iHandlerRTP, *iHandlerRTCP), |
|
231 sizeof(TSRTPStreamOutStateUninit)); |
|
232 iStates.AppendL(TSRTPStreamOutStateNormal(*this, *iHandlerRTP, *iHandlerRTCP), |
|
233 sizeof(TSRTPStreamOutStateNormal)); |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // CSRTPStreamOut::~CSRTPStreamOut |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 CSRTPStreamOut::~CSRTPStreamOut( ) |
|
241 { |
|
242 delete iHandlerRTP; |
|
243 delete iHandlerRTCP; |
|
244 if (iStrmSpecificCrypto ) |
|
245 { |
|
246 delete iContext; iContext=NULL; |
|
247 } |
|
248 |
|
249 iStates.Reset(); |
|
250 iHandlerRTP=NULL; |
|
251 iHandlerRTCP=NULL; |
|
252 } |
|
253 |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CSRTPStreamOut::ChangeRTPState |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CSRTPStreamOut::ChangeRTPState(MSRTPStreamOutContext::TContextOutState aNewState) |
|
260 { |
|
261 SRTP_DEBUG_TINT_VALUE( "CSRTPStreamOut::ChangeRTPState to new State", aNewState); |
|
262 |
|
263 iCurrentRTPState = aNewState; |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CSRTPStreamOut::ChangeRTCPState |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 void CSRTPStreamOut::ChangeRTCPState(TContextOutState aNewState) |
|
271 { |
|
272 iCurrentRTCPState = aNewState; |
|
273 } |
|
274 |
|
275 // ---------------------------------------------------------------------------- |
|
276 // CSRTPStreamOut::CurrentRTPState |
|
277 // ---------------------------------------------------------------------------- |
|
278 // |
|
279 TSRTPStreamOutStateBase& CSRTPStreamOut::CurrentRTPState() |
|
280 { |
|
281 SRTP_DEBUG_TINT_VALUE( "CSRTPStreamOut::CurrentRTPState()", iCurrentRTPState); |
|
282 SRTP_DEBUG_TINT_VALUE( "CSRTPStreamOut State count", iStates.Count() ); |
|
283 |
|
284 |
|
285 return iStates.At(iCurrentRTPState); |
|
286 } |
|
287 |
|
288 // ---------------------------------------------------------------------------- |
|
289 // CSRTPStreamOut::CurrentRTCPState |
|
290 // ---------------------------------------------------------------------------- |
|
291 // |
|
292 TSRTPStreamOutStateBase& CSRTPStreamOut::CurrentRTCPState() |
|
293 { |
|
294 SRTP_DEBUG_TINT_VALUE( "CSRTPStreamOut::CurrentRTCPState()", iCurrentRTCPState); |
|
295 SRTP_DEBUG_TINT_VALUE( "CSRTPStreamOut State count", iStates.Count() ); |
|
296 |
|
297 return iStates.At(iCurrentRTCPState); |
|
298 } |