|
1 /* |
|
2 * Copyright (c) 2005 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 #include "mcemessagestream.h" |
|
21 #include "mcecommessagestream.h" |
|
22 #include "mcemanager.h" |
|
23 #include "mcemessagecodec.h" |
|
24 #include "mcecommessagestream.h" |
|
25 #include "mceserial.h" |
|
26 #include "mcemessagecodec.h" |
|
27 #include "mcecommessagestream.h" |
|
28 #include "mceclilogs.h" |
|
29 |
|
30 #define _FLAT_DATA static_cast<CMceComMessageStream*>( iFlatData ) |
|
31 #define FLAT_DATA( data ) (_FLAT_DATA->data) |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CMceAudioStream::NewL |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CMceMessageStream* CMceMessageStream::NewL() |
|
40 { |
|
41 CMceMessageStream* self = CMceMessageStream::NewLC(); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CMceAudioStream::NewLC |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CMceMessageStream* CMceMessageStream::NewLC() |
|
51 { |
|
52 CMceMessageStream* self = new (ELeave) CMceMessageStream(); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CMceMessageStream::~CMceMessageStream |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 EXPORT_C CMceMessageStream::~CMceMessageStream() |
|
63 { |
|
64 iCodecs.ResetAndDestroy(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CMceMessageStream::Codecs |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C const RPointerArray<CMceMessageCodec>& CMceMessageStream::Codecs() |
|
72 { |
|
73 return iCodecs; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CMceMessageStream::AddCodecL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 EXPORT_C void CMceMessageStream::AddCodecL(CMceMessageCodec* aCodec) |
|
81 { |
|
82 __ASSERT_ALWAYS(aCodec, User::Leave(KErrArgument)); |
|
83 iCodecs.AppendL(aCodec); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CMceMessageStream::RemoveCodecL |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C void CMceMessageStream::RemoveCodecL(CMceMessageCodec& aCodec) |
|
91 { |
|
92 RemoveCodecL( aCodec, Binder() ); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CMceMessageStream::ReplaceCodecsL |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 EXPORT_C void CMceMessageStream::ReplaceCodecsL( |
|
100 RPointerArray<CMceMessageCodec>* /*aCodecs*/ ) |
|
101 { |
|
102 User::Leave( KErrNotSupported ); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CMceMessageStream::CMceMessageStream |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 CMceMessageStream::CMceMessageStream() |
|
110 :CMceMediaStream() |
|
111 { |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CMceMessageStream::ConstructL |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CMceMessageStream::ConstructL() |
|
119 { |
|
120 CMceComMessageStream *stream = CMceComMessageStream::NewLC(); |
|
121 CMceMediaStream::ConstructL( stream ); |
|
122 CleanupStack::Pop(stream); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CMceMessageStream::InitializeL |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CMceMessageStream::InitializeL( CMceSession& aParent ) |
|
130 { |
|
131 |
|
132 CMceMediaStream::InitializeL( aParent, 0 ); |
|
133 |
|
134 for( TInt i = 0; i < iCodecs.Count(); i++ ) |
|
135 { |
|
136 iCodecs[i]->InitializeL( *this ); |
|
137 } |
|
138 } |
|
139 |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CMceMessageStream::InitializeL |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 void CMceMessageStream::InitializeL( CMceManager* aManager, CMceSession& aSession ) |
|
146 { |
|
147 |
|
148 __ASSERT_ALWAYS( aManager, User::Leave( KErrArgument ) ); |
|
149 |
|
150 CMceMediaStream::InitializeL( aManager, aSession ); |
|
151 |
|
152 if ( iCodecs.Count() == 0 ) |
|
153 { |
|
154 const RPointerArray<const CMceMessageCodec>& supportedCodes = |
|
155 aManager->SupportedMessageCodecs(); |
|
156 |
|
157 for( TInt i = 0; i < supportedCodes.Count(); i++ ) |
|
158 { |
|
159 CMceMessageCodec* codec = supportedCodes[i]->CloneL(); |
|
160 CleanupStack::PushL( codec ); |
|
161 iCodecs.AppendL( codec ); |
|
162 CleanupStack::Pop( codec ); |
|
163 MCECLI_DEBUG_SVALUE("CMceMessageStream::InitializeL, \ |
|
164 Added supported codec", codec->SdpName() ); |
|
165 } |
|
166 |
|
167 } |
|
168 |
|
169 } |
|
170 |
|
171 |
|
172 void CMceMessageStream::SynchronizeWithFileL( CMceFileSource& /*aFile*/ ) |
|
173 { |
|
174 } |
|
175 |
|
176 CMceCodec* CMceMessageStream::FindCodec( CMceCodec& aCodec ) |
|
177 { |
|
178 const RPointerArray<CMceCodec>& codecs = |
|
179 reinterpret_cast<const RPointerArray<CMceCodec>&>( Codecs() ); |
|
180 return CMceMediaStream::FindCodec( codecs, aCodec ); |
|
181 } |
|
182 |
|
183 void CMceMessageStream::ReorderCodecsByPreferenceL( TBool /*aDiscardUnusedCodecs*/ ) |
|
184 { |
|
185 } |
|
186 |
|
187 const RPointerArray<CMceCodec>& CMceMessageStream::BaseCodecs() |
|
188 { |
|
189 const RPointerArray<CMceCodec>& codecs = |
|
190 reinterpret_cast<const RPointerArray<CMceCodec>&>( Codecs() ); |
|
191 return codecs; |
|
192 } |
|
193 |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CMceMessageStream::RemoveCodecL |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void CMceMessageStream::RemoveCodecL( CMceMessageCodec& aCodec, TBool aBinderOriginated ) |
|
200 { |
|
201 MCECLI_DEBUG_SVALUE( "CMceMessageStream::RemoveCodecL, sdp name:", aCodec.SdpName() ) |
|
202 |
|
203 TBool removed( EFalse ); |
|
204 for(int i = 0; i < iCodecs.Count() && !removed; i++ ) |
|
205 { |
|
206 if( iCodecs[i] == &aCodec || |
|
207 iCodecs[i]->SdpName().CompareF( aCodec.SdpName() ) == 0 ) |
|
208 { |
|
209 MCECLI_DEBUG( "CMceMessageStream::RemoveCodecL, removing" ) |
|
210 |
|
211 TBool commandBound = aBinderOriginated ? ( Binder() ) : ( !Binder() ); |
|
212 if ( BoundStream() && commandBound ) |
|
213 { |
|
214 static_cast<CMceMessageStream*>( |
|
215 iLinkedStream )->RemoveCodecL( aCodec, aBinderOriginated ); |
|
216 } |
|
217 |
|
218 delete iCodecs[i]; |
|
219 iCodecs.Remove( i ); |
|
220 removed = ETrue; |
|
221 } |
|
222 } |
|
223 |
|
224 MCECLI_DEBUG( "CMceMessageStream::RemoveCodecL, Exit" ) |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CMceMessageStream::InternalizeL |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 void CMceMessageStream::InternalizeL( MMceComSerializationContext& aSerCtx ) |
|
232 { |
|
233 CMceMediaStream::InternalizeL( aSerCtx ); |
|
234 |
|
235 TMceMessageStreamSerializer<CMceMessageStream> serial( *this ); |
|
236 serial.InternalizeL( aSerCtx ); |
|
237 |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CMceMessageStream::ExternalizeL |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 void CMceMessageStream::ExternalizeL( MMceComSerializationContext& aSerCtx ) |
|
245 { |
|
246 CMceMediaStream::ExternalizeL( aSerCtx ); |
|
247 |
|
248 TMceMessageStreamSerializer<CMceMessageStream> serial( *this ); |
|
249 serial.ExternalizeL( aSerCtx ); |
|
250 |
|
251 } |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CMceMessageStream::EventReceivedL |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 TInt CMceMessageStream::EventReceivedL( TMceEvent& aEvent ) |
|
261 { |
|
262 |
|
263 TInt status = CMceMediaStream::EventReceivedL( aEvent ); |
|
264 if ( status != KMceEventNotConsumed ) |
|
265 { |
|
266 return status; |
|
267 } |
|
268 |
|
269 //try codecs |
|
270 if ( aEvent.Id().IsCodecId() ) |
|
271 { |
|
272 TInt codecStatus = status; |
|
273 TInt j = 0; |
|
274 while ( codecStatus != KMceEventConsumed && j < iCodecs.Count() ) |
|
275 { |
|
276 CMceMessageCodec* codec = iCodecs[j]; |
|
277 codecStatus = codec->EventReceivedL( aEvent ); |
|
278 if ( codecStatus == KMceEventUpdate ) |
|
279 { |
|
280 MCECLI_DEBUG("CMceMessageStream::EventReceivedL, \ |
|
281 update codec by replacing old version with new one"); |
|
282 CMceMsgObject<CMceMessageCodec>* updateMsg = |
|
283 static_cast<CMceMsgObject<CMceMessageCodec>*>( aEvent.Message() ); |
|
284 CMceMessageCodec* updateCodec = updateMsg->Object(); |
|
285 CleanupStack::PushL( updateCodec ); |
|
286 iCodecs.Remove( j ); |
|
287 delete codec; |
|
288 updateCodec->InitializeL( *this ); |
|
289 iCodecs.AppendL( updateCodec ); |
|
290 CleanupStack::Pop( updateCodec ); |
|
291 updateCodec->Updated(); |
|
292 codecStatus = KMceEventConsumed; |
|
293 } |
|
294 j++; |
|
295 } |
|
296 status = codecStatus == KMceEventNotOwner ? KMceEventNotConsumed : codecStatus; |
|
297 } |
|
298 |
|
299 return status; |
|
300 |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CMceMessageStream::ConnectionSetUpL |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C void CMceMessageStream::ConnectionSetUpL(TConnSetup aSetup) |
|
308 { |
|
309 // create media level setup SDP a-line and add to localmediasdp lines |
|
310 |
|
311 CDesC8Array* LocalMediaSDPLines = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity ); |
|
312 CDesC8Array* CurrMediaSdpLines = FlatData()->iLocalMediaSDPLines; |
|
313 CleanupStack::PushL(LocalMediaSDPLines); |
|
314 // prepare setup adp attribute line |
|
315 _LIT8(KSetupAttr, "a=setup:"); |
|
316 // Retain the current media level attributes and keep adding to these |
|
317 for(TInt i=0; i<CurrMediaSdpLines->MdcaCount(); i++) |
|
318 { |
|
319 if (CurrMediaSdpLines->MdcaPoint(i).Find(KSetupAttr) != KErrNotFound) |
|
320 { |
|
321 User::Leave(KErrAlreadyExists); |
|
322 } |
|
323 LocalMediaSDPLines->AppendL(CurrMediaSdpLines->MdcaPoint(i)); |
|
324 } |
|
325 CleanupStack::Pop(LocalMediaSDPLines); |
|
326 |
|
327 TBuf8<25> setupAttr(KSetupAttr); |
|
328 switch(aSetup) |
|
329 { |
|
330 case CMceMessageStream::EActive: |
|
331 setupAttr.Append(_L8("active\r\n")); |
|
332 break; |
|
333 case CMceMessageStream::EActpass: |
|
334 setupAttr.Append(_L8("actpass\r\n")); |
|
335 break; |
|
336 case CMceMessageStream::EPassive: |
|
337 setupAttr.Append(_L8("passive\r\n")); |
|
338 break; |
|
339 default: User::Leave(KErrNotSupported); |
|
340 } |
|
341 // Append the accepttype attribute line to Media level attribute list |
|
342 LocalMediaSDPLines->AppendL(setupAttr); |
|
343 SetMediaAttributeLinesL(LocalMediaSDPLines ); |
|
344 FLAT_DATA(iConnSetup) = aSetup; |
|
345 } |
|
346 |
|
347 |
|
348 // ----------------------------------------------------------------------------- |
|
349 // CMceMessageStream::GetConnectionSetup |
|
350 // ----------------------------------------------------------------------------- |
|
351 // |
|
352 EXPORT_C CMceMessageStream::TConnSetup CMceMessageStream::GetConnectionSetup() |
|
353 { |
|
354 return FLAT_DATA(iConnSetup); |
|
355 } |
|
356 |
|
357 |
|
358 // ----------------------------------------------------------------------------- |
|
359 // CMceMessageStream::ReuseMsrpConnection |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 void CMceMessageStream::ReuseMsrpConnectionL(TBool aReUse) |
|
363 { |
|
364 __ASSERT_ALWAYS(iFlatData!=NULL, User::Leave(KErrArgument)); |
|
365 FLAT_DATA(iMsrpConnUsage) = aReUse; |
|
366 } |