multimediacommscontroller/mmccsubcontroller/src/mccsymstreambase.cpp
changeset 0 1bce908db942
child 49 64c62431ac08
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004-2008 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:    Mcc Symmetric subthread stream baseclass
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <mmf/server/sounddevice.h>
       
    22 #include "mccsymstreambase.h"
       
    23 #include "mccdatapathbase.h"
       
    24 #include "mccinternaldef.h"
       
    25 #include "mccsubcontrollerlogs.h"
       
    26 #include "mccsymsubthreadclient.h"
       
    27 #include "mccinternalevents.h"
       
    28 #include "mmccevents.h"
       
    29 #include "mccresources.h"
       
    30 #include "mccmultiplexer.h"
       
    31 #include "mccrtpdatasink.h"
       
    32 #include "mccrtpdatasource.h"
       
    33 #include "mmccinterface.h"
       
    34 
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CMccSymStreamBase::CMccSymStreamBase
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CMccSymStreamBase::CMccSymStreamBase( 
       
    45     TUint32 aMccStreamId, 
       
    46     MAsyncEventHandler* aEventhandler, 
       
    47     MMccResources* aMccResources,
       
    48     CMccRtpManager* aManager, 
       
    49     TInt aStreamType ) : 
       
    50     iDatapath( NULL ), 
       
    51     iEventhandler( aEventhandler ), 
       
    52     iMccResources( aMccResources ),
       
    53     iDatasink( NULL ), 
       
    54     iDatasource( NULL ), 
       
    55     iFmtpAttr( NULL ), 
       
    56     iRtpmanager( aManager ),
       
    57     iSoundDevice( NULL ), 
       
    58     iMccStreamId( aMccStreamId ), 
       
    59     iType( aStreamType )
       
    60     {
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CMccSymStreamBase::~CMccSymStreamBase
       
    65 // Destructor
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CMccSymStreamBase::~CMccSymStreamBase()
       
    69     {
       
    70     HandleSpecialSinksAndSources();
       
    71     
       
    72     if( iDatasink )
       
    73         {
       
    74         iDatasink->SinkThreadLogoff();
       
    75         iDatasink = 0;
       
    76         }
       
    77         
       
    78     if( iDatapath )
       
    79         {
       
    80         delete iDatapath;
       
    81         iDatapath = 0;
       
    82         }
       
    83             
       
    84     if ( iFmtpAttr )
       
    85         {
       
    86         delete iFmtpAttr;
       
    87         iFmtpAttr = 0;
       
    88         }
       
    89 
       
    90 	iControlledEndpoints.Reset();
       
    91 	iUncontrolledEndpoints.Reset();
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CMccSymStreamBase::SendEventToClient
       
    96 // -----------------------------------------------------------------------------
       
    97 //    
       
    98 TInt CMccSymStreamBase::SendEventToClient( const TMMFEvent& aEvent )
       
    99 	{
       
   100 	TInt err( KErrNone );
       
   101 
       
   102 	// Do in a bit ackward way in order to save stack memory
       
   103 	TMccEvent* mccEventPtr = 0;
       
   104 	if ( IS_MCC_EVENT( aEvent ) )
       
   105 	    {
       
   106 	    mccEventPtr = 
       
   107 	        reinterpret_cast<const TMccInternalEvent&>( aEvent ).iMccEvent;                                     
       
   108 	    }
       
   109 	
       
   110 	if ( mccEventPtr )
       
   111 	    {	 
       
   112 	    __SUBCONTROLLER( "CMccSymStreamBase::SendEventToClient #1" )
       
   113 	       
       
   114 	    mccEventPtr->iStreamId = iMccStreamId;
       
   115     	err = iEventhandler->SendEventToClient( aEvent );	
       
   116 	    }
       
   117 	else
       
   118 	    {
       
   119 	    __SUBCONTROLLER( "CMccSymStreamBase::SendEventToClient #2" )
       
   120 	    
       
   121 	    // Fill stream id for all MMF events and try to fill endpointId as well
       
   122 	    
       
   123 	    TUint32 endpointId = ( iDatasink->DataSinkType() == KUidMmfAudioOutput ) ?
       
   124 	         MCC_ENDPOINT_ID( iDatasink ) : 0;
       
   125         endpointId = ( iDatasource->DataSourceType() == KUidMmfAudioInput ) ?
       
   126             MCC_ENDPOINT_ID( iDatasource ) : endpointId;
       
   127     
       
   128 	    err = SendStreamEventToClient( KMccStreamMMFEvent, endpointId, aEvent.iErrorCode );
       
   129 	    }
       
   130     
       
   131 	__SUBCONTROLLER( "CMccSymStreamBase::SendEventToClient, exit" )
       
   132     return err;
       
   133 	}
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CMccSymStreamBase::MultiplexerSink
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 MDataSink* CMccSymStreamBase::MultiplexerSink()
       
   140     {
       
   141     return 0;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CMccSymStreamBase::SetStateL
       
   146 // Sets the new state of the stream
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 TBool CMccSymStreamBase::SetStateL( TStreamState aState, TUint32 aEndpointId )
       
   150     {
       
   151     __SUBCONTROLLER( "CMccSymStreamBase::SetStateL" )
       
   152     
       
   153     TBool stateOK = EFalse;
       
   154     
       
   155     TBool controlNetworkResources = ETrue;
       
   156      
       
   157     MMccResources::TResourceState resourceState = MMccResources::EConstructed;
       
   158     
       
   159     switch( aState )
       
   160         {
       
   161         case EStateNone:
       
   162             __SUBCONTROLLER( "CMccSymStreamBase::SetStateL, EStateNone" )
       
   163             if( EStateStopped == iState )
       
   164                 {
       
   165                 resourceState = MMccResources::EConstructed;
       
   166                 stateOK = ETrue;
       
   167                 }
       
   168             break;
       
   169         case EStatePrepared:
       
   170             __SUBCONTROLLER( "CMccSymStreamBase::SetStateL, EStatePrepared" )
       
   171             resourceState = MMccResources::EPrepared;
       
   172             stateOK = ETrue;
       
   173             break;
       
   174         case EStateStreaming:
       
   175             __SUBCONTROLLER( "CMccSymStreamBase::SetStateL, EStateStreaming" )
       
   176             resourceState = MMccResources::EStarted;
       
   177             stateOK = ETrue;
       
   178             break;
       
   179         case EStatePaused:
       
   180             __SUBCONTROLLER( "CMccSymStreamBase::SetStateL, EStatePaused" )
       
   181             resourceState = MMccResources::EResourcePaused;
       
   182             stateOK = ETrue;
       
   183             break;
       
   184         case EStateStopped:
       
   185             __SUBCONTROLLER( "CMccSymStreamBase::SetStateL, EStateStopped" )
       
   186             resourceState = MMccResources::EResourceStopped;
       
   187             stateOK = ETrue;
       
   188             break;
       
   189         default:
       
   190             stateOK = EFalse;
       
   191             break;
       
   192         }
       
   193     
       
   194     __ASSERT_ALWAYS( stateOK, User::Leave( KErrArgument ) );
       
   195 
       
   196     if ( resourceState != MMccResources::EConstructed )
       
   197         {
       
   198         __SUBCONTROLLER( "CMccSymStreamBase::SetStateL, set resource state" )
       
   199         
       
   200         iControlledEndpoints.Reset();
       
   201         iUncontrolledEndpoints.Reset();
       
   202         
       
   203         iMccResources->SetResourceStateL( iMccStreamId,
       
   204                                           aEndpointId, 
       
   205                                           resourceState, 
       
   206                                           controlNetworkResources,
       
   207                                           iControlledEndpoints,
       
   208                                           iUncontrolledEndpoints );
       
   209         
       
   210         // Update multiplexer
       
   211         HandleMultiplexerL();
       
   212         
       
   213         // Update sink
       
   214         HandleSpecialSinksAndSources();
       
   215         }
       
   216     
       
   217     // Stream state follows network resource state or in case of
       
   218     // local stream any change affect to the stream state 
       
   219     if ( controlNetworkResources || LocalStream() )
       
   220         {
       
   221         iState = aState;
       
   222         }
       
   223     
       
   224     __SUBCONTROLLER( "CMccSymStreamBase::SetStateL, exit" )
       
   225         
       
   226     return controlNetworkResources;
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CMccSymStreamBase::CurrentState
       
   231 // Returns the current state of the stream
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 CMccSymStreamBase::TStreamState CMccSymStreamBase::CurrentState()
       
   235     {
       
   236     return iState;
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CMccSymStreamBase::SetGainL
       
   241 // Sets the current gain
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void CMccSymStreamBase::SetGainL( TInt aGain )
       
   245     {
       
   246     if( iSoundDevice )
       
   247 	    {
       
   248         iSoundDevice->SetGain( aGain );
       
   249         }
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CMccSymStreamBase::SetVolumeL
       
   254 // Sets the current volume
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CMccSymStreamBase::SetVolumeL( TInt aVolume )
       
   258     {
       
   259     if( iSoundDevice )
       
   260         {
       
   261         iSoundDevice->SetVolume( aVolume );
       
   262         }
       
   263     else if ( iDatasink && iDatasink->DataSinkType() == KMccVideoSinkUid )
       
   264         {
       
   265         CMccDataSink* sink = static_cast<CMccDataSink*>( iDatasink );
       
   266         sink->SetParameterL( KMccSpeakerVolume, TPckgBuf<TInt>( aVolume ) );
       
   267         }
       
   268     else
       
   269         {
       
   270         // NOP
       
   271         }
       
   272     }
       
   273 
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CMccSymStreamBase::SetVolumeL
       
   277 // Sets the current volume
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CMccSymStreamBase::SetMMFPriority( 
       
   281                 const TMMFPrioritySettings& aPriority )
       
   282 	{
       
   283 	__SUBCONTROLLER( "CMccSymStreamBase::SetPriorityToCodecsL entry " )
       
   284 	//Check if the codec info priority is same otherwise don't do it
       
   285 	if ( iPrioritySettings.iPref != aPriority.iPref ||
       
   286 		 iPrioritySettings.iState != aPriority.iState ||
       
   287 		 iPrioritySettings.iPriority != aPriority.iPriority )
       
   288 		{
       
   289 		__SUBCONTROLLER( " Different from privous setting " )
       
   290 		TRAPD( err, SetPrioritySettingsL( aPriority ) );	
       
   291 		
       
   292 		__SUBCONTROLLER_INT1 ( " Setting priority preference to", aPriority.iPref );
       
   293 		__SUBCONTROLLER_INT1 ( " Setting priority state to ", aPriority.iState );
       
   294 		__SUBCONTROLLER_INT1 ( " Setting client priority to ", aPriority.iPriority );
       
   295 		__SUBCONTROLLER_INT1 ( " SetPrioritySettingsL err =", err );
       
   296 		
       
   297 		if ( err == KErrNone )
       
   298 			{
       
   299 			iPrioritySettings = aPriority;
       
   300 			}
       
   301 		else
       
   302 			{
       
   303 			//Ignore error 
       
   304 			__SUBCONTROLLER_INT1 ( " Sink or Source is not existed err =", err );
       
   305 		
       
   306 			err = KErrNone;
       
   307 			}
       
   308 		}
       
   309 	__SUBCONTROLLER( "CMccSymStreamBase::SetPriorityToCodecsL exit " )
       
   310     }
       
   311 // -----------------------------------------------------------------------------
       
   312 // CMccSymStreamBase::MaxVolumeL
       
   313 // Return the maximum volume
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 TInt CMccSymStreamBase::MaxVolumeL()
       
   317     {
       
   318     if( iSoundDevice )
       
   319         {
       
   320         return iSoundDevice->MaxVolume();
       
   321         }
       
   322     return KErrNone;    
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CMccSymStreamBase::MaxGainL
       
   327 // Return the maximum gain
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 TInt CMccSymStreamBase::MaxGainL()
       
   331     {
       
   332     if( iSoundDevice )
       
   333         {
       
   334         return iSoundDevice->MaxGain();
       
   335         }
       
   336     return KErrNone;    
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // CMccSymStreamBase::VolumeL
       
   341 // Return the current volume
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 TInt CMccSymStreamBase::VolumeL()
       
   345     {
       
   346     if( iSoundDevice )
       
   347         {
       
   348         return iSoundDevice->Volume();
       
   349         }
       
   350     return KErrNone;    
       
   351     }
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CMccSymStreamBase::GainL
       
   355 // Return the current gain
       
   356 // -----------------------------------------------------------------------------
       
   357 //
       
   358 TInt CMccSymStreamBase::GainL()
       
   359     {
       
   360     if( iSoundDevice )
       
   361         {
       
   362         return iSoundDevice->Gain();
       
   363         }
       
   364     return KErrNone;    
       
   365     }
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CMccSymStreamBase::SendMediaSignalL
       
   369 // Default implementation of media signal sending
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 void CMccSymStreamBase::SendMediaSignalL( const TMccEvent& /*aEvent*/ )
       
   373     {
       
   374     User::Leave( KErrNotSupported );
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CMccSymStreamBase::SendRTCPReceiverReportL
       
   379 // -----------------------------------------------------------------------------
       
   380 // 
       
   381 void CMccSymStreamBase::SendRTCPReceiverReportL()
       
   382     {
       
   383     User::Leave( KErrNotSupported );
       
   384     }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // CMccSymStreamBase::SendRTCPSenderReportL
       
   388 // -----------------------------------------------------------------------------
       
   389 // 
       
   390 void CMccSymStreamBase::SendRTCPSenderReportL()
       
   391     {
       
   392     User::Leave( KErrNotSupported );
       
   393     }
       
   394         
       
   395 // -----------------------------------------------------------------------------
       
   396 // CMccSymStreamBase::SendRTCPDataL
       
   397 // Sends Non-RTCP data
       
   398 // -----------------------------------------------------------------------------
       
   399 // 
       
   400 void CMccSymStreamBase::SendRTCPDataL( const TDesC8& /*aData*/ )
       
   401     {
       
   402     User::Leave( KErrNotSupported );
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CMccSymStreamBase::StartInactivityTimerL
       
   407 // Starts inactivity timer for a stream
       
   408 // -----------------------------------------------------------------------------
       
   409 // 
       
   410 void CMccSymStreamBase::StartInactivityTimerL( TUint32 /*aTimeoutTime*/ )
       
   411     {
       
   412     User::Leave( KErrNotSupported );
       
   413     }
       
   414 
       
   415       
       
   416 // -----------------------------------------------------------------------------
       
   417 // CMccSymStreamBase::StopInactivityTimerL
       
   418 // Stops inactivity timer for a stream 
       
   419 // -----------------------------------------------------------------------------
       
   420 // 
       
   421 void CMccSymStreamBase::StopInactivityTimerL()
       
   422     {
       
   423     User::Leave( KErrNotSupported );
       
   424     }
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 // CMccSymStreamBase::GetFmtpL
       
   428 // Fetches the FMTP attribute
       
   429 // -----------------------------------------------------------------------------
       
   430 // 
       
   431 void CMccSymStreamBase::GetFmtpL( TDes8& aFmtp )
       
   432     {
       
   433     __ASSERT_ALWAYS ( iFmtpAttr, User::Leave(KErrArgument) );
       
   434 
       
   435 	aFmtp.Copy( iFmtpAttr->Des() );
       
   436     }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // CMccSymStreamBase::GetCodecL
       
   440 // Fetches codec info
       
   441 // -----------------------------------------------------------------------------
       
   442 // 
       
   443 void CMccSymStreamBase::GetCodecL( TMccCodecInfo& aCodec )
       
   444     {
       
   445     aCodec = iCodecInfo;
       
   446     }
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // CMccSymStreamBase::SetAudioRouteL
       
   450 // -----------------------------------------------------------------------------
       
   451 //    
       
   452 void CMccSymStreamBase::SetAudioRouteL( TUint32 /*aRoutingDestination*/ )
       
   453     {
       
   454     User::Leave( KErrNotSupported );
       
   455     }
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CMccSymStreamBase::GetAudioRouteL
       
   459 // -----------------------------------------------------------------------------
       
   460 //     
       
   461 void CMccSymStreamBase::GetAudioRouteL( TUint32& /*aRoutingDestination*/ )
       
   462     {
       
   463     User::Leave( KErrNotSupported );
       
   464     }
       
   465     
       
   466 // -----------------------------------------------------------------------------
       
   467 // CMccSymStreamBase::Type
       
   468 // -----------------------------------------------------------------------------
       
   469 //     
       
   470 const TUid CMccSymStreamBase::Type()
       
   471     {
       
   472     TUid type = KUidMediaTypeAudio;
       
   473     
       
   474     if (iType == KMccVideoUplinkStream ||
       
   475         iType == KMccVideoDownlinkStream ||
       
   476         iType == KMccVideoLocalStream )
       
   477         {
       
   478         type = KUidMediaTypeVideo;
       
   479         }
       
   480         
       
   481     return type;
       
   482     }
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 // CMccSymStreamBase::LocalStream
       
   486 // -----------------------------------------------------------------------------
       
   487 //     
       
   488 TBool CMccSymStreamBase::LocalStream() const
       
   489     {
       
   490     return ( iType == KMccVideoLocalStream || iType == KMccAudioLocalStream );
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CMccSymStreamBase::StandbyStream
       
   495 // -----------------------------------------------------------------------------
       
   496 //     
       
   497 TBool CMccSymStreamBase::StandbyStream() const
       
   498     {
       
   499     return ( iType == KMccAudioDownlinkStandbyStream );
       
   500     }
       
   501      
       
   502 // -----------------------------------------------------------------------------
       
   503 // CMccSymStreamBase::InformStreamStateChange
       
   504 // -----------------------------------------------------------------------------
       
   505 //   
       
   506 void CMccSymStreamBase::InformStreamStateChange( 
       
   507     TMccEventType aEventType, TUint32 aEndpointId )
       
   508     {
       
   509     __SUBCONTROLLER_INT2( "CMccSymStreamBase::InformStreamStateChange, \
       
   510     aEventType=", aEventType, "aEndpointId=", aEndpointId )
       
   511     
       
   512     // Only state changes of mmf audio and uncontrolled endpoints (e.g. shared
       
   513     // ones which are already in state the client tried to set) are generated
       
   514     // at this level
       
   515 
       
   516     TBool isAudioOutput = ( iDatasink->DataSinkType() == KUidMmfAudioOutput );
       
   517     TBool isAudioInput = ( iDatasource->DataSourceType() == KUidMmfAudioInput );
       
   518     
       
   519     if ( iUncontrolledEndpoints.Count() > 0 )
       
   520         {
       
   521         __SUBCONTROLLER( "CMccSymStreamBase::InformStreamStateChange, \
       
   522         handle uncontrolled endpoints" )
       
   523         
       
   524         for ( TInt i = 0; i < iUncontrolledEndpoints.Count(); i++ )
       
   525             {  
       
   526             SendStreamEventToClient( aEventType, iUncontrolledEndpoints[ i ] );
       
   527             }
       
   528         }
       
   529     else if ( iCodecInfo.iType == KUidMediaTypeAudio &&
       
   530             ( isAudioOutput || isAudioInput ) )
       
   531 	    {
       
   532 	    __SUBCONTROLLER( "CMccSymStreamBase::InformStreamStateChange, \
       
   533         report state change" )
       
   534 	    
       
   535         if ( MCC_CONTROL_ALL_ENDPOINTS( aEndpointId ) )
       
   536             {
       
   537             // Modify endpoint id
       
   538             aEndpointId = isAudioOutput ? MCC_ENDPOINT_ID( iDatasink ) :
       
   539                                           MCC_ENDPOINT_ID( iDatasource ); 
       
   540                                           
       
   541             SendStreamEventToClient( aEventType, aEndpointId );
       
   542             }
       
   543         else if ( ( aEndpointId == MCC_ENDPOINT_ID( iDatasink ) && isAudioOutput ) ||
       
   544                   ( aEndpointId == MCC_ENDPOINT_ID( iDatasource ) && isAudioInput ) )
       
   545             {
       
   546             // MMF endpoint is specificly controlled
       
   547             SendStreamEventToClient( aEventType, aEndpointId );
       
   548             }
       
   549         else
       
   550             {
       
   551             __SUBCONTROLLER("CMccSymStreamBase::InformStreamStateChange, not reported")
       
   552             }
       
   553 	    }
       
   554 	else
       
   555 		{
       
   556 		__SUBCONTROLLER("CMccSymStreamBase::InformStreamStateChange, not reported")	
       
   557 		}	
       
   558     }
       
   559 
       
   560 // -----------------------------------------------------------------------------
       
   561 // CMccSymStreamBase::HandleStandby
       
   562 // If stream is paused and standby endpoint (speaker) is controlled, 
       
   563 // standby is activated as we want that it will be resumed when receiving
       
   564 // data for this stream. If stream is playing but standby endpoint control
       
   565 // is non-effective, standby mechanism is re-activated in order to get the
       
   566 // standby resource later into use (this scenario might occur if client has
       
   567 // paused the speaker while standby occurs).
       
   568 // -----------------------------------------------------------------------------
       
   569 //    
       
   570 void CMccSymStreamBase::HandleStandby( 
       
   571     TUint32 aEndpointId,
       
   572     TBool aStreamPaused )
       
   573     {  
       
   574     TUint32 standbyEndpointId( MCC_ENDPOINT_ID( iDatasink ) );
       
   575     TBool standbyEndpointControl( StandbyStream() && 
       
   576                                   ( aEndpointId == standbyEndpointId ||
       
   577                                     MCC_CONTROL_ALL_ENDPOINTS( aEndpointId ) ) );
       
   578     
       
   579     TBool isStandbyEndpointControlled( IsControlled( standbyEndpointId ) );
       
   580     
       
   581     if ( standbyEndpointControl && 
       
   582        ( ( aStreamPaused && isStandbyEndpointControlled ) || 
       
   583          ( !aStreamPaused && !isStandbyEndpointControlled ) ) )
       
   584         {
       
   585         CMccRtpDataSource* dSource = static_cast<CMccRtpDataSource*>( iDatasource );
       
   586         dSource->StandBy( EActivateStandby, iCodecInfo.iPayloadType );
       
   587         }
       
   588     }
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // CMccSymStreamBase::SendStreamEventToClient
       
   592 // -----------------------------------------------------------------------------
       
   593 //     
       
   594 TInt CMccSymStreamBase::SendStreamEventToClient( 
       
   595     TMccEventType aEventType, 
       
   596     TUint32 aEndpointId,
       
   597     TInt aError )
       
   598     {
       
   599     ClearStateChangeEvent();
       
   600     
       
   601     iStreamStateChangeEvent.iStreamId = iMccStreamId;
       
   602     iStreamStateChangeEvent.iEndpointId = aEndpointId;
       
   603     iStreamStateChangeEvent.iEventCategory = KMccEventCategoryStream;
       
   604     iStreamStateChangeEvent.iEventType = aEventType;
       
   605     iStreamStateChangeEvent.iErrorCode = aError;
       
   606    
       
   607     TMccInternalEvent internalEvent( Type(), 
       
   608                                      EMccInternalEventNone,
       
   609                                      iStreamStateChangeEvent );
       
   610                                      
       
   611     return iEventhandler->SendEventToClient( internalEvent );
       
   612     }
       
   613 
       
   614 // -----------------------------------------------------------------------------
       
   615 // CMccSymStreamBase::HandleMultiplexerL
       
   616 // -----------------------------------------------------------------------------
       
   617 //     
       
   618 void CMccSymStreamBase::HandleMultiplexerL()
       
   619     {
       
   620     __SUBCONTROLLER( "CMccSymStreamBase::HandleMultiplexerL" )
       
   621         
       
   622     if ( iMultiplexer )
       
   623         {
       
   624         MDataSink* multiplexerSink = MultiplexerSink();
       
   625         if ( multiplexerSink )
       
   626             {
       
   627             iMultiplexer->SetCurrentUserL( *multiplexerSink );
       
   628             }
       
   629         }
       
   630         
       
   631     __SUBCONTROLLER( "CMccSymStreamBase::HandleMultiplexerL, exit" )
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // CMccSymStreamBase::HandleSpecialSinksAndSources
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 void CMccSymStreamBase::HandleSpecialSinksAndSources()
       
   639     {
       
   640     if ( iDatasink && 
       
   641        ( iDatasink->DataSinkType() == KUidMccVideoSink || 
       
   642          iDatasink->DataSinkType() == KUidMccRtpSink ||
       
   643          iDatasink->DataSinkType() == KUidMccFileSink ) )
       
   644         {
       
   645         static_cast<CMccDataSink*>( iDatasink )->SetCurrentUser( this );
       
   646         }
       
   647         
       
   648     if ( iDatasource && iDatasource->DataSourceType() == KUidMccVideoSource )
       
   649         {
       
   650         static_cast<CMccDataSource*>( iDatasource )->SetCurrentUser( this );
       
   651         }
       
   652     }
       
   653     
       
   654 // -----------------------------------------------------------------------------
       
   655 // CMccSymStreamBase::MultiplexerCleanup
       
   656 // -----------------------------------------------------------------------------
       
   657 //   
       
   658 void CMccSymStreamBase::MultiplexerCleanup()
       
   659     {
       
   660     // If multiplexer exists, sourcethread logoff is routed through it to the
       
   661     // datasource
       
   662     if ( iMultiplexer )
       
   663         {
       
   664         iMultiplexer->MultiplexerSourceThreadLogoff( MultiplexerSink() );
       
   665         iMultiplexer = 0;
       
   666         }
       
   667     else if ( iDatasource )
       
   668         {
       
   669         iDatasource->SourceThreadLogoff();
       
   670         iDatasource = 0;
       
   671         }
       
   672     else
       
   673         {
       
   674         // NOP
       
   675         }
       
   676     }
       
   677 
       
   678 // -----------------------------------------------------------------------------
       
   679 // CMccSymStreamBase::DoPrimeL
       
   680 // -----------------------------------------------------------------------------
       
   681 //
       
   682 void CMccSymStreamBase::DoPrimeL()
       
   683     {
       
   684     for ( TInt i = 0; i < iControlledEndpoints.Count(); i++ )
       
   685         { 
       
   686         iDatapath->PrimeL( iControlledEndpoints[ i ] );
       
   687         }   
       
   688     
       
   689     iMccResources->ResourceStateSetL();
       
   690     }
       
   691     
       
   692 // -----------------------------------------------------------------------------
       
   693 // CMccSymStreamBase::DoPlayL
       
   694 // -----------------------------------------------------------------------------
       
   695 //
       
   696 void CMccSymStreamBase::DoPlayL()
       
   697     {
       
   698     for ( TInt i = 0; i < iControlledEndpoints.Count(); i++ )
       
   699         { 
       
   700         iDatapath->PlayL( iControlledEndpoints[ i ] );
       
   701         }  
       
   702         
       
   703     iMccResources->ResourceStateSetL();  
       
   704     }
       
   705     
       
   706 // -----------------------------------------------------------------------------
       
   707 // CMccSymStreamBase::DoPauseL
       
   708 // -----------------------------------------------------------------------------
       
   709 //
       
   710 void CMccSymStreamBase::DoPauseL()
       
   711     {
       
   712     for ( TInt i = 0; i < iControlledEndpoints.Count(); i++ )
       
   713         { 
       
   714         iDatapath->PauseL( iControlledEndpoints[ i ] );
       
   715         }    
       
   716         
       
   717     iMccResources->ResourceStateSetL();
       
   718     }
       
   719     
       
   720 // -----------------------------------------------------------------------------
       
   721 // CMccSymStreamBase::DoResumeL
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 void CMccSymStreamBase::DoResumeL()
       
   725     {
       
   726     for ( TInt i = 0; i < iControlledEndpoints.Count(); i++ )
       
   727         { 
       
   728         iDatapath->ResumeL( iControlledEndpoints[ i ] );
       
   729         }    
       
   730         
       
   731     iMccResources->ResourceStateSetL();
       
   732     }
       
   733     
       
   734 // -----------------------------------------------------------------------------
       
   735 // CMccSymStreamBase::DoStopL
       
   736 // -----------------------------------------------------------------------------
       
   737 //
       
   738 void CMccSymStreamBase::DoStopL()
       
   739     {
       
   740     for ( TInt i = 0; i < iControlledEndpoints.Count(); i++ )
       
   741         { 
       
   742         iDatapath->StopL( iControlledEndpoints[ i ] );
       
   743         }    
       
   744         
       
   745     iMccResources->ResourceStateSetL();    
       
   746     }
       
   747   
       
   748 // -----------------------------------------------------------------------------
       
   749 // CMccSymStreamBase::ParsePayloadTypesL
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 void CMccSymStreamBase::ParsePayloadTypesL( RArray<TUint>& aPayloadTypes,
       
   753         const TMccCodecInfo& aCodecInfo ) const
       
   754     {
       
   755     __ASSERT_DEBUG( KMccPayloadTypeMax != aCodecInfo.iPayloadType,
       
   756         User::Panic( _L("PT PARSE, PT NOT SET"), KErrArgument ) );
       
   757     
       
   758     aPayloadTypes.AppendL( aCodecInfo.iPayloadType );
       
   759     
       
   760     if ( KMccPayloadTypeMax != aCodecInfo.iRedundantPayload )
       
   761         {
       
   762         aPayloadTypes.AppendL( aCodecInfo.iRedundantPayload );
       
   763         }
       
   764     
       
   765     
       
   766     if ( KPayloadTypeUndefined != aCodecInfo.iComfortNoiseGenerationPt &&
       
   767          aCodecInfo.iEnableDTX )
       
   768         {
       
   769         aPayloadTypes.AppendL( KCnPayloadType );
       
   770         aPayloadTypes.AppendL( KCnPayloadTypeReserved );
       
   771         }
       
   772     }
       
   773 
       
   774   
       
   775 // -----------------------------------------------------------------------------
       
   776 // CMccSymStreamBase::IsControllingMmfEndpoint
       
   777 // -----------------------------------------------------------------------------
       
   778 //   
       
   779 TBool CMccSymStreamBase::IsControllingMmfEndpoint() const
       
   780     {
       
   781     TBool controlling( EFalse );
       
   782     for ( TInt i = 0; i < iControlledEndpoints.Count() && !controlling; i++ )
       
   783         { 
       
   784         TUint32 endpointId = iControlledEndpoints[ i ];
       
   785         controlling =
       
   786             MCC_CONTROL_ALL_ENDPOINTS( endpointId ) ||
       
   787             ( iDatasink->DataSinkType() == KUidMmfAudioOutput && 
       
   788               endpointId == MCC_ENDPOINT_ID( iDatasink ) ) ||
       
   789             ( iDatasource->DataSourceType() == KUidMmfAudioInput &&
       
   790               endpointId == MCC_ENDPOINT_ID( iDatasource ) );
       
   791             
       
   792         }
       
   793     return controlling;
       
   794     }
       
   795 
       
   796 // -----------------------------------------------------------------------------
       
   797 // CMccSymStreamBase::IsCodecOperationAllowed
       
   798 // -----------------------------------------------------------------------------
       
   799 //   
       
   800 TBool CMccSymStreamBase::IsCodecOperationAllowed() const
       
   801     {
       
   802     TBool allowed( ETrue );
       
   803     
       
   804     if ( iDatasink->DataSinkType() == KUidMmfAudioOutput ||
       
   805          iDatasource->DataSourceType() == KUidMmfAudioInput )
       
   806         {
       
   807         allowed = IsControllingMmfEndpoint();
       
   808         }
       
   809         
       
   810     return allowed;
       
   811     
       
   812     }
       
   813 
       
   814 
       
   815 // -----------------------------------------------------------------------------
       
   816 // CMccSymStreamBase::CurrentCodecState
       
   817 // -----------------------------------------------------------------------------
       
   818 //   
       
   819 CMccSymStreamBase::TCodecState CMccSymStreamBase::CurrentCodecState() const
       
   820     {
       
   821     return iCodecState;
       
   822     }
       
   823 
       
   824 // -----------------------------------------------------------------------------
       
   825 // CMccSymStreamBase::SetCodecState
       
   826 // -----------------------------------------------------------------------------
       
   827 //   
       
   828         
       
   829 void CMccSymStreamBase::SetCodecState( TCodecState aState )
       
   830     {
       
   831     iCodecState = aState;
       
   832     }
       
   833 
       
   834 // -----------------------------------------------------------------------------
       
   835 // CMccSymStreamBase::UpdateCodecLoadingPermission
       
   836 // -----------------------------------------------------------------------------
       
   837 //     
       
   838 void CMccSymStreamBase::UpdateCodecLoadingPermission( TBool aLoadingAllowed )
       
   839     {
       
   840     iCodecLoadingAllowed = aLoadingAllowed;
       
   841     }
       
   842 
       
   843 // -----------------------------------------------------------------------------
       
   844 // CMccSymStreamBase::CodecLoadingAllowed
       
   845 // -----------------------------------------------------------------------------
       
   846 //         
       
   847 TBool CMccSymStreamBase::CodecLoadingAllowed() const
       
   848     {
       
   849     return iCodecLoadingAllowed;
       
   850     }
       
   851 
       
   852 // -----------------------------------------------------------------------------
       
   853 // CMccSymStreamBase::ChangeBitrate
       
   854 // Traps the call to dynamic bitrate change function
       
   855 // -----------------------------------------------------------------------------
       
   856 //
       
   857 TInt CMccSymStreamBase::ChangeBitrate( TInt aBitrate )
       
   858     {
       
   859     TRAPD( err, this->DoChangeBitrateL( aBitrate ) ); 
       
   860          
       
   861     // If the bitrate change is not supported, we may just suppress the error
       
   862     // as this function may have been called to e.g a dl stream.
       
   863     if( KErrNotSupported == err )
       
   864         {
       
   865         __SUBCONTROLLER( "CMccSymStreamBase::ChangeBitrate KErrNotSupported" );
       
   866         return KErrNone;
       
   867         }
       
   868     else
       
   869         {
       
   870         // Something else has happened, maybe bitrate was wrong, so report it
       
   871         // back
       
   872         __SUBCONTROLLER_INT1( "CMccSymStreamBase::ChangeBitrate ERROR:", err );
       
   873         return err;
       
   874         }
       
   875     }
       
   876     
       
   877 // -----------------------------------------------------------------------------
       
   878 // CMccSymStreamBase::DoChangeBitrateL
       
   879 // Downlink cannot support bitrate change
       
   880 // -----------------------------------------------------------------------------
       
   881 //
       
   882 void CMccSymStreamBase::DoChangeBitrateL( TInt /*aBitrate*/ )
       
   883     {
       
   884     // This will be trapped inside ChangeBitrate() function
       
   885     __SUBCONTROLLER( "CMccSymStreamBase::DoChangeBitrateL KErrNotSupported" );
       
   886     User::Leave( KErrNotSupported );
       
   887     }
       
   888 
       
   889 // -----------------------------------------------------------------------------
       
   890 // CMccSymStreamBase::BindContextIntoStreamL
       
   891 // -----------------------------------------------------------------------------
       
   892 //
       
   893 void CMccSymStreamBase::BindContextIntoStreamL( TUint32 /*aEndpointId*/,
       
   894                                                 const TMccCryptoContext& /*aContextParams*/ )
       
   895     {              
       
   896 
       
   897     __SUBCONTROLLER( "CMccSymStreamBase::BindContextIntoStreamL KErrNotSupported" );
       
   898     User::Leave( KErrNotSupported );
       
   899     }
       
   900     
       
   901 // -----------------------------------------------------------------------------
       
   902 // CMccSymStreamBase::RemoveCryptoContext
       
   903 // -----------------------------------------------------------------------------
       
   904 //
       
   905 TInt CMccSymStreamBase::RemoveContext( TUint32 aEndpointId )
       
   906     {
       
   907     if ( iDatasource && iDatasource->DataSourceType() == KMccRtpSourceUid &&
       
   908          ( aEndpointId == MCC_ENDPOINT_ID( iDatasource ) || 0 == aEndpointId ) )
       
   909 	    {
       
   910 	    static_cast<CMccRtpDataSource*>( iDatasource )->RemoveCryptoContext();
       
   911 	    } 
       
   912 	
       
   913     if ( iDatasink && iDatasink->DataSinkType() == KMccRtpSinkUid &&
       
   914 	     ( aEndpointId == MCC_ENDPOINT_ID( iDatasink ) || 0 == aEndpointId ) )
       
   915 	    {
       
   916 	    static_cast<CMccRtpDataSink*>( iDatasink )->RemoveCryptoContext();
       
   917 	    } 
       
   918 	       
       
   919     return KErrNone;    
       
   920     }    
       
   921 
       
   922 // -----------------------------------------------------------------------------
       
   923 // CMccSymStreamBase::IsControlled
       
   924 // -----------------------------------------------------------------------------
       
   925 //   
       
   926 TBool CMccSymStreamBase::IsControlled( TUint32 aEndpointId ) const
       
   927     {
       
   928     TBool controlled( EFalse );
       
   929     for ( TInt i = 0; i < iControlledEndpoints.Count() && !controlled; i++ )
       
   930         { 
       
   931         controlled = ( iControlledEndpoints[ i ] == aEndpointId );
       
   932         }
       
   933     return controlled;
       
   934     }
       
   935 
       
   936 // -----------------------------------------------------------------------------
       
   937 // CMccSymStreamBase::ClearStateChangeEvent
       
   938 // -----------------------------------------------------------------------------
       
   939 // 
       
   940 void CMccSymStreamBase::ClearStateChangeEvent()
       
   941     {
       
   942     iStreamStateChangeEvent = TMccEvent();
       
   943     }
       
   944           
       
   945 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   946 
       
   947 //  End of File