|
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 |
|
21 #include "mcevideostream.h" |
|
22 #include "mcecomvideostream.h" |
|
23 #include "mcecomvideocodec.h" |
|
24 #include "mcecommediasource.h" |
|
25 #include "mcecommediasink.h" |
|
26 #include "mceserial.h" |
|
27 #include "mceevents.h" |
|
28 #include "cleanupresetanddestroy.h" |
|
29 |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CMceComVideoStream::NewL |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CMceComVideoStream* CMceComVideoStream::NewL() |
|
39 { |
|
40 CMceComVideoStream* self = NewLC(); |
|
41 CleanupStack::Pop( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CMceComVideoStream::NewLC |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CMceComVideoStream* CMceComVideoStream::NewLC() |
|
50 { |
|
51 CMceComVideoStream* self = new (ELeave) CMceComVideoStream(); |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CMceComVideoStream::~CMceComVideoStream |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CMceComVideoStream::~CMceComVideoStream() |
|
63 { |
|
64 iCodecs.ResetAndDestroy(); |
|
65 } |
|
66 |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CMceComVideoStream::CMceComVideoStream |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CMceComVideoStream::CMceComVideoStream() |
|
73 :CMceComMediaStream( KMceVideo ) |
|
74 { |
|
75 } |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CMceComVideoStream::AddCodecL |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CMceComVideoStream::AddCodecL( CMceComCodec* aCodec ) |
|
83 { |
|
84 __ASSERT_ALWAYS( aCodec, User::Leave( KErrArgument ) ); |
|
85 |
|
86 CMceComVideoCodec* codec = static_cast< CMceComVideoCodec* >( aCodec ); |
|
87 iCodecs.AppendL( codec ); |
|
88 } |
|
89 |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CMceComVideoStream::RemoveCodecL |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CMceComVideoStream::RemoveCodecL( CMceComCodec* aCodec ) |
|
96 { |
|
97 TInt index = FindCodecFromList( aCodec ); |
|
98 |
|
99 if ( index >= 0 ) |
|
100 { |
|
101 RemoveCodecFromListL( index ); |
|
102 } |
|
103 |
|
104 delete aCodec; |
|
105 } |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CMceComVideoStream::CodecL |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 CMceComVideoCodec* CMceComVideoStream::CodecL( TInt aIndex ) const |
|
113 { |
|
114 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iCodecs.Count(), |
|
115 User::Leave( KErrArgument ) ); |
|
116 |
|
117 return iCodecs[aIndex]; |
|
118 } |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CMceComVideoStream::CodecCount |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TInt CMceComVideoStream::CodecCount() const |
|
126 { |
|
127 return iCodecs.Count(); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CMceComVideoStream::Codecs |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 const RPointerArray<CMceComVideoCodec>& CMceComVideoStream::Codecs() const |
|
135 { |
|
136 return iCodecs; |
|
137 } |
|
138 |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CMceComVideoStream::FindCodecL |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 CMceComCodec* CMceComVideoStream::FindCodecL( CMceComCodec& aCodec ) |
|
145 { |
|
146 CMceComCodec* foundCodec = NULL; |
|
147 CMceComVideoCodec* codec = static_cast< CMceComVideoCodec* >( &aCodec ); |
|
148 |
|
149 TInt index = FindCodecFromList( codec ); |
|
150 |
|
151 if ( index == KErrNotFound ) |
|
152 { |
|
153 const TInt codecCount = CodecCount(); |
|
154 |
|
155 for ( TInt i = 0; i < codecCount && !foundCodec; ++i ) |
|
156 { |
|
157 // Video codec may be identified also based on fmtp |
|
158 if ( CodecL( i )->Decodes( aCodec.iSdpName, aCodec.FmtpAttr() ) ) |
|
159 { |
|
160 foundCodec = CodecL( i ); |
|
161 } |
|
162 } |
|
163 } |
|
164 else |
|
165 { |
|
166 foundCodec = CodecL( index ); |
|
167 } |
|
168 |
|
169 return foundCodec; |
|
170 } |
|
171 |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CMceComVideoStream::FindCodecFromList |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TInt CMceComVideoStream::FindCodecFromList( CMceComCodec* aCodec ) const |
|
178 { |
|
179 CMceComVideoCodec* codec = static_cast< CMceComVideoCodec* >( aCodec ); |
|
180 return iCodecs.Find( codec ); |
|
181 } |
|
182 |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CMceComVideoStream::RemoveCodecFromListL |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CMceComVideoStream::RemoveCodecFromListL( TInt aIndex ) |
|
189 { |
|
190 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iCodecs.Count(), |
|
191 User::Leave( KErrArgument ) ); |
|
192 |
|
193 iCodecs.Remove( aIndex ); |
|
194 } |
|
195 |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CMceComVideoStream::DestroyCodecs |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CMceComVideoStream::DestroyCodecs() |
|
202 { |
|
203 iCodecs.ResetAndDestroy(); |
|
204 } |
|
205 |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CMceComVideoStream::InternalizeFlatL |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CMceComVideoStream::InternalizeFlatL( RReadStream& aReadStream ) |
|
212 { |
|
213 CMceComMediaStream::InternalizeFlatL( aReadStream ); |
|
214 } |
|
215 |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CMceComVideoStream::ExternalizeFlatL |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CMceComVideoStream::ExternalizeFlatL( RWriteStream& aWriteStream ) |
|
222 { |
|
223 CMceComMediaStream::ExternalizeFlatL( aWriteStream ); |
|
224 } |
|
225 |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CMceComVideoStream::InternalizeL |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 void CMceComVideoStream::InternalizeL( MMceComSerializationContext& aSerCtx ) |
|
232 { |
|
233 CMceComMediaStream::InternalizeL( aSerCtx ); |
|
234 |
|
235 TMceVideoStreamSerializer<CMceComVideoStream> serial( *this ); |
|
236 serial.InternalizeL( aSerCtx ); |
|
237 |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CMceComVideoStream::ExternalizeL |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 void CMceComVideoStream::ExternalizeL( MMceComSerializationContext& aSerCtx ) |
|
245 { |
|
246 |
|
247 CMceComMediaStream::ExternalizeL( aSerCtx ); |
|
248 |
|
249 TMceVideoStreamSerializer<CMceComVideoStream> serial( *this ); |
|
250 serial.ExternalizeL( aSerCtx ); |
|
251 |
|
252 } |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CMceComVideoStream::CloneL |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 CMceComMediaStream* CMceComVideoStream::CloneL() |
|
259 { |
|
260 CMceComVideoStream* copy = new (ELeave) CMceComVideoStream(); |
|
261 CleanupStack::PushL( copy ); |
|
262 copy->ConstructL( *this ); |
|
263 CleanupStack::Pop( copy ); |
|
264 return copy; |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CMceComVideoStream::ConstructL |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 void CMceComVideoStream::ConstructL() |
|
272 { |
|
273 |
|
274 CMceComMediaStream::ConstructL(); |
|
275 |
|
276 } |
|
277 |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CMceComVideoStream::ConstructL |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 void CMceComVideoStream::ConstructL( CMceComVideoStream& aStream ) |
|
284 { |
|
285 CMceComMediaStream::ConstructL( aStream ); |
|
286 |
|
287 const TInt codecCount = aStream.CodecCount(); |
|
288 |
|
289 for ( TInt i = 0; i < codecCount ; ++i ) |
|
290 { |
|
291 CMceComVideoCodec* codec = aStream.CodecL( i )->CloneL(); |
|
292 CleanupStack::PushL( codec ); |
|
293 AddCodecL( codec ); |
|
294 CleanupStack::Pop( codec ); |
|
295 } |
|
296 |
|
297 } |
|
298 |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // CMceComVideoStream::ConstructL |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 void CMceComVideoStream::InitializeL( CMceComSession& aParent ) |
|
305 { |
|
306 CMceComMediaStream::InitializeL( aParent ); |
|
307 |
|
308 const TInt codecCount = CodecCount(); |
|
309 |
|
310 for ( TInt i = 0; i < codecCount ; ++i ) |
|
311 { |
|
312 CodecL( i )->InitializeL( *this ); |
|
313 } |
|
314 } |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CMceComVideoStream::UpdateL |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 void CMceComVideoStream::UpdateL( CMceComMediaStream& aStream ) |
|
324 { |
|
325 CMceComMediaStream::UpdateL( aStream ); |
|
326 |
|
327 CMceComVideoStream* stream = static_cast< CMceComVideoStream* >( &aStream ); |
|
328 |
|
329 RPointerArray<CMceComVideoCodec> updated; |
|
330 |
|
331 MceCleanupResetAndDestroyPushL( updated ); |
|
332 |
|
333 for( TInt i = 0; i < stream->CodecCount() ; ++i ) |
|
334 { |
|
335 CMceComVideoCodec* update = stream->CodecL( i ); |
|
336 TBool isUpdated = EFalse; |
|
337 TInt j = 0; |
|
338 |
|
339 while( !isUpdated && j < CodecCount() ) |
|
340 { |
|
341 CMceComVideoCodec* codec = CodecL( j ); |
|
342 |
|
343 if ( codec->Id() == update->Id() ) |
|
344 { |
|
345 codec->UpdateL( *update ); |
|
346 stream->RemoveCodecFromListL( i ); |
|
347 delete update; |
|
348 updated.AppendL( codec ); |
|
349 RemoveCodecFromListL( j ); |
|
350 i--; |
|
351 isUpdated = ETrue; |
|
352 } |
|
353 j++; |
|
354 } |
|
355 } |
|
356 |
|
357 if ( CodecCount() > 0 ) // Codecs have been removed |
|
358 { |
|
359 Session()->IsStructureChanged() = ETrue; |
|
360 } |
|
361 |
|
362 DestroyCodecs(); |
|
363 |
|
364 while( updated.Count() > 0 ) |
|
365 { |
|
366 AddCodecL( updated[0] ); |
|
367 updated.Remove( 0 ); |
|
368 } |
|
369 |
|
370 CleanupStack::PopAndDestroy(); // updated |
|
371 |
|
372 if ( stream->CodecCount() > 0 ) // Streams have been added |
|
373 { |
|
374 Session()->IsStructureChanged() = ETrue; |
|
375 |
|
376 while( stream->CodecCount() > 0 ) |
|
377 { |
|
378 CMceComVideoCodec* add = stream->CodecL( 0 ); |
|
379 AddCodecL( add ); |
|
380 stream->RemoveCodecFromListL( 0 ); |
|
381 } |
|
382 } |
|
383 |
|
384 } |
|
385 |
|
386 |
|
387 // ----------------------------------------------------------------------------- |
|
388 // CMceComVideoStream::ReorderCodecs |
|
389 // ----------------------------------------------------------------------------- |
|
390 // |
|
391 void CMceComVideoStream::ReorderCodecs() |
|
392 { |
|
393 TLinearOrder<CMceComVideoCodec> order( CMceComVideoCodec::CompareSdpIndex ); |
|
394 |
|
395 iCodecs.Sort( order ); |
|
396 } |
|
397 |
|
398 |
|
399 #ifdef MCE_COMMON_SERVER_SIDE |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CMceComVideoStream::SynchronizeL |
|
403 // ----------------------------------------------------------------------------- |
|
404 // |
|
405 void CMceComVideoStream::SynchronizeL( TBool aRoleAnswerer ) |
|
406 { |
|
407 TInt codecIndex( 0 ); |
|
408 |
|
409 while ( codecIndex < CodecCount() ) |
|
410 { |
|
411 CMceComCodec& codec = *CodecL( codecIndex ); |
|
412 |
|
413 TBool remove( !codec.iIsNegotiated && aRoleAnswerer ); |
|
414 |
|
415 if ( BoundStream() ) |
|
416 { |
|
417 CMceComCodec* sync = BoundStreamL().FindCodecL( codec ); |
|
418 |
|
419 if ( remove ) |
|
420 { |
|
421 BoundStreamL().RemoveCodecL( sync ); |
|
422 } |
|
423 else if ( sync ) |
|
424 { |
|
425 sync->SynchronizeL( codec, aRoleAnswerer ); |
|
426 } |
|
427 else if ( aRoleAnswerer ) |
|
428 { |
|
429 MCE_DEFINE_VIDEO_CODEC( videoCodec, codec ); |
|
430 CMceComVideoCodec* copy = videoCodec.CloneL(); |
|
431 CleanupStack::PushL( copy ); |
|
432 copy->InitializeL( BoundStreamL() ); |
|
433 MCE_VIDEO( BoundStreamL() ).AddCodecL( copy ); |
|
434 CleanupStack::Pop( copy ); |
|
435 copy->SynchronizeL( codec, aRoleAnswerer ); |
|
436 } |
|
437 else |
|
438 { |
|
439 //NOP |
|
440 } |
|
441 } |
|
442 |
|
443 if ( remove ) |
|
444 { |
|
445 RemoveCodecL( &codec ); |
|
446 } |
|
447 else |
|
448 { |
|
449 codecIndex++; |
|
450 } |
|
451 } |
|
452 } |
|
453 |
|
454 // ----------------------------------------------------------------------------- |
|
455 // CMceComAudioStream::UpdateDefaultCodecL |
|
456 // ----------------------------------------------------------------------------- |
|
457 // |
|
458 void CMceComVideoStream::UpdateDefaultCodecL() |
|
459 { |
|
460 CMceComCodec* highestPrioritySendCodec = NULL; |
|
461 CMceComCodec* codec = NULL; |
|
462 |
|
463 const RPointerArray< CMceComCodec >& allCodecs = |
|
464 reinterpret_cast< const RPointerArray< CMceComCodec >& >( Codecs() ); |
|
465 |
|
466 CMceComCodec::TIterator codecs( allCodecs, |
|
467 CMceComCodec::TIterator::EFilterIsNegotiated ); |
|
468 |
|
469 MCE_ITERATOR_FIND_NEXT( codecs, highestPrioritySendCodec, |
|
470 highestPrioritySendCodec->SendSupported() ); |
|
471 |
|
472 // If no negotiated send codecs, disable all. |
|
473 // If send codec changed, enable new one and disable other send codecs. |
|
474 if ( !highestPrioritySendCodec || |
|
475 ( highestPrioritySendCodec && |
|
476 !highestPrioritySendCodec->iIsEnabled ) ) |
|
477 { |
|
478 CMceComCodec* newDefaultCodec = NULL; |
|
479 codecs.Reset(); |
|
480 codecs.SetFilter( CMceComCodec::TIterator::EFilterNone ); |
|
481 while( codecs.Next( codec ) ) |
|
482 { |
|
483 if ( !newDefaultCodec && codec->iIsNegotiated && codec->SendSupported() ) |
|
484 { |
|
485 codec->SetEnabled( ETrue ); |
|
486 newDefaultCodec = codec; |
|
487 } |
|
488 else |
|
489 { |
|
490 codec->SetEnabled( EFalse ); |
|
491 } |
|
492 } |
|
493 |
|
494 // Enable also new codecs of associated local streams |
|
495 UpdateDefaultCodecForAssociatedLocalL( newDefaultCodec ); |
|
496 } |
|
497 } |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // CMceComVideoStream::UpdateDefaultCodecForAssociatedLocalL |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 void CMceComVideoStream::UpdateDefaultCodecForAssociatedLocalL( |
|
504 CMceComCodec* aNewDefaultCodec ) |
|
505 { |
|
506 CMceComCodec* codec = NULL; |
|
507 if ( aNewDefaultCodec && Session() ) |
|
508 { |
|
509 for ( TInt i = 0; i < Session()->Streams().Count(); i++ ) |
|
510 { |
|
511 if ( Session()->Streams()[ i ]->iType == KMceVideo ) |
|
512 { |
|
513 CMceComVideoStream* videoStream = static_cast<CMceComVideoStream*>( |
|
514 Session()->Streams()[ i ] ); |
|
515 const RPointerArray< CMceComCodec >& allCodecs = |
|
516 reinterpret_cast< const RPointerArray< CMceComCodec >& >( |
|
517 videoStream->Codecs() ); |
|
518 |
|
519 // Enabling |
|
520 CMceComCodec::TIterator codecs( allCodecs, |
|
521 CMceComCodec::TIterator::EFilterAssociatedLocal, aNewDefaultCodec ); |
|
522 while( codecs.Next( codec ) ) |
|
523 { |
|
524 codec->SetEnabled( ETrue ); |
|
525 } |
|
526 |
|
527 // Disabling |
|
528 codecs.Reset(); |
|
529 while( codecs.Next( codec, CMceComCodec::TIterator::EOtherSdpName ) ) |
|
530 { |
|
531 codec->SetEnabled( EFalse ); |
|
532 } |
|
533 } |
|
534 } |
|
535 } |
|
536 } |
|
537 |
|
538 // ----------------------------------------------------------------------------- |
|
539 // CMceComVideoStream::PrepareL |
|
540 // ----------------------------------------------------------------------------- |
|
541 // |
|
542 void CMceComVideoStream::PrepareL() |
|
543 { |
|
544 __ASSERT_ALWAYS ( CodecCount() > 0, User::Leave( KErrArgument ) ); |
|
545 |
|
546 if ( BoundStream() ) |
|
547 { |
|
548 MCE_DEFINE_VIDEO( boundStream, BoundStreamL() ); |
|
549 __ASSERT_ALWAYS ( boundStream.CodecCount() > 0, User::Leave( KErrArgument ) ); |
|
550 } |
|
551 } |
|
552 |
|
553 |
|
554 |
|
555 // ----------------------------------------------------------------------------- |
|
556 // CMceComVideoStream::MccStreamType |
|
557 // ----------------------------------------------------------------------------- |
|
558 // |
|
559 TInt CMceComVideoStream::MccStreamType() const |
|
560 { |
|
561 |
|
562 TInt type = KMccVideoLocalStream; |
|
563 |
|
564 if ( iStreamType == EReceiveStream || |
|
565 iStreamType == EReceiveOnlyStream ) |
|
566 { |
|
567 type = KMccVideoDownlinkStream; |
|
568 } |
|
569 else if ( iStreamType == ESendStream || |
|
570 iStreamType == ESendOnlyStream ) |
|
571 { |
|
572 type = KMccVideoUplinkStream; |
|
573 } |
|
574 else |
|
575 { |
|
576 type = KMccVideoLocalStream; |
|
577 } |
|
578 |
|
579 return type; |
|
580 |
|
581 } |
|
582 |
|
583 |
|
584 // ----------------------------------------------------------------------------- |
|
585 // CMceComVideoStream::MccStreamType |
|
586 // ----------------------------------------------------------------------------- |
|
587 // |
|
588 TInt CMceComVideoStream::MccLinkType() const |
|
589 { |
|
590 TInt type = KMccLinkGeneralVideo; |
|
591 |
|
592 if ( iStreamType == ELocalStream ) |
|
593 { |
|
594 type = KMccLinkLocal; |
|
595 } |
|
596 |
|
597 if (iSession->iClientCryptoSuites.Count()>0) |
|
598 { |
|
599 type =KMccLinkSecureVideo; |
|
600 } |
|
601 |
|
602 return type; |
|
603 } |
|
604 |
|
605 #endif//MCE_COMMON_SERVER_SIDE |