mmsharing/mmshengine/src/musengmceutils.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
    49     return ( aStream.Type() == KMceVideo &&
    49     return ( aStream.Type() == KMceVideo &&
    50              aStream.Source() && 
    50              aStream.Source() && 
    51              aStream.Source()->Type() == KMceRTPSource );
    51              aStream.Source()->Type() == KMceRTPSource );
    52     }
    52     }
    53 
    53 
    54 // -----------------------------------------------------------------------------
       
    55 // Tells if parameter stream is a video stream with RTP sink
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 TBool MusEngMceUtils::IsVideoOutStream( CMceMediaStream& aStream )
       
    59     {
       
    60     TBool isOutStream( EFalse );
       
    61     if ( aStream.Type() == KMceVideo )
       
    62         {
       
    63         CMceMediaSink* rtpSink = MusEngMceUtils::GetMediaSink(
       
    64                                                    aStream,
       
    65                                                    KMceRTPSink );
       
    66         
       
    67         isOutStream = ( rtpSink != NULL );
       
    68         }
       
    69     return isOutStream;
       
    70     }
       
    71 
    54 
    72 // -----------------------------------------------------------------------------
    55 // -----------------------------------------------------------------------------
    73 // Tells if parameter stream is an audio stream with RTP source
    56 // Tells if parameter stream is an audio stream with RTP source
    74 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    75 //
    58 //
    93 
    76 
    94     CMceVideoStream* videoOut = NULL;
    77     CMceVideoStream* videoOut = NULL;
    95 
    78 
    96     for ( TInt i = 0; i < streams.Count(); ++i )
    79     for ( TInt i = 0; i < streams.Count(); ++i )
    97         {
    80         {
    98         if ( MusEngMceUtils::IsVideoOutStream( *streams[i] ) )      
    81         if ( streams[i]->Type() == KMceVideo )
    99             {
    82             {
   100             __ASSERT_ALWAYS( !videoOut, User::Leave( KErrOverflow ) );
    83             CMceMediaSink* rtpSink = MusEngMceUtils::GetMediaSink(
       
    84                                             *streams[i],
       
    85                                             KMceRTPSink );
       
    86             if ( rtpSink )
       
    87                 {
       
    88                 __ASSERT_ALWAYS( !videoOut, User::Leave( KErrOverflow ) );
       
    89 
       
    90                 videoOut = static_cast<CMceVideoStream*>( streams[i] );
       
    91                 }
   101             
    92             
   102             videoOut = static_cast<CMceVideoStream*>( streams[i] );
    93             // There is no need to investigate bound stream since
   103             }
    94             // outstream is always constructed by Mus instead of MCE
   104             
    95             }
   105             // Check if bound stream is a video stream with RTP sink.
       
   106         if ( streams[i]->BoundStream() &&
       
   107              MusEngMceUtils::IsVideoOutStream( streams[i]->BoundStreamL() ) )
       
   108             {
       
   109             __ASSERT_ALWAYS( !videoOut, User::Leave( KErrOverflow ) );
       
   110             
       
   111             videoOut = static_cast<CMceVideoStream*>( 
       
   112                                    &streams[i]->BoundStreamL() );
       
   113             }   
       
   114         }
    96         }
   115 
    97 
   116     __ASSERT_ALWAYS( videoOut, User::Leave( KErrNotFound ) );
    98     __ASSERT_ALWAYS( videoOut, User::Leave( KErrNotFound ) );
   117 
    99 
   118     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::GetVideoOutStreamL()" )
   100     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::GetVideoOutStreamL()" )
   194 // -----------------------------------------------------------------------------
   176 // -----------------------------------------------------------------------------
   195 // Gets handle to a media sink of spesified type contained by a mediastream.
   177 // Gets handle to a media sink of spesified type contained by a mediastream.
   196 // -----------------------------------------------------------------------------
   178 // -----------------------------------------------------------------------------
   197 //
   179 //
   198 CMceMediaSink* MusEngMceUtils::GetMediaSink( CMceMediaStream& aStream,
   180 CMceMediaSink* MusEngMceUtils::GetMediaSink( CMceMediaStream& aStream,
   199                                              TMceSinkType aType,
   181                                              TMceSinkType aType )
   200                                              TMceSourceType aAssociatedSourceType )
       
   201     {
   182     {
   202     const RPointerArray<CMceMediaSink>& sinks = aStream.Sinks();
   183     const RPointerArray<CMceMediaSink>& sinks = aStream.Sinks();
   203     for ( TInt i = 0; i < sinks.Count(); ++i )
   184     for ( TInt i = 0; i < sinks.Count(); ++i )
   204         {
   185         {
   205         if ( sinks[i]->Type() == aType && 
   186         if ( sinks[i]->Type() == aType )
   206            ( aAssociatedSourceType == KMusEngNoAssociatedSourceType || 
       
   207              aStream.Source()->Type() == aAssociatedSourceType ) )
       
   208             {
   187             {
   209             return sinks[i];
   188             return sinks[i];
   210             }
   189             }
   211         }
   190         }
   212         
   191         
   217 // -----------------------------------------------------------------------------
   196 // -----------------------------------------------------------------------------
   218 // Gets handle to a media sink of spesified type contained by a mediastream.
   197 // Gets handle to a media sink of spesified type contained by a mediastream.
   219 // -----------------------------------------------------------------------------
   198 // -----------------------------------------------------------------------------
   220 //
   199 //
   221 CMceMediaSink* MusEngMceUtils::GetMediaSinkL( CMceMediaStream& aStream,
   200 CMceMediaSink* MusEngMceUtils::GetMediaSinkL( CMceMediaStream& aStream,
   222                                               TMceSinkType aType,
   201                                               TMceSinkType aType )
   223                                               TMceSourceType aAssociatedSourceType )
   202     {
   224     {
   203 
   225 
   204     CMceMediaSink* sink = MusEngMceUtils::GetMediaSink( aStream, aType );
   226     CMceMediaSink* sink = MusEngMceUtils::GetMediaSink( aStream, aType, aAssociatedSourceType );
       
   227 
   205 
   228     __ASSERT_ALWAYS( sink, User::Leave( KErrNotFound ) );
   206     __ASSERT_ALWAYS( sink, User::Leave( KErrNotFound ) );
   229 
   207 
   230     return sink;
   208     return sink;
   231     }
   209     }
   234 // -----------------------------------------------------------------------------
   212 // -----------------------------------------------------------------------------
   235 // Gets handle to a media sink of spesified type contained by a session.
   213 // Gets handle to a media sink of spesified type contained by a session.
   236 // -----------------------------------------------------------------------------
   214 // -----------------------------------------------------------------------------
   237 //
   215 //
   238 CMceMediaSink* MusEngMceUtils::GetMediaSink( CMceSession& aSession,
   216 CMceMediaSink* MusEngMceUtils::GetMediaSink( CMceSession& aSession,
   239                                              TMceSinkType aType,
   217                                              TMceSinkType aType )
   240                                              TMceSourceType aAssociatedSourceType,
       
   241                                              TBool aStrictMatch )
       
   242     {
   218     {
   243     CMceMediaSink* sink = NULL;
   219     CMceMediaSink* sink = NULL;
   244 
   220 
   245     TRAP_IGNORE( sink = MusEngMceUtils::GetMediaSinkL( 
   221     TRAP_IGNORE( sink = MusEngMceUtils::GetMediaSinkL( aSession, aType ) )
   246             aSession, aType, aAssociatedSourceType, aStrictMatch ) )
       
   247 
   222 
   248     return sink;
   223     return sink;
   249     }
   224     }
   250 
   225 
   251 
   226 
   252 // -----------------------------------------------------------------------------
   227 // -----------------------------------------------------------------------------
   253 // Gets handle to a media sink of spesified type contained by a session.
   228 // Gets handle to a media sink of spesified type contained by a session.
   254 // -----------------------------------------------------------------------------
   229 // -----------------------------------------------------------------------------
   255 //
   230 //
   256 CMceMediaSink* MusEngMceUtils::GetMediaSinkL( CMceSession& aSession,
   231 CMceMediaSink* MusEngMceUtils::GetMediaSinkL( CMceSession& aSession,
   257                                               TMceSinkType aType,
   232                                               TMceSinkType aType )
   258                                               TMceSourceType aAssociatedSourceType,
       
   259                                               TBool aStrictMatch )
       
   260     {
   233     {
   261     CMceMediaSink* sink = NULL;
   234     CMceMediaSink* sink = NULL;
   262     
   235     
   263     const RPointerArray<CMceMediaStream>& streams = aSession.Streams();
   236     const RPointerArray<CMceMediaStream>& streams = aSession.Streams();
   264 
   237 
   265     for ( TInt i = 0; i < streams.Count(); ++i )
   238     for ( TInt i = 0; i < streams.Count(); ++i )
   266         {
   239         {
   267         sink = MusEngMceUtils::GetMediaSink( *streams[i], aType, aAssociatedSourceType );
   240         sink = MusEngMceUtils::GetMediaSink( *streams[i], aType );
   268         if ( sink )
   241         if ( sink )
   269             {
   242             {
   270             return sink;
   243             return sink;
   271             }
   244             }
   272         
   245         
   273         if ( streams[i]->BoundStream() )
   246         if ( streams[i]->BoundStream() )
   274             {
   247             {
   275             sink = MusEngMceUtils::GetMediaSink( streams[i]->BoundStreamL(), 
   248             sink = MusEngMceUtils::GetMediaSink( streams[i]->BoundStreamL(), 
   276                                                  aType,
   249                                                  aType );
   277                                                  aAssociatedSourceType );
       
   278             if ( sink )
   250             if ( sink )
   279                 {
   251                 {
   280                 return sink;
   252                 return sink;
   281                 }
   253                 }
   282             }
   254             }
   283         }
       
   284     
       
   285     if ( !sink && aAssociatedSourceType != KMusEngNoAssociatedSourceType && !aStrictMatch )
       
   286         {
       
   287         // No preferred match, try without source preference
       
   288         sink = GetMediaSinkL( aSession, aType );
       
   289         }
   255         }
   290 
   256 
   291     __ASSERT_ALWAYS( sink, User::Leave( KErrNotFound ) );
   257     __ASSERT_ALWAYS( sink, User::Leave( KErrNotFound ) );
   292 
   258 
   293     return sink;
   259     return sink;
   374 
   340 
   375 // -----------------------------------------------------------------------------
   341 // -----------------------------------------------------------------------------
   376 // Gets handle to a display sink.
   342 // Gets handle to a display sink.
   377 // -----------------------------------------------------------------------------
   343 // -----------------------------------------------------------------------------
   378 //
   344 //
   379 CMceDisplaySink* MusEngMceUtils::GetDisplay( 
   345 CMceDisplaySink* MusEngMceUtils::GetDisplay( CMceSession& aSession )
   380     CMceSession& aSession, TBool aPreferViewFinder  )
       
   381     {
   346     {
   382     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::GetDisplay()" )
   347     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::GetDisplay()" )
   383     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::GetDisplay()" )
   348     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::GetDisplay()" )
   384     TMceSourceType preferredSource = 
       
   385         aPreferViewFinder ? KMceCameraSource : KMusEngNoAssociatedSourceType;
       
   386     return static_cast<CMceDisplaySink*>(
   349     return static_cast<CMceDisplaySink*>(
   387             MusEngMceUtils::GetMediaSink( aSession, KMceDisplaySink, preferredSource ) );
   350             MusEngMceUtils::GetMediaSink( aSession, KMceDisplaySink ) );
   388 
   351 
   389     }
   352     }
   390 
   353 
   391 
   354 
   392 // -----------------------------------------------------------------------------
   355 // -----------------------------------------------------------------------------
   393 // Gets handle to a display sink.
   356 // Gets handle to a display sink.
   394 // -----------------------------------------------------------------------------
   357 // -----------------------------------------------------------------------------
   395 //
   358 //
   396 CMceDisplaySink* MusEngMceUtils::GetDisplayL( 
   359 CMceDisplaySink* MusEngMceUtils::GetDisplayL( CMceSession& aSession )
   397     CMceSession& aSession, TBool aPreferViewFinder )
       
   398     {
   360     {
   399     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::GetDisplayL()" )
   361     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::GetDisplayL()" )
   400 
   362 
   401     CMceDisplaySink* display = MusEngMceUtils::GetDisplay( aSession, aPreferViewFinder );
   363     CMceDisplaySink* display = MusEngMceUtils::GetDisplay( aSession );
   402 
   364 
   403     __ASSERT_ALWAYS( display, User::Leave( KErrNotFound ) );
   365     __ASSERT_ALWAYS( display, User::Leave( KErrNotFound ) );
   404 
   366 
   405     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::GetDisplayL()" )
   367     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::GetDisplayL()" )
   406     return display;
   368     return display;
   407     }
   369     }
   408 
   370 
   409 // -----------------------------------------------------------------------------
       
   410 // Gets handle to a display sink displaying received video.
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 CMceDisplaySink* MusEngMceUtils::GetReceivingDisplay( CMceSession& aSession )
       
   414     {
       
   415     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::GetReceivingDisplay()" )
       
   416     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::GetReceivingDisplay()" )
       
   417     
       
   418     // Search display which is connected with rtp source
       
   419     TMceSourceType preferredSource = KMceRTPSource;
       
   420     return static_cast<CMceDisplaySink*>( MusEngMceUtils::GetMediaSink( 
       
   421                 aSession, KMceDisplaySink, preferredSource, ETrue ) );
       
   422     }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // Gets handle to a display sink displaying received video.
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 CMceDisplaySink* MusEngMceUtils::GetReceivingDisplayL( CMceSession& aSession )
       
   429     {
       
   430     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::GetReceivingDisplayL()" )
       
   431 
       
   432     CMceDisplaySink* display = GetReceivingDisplay( aSession );
       
   433     __ASSERT_ALWAYS( display != NULL, User::Leave( KErrNotFound ) );
       
   434     
       
   435     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::GetReceivingDisplay()" )
       
   436     
       
   437     return display;
       
   438     }
       
   439 
       
   440 // -----------------------------------------------------------------------------
       
   441 // Gets handle to a display sink displaying viewfinder content.
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 CMceDisplaySink* MusEngMceUtils::GetVfDisplay( CMceSession& aSession )
       
   445     {
       
   446     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::GetVfDisplay()" )
       
   447     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::GetVfDisplay()" )
       
   448     
       
   449     // Search display which is connected with camera
       
   450     TMceSourceType preferredSource = KMceCameraSource;
       
   451     return static_cast<CMceDisplaySink*>( MusEngMceUtils::GetMediaSink( 
       
   452                 aSession, KMceDisplaySink, preferredSource, ETrue ) );
       
   453     }
       
   454 
   371 
   455 // -----------------------------------------------------------------------------
   372 // -----------------------------------------------------------------------------
   456 // Adds display sink to specified stream if one does not exist already.
   373 // Adds display sink to specified stream if one does not exist already.
   457 // Display rect is set in both cases.
   374 // Display rect is set in both cases.
   458 // -----------------------------------------------------------------------------
   375 // -----------------------------------------------------------------------------
   459 //
   376 //
   460 void MusEngMceUtils::AddDisplayL( CMceMediaStream& aStream, 
   377 void MusEngMceUtils::AddDisplayL( CMceMediaStream& aStream, 
   461                                   CMceManager& aManager,
   378                                   CMceManager& aManager,
   462                                   const TRect& aDisplayRect,
   379                                   const TRect& aDisplayRect )
   463                                   TBool aDisabled )
       
   464     {
   380     {
   465     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::AddDisplayL()" )
   381     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::AddDisplayL()" )
   466     
   382     
   467     __ASSERT_ALWAYS( aStream.Type() == KMceVideo, User::Leave( KErrArgument ) );
   383     __ASSERT_ALWAYS( aStream.Type() == KMceVideo, User::Leave( KErrArgument ) );
   468 
   384 
   476         display = CMceDisplaySink::NewLC( aManager );
   392         display = CMceDisplaySink::NewLC( aManager );
   477         aStream.AddSinkL( display );
   393         aStream.AddSinkL( display );
   478         CleanupStack::Pop( display );
   394         CleanupStack::Pop( display );
   479         }
   395         }
   480 
   396 
   481     if ( aDisabled )
       
   482         {
       
   483         MUS_LOG( "mus: [ENGINE]     Initially disabled display" )
       
   484         display->DisableL();
       
   485         }
       
   486     display->SetDisplayRectL( aDisplayRect );
   397     display->SetDisplayRectL( aDisplayRect );
   487     
   398     
   488     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::AddDisplayL()" )
   399     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::AddDisplayL()" )
   489     }
   400     }
   490 
   401 
   536         }
   447         }
   537         
   448         
   538     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::DisableStreamL()" )
   449     MUS_LOG( "mus: [ENGINE]  -> MusEngMceUtils::DisableStreamL()" )
   539     }
   450     }
   540 
   451 
   541 // -----------------------------------------------------------------------------
   452 
   542 // 
   453 
   543 // -----------------------------------------------------------------------------
   454 
   544 //
   455 
   545 void MusEngMceUtils::DoEnableDisplayL( CMceDisplaySink& aDisplay, TBool aEnable )
   456 
   546     {
   457 
   547     MUS_LOG1( "mus: [ENGINE]     -> MusEngMceUtils::DoEnableDisplayL() %d", 
       
   548               aEnable )
       
   549     
       
   550     if ( aEnable )
       
   551         {
       
   552         if ( !aDisplay.IsEnabled() )
       
   553             {
       
   554             aDisplay.EnableL();
       
   555             MUS_LOG( "                  Display enabled" )
       
   556             }
       
   557         else
       
   558             {
       
   559             MUS_LOG( "                  Display already enabled, ignore" )
       
   560             }
       
   561         }
       
   562     else
       
   563         {
       
   564         if ( aDisplay.IsEnabled() )
       
   565             {
       
   566             aDisplay.DisableL();
       
   567             MUS_LOG( "                  Display disabled" )
       
   568             }
       
   569         else
       
   570             {
       
   571             MUS_LOG( "                  Display already disabled, ignore" )
       
   572             }
       
   573         }  
       
   574         
       
   575     MUS_LOG( "mus: [ENGINE]  <- MusEngMceUtils::DoEnableDisplayL()")
       
   576     }
       
   577 
       
   578 // -----------------------------------------------------------------------------
       
   579 // 
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 TInt MusEngMceUtils::EnableInactivityTimer( 
       
   583     CMceSession& aSession, 
       
   584     TUint32 aInactivityTimeout )
       
   585     {
       
   586     TInt err( KErrNotFound );
       
   587     CMceVideoStream* stream = NULL;
       
   588     TRAP_IGNORE( stream = MusEngMceUtils::GetVideoInStreamL( aSession ) )
       
   589     if ( stream )
       
   590         {
       
   591         // Instream has always RTP source
       
   592         err = KErrNone;
       
   593         CMceRtpSource* rtpSource = static_cast<CMceRtpSource*>( stream->Source() );
       
   594         TRAP( err, rtpSource->EnableInactivityTimerL( aInactivityTimeout ) ) 
       
   595         }
       
   596     
       
   597     return err;
       
   598     }
       
   599       
       
   600 // End of file