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 #include "mcemediastream.h" |
|
20 #include "mcesession.h" |
|
21 #include "mcemanager.h" |
|
22 #include "mcestreamobserver.h" |
|
23 #include "mcemediasource.h" |
|
24 #include "mcemediasink.h" |
|
25 |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CMceMediaStream::~CMceMediaStream |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C CMceMediaStream::~CMceMediaStream() |
|
36 { |
|
37 delete iMediaSDPLines; |
|
38 |
|
39 if ( iSource ) |
|
40 { |
|
41 DeleteSource(); |
|
42 } |
|
43 |
|
44 if ( iLinkOwner ) |
|
45 { |
|
46 delete iLinkedStream; |
|
47 } |
|
48 |
|
49 while( iSinks.Count() > 0 ) |
|
50 { |
|
51 DeleteSink( 0 ); |
|
52 } |
|
53 |
|
54 iSinks.Reset(); |
|
55 iSinks.Close(); |
|
56 |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C CMceMediaStream::TState CMceMediaStream::State() const |
|
64 { |
|
65 return iState; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CMceMediaStream::Type |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 EXPORT_C TMceMediaType CMceMediaStream::Type() const |
|
73 { |
|
74 return iType; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C void CMceMediaStream::SetMediaAttributeLinesL( |
|
82 CDesC8Array* aMediaSDPLines ) |
|
83 { |
|
84 delete iMediaSDPLines; |
|
85 iMediaSDPLines = aMediaSDPLines; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C MDesC8Array* CMceMediaStream::MediaAttributeLinesL() |
|
93 { |
|
94 if ( iMediaSDPLines ) |
|
95 { |
|
96 CDesC8Array* array = new ( ELeave ) CDesC8ArrayFlat( 1 ); |
|
97 CleanupStack::PushL( array ); |
|
98 for ( TInt i = 0; i < iMediaSDPLines->Count(); ++i ) |
|
99 { |
|
100 array->AppendL( iMediaSDPLines->MdcaPoint(i) ); |
|
101 } |
|
102 CleanupStack::Pop( array ); |
|
103 return array; |
|
104 } |
|
105 |
|
106 return NULL; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CMceMediaStream::SetStartMediaPort |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C void CMceMediaStream::SetLocalMediaPortL( TUint aLocalMediaPort ) |
|
114 { |
|
115 iLocalMediaPort = aLocalMediaPort; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CMceMediaStream::StartMediaPort |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C TUint CMceMediaStream::LocalMediaPort() const |
|
123 { |
|
124 return iLocalMediaPort; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CMceMediaStream::Session |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C CMceSession* CMceMediaStream::Session() const |
|
132 { |
|
133 return iSession; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CMceMediaStream::EnableL |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 EXPORT_C void CMceMediaStream::EnableL() |
|
141 { |
|
142 iIsEnabled = ETrue; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CMceMediaStream::DisableL |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C void CMceMediaStream::DisableL() |
|
150 { |
|
151 iIsEnabled = EFalse; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CMceMediaStream::IsEnabled |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C TBool CMceMediaStream::IsEnabled() const |
|
159 { |
|
160 return iIsEnabled; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CMceMediaStream::SetSourceL |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C void CMceMediaStream::SetSourceL( CMceMediaSource* aSource ) |
|
168 { |
|
169 if ( aSource ) |
|
170 { |
|
171 aSource->ReferenceCount()++; |
|
172 } |
|
173 |
|
174 if ( iSource ) |
|
175 { |
|
176 DeleteSource(); |
|
177 } |
|
178 iSource = aSource; |
|
179 |
|
180 } |
|
181 |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CMceMediaStream::AddSinkL |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 EXPORT_C void CMceMediaStream::AddSinkL( CMceMediaSink* aSink ) |
|
188 { |
|
189 __ASSERT_ALWAYS( aSink, User::Leave( KErrArgument ) ); |
|
190 iSinks.AppendL( aSink ); |
|
191 aSink->ReferenceCount()++; |
|
192 } |
|
193 |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CMceMediaStream::Source |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 EXPORT_C CMceMediaSource* CMceMediaStream::Source() const |
|
200 { |
|
201 return iSource; |
|
202 } |
|
203 |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CMceMediaStream::Sinks |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 EXPORT_C const RPointerArray<CMceMediaSink>& CMceMediaStream::Sinks() const |
|
210 { |
|
211 return iSinks; |
|
212 } |
|
213 |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CMceMediaStream::RemoveSinkL |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 EXPORT_C void CMceMediaStream::RemoveSinkL( CMceMediaSink& aSink ) |
|
220 { |
|
221 for ( TInt i = 0; i < iSinks.Count(); i++ ) |
|
222 { |
|
223 if ( iSinks[i] == &aSink ) |
|
224 { |
|
225 DeleteSink( i ); |
|
226 iSinks.Compress(); |
|
227 return; |
|
228 } |
|
229 } |
|
230 User::Leave( KErrNotFound ); |
|
231 } |
|
232 |
|
233 |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CMceMediaStream::BindL |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 EXPORT_C void CMceMediaStream::BindL( CMceMediaStream* aStream ) |
|
240 { |
|
241 |
|
242 __ASSERT_ALWAYS( !(! iLinkOwner && |
|
243 iLinkedStream ), |
|
244 User::Leave( KErrArgument ) ); |
|
245 |
|
246 if ( aStream ) |
|
247 { |
|
248 iLinkOwner = ETrue; |
|
249 aStream->DoBindL( this ); |
|
250 DoBindL( aStream ); |
|
251 } |
|
252 else |
|
253 { |
|
254 iLinkOwner = EFalse; |
|
255 delete iLinkedStream; |
|
256 iLinkedStream = NULL; |
|
257 } |
|
258 |
|
259 } |
|
260 |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CMceMediaStream::BoundStreamL |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 EXPORT_C CMceMediaStream& CMceMediaStream::BoundStreamL() const |
|
267 { |
|
268 __ASSERT_ALWAYS( iLinkedStream , User::Leave( KErrNotFound ) ); |
|
269 |
|
270 return *iLinkedStream; |
|
271 |
|
272 } |
|
273 |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CMceMediaStream::BoundStream |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 EXPORT_C TBool CMceMediaStream::BoundStream() const |
|
280 { |
|
281 return iLinkedStream != NULL; |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CMceMediaStream::Binder |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 TBool CMceMediaStream::Binder() const |
|
289 { |
|
290 return iLinkOwner; |
|
291 } |
|
292 |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CMceMediaStream::InitializeL |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CMceMediaStream::InitializeL( CMceSession& aParent ) |
|
299 { |
|
300 iSession = &aParent; |
|
301 |
|
302 if ( Binder() && BoundStream() ) |
|
303 { |
|
304 iLinkedStream->InitializeL( aParent ); |
|
305 } |
|
306 |
|
307 if ( iSource ) |
|
308 { |
|
309 iSource->InitializeL( *this ); |
|
310 } |
|
311 |
|
312 for( TInt i = 0; i < iSinks.Count();i++) |
|
313 { |
|
314 iSinks[i]->InitializeL( *this ); |
|
315 } |
|
316 |
|
317 } |
|
318 |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CMceMediaStream::InitializeL |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 void CMceMediaStream::InitializeL( CMceManager* aManager ) |
|
325 { |
|
326 if ( Binder() && BoundStream() ) |
|
327 { |
|
328 iLinkedStream->InitializeL( aManager ); |
|
329 } |
|
330 |
|
331 if ( iSource ) |
|
332 { |
|
333 iSource->InitializeL( aManager ); |
|
334 } |
|
335 |
|
336 for( TInt i = 0; i < iSinks.Count();i++) |
|
337 { |
|
338 iSinks[i]->InitializeL( aManager ); |
|
339 } |
|
340 } |
|
341 |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CMceMediaStream::CMceMediaStream |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 CMceMediaStream::CMceMediaStream() |
|
348 :iLinkedStream( NULL ), |
|
349 iSource( NULL ), |
|
350 iLinkOwner( EFalse ), |
|
351 iIsEnabled( ETrue ), |
|
352 iState( CMceMediaStream::EUninitialized ) |
|
353 { |
|
354 } |
|
355 |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CMceMediaStream::DeleteSink |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 void CMceMediaStream::DeleteSink( TInt aIndex ) |
|
362 { |
|
363 |
|
364 iSinks[ aIndex ]->ReferenceCount()--; |
|
365 if ( iSinks[ aIndex ]->ReferenceCount() == 0 ) |
|
366 { |
|
367 delete iSinks[ aIndex ]; |
|
368 } |
|
369 iSinks.Remove( aIndex ); |
|
370 |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CMceMediaStream::DeleteSource |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 void CMceMediaStream::DeleteSource() |
|
378 { |
|
379 iSource->ReferenceCount()--; |
|
380 if ( iSource->ReferenceCount() == 0 ) |
|
381 { |
|
382 delete iSource; |
|
383 } |
|
384 iSource = NULL; |
|
385 } |
|
386 |
|
387 |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // CMceMediaStream::DoBindL |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 void CMceMediaStream::DoBindL( CMceMediaStream* aStream ) |
|
394 { |
|
395 if ( Session() ) |
|
396 { |
|
397 aStream->InitializeL( *Session() ); |
|
398 } |
|
399 delete iLinkedStream; |
|
400 iLinkedStream = aStream; |
|
401 } |
|