multimediacommscontroller/mmcccontroller/src/mcccontroller.cpp
changeset 0 1bce908db942
child 49 64c62431ac08
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:    Controller
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <mmf/common/mmfbase.h>
       
    23 #include <ecam.h>
       
    24 #include <mmf/server/sounddevice.h>
       
    25 
       
    26 #include "mmccinterface.h"
       
    27 #include "mmcccodecinformation.h"
       
    28 
       
    29 #include "mcccontroller.h"
       
    30 #include "mcccamerahandler.h"
       
    31 #include "mcculdlclient.h"
       
    32 #include "mccuids.hrh"
       
    33 #include "mccresourcepool.h"
       
    34 #include "mccresourceitem.h"
       
    35 #include "mccqoscontroller.h"
       
    36 #include "mcccontrollerlogs.h"
       
    37 #include "mccasynclinkcreator.h"
       
    38 #include "mmcccryptocontext.h"
       
    39 #include "mccdatasink.h"
       
    40 #include "mccdatasource.h"
       
    41 #include "mccrtpdatasink.h"
       
    42 
       
    43 const TInt KNumValue2 = 2;
       
    44 
       
    45 _LIT( KMccControllerName, "mmcccontroller" );
       
    46 
       
    47 // EXTERNAL DATA STRUCTURES
       
    48 
       
    49 // EXTERNAL FUNCTION PROTOTYPES  
       
    50 
       
    51 // CONSTANTS
       
    52 
       
    53 // MACROS
       
    54 
       
    55 // LOCAL CONSTANTS AND MACROS
       
    56 
       
    57 // MODULE DATA STRUCTURES
       
    58 
       
    59 // LOCAL FUNCTION PROTOTYPES
       
    60 
       
    61 // FORWARD DECLARATIONS
       
    62 
       
    63 // ============================= LOCAL FUNCTIONS ===============================
       
    64 
       
    65 
       
    66 // ============================ MEMBER FUNCTIONS ===============================
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CMccController::CMccController
       
    70 // C++ default constructor can NOT contain any code, that
       
    71 // might leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CMccController::CMccController()
       
    75     {
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CMccController::~CMccController
       
    80 // Destructor
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CMccController::~CMccController()
       
    84     {
       
    85 	__CONTROLLER( "CMccController::~CMccController" )
       
    86     
       
    87     CancelMmfMessage();
       
    88 
       
    89     // delete isessionarray
       
    90     iSessionArray.ResetAndDestroy();
       
    91     iSessionArray.Close();
       
    92     
       
    93     iCreatorArray.ResetAndDestroy();
       
    94     iCreatorArray.Close();
       
    95     
       
    96     // delete eventbuffer and contents of it
       
    97     iEventBuf.ResetAndDestroy();
       
    98     iEventBuf.Close();
       
    99     
       
   100     delete iQosController;
       
   101     
       
   102     delete iResourcePool;
       
   103     
       
   104     if ( iTranscoder )
       
   105         {
       
   106         iTranscoder->UnregisterEventObserver();
       
   107         
       
   108         /* Commented off since causes crash
       
   109         REComSession::DestroyedImplementation( iTranscoderKey );
       
   110         */
       
   111         delete iTranscoder;
       
   112         iTranscoder = NULL;   
       
   113         }
       
   114     
       
   115     iDtmfPayloadTypes.Close();
       
   116        
       
   117     #ifdef FTD_ENABLED
       
   118     iStreamStatsQueue.Close();
       
   119     iCodecStatsQueue.Close();
       
   120     iJBufferStatsQueue.Close();
       
   121     #endif
       
   122 	__CONTROLLER( "CMccController::~CMccController, exit" )
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CMccController::NewL
       
   127 // Static constructor.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 CMccController* CMccController::NewL()
       
   131     {
       
   132     CMccController* self = new ( ELeave ) CMccController;
       
   133     
       
   134     CleanupStack::PushL( self );
       
   135     self->ConstructL();
       
   136     CleanupStack::Pop( self );
       
   137     
       
   138     return self;
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CMccController::ConstructL
       
   143 // Symbian 2nd phase constructor can leave.
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CMccController::ConstructL()
       
   147     {
       
   148 	__CONTROLLER( "CMccController::ConstructL" )
       
   149 	User::LeaveIfError( User::RenameThread( KMccControllerName ) );
       
   150 
       
   151     CMMFAudioPlayDeviceCustomCommandParser* audPlayDevParser
       
   152         = CMMFAudioPlayDeviceCustomCommandParser::NewL( *this );
       
   153     CleanupStack::PushL( audPlayDevParser );
       
   154     AddCustomCommandParserL( *audPlayDevParser );
       
   155     CleanupStack::Pop( audPlayDevParser );
       
   156 
       
   157     CMMFAudioRecordDeviceCustomCommandParser* audRecDevParser
       
   158         = CMMFAudioRecordDeviceCustomCommandParser::NewL( *this );
       
   159     CleanupStack::PushL( audRecDevParser );
       
   160     AddCustomCommandParserL( *audRecDevParser );
       
   161     CleanupStack::Pop( audRecDevParser );
       
   162     
       
   163     iResourcePool = CMccResourcePool::NewL();
       
   164     
       
   165     iQosController = CMccQosController::NewL( *this, *iResourcePool );
       
   166     
       
   167     __CONTROLLER( "CMccController::ConstructL, creating devsound" )
       
   168     
       
   169     CMMFDevSound* devSound = CMMFDevSound::NewL();
       
   170     iMaxVolume = devSound->MaxVolume();
       
   171     __CONTROLLER_INT1( "CMccController::ConstructL, max vol:", iMaxVolume )
       
   172     iMaxGain = devSound->MaxGain();
       
   173     __CONTROLLER_INT1( "CMccController::ConstructL, max gain:", iMaxGain )
       
   174     delete devSound;
       
   175     iVolume = iMaxVolume / KNumValue2;
       
   176     iGain = iMaxGain / KNumValue2;
       
   177 
       
   178     #ifdef FTD_ENABLED
       
   179     // Message queues are created here and opened by components,
       
   180     // which will produce messages
       
   181     User::LeaveIfError( iStreamStatsQueue.CreateGlobal( KMccStreamStats,
       
   182             KNumOfStreamStatsSlots, EOwnerProcess ) );
       
   183     
       
   184     User::LeaveIfError( iCodecStatsQueue.CreateGlobal( KMccCodecStats,
       
   185             KNumOfCodecStatsSlots, EOwnerProcess ) );
       
   186     
       
   187     User::LeaveIfError( iJBufferStatsQueue.CreateGlobal( KMccJBufferStats,
       
   188             KNumOfJBufferStatsSlots, EOwnerProcess ) );
       
   189     #endif
       
   190 	__CONTROLLER( "CMccController::ConstructL, exit" )
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CMccController::GetSourceIdL
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CMccController::GetSourceIdL( TMMFMessage& aMessage )
       
   198     {
       
   199     MDataSource* dataSource = iResourcePool->SourceCandidate();
       
   200     __ASSERT_ALWAYS( dataSource, User::Leave( KErrNotFound ) );
       
   201     TMccSessionPckg pckg;
       
   202     aMessage.ReadData1FromClientL( pckg );
       
   203     pckg().iEndpointID = MCC_ENDPOINT_ID( dataSource );
       
   204     aMessage.WriteDataToClientL( pckg );
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CMccController::GetSinkIdL
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void CMccController::GetSinkIdL( TMMFMessage& aMessage )
       
   212     {
       
   213     MDataSink* dataSink = iResourcePool->SinkCandidate();
       
   214     __ASSERT_ALWAYS( dataSink, User::Leave( KErrNotFound ) );
       
   215     
       
   216     TMccSessionPckg pckg;
       
   217     aMessage.ReadData1FromClientL( pckg );
       
   218     pckg().iEndpointID = MCC_ENDPOINT_ID( dataSink );
       
   219     aMessage.WriteDataToClientL( pckg );
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CMccController::CreateSessionL
       
   224 // Creates new UlDlClient session
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CMccController::CreateSessionL( TMMFMessage& aMessage )
       
   228     {
       
   229 	__CONTROLLER( "CMccController::CreateSessionL" )
       
   230     TMccCreateSessionPckg pckg;
       
   231     aMessage.ReadData1FromClientL( pckg );
       
   232 
       
   233     // Mcc ULDL Client -> NewL
       
   234     CMccUlDlClient* ulDlClient = 
       
   235         CMccUlDlClient::NewL( this, iResourcePool, iSessionIndex );
       
   236     CleanupStack::PushL( ulDlClient );
       
   237     iSessionArray.AppendL( ulDlClient );
       
   238     CleanupStack::Pop( ulDlClient );
       
   239 
       
   240 	__CONTROLLER_INT1( "CMccController::CreateSessionL, session id", iSessionIndex )
       
   241     pckg().iSessionID = iSessionIndex;
       
   242     iSessionIndex++;
       
   243     
       
   244     aMessage.WriteDataToClientL( pckg );
       
   245 	__CONTROLLER( "CMccController::CreateSessionL, exit" )
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CMccController::CloseSessionL
       
   250 // Closes UlDlClient
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CMccController::CloseSessionL( TMMFMessage& aMessage )
       
   254     {
       
   255 	__CONTROLLER( "CMccController::CloseSessionL" )
       
   256     TMccSessionPckg pckg;
       
   257     aMessage.ReadData1FromClientL( pckg );
       
   258 
       
   259     TInt session = FindSessionL( pckg().iSessionID );
       
   260     
       
   261 	TInt lastIndex = iCreatorArray.Count() - 1;
       
   262 	
       
   263 	for ( TInt i = lastIndex; i >= 0; i-- )
       
   264 	    {
       
   265    		if ( iCreatorArray[i]->GetSessionId() == pckg().iSessionID )
       
   266 			{
       
   267 			delete iCreatorArray[i];
       
   268 			iCreatorArray.Remove( i );
       
   269 			}
       
   270 	    }
       
   271 
       
   272     delete iSessionArray[session];
       
   273     iSessionArray.Remove( session );
       
   274 	__CONTROLLER( "CMccController::CloseSessionL, exit" )
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CMccController::CreateLinkL
       
   279 // Creates new Ul/Dl Client
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CMccController::CreateLinkL( TMMFMessage& aMessage )
       
   283     {
       
   284 	__CONTROLLER( "CMccController::CreateLinkL" )
       
   285     TMccCreateLinkPckg pckg;
       
   286     aMessage.ReadData1FromClientL( pckg );
       
   287     TInt session = FindSessionL( pckg().iSessionID );
       
   288     
       
   289     CMccAsyncLinkCreator* creator =
       
   290     CMccAsyncLinkCreator::NewLC( *this, iSessionArray[session] );
       
   291 
       
   292     creator->StartLinkCreationL( aMessage );
       
   293     iCreatorArray.AppendL( creator );
       
   294     
       
   295     CleanupStack::Pop( creator );
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CMccController::CloseLinkL
       
   300 // Closes a Ul/Dl Client
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CMccController::CloseLinkL( TMMFMessage& aMessage )
       
   304     {
       
   305 	__CONTROLLER( "CMccController::CloseLinkL" )
       
   306     TMccGenericMsgBuffer pckg;
       
   307     aMessage.ReadData1FromClientL( pckg );
       
   308     
       
   309     TInt session = FindSessionL( pckg().iSessionID );
       
   310     iSessionArray[session]->CloseLinkL( pckg().iLinkID );
       
   311     // Remove DTMF payload associated with the closed link.
       
   312     TInt index = iDtmfPayloadTypes.Find( pckg().iLinkID, 
       
   313         TMccKeyValuePair<TUint32, TUint8>::CompareKey );
       
   314     if ( KErrNotFound != index )
       
   315         {
       
   316         __CONTROLLER_INT1( "CMccController::CloseLinkL, REMOVING DTMF PT: ",
       
   317              iDtmfPayloadTypes[index].Value() );
       
   318         
       
   319         iDtmfPayloadTypes.Remove( index );
       
   320         }
       
   321     
       
   322 	__CONTROLLER( "CMccController::CloseLinkL, exit" )
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CMccController::StartStreamL
       
   327 // Starts stream
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void CMccController::StartStreamL( TMMFMessage& aMessage )
       
   331     {
       
   332 	__CONTROLLER( "CMccController::StartStreamL" )
       
   333     TMccStreamPckg pckg;
       
   334     aMessage.ReadData1FromClientL( pckg );
       
   335 
       
   336     TInt session = FindSessionL( pckg().iSessionID );
       
   337     iResourcePool->SetEnableRtcpL( pckg().iStreamID, pckg().iEnableRTCP );
       
   338     
       
   339     iSessionArray[session]->PlayL( pckg().iLinkID, pckg().iStreamID, pckg().iEndpointID,
       
   340                                          pckg().iStreamPaused,
       
   341                                          pckg().iEnableRTCP );
       
   342 	__CONTROLLER( "CMccController::StartStreamL, exit" )
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CMccController::StopStreamL
       
   347 // Stops stream
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CMccController::StopStreamL( TMMFMessage& aMessage )
       
   351     {
       
   352 	__CONTROLLER( "CMccController::StopStreamL" )
       
   353     TMccSessionPckg pckg;
       
   354     aMessage.ReadData1FromClientL( pckg );
       
   355 
       
   356     TInt session = FindSessionL( pckg().iSessionID );
       
   357     iSessionArray[session]->StopL( pckg().iLinkID, pckg().iStreamID,
       
   358     	pckg().iEndpointID );
       
   359 	__CONTROLLER( "CMccController::StopStreamL, exit" )
       
   360     }
       
   361 
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // CMccController::StartInactivityTimerL
       
   365 // Starts inactivity timer for a stream in a given session.
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 void CMccController::StartInactivityTimerL( TMMFMessage& aMessage )
       
   369 	{
       
   370 	__CONTROLLER( "CMccController::StartInactivityTimerL" )
       
   371 	TMccInactivityTimerPckg buffer;
       
   372     aMessage.ReadData1FromClientL( buffer );
       
   373    
       
   374     TInt session = FindSessionL( buffer().iSessionID );
       
   375     iSessionArray[session]->StartInactivityTimerL( buffer().iLinkID,
       
   376                                                    buffer().iStreamID,
       
   377                                                    buffer().iTimeoutTime );
       
   378 	__CONTROLLER( "CMccController::StartInactivityTimerL, exit" )
       
   379 	}	
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CMccController::StopInactivityTimerL
       
   383 // Stops inactivity timer for a stream in a given session.
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 void CMccController::StopInactivityTimerL( TMMFMessage& aMessage )
       
   387 	{
       
   388 	__CONTROLLER( "CMccController::StopInactivityTimerL" )
       
   389 	TMccGenericMsgBuffer buffer;
       
   390     aMessage.ReadData1FromClientL( buffer );
       
   391    
       
   392     TInt session = FindSessionL( buffer().iSessionID );
       
   393     iSessionArray[session]->StopInactivityTimerL( buffer().iLinkID,
       
   394                                                   buffer().iStreamID );
       
   395 	__CONTROLLER( "CMccController::StopInactivityTimerL, exit" )
       
   396 	}	
       
   397 
       
   398 // -----------------------------------------------------------------------------
       
   399 // CMccController::RequestEventNotificationL
       
   400 // Requests Event notification
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 void CMccController::RequestEventNotificationL( TMMFMessage& aMessage )
       
   404     {
       
   405 	__CONTROLLER( "CMccController::RequestEventNotificationL" )
       
   406     
       
   407     CancelMmfMessage();
       
   408 
       
   409     TMccEventPackage pckg;
       
   410     aMessage.ReadData1FromClientL( pckg );
       
   411     
       
   412     iMessage = new ( ELeave ) TMMFMessage( aMessage );
       
   413     
       
   414     SendEvent();
       
   415 
       
   416 	__CONTROLLER( "CMccController::RequestEventNotificationL, exit" )
       
   417     }
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CMccController::SendEvent
       
   421 // Calls SendEventL()
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CMccController::SendEvent()
       
   425     {
       
   426 	__CONTROLLER( "CMccController::SendEvent" )
       
   427     TRAPD( err, SendEventL() );
       
   428     if ( err )
       
   429         {
       
   430         __CONTROLLER_INT1( "CMccController::SendEventL, leaved with err:", err )
       
   431         }
       
   432     }
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CMccController::SendEventL
       
   436 // Sends event to clientside
       
   437 // -----------------------------------------------------------------------------
       
   438 //
       
   439 void CMccController::SendEventL()
       
   440     {
       
   441     if ( iMessage && iEventBuf.Count() )
       
   442         {
       
   443         TMccEvent* event = iEventBuf[ 0 ];
       
   444         
       
   445         TMccEventPackage pckg( *event );
       
   446         iMessage->WriteDataToClientL( pckg );
       
   447 
       
   448         // 2) Complete the iMessage.
       
   449         iMessage->Complete( KErrNone ); 
       
   450         delete iMessage;
       
   451         iMessage = 0;
       
   452         
       
   453         iEventBuf.Remove( 0 );
       
   454         delete event;        
       
   455         }
       
   456     }
       
   457     
       
   458 
       
   459 // -----------------------------------------------------------------------------
       
   460 // CMccController::AddDataSinkL
       
   461 // Adds data sink
       
   462 // -----------------------------------------------------------------------------
       
   463 //
       
   464 void CMccController::AddDataSinkL( MDataSink& aSink )
       
   465     {
       
   466 	__CONTROLLER( "CMccController::AddDataSinkL" )
       
   467 	__CONTROLLER_INT1( "CMccController sink", aSink.DataSinkType().iUid )
       
   468     
       
   469     iResourcePool->ReserveSinkL( &aSink, MCC_ENDPOINT_ID( &aSink ) );
       
   470     }
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // CMccController::AddDataSourceL
       
   474 // Adds data source
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 void CMccController::AddDataSourceL( MDataSource& aSource )
       
   478     {
       
   479 	__CONTROLLER( "CMccController::AddDataSourceL" )
       
   480 	__CONTROLLER_INT1( "CMccController source", aSource.DataSourceType().iUid )
       
   481 	
       
   482     iResourcePool->ReserveSourceL( &aSource, MCC_ENDPOINT_ID( &aSource ) );
       
   483     }
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CMccController::RemoveDataSourceL
       
   487 // -----------------------------------------------------------------------------
       
   488 //
       
   489 void CMccController::RemoveDataSourceL( MDataSource& aDataSource )
       
   490     {
       
   491     RemoveEndpointL( MCC_ENDPOINT_ID( &aDataSource ) ); 
       
   492     }
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CMccController::RemoveDataSinkL
       
   496 // -----------------------------------------------------------------------------
       
   497 //
       
   498 void CMccController::RemoveDataSinkL( MDataSink& aDataSink )
       
   499     {
       
   500     RemoveEndpointL( MCC_ENDPOINT_ID( &aDataSink ) ); 
       
   501     }
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // CMccController::ResetL
       
   505 // Not used
       
   506 // -----------------------------------------------------------------------------
       
   507 //
       
   508 void CMccController::ResetL()
       
   509     {
       
   510     User::Leave( KErrNotSupported );
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CMccController::PlayL
       
   515 // Not used
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 void CMccController::PlayL()
       
   519     {
       
   520     User::Leave( KErrNotSupported );
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // CMccController::StopL
       
   525 // Not used
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 void CMccController::StopL()
       
   529     {
       
   530     User::Leave( KErrNotSupported );
       
   531     }
       
   532 
       
   533 // -----------------------------------------------------------------------------
       
   534 // CMccController::PrimeL
       
   535 // Not used
       
   536 // -----------------------------------------------------------------------------
       
   537 //
       
   538 void CMccController::PrimeL()
       
   539     {
       
   540     User::Leave( KErrNotSupported );
       
   541     }
       
   542 
       
   543 // -----------------------------------------------------------------------------
       
   544 // CMccController::PauseL
       
   545 // Not used
       
   546 // -----------------------------------------------------------------------------
       
   547 //
       
   548 void CMccController::PauseL()
       
   549     {
       
   550     User::Leave( KErrNotSupported );
       
   551     }
       
   552 
       
   553 // -----------------------------------------------------------------------------
       
   554 // CMccController::PositionL
       
   555 // Not supported
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 TTimeIntervalMicroSeconds CMccController::PositionL() const
       
   559     {
       
   560     User::Leave( KErrNotSupported );
       
   561     // Make CW happy, lint #527
       
   562     TTimeIntervalMicroSeconds pos( static_cast<TUint64>( 0 ) );
       
   563     return pos;
       
   564     }
       
   565 
       
   566 // -----------------------------------------------------------------------------
       
   567 // CMccController::SetPositionL
       
   568 // Position setting not supported
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 void CMccController::SetPositionL( const TTimeIntervalMicroSeconds& /*aPosition*/ )
       
   572     {
       
   573     User::Leave( KErrNotSupported );
       
   574     }
       
   575 
       
   576 // -----------------------------------------------------------------------------
       
   577 // CMccController::DurationL
       
   578 // Duration not supported
       
   579 // -----------------------------------------------------------------------------
       
   580 //
       
   581 TTimeIntervalMicroSeconds CMccController::DurationL() const
       
   582     {
       
   583     User::Leave( KErrNotSupported );
       
   584     // Make CW happy, lint #527
       
   585     return TTimeIntervalMicroSeconds( static_cast<TUint64>( 0 ) );
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CMccController::SetPrioritySettings
       
   590 // Sets priority settings
       
   591 // -----------------------------------------------------------------------------
       
   592 //
       
   593 void CMccController::SetPrioritySettings( const TMMFPrioritySettings& aPrioritySettings )
       
   594     {
       
   595 	__CONTROLLER( "CMccController::SetPrioritySettings" )
       
   596     iPrioritySettings = aPrioritySettings;
       
   597     }
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // CMccController::SetPriorityL
       
   601 // Set link priority
       
   602 // -----------------------------------------------------------------------------
       
   603 //
       
   604 void CMccController::SetPriorityL( TMMFMessage& aMessage )
       
   605     {
       
   606 	__CONTROLLER( "CMccController::SetPriorityL" )
       
   607     TMccStreamPckg pckg;
       
   608     aMessage.ReadData1FromClientL( pckg );
       
   609 
       
   610     TMMFPrioritySettings settings;
       
   611     settings.iPref = EMdaPriorityPreferenceNone;
       
   612     settings.iState = EMMFStateIdle;
       
   613     settings.iPriority = pckg().iPriority;
       
   614 
       
   615     TInt session = FindSessionL( pckg().iSessionID );
       
   616     iSessionArray[session]->SetPriorityL( pckg().iLinkID, pckg().iStreamID,
       
   617                                           settings );
       
   618 	__CONTROLLER( "CMccController::SetPriorityL, exit" )
       
   619     }
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 // CMccController::GetNumberOfMetaDataEntriesL
       
   623 // -----------------------------------------------------------------------------
       
   624 //
       
   625 void CMccController::GetNumberOfMetaDataEntriesL( TInt& /*aNumberOfEntries*/ )
       
   626     {
       
   627     User::Leave( KErrNotSupported ); 
       
   628     }
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 // CMccController::GetMetaDataEntryL
       
   632 // -----------------------------------------------------------------------------
       
   633 //
       
   634 CMMFMetaDataEntry* CMccController::GetMetaDataEntryL( TInt /*aIndex*/ )
       
   635     {
       
   636     User::Leave( KErrNotSupported );
       
   637     // Make CW happy, lint #527    
       
   638     return NULL;
       
   639     }
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 // CMccController::CreateStreamL
       
   643 // Creates stream
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 void CMccController::CreateStreamL( TMMFMessage& aMessage )
       
   647     {
       
   648 	__CONTROLLER( "CMccController::CreateStreamL" )
       
   649 	
       
   650 	MDataSource* dataSource = iResourcePool->SourceCandidate();
       
   651 	MDataSink* dataSink = iResourcePool->SinkCandidate();
       
   652     __ASSERT_ALWAYS( dataSource, User::Leave( KErrNotReady ) );
       
   653     __ASSERT_ALWAYS( dataSink, User::Leave( KErrNotReady ) );
       
   654     
       
   655     TMccGenericMsgBuffer localBuffer;
       
   656     aMessage.ReadData1FromClientL( localBuffer );
       
   657 
       
   658     TInt session = FindSessionL( localBuffer().iSessionID );
       
   659     
       
   660     // Read stream creation parameters from message
       
   661     TMccCreateStreamParamPckg paramPckg;
       
   662     aMessage.ReadData2FromClientL( paramPckg );
       
   663    
       
   664    	TUint32 dataSourceUid = dataSource->DataSourceType().iUid;
       
   665    
       
   666     if ( MCC_INTERNAL_ENDPOINT( dataSourceUid ) )
       
   667 	   {  	
       
   668 	   CMccDataSource* mccDataSource = static_cast<CMccDataSource*>( dataSource );
       
   669 	   UpdateEndpointVolumeSettings( *mccDataSource );
       
   670 	   }
       
   671 	   
       
   672 	TUint32 dataSinkUid = dataSink->DataSinkType().iUid;
       
   673 
       
   674 	if ( MCC_INTERNAL_ENDPOINT( dataSinkUid ) )
       
   675 	   {  
       
   676 	   CMccDataSink* mccDataSink = static_cast<CMccDataSink*>( dataSink );
       
   677 	   UpdateEndpointVolumeSettings( *mccDataSink );	
       
   678 	   }
       
   679 
       
   680     localBuffer().iStreamID = iSessionArray[session]->GenerateStreamId();
       
   681  
       
   682     // TBD! IapId has to be fetched from link 
       
   683     
       
   684     // Standby should be enabled only for audio downlink
       
   685     TBool isStandBy( paramPckg().iStandByTimer != 0 &&
       
   686                      dataSink->DataSinkType() == KUidMmfAudioOutput &&
       
   687                      dataSource->DataSourceType() == KMccRtpSourceUid );
       
   688                      
       
   689     // TMccGenericMessage's iMessageFunction contains the stream type in the
       
   690     // case of stream creation, modify stream type if standby timer is enabled
       
   691     // and allowed (usage rights are checked in resource pool).
       
   692     TInt streamType = isStandBy ?
       
   693          KMccAudioDownlinkStandbyStream : paramPckg().iStreamType;
       
   694                      
       
   695     TMccResourceParams resourceParams( localBuffer().iSessionID, 
       
   696                                        localBuffer().iLinkID,
       
   697                                        localBuffer().iStreamID,
       
   698                                        0,
       
   699                                        isStandBy,
       
   700                                        streamType );
       
   701                                         
       
   702     iResourcePool->ReserveResourcesL( resourceParams );
       
   703     
       
   704     iSessionArray[session]->OpenL( localBuffer().iLinkID,
       
   705                                    localBuffer().iStreamID,
       
   706                                    streamType,
       
   707                                    paramPckg().iFourCC,
       
   708                                    dataSource,
       
   709                                    dataSink,
       
   710                                    paramPckg().iPrioritySettings );
       
   711   
       
   712     iSessionArray[session]->SetVolumeL( iVolume );
       
   713     
       
   714     // Need to write the stream ID back to client side
       
   715     aMessage.WriteDataToClientL( localBuffer );
       
   716 
       
   717 	__CONTROLLER( "CMccController::CreateStreamL, exit" )
       
   718     }
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CMccController::DeleteStreamL
       
   722 // Deletes stream
       
   723 // -----------------------------------------------------------------------------
       
   724 //
       
   725 void CMccController::DeleteStreamL( TMMFMessage& aMessage )
       
   726     {
       
   727 	__CONTROLLER( "CMccController::DeleteStreamL" )
       
   728     TMccSessionPckg pckg;
       
   729     aMessage.ReadData1FromClientL( pckg );
       
   730 
       
   731     TInt session = FindSessionL( pckg().iSessionID );
       
   732     iSessionArray[session]->CloseL( pckg().iLinkID, pckg().iStreamID );
       
   733     
       
   734     iResourcePool->FreeResources( pckg().iStreamID );
       
   735     
       
   736 	__CONTROLLER( "CMccController::DeleteStreamL, exit" )
       
   737     }
       
   738 
       
   739 // -----------------------------------------------------------------------------
       
   740 // CMccController::PrepareStreamL
       
   741 // Prepares stream
       
   742 // -----------------------------------------------------------------------------
       
   743 //
       
   744 void CMccController::PrepareStreamL( TMMFMessage& aMessage )
       
   745     {
       
   746 	__CONTROLLER( "CMccController::PrepareStreamL" )
       
   747     TMccSessionPckg pckg;
       
   748     aMessage.ReadData1FromClientL( pckg );
       
   749 
       
   750     TInt session = FindSessionL( pckg().iSessionID );
       
   751     iSessionArray[session]->PrepareL( pckg().iLinkID, pckg().iStreamID,
       
   752         	pckg().iEndpointID );
       
   753 	__CONTROLLER( "CMccController::PrepareStreamL, exit" )
       
   754     }
       
   755 
       
   756 // -----------------------------------------------------------------------------
       
   757 // CMccController::PauseStreamL
       
   758 // Pauses stream
       
   759 // -----------------------------------------------------------------------------
       
   760 //
       
   761 void CMccController::PauseStreamL( TMMFMessage& aMessage )
       
   762     {
       
   763 	__CONTROLLER( "CMccController::PauseStreamL" )
       
   764     TMccStreamPckg pckg;
       
   765     aMessage.ReadData1FromClientL( pckg );
       
   766 
       
   767     TInt session = FindSessionL( pckg().iSessionID );
       
   768     iResourcePool->SetEnableRtcpL( pckg().iStreamID, pckg().iEnableRTCP );
       
   769     iSessionArray[session]->PauseL( pckg().iLinkID, pckg().iStreamID,
       
   770     	pckg().iEndpointID, pckg().iEnableRTCP );
       
   771 	__CONTROLLER( "CMccController::PauseStreamL, exit" )
       
   772     }
       
   773 
       
   774 // -----------------------------------------------------------------------------
       
   775 // CMccController::ResumeStreamL
       
   776 // Resumes stream
       
   777 // -----------------------------------------------------------------------------
       
   778 //
       
   779 void CMccController::ResumeStreamL( TMMFMessage& aMessage )
       
   780     {
       
   781 	__CONTROLLER( "CMccController::ResumeStreamL" )
       
   782     TMccStreamPckg pckg;
       
   783     aMessage.ReadData1FromClientL( pckg );
       
   784 
       
   785     TInt session = FindSessionL( pckg().iSessionID );
       
   786     iResourcePool->SetEnableRtcpL( pckg().iStreamID, pckg().iEnableRTCP );
       
   787     iSessionArray[session]->ResumeL( pckg().iLinkID, pckg().iStreamID,
       
   788         pckg().iEndpointID, pckg().iEnableRTCP );
       
   789 	__CONTROLLER( "CMccController::ResumeStreamL, exit" )
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CMccController::ResumeStreamL
       
   794 // Resumes stream
       
   795 // -----------------------------------------------------------------------------
       
   796 //
       
   797 void CMccController::StreamsExistsL( TMMFMessage& aMessage )
       
   798     {
       
   799 	__CONTROLLER( "CMccController::StreamsExistsL" )
       
   800     TMccStreamPckg pckg;
       
   801     aMessage.ReadData1FromClientL( pckg );
       
   802 
       
   803     TInt session = FindSessionL( pckg().iSessionID );
       
   804     TBool ret = iSessionArray[session]->StreamsExistsL( pckg().iLinkID );
       
   805     if ( !ret )
       
   806         {
       
   807         User::Leave( KErrNotFound );
       
   808         }
       
   809 	__CONTROLLER( "CMccController::StreamsExistsL, exit" )
       
   810     }
       
   811 
       
   812 // -----------------------------------------------------------------------------
       
   813 // CMccController::CustomCommand
       
   814 // Controller custom commands
       
   815 // -----------------------------------------------------------------------------
       
   816 //
       
   817 void CMccController::CustomCommand( TMMFMessage& aMessage )
       
   818     {
       
   819     if( KMccUidInterface != aMessage.Destination().InterfaceId() )
       
   820         {
       
   821         // This message was not intended for us
       
   822         aMessage.Complete( KErrNotSupported );
       
   823         return;
       
   824         }
       
   825     else
       
   826         {
       
   827         // Interface ID matches ours, lets do the custom command
       
   828         TRAPD( err, CustomCommandL( aMessage ) )
       
   829 
       
   830         if( KErrNone != err )
       
   831             {
       
   832             // Complete the message as it leaved with error. This will probably
       
   833             // leave the client.
       
   834             aMessage.Complete( err );
       
   835             }
       
   836         else
       
   837             {
       
   838             // ERequestEventNotification is asynchronous and will be 
       
   839             // completed later when events start pouring in
       
   840             if( ERequestEventNotification != aMessage.Function() )
       
   841                 {
       
   842                 aMessage.Complete( err );
       
   843                 }
       
   844             }
       
   845         }
       
   846     }
       
   847 
       
   848 // -----------------------------------------------------------------------------
       
   849 // CMccController::CustomCommandL
       
   850 // Controller custom commands
       
   851 // -----------------------------------------------------------------------------
       
   852 //
       
   853 void CMccController::CustomCommandL( TMMFMessage& aMessage )
       
   854     {
       
   855     switch( aMessage.Function() )
       
   856         {
       
   857 		case EMccClose:
       
   858 			break;
       
   859 			
       
   860         case EMccGetSinkId:
       
   861             GetSinkIdL( aMessage );
       
   862             break;
       
   863         case EMccGetSourceId:
       
   864             GetSourceIdL( aMessage );
       
   865             break;
       
   866                         
       
   867         // Session
       
   868         case EMccCreateSession:
       
   869             CreateSessionL( aMessage );
       
   870             break;
       
   871         case EMccSetRemoteAddress:
       
   872             SetRemoteAddressL( aMessage );
       
   873             break;
       
   874         case EMccSetRemoteRtcpAddr:
       
   875         	SetRemoteRtcpAddrL( aMessage );
       
   876         	break;
       
   877         case EMccCloseSession:
       
   878             CloseSessionL( aMessage );
       
   879             break;
       
   880 
       
   881         // Link
       
   882         case EMccCreateLink:
       
   883             CreateLinkL( aMessage );
       
   884             break;
       
   885         case EMccCloseLink:
       
   886             CloseLinkL( aMessage );
       
   887             break;
       
   888 
       
   889         // Stream
       
   890         case EMccCreateStream:
       
   891             CreateStreamL( aMessage );
       
   892             break;
       
   893         case EMccPrepareStream:
       
   894             PrepareStreamL( aMessage );
       
   895             break;
       
   896         case EMccStartStream:
       
   897             StartStreamL( aMessage );
       
   898             break;
       
   899         case EMccPauseStream:
       
   900             PauseStreamL( aMessage );
       
   901             break;
       
   902         case EMccResumeStream:
       
   903             ResumeStreamL( aMessage );
       
   904             break;
       
   905         case EMccStopStream:
       
   906             StopStreamL( aMessage );
       
   907             break;
       
   908         case EMccDeleteStream:
       
   909             DeleteStreamL( aMessage );
       
   910             break;
       
   911         case EMccStreamSettings:
       
   912             StreamSettingsL( aMessage );
       
   913             break;
       
   914         case EMccStreamsExists:
       
   915             StreamsExistsL( aMessage );
       
   916             break;
       
   917         
       
   918         // Inactivity Timer
       
   919         case EMccInactivityTimerStart:
       
   920         	StartInactivityTimerL( aMessage );
       
   921         	break;
       
   922         case EMccInactivityTimerStop:
       
   923         	StopInactivityTimerL( aMessage );
       
   924         	break;
       
   925         
       
   926         // RTCP reports and non-RTCP data
       
   927         case EMccSendRtcpRR:
       
   928             SendRTCPReceiverReportL( aMessage );
       
   929             break;
       
   930         case EMccSendRtcpSR:
       
   931             SendRTCPSenderReportL( aMessage );
       
   932             break;
       
   933         case EMccSendRtcpData:
       
   934             SendRTCPDataL( aMessage );
       
   935             break;
       
   936             
       
   937         // Codec
       
   938         case EMccGetSupportedCodecs:
       
   939             GetSupportedCodecsL( aMessage );
       
   940             break;
       
   941         case EMccGetCodec:
       
   942             GetCodecL( aMessage );
       
   943             break;
       
   944         case EMccGetFmtpAttr:
       
   945             GetFmtpAttrL( aMessage );
       
   946             break;
       
   947         case EMccSetCodec:
       
   948             SetCodecL( aMessage );
       
   949             break;
       
   950         case EMccGetSupportedBitrates:
       
   951             GetSupportedBitratesL( aMessage );
       
   952             break;
       
   953             
       
   954         // SSRC
       
   955         case EMccGetSSRC:
       
   956             GetSSRCL( aMessage );
       
   957             break;
       
   958         case EMccSetAudioPriority:
       
   959             SetPriorityL( aMessage );
       
   960             break;
       
   961 
       
   962         // Camera
       
   963         case EMccEnableViewFinder:
       
   964             EnableViewFinderL( aMessage );
       
   965             break;
       
   966         case EMccDisableViewFinder:
       
   967             DisableViewFinderL( aMessage );
       
   968             break;
       
   969         case EMccGetViewFinderSettings:
       
   970             ViewFinderSettingsL( aMessage );
       
   971             break;
       
   972         case EMccGetCamInfo:
       
   973             GetCamInfoL( aMessage );        
       
   974             break;
       
   975         case EMccGetNumOfCams:
       
   976             GetNumOfCamsL( aMessage );        
       
   977             break;
       
   978         case EMccSetCamValue1:
       
   979             SetCamValue1L( aMessage );
       
   980             break;
       
   981         case EMccGetCamValue1:
       
   982             GetCamValue1L( aMessage );
       
   983             break;
       
   984         case EMccSetCamValue2:
       
   985             SetCamValue2L( aMessage );
       
   986             break;
       
   987         case EMccGetCamValue2:
       
   988             GetCamValue2L( aMessage );
       
   989             break;
       
   990             
       
   991         // Audio routing
       
   992         case EMccSetAudioRoute:
       
   993             SetAudioRouteL( aMessage );
       
   994             break;
       
   995         case EMccGetAudioRoute:
       
   996             GetAudioRouteL( aMessage );
       
   997             break;
       
   998 
       
   999         // Endpoint handling
       
  1000         case EMccReuse:
       
  1001             ReuseL( aMessage );
       
  1002             break;
       
  1003         case EMccGetReferenceCount:
       
  1004             ReferenceCountL( aMessage );
       
  1005             break;      
       
  1006         case EMccSetEndpointParameter:
       
  1007             SetEndpointParameterL( aMessage );
       
  1008             break;
       
  1009         case EMccGetEndpointParameter:
       
  1010             GetEndpointParameterL( aMessage );
       
  1011             break;
       
  1012         case EMccUpdateDataSink:
       
  1013         case EMccUpdateDataSource:
       
  1014             UpdateEndpointL( aMessage );
       
  1015             break;
       
  1016             
       
  1017         // transcode file
       
  1018         case EMccTranscodeFile:
       
  1019             TranscodeFileL( aMessage );
       
  1020             break;
       
  1021         case EMccCancelTranscodeFile:
       
  1022             CancelTranscodeFileL( aMessage );
       
  1023             break;
       
  1024             
       
  1025         // Generic    
       
  1026         case ERequestEventNotification:
       
  1027             RequestEventNotificationL( aMessage );
       
  1028             break;
       
  1029         case EMccSendMediaSignal:
       
  1030             SendMediaSignalL( aMessage );
       
  1031             break;
       
  1032         case EMccCancel:
       
  1033             CancelMmfMessage();        
       
  1034             break;
       
  1035             
       
  1036         // Secure    
       
  1037         case EMccBindContextIntoStream:
       
  1038             BindContextIntoStreamL( aMessage );
       
  1039             break;
       
  1040         case EMccRemoveContext:
       
  1041             RemoveContextL( aMessage );
       
  1042             break;    
       
  1043         default:
       
  1044             User::Leave( KErrNotSupported );
       
  1045             break;
       
  1046         }   // end of switch
       
  1047     }
       
  1048 
       
  1049 // -----------------------------------------------------------------------------
       
  1050 // CMccController::GetSupportedCodecsL
       
  1051 // Puts supported codecs into fourcc array
       
  1052 // -----------------------------------------------------------------------------
       
  1053 //
       
  1054 void CMccController::GetSupportedCodecsL( TMMFMessage& aMessage ) const
       
  1055     {
       
  1056     __CONTROLLER( "CMccController::GetSupportedCodecsL" )
       
  1057 
       
  1058     TMccSessionPckg pckg;
       
  1059     aMessage.ReadData1FromClientL( pckg );
       
  1060     TFixedArray<TFourCC, KMccFourCCArraySize>& codecs = pckg().iFourCCArray;
       
  1061     TInt index( 0 );
       
  1062     
       
  1063     // Audio codecs
       
  1064     CMMFDevSound* devSound = CMMFDevSound::NewL();
       
  1065     CleanupStack::PushL( devSound );
       
  1066     
       
  1067     TMMFPrioritySettings dummy;
       
  1068     RArray< TFourCC > outCodecs;
       
  1069     devSound->GetSupportedOutputDataTypesL( outCodecs, dummy );
       
  1070     CleanupClosePushL( outCodecs );
       
  1071     
       
  1072     RArray< TFourCC > inCodecs;
       
  1073     devSound->GetSupportedInputDataTypesL( inCodecs, dummy );
       
  1074     CleanupClosePushL( inCodecs );
       
  1075     
       
  1076     // Support dynamically checked from CMMFDevSound in HW
       
  1077     AddCodec( KMccFourCCIdAMRWB, outCodecs, inCodecs, codecs, index++ );
       
  1078     AddCodec( KMccFourCCIdAMRNB, outCodecs, inCodecs, codecs, index++ );
       
  1079     AddCodec( KMccFourCCIdG711, outCodecs, inCodecs, codecs, index++ );
       
  1080     AddCodec( KMccFourCCIdILBC, outCodecs, inCodecs, codecs, index++ );
       
  1081     AddCodec( KMccFourCCIdG729, outCodecs, inCodecs, codecs, index++ );
       
  1082     // Not in CMMFDevSound's list
       
  1083     codecs[ index++ ] = TFourCC( KMccFourCCIdDTMF ); 
       
  1084     codecs[ index++ ] = TFourCC( KMccFourCCIdRed );
       
  1085     codecs[ index++ ] = TFourCC( KMccFourCCIdCN );
       
  1086  
       
  1087     CleanupStack::PopAndDestroy( &inCodecs );
       
  1088     CleanupStack::PopAndDestroy( &outCodecs );
       
  1089     CleanupStack::PopAndDestroy( devSound );
       
  1090     
       
  1091     // Video codecs
       
  1092     codecs[ index++ ] = TFourCC( KMccFourCCIdAVC );
       
  1093     codecs[ index ] = TFourCC( KMccFourCCIdH263 );
       
  1094 
       
  1095     aMessage.WriteDataToClientL( pckg );
       
  1096 
       
  1097     __CONTROLLER( "CMccController::GetSupportedCodecsL, exit" )
       
  1098     }
       
  1099 
       
  1100 // -----------------------------------------------------------------------------
       
  1101 // CMccController::GetCodecL
       
  1102 // Gets current codec
       
  1103 // -----------------------------------------------------------------------------
       
  1104 //
       
  1105 void CMccController::GetCodecL( TMMFMessage& aMessage )
       
  1106     {
       
  1107 	__CONTROLLER( "CMccController::GetCodecL" )
       
  1108     TMccGenericMsgBuffer pckg;
       
  1109 	TMccCodecInfo codecInfo;
       
  1110     aMessage.ReadData1FromClientL( pckg );
       
  1111 
       
  1112     if( pckg().iSessionID == 0 && pckg().iLinkID == 0)
       
  1113     	{
       
  1114     	TUid targetUid;
       
  1115     	targetUid.iUid = (TUint) pckg().iStreamID;
       
  1116     	CMccUlDlClient::GetCodecDefaultsL( targetUid, pckg().iParam1, codecInfo);
       
  1117     	}
       
  1118     else
       
  1119     	{
       
  1120 	    TInt session = FindSessionL( pckg().iSessionID );
       
  1121 	    iSessionArray[session]->GetCodecL( pckg().iLinkID,
       
  1122 	                                       pckg().iStreamID,
       
  1123 	                                       codecInfo );    	
       
  1124     	}		    	
       
  1125     TMccCodecInfoBuffer writeBuffer( codecInfo );
       
  1126     aMessage.WriteDataToClientL( writeBuffer );    
       
  1127 	__CONTROLLER( "CMccController::GetCodecL, exit" )
       
  1128     }
       
  1129 
       
  1130 // -----------------------------------------------------------------------------
       
  1131 // CMccController::GetFmtpAttrL
       
  1132 // Gets current codec
       
  1133 // -----------------------------------------------------------------------------
       
  1134 //
       
  1135 void CMccController::GetFmtpAttrL( TMMFMessage& /*aMessage*/ )
       
  1136     {
       
  1137 	__CONTROLLER( "CMccController::GetFmtpAttrL" )
       
  1138 	User::Leave( KErrNotSupported );
       
  1139 	__CONTROLLER( "CMccController::GetFmtpAttrL, exit" )
       
  1140     }
       
  1141 
       
  1142 // -----------------------------------------------------------------------------
       
  1143 // CMccController::SetCodecL
       
  1144 // Sets codec.
       
  1145 // -----------------------------------------------------------------------------
       
  1146 //
       
  1147 void CMccController::SetCodecL( TMMFMessage& aMessage )
       
  1148     {
       
  1149 	__CONTROLLER( "CMccController::SetCodecL" )
       
  1150     TMccCodecInfoBuffer readBuffer;
       
  1151     aMessage.ReadData1FromClientL( readBuffer );
       
  1152     
       
  1153     TInt session = FindSessionL( readBuffer().iSessionID );
       
  1154     iSessionArray[session]->SetCodecInformationL( readBuffer().iLinkID,
       
  1155                                                   readBuffer().iStreamID,
       
  1156                                                   readBuffer(),
       
  1157                                                   KNullDesC8 );
       
  1158     aMessage.WriteDataToClientL( readBuffer );
       
  1159     
       
  1160     if ( 0 == readBuffer().iSdpName.Compare( KTelephoneEvent ) )
       
  1161         {
       
  1162         TInt index = iDtmfPayloadTypes.Find( readBuffer().iLinkID, 
       
  1163             TMccKeyValuePair<TUint32, TUint8>::CompareKey );
       
  1164         if ( KErrNotFound != index )
       
  1165             {
       
  1166             // Remove DTMF payload type for audio muting functionality
       
  1167             __CONTROLLER_INT1( "CMccController::SetCodecL, REMOVE INDEX:",
       
  1168                 index );
       
  1169             iDtmfPayloadTypes.Remove( index );
       
  1170             }
       
  1171             // Save DTMF payload type for audio muting functionality during
       
  1172             // DTMF sending.
       
  1173             __CONTROLLER_INT1( "CMccController::SetCodecL, SAVING DTMF PT:",
       
  1174                 readBuffer().iPayloadType );
       
  1175             TMccKeyValuePair< TUint32, TUint8 > keyValuePair( 
       
  1176                 readBuffer().iLinkID, readBuffer().iPayloadType );
       
  1177             iDtmfPayloadTypes.AppendL( keyValuePair );
       
  1178         }
       
  1179     
       
  1180 	__CONTROLLER( "CMccController::SetCodecL, exit" )
       
  1181     }
       
  1182 
       
  1183 // -----------------------------------------------------------------------------
       
  1184 // CMccController::GetSupportedBitratesL
       
  1185 // Gets the supported bitrates from the codec of the specified stream
       
  1186 // -----------------------------------------------------------------------------
       
  1187 //
       
  1188 void CMccController::GetSupportedBitratesL( TMMFMessage& aMessage )
       
  1189     {
       
  1190 	__CONTROLLER( "CMccController::GetSupportedBitratesL" )
       
  1191     TMccGenericMsgBuffer pckg;
       
  1192     aMessage.ReadData1FromClientL( pckg );
       
  1193     TInt session = FindSessionL( pckg().iSessionID );
       
  1194     
       
  1195     RArray<TUint> bitrateArray;    
       
  1196     iSessionArray[session]->GetSupportedBitratesL( pckg().iLinkID,
       
  1197                                                    pckg().iStreamID,
       
  1198                                                    bitrateArray );
       
  1199 
       
  1200     // Move the bitrates to a package descriptor
       
  1201     TMccBitrates bitrates;
       
  1202     for ( TInt i = 0; ( i < bitrateArray.Count() ) && i < KMaxBitrates; i++ )
       
  1203         {
       
  1204         bitrates.iBitrates[i] = bitrateArray[i];
       
  1205         }
       
  1206     bitrateArray.Close();
       
  1207     
       
  1208     TMccBitratesPckg writeBuffer( bitrates );
       
  1209     aMessage.WriteDataToClientL( writeBuffer );
       
  1210 	__CONTROLLER( "CMccController::GetSupportedBitratesL, exit" )
       
  1211     }
       
  1212 
       
  1213 
       
  1214 // -----------------------------------------------------------------------------
       
  1215 // CMccController::GetSSRCL
       
  1216 // Gets the syncronization source from the specified stream
       
  1217 // -----------------------------------------------------------------------------
       
  1218 //
       
  1219 void CMccController::GetSSRCL ( TMMFMessage& aMessage )
       
  1220     {
       
  1221 	__CONTROLLER( "CMccController::GetSSRCL" )
       
  1222     TMccGenericMsgBuffer pckg;
       
  1223     aMessage.ReadData1FromClientL( pckg );
       
  1224     TInt session = FindSessionL( pckg().iSessionID );
       
  1225     
       
  1226     TMccSSRC ssrc;
       
  1227     iSessionArray[session]->GetSSRCL( pckg().iLinkID,
       
  1228                                       pckg().iStreamID,
       
  1229                                       ssrc.iSSRC );
       
  1230                                      
       
  1231     TMccSSRCPckg ssrcPckg(ssrc);
       
  1232     aMessage.WriteDataToClientL( ssrcPckg );
       
  1233 	__CONTROLLER( "CMccController::GetSSRCL, exit" )
       
  1234     }
       
  1235     
       
  1236 // -----------------------------------------------------------------------------
       
  1237 // CMccController::SetRemoteAddressL
       
  1238 // Sets remote address
       
  1239 // -----------------------------------------------------------------------------
       
  1240 //
       
  1241 void CMccController::SetRemoteAddressL( TMMFMessage& aMessage )
       
  1242     {
       
  1243 	__CONTROLLER( "CMccController::SetRemoteAddressL" )
       
  1244     TMccAddressPckg pckg;
       
  1245     aMessage.ReadData1FromClientL( pckg );
       
  1246 
       
  1247     TInt session = FindSessionL( pckg().iSessionID );
       
  1248     
       
  1249     iSessionArray[session]->SetRemoteAddressL( pckg().iAddress,
       
  1250                                                pckg().iLinkID );
       
  1251 	__CONTROLLER( "CMccController::SetRemoteAddressL, exit" )
       
  1252     }
       
  1253 
       
  1254 // -----------------------------------------------------------------------------
       
  1255 // CMccController::SetRemoteRtcpAddrL
       
  1256 // Sets remote address
       
  1257 // -----------------------------------------------------------------------------
       
  1258 //
       
  1259 void CMccController::SetRemoteRtcpAddrL( TMMFMessage& aMessage )
       
  1260     {
       
  1261 	__CONTROLLER( "CMccController::SetRemoteRtcpAddrL" )
       
  1262     TMccAddressPckg pckg;
       
  1263     aMessage.ReadData1FromClientL( pckg );
       
  1264 
       
  1265     TInt session = FindSessionL( pckg().iSessionID );
       
  1266     
       
  1267     iSessionArray[session]->SetRemoteRtcpAddrL( pckg().iAddress,
       
  1268                                                pckg().iLinkID );
       
  1269 	__CONTROLLER( "CMccController::SetRemoteAddrL, exit" )
       
  1270     }
       
  1271 
       
  1272 // -----------------------------------------------------------------------------
       
  1273 // CMccController::SendMccEventToClient
       
  1274 // Enqueues MccEvent to eventbuffer and sends it to client
       
  1275 // -----------------------------------------------------------------------------
       
  1276 //
       
  1277 TInt CMccController::SendMccEventToClient( TMccEvent& aEvent )
       
  1278     {
       
  1279 	__CONTROLLER( "CMccController::SendMccEventToClient" )
       
  1280 	__CONTROLLER_INT1( "CMccController event category", aEvent.iEventCategory )
       
  1281 	__CONTROLLER_INT1( "CMccController event type", aEvent.iEventType )
       
  1282    
       
  1283     TInt err( KErrNone );
       
  1284     TBool discardEvent( EFalse );
       
  1285     TBool streamControl( EFalse );
       
  1286     TMccEvent* additionalControlEvent( NULL );
       
  1287     
       
  1288     // Show event to the QosController
       
  1289     discardEvent = iQosController->EventReceived( aEvent );
       
  1290     
       
  1291     if ( !discardEvent )
       
  1292         {
       
  1293         if ( aEvent.iEventCategory == KMccEventCategoryStream ) 
       
  1294     	    {
       
  1295     	    if ( aEvent.iEventType == KMccStreamMMFEvent &&
       
  1296                  aEvent.iErrorCode == KErrDied )
       
  1297                 {
       
  1298                 // Resource not available, disable the endpoint
       
  1299                 
       
  1300                 __CONTROLLER( "CMccController::SendMccEventToClient, \
       
  1301 MMF resource not available" )
       
  1302                 
       
  1303                 discardEvent = ETrue;
       
  1304                 streamControl = ETrue;
       
  1305                 
       
  1306                 // Modify event to be "resource not available" event
       
  1307                 aEvent.iEventCategory = KMccEventCategoryStream;
       
  1308                 aEvent.iEventType = KMccResourceNotAvailable;
       
  1309                 StoreAndSendEvent( aEvent );
       
  1310                 
       
  1311                 // Modify event to be "stream control" event
       
  1312                 aEvent.iEventType = KMccStreamPaused;
       
  1313                 }
       
  1314             else
       
  1315                 {
       
  1316                 TBool effectiveStandby( EFalse );
       
  1317         	   	err = iResourcePool->EventReceived( aEvent, 
       
  1318         	   	                                    discardEvent, 
       
  1319         	   	                                    effectiveStandby,
       
  1320         	   	                                    &additionalControlEvent );
       
  1321         	   	streamControl = effectiveStandby;
       
  1322                 }
       
  1323     	    }
       
  1324         else if ( aEvent.iEventCategory == KMccEventCategoryStreamControl )
       
  1325             {
       
  1326             // Filter stream control event over here
       
  1327             discardEvent = ETrue;
       
  1328             streamControl = ETrue;
       
  1329             }
       
  1330         else if ( KMccEventCategoryDtmf == aEvent.iEventCategory &&
       
  1331                   KMccDtmfControl == aEvent.iEventType )
       
  1332             {
       
  1333             // Unmute RTP sink regarding audio payloads when DTMF sending is
       
  1334             // stopped. Audio can be sent between key presses.
       
  1335             const TMccDtmfEventData& dtmfEvent = 
       
  1336                 (*reinterpret_cast<const TMccDtmfEventDataPackage*>( 
       
  1337                 &aEvent.iEventData ) ) ();
       
  1338             
       
  1339             if ( KMccDtmfManualStop == dtmfEvent.iDtmfEventType ||
       
  1340                  KMccDtmfManualAbort == dtmfEvent.iDtmfEventType ||
       
  1341                  KMccDtmfSequenceStop == dtmfEvent.iDtmfEventType ||
       
  1342                  KMccDtmfSequenceAbort == dtmfEvent.iDtmfEventType ||
       
  1343                  KMccDtmfStopInDtmfString == dtmfEvent.iDtmfEventType )
       
  1344                 {
       
  1345                 MDataSource* dataSource;
       
  1346                 MDataSink* dataSink;
       
  1347                 err = iResourcePool->FindResource( aEvent.iLinkId, 
       
  1348                     aEvent.iEndpointId, KMccRtpSinkUid, &dataSource, 
       
  1349                     &dataSink );
       
  1350                 
       
  1351                 if ( KErrNone == err )
       
  1352                     {
       
  1353                     CMccRtpDataSink* rtpSink 
       
  1354                         = static_cast<CMccRtpDataSink*>( dataSink );
       
  1355                     if ( rtpSink )
       
  1356                         {
       
  1357                         rtpSink->Mute( EFalse, KPayloadTypeUndefined );
       
  1358                         }
       
  1359                     }
       
  1360                 else
       
  1361                     {
       
  1362                     __CONTROLLER_INT1( 
       
  1363                         "CMccController::SendMccEventToClient DTMF ERR", err )
       
  1364                     }
       
  1365                 }
       
  1366             }
       
  1367         else
       
  1368             {
       
  1369             }
       
  1370         }
       
  1371 	    
       
  1372     if ( !err && !discardEvent )
       
  1373 	    {
       
  1374 	    err = StoreAndSendEvent( aEvent );
       
  1375 	    }
       
  1376     
       
  1377     if ( !err && streamControl )
       
  1378 	    {
       
  1379 	    TRAP( err, StreamActionL( aEvent, additionalControlEvent ) );
       
  1380 	    if ( err )
       
  1381 	        {
       
  1382 	        // Modify event to contain error info
       
  1383 	        aEvent.iEventCategory = KMccEventCategoryStream;
       
  1384 	        aEvent.iEventType = KMccStreamError;
       
  1385 	        aEvent.iEventData.Zero();
       
  1386 	        aEvent.iErrorCode = err;
       
  1387 	        StoreAndSendEvent( aEvent );
       
  1388 	        }
       
  1389 	    }
       
  1390 	    
       
  1391 	delete additionalControlEvent;
       
  1392 	   
       
  1393     return err;
       
  1394     }
       
  1395 
       
  1396 // -----------------------------------------------------------------------------
       
  1397 // CMccController::PauseByEndPointIdL
       
  1398 // -----------------------------------------------------------------------------
       
  1399 //
       
  1400 void CMccController::PauseByEndPointIdL( 
       
  1401     const TMccEvent& aEvent, 
       
  1402     TUint32 aEndPointId )
       
  1403 	{
       
  1404 	TInt session = FindSessionL( aEvent.iSessionId );
       
  1405     
       
  1406     iSessionArray[session]->PauseL( 
       
  1407             aEvent.iLinkId, 
       
  1408      		aEvent.iStreamId, 
       
  1409      		aEndPointId, 
       
  1410      		iResourcePool->EnableRtcp( aEvent.iStreamId ) );	
       
  1411 	}
       
  1412 
       
  1413 // -----------------------------------------------------------------------------
       
  1414 // CMccController::ResumeByEndPointIdL
       
  1415 // -----------------------------------------------------------------------------
       
  1416 //
       
  1417 void CMccController::ResumeByEndPointIdL( 
       
  1418     const TMccEvent& aEvent, 
       
  1419     TUint32 aEndPointId )
       
  1420 	{
       
  1421 	TInt session = FindSessionL( aEvent.iSessionId );
       
  1422     
       
  1423     iSessionArray[session]->ResumeL( 
       
  1424             aEvent.iLinkId, 
       
  1425      		aEvent.iStreamId, 
       
  1426      		aEndPointId, 
       
  1427      		iResourcePool->EnableRtcp( aEvent.iStreamId ) );	
       
  1428 	}
       
  1429 
       
  1430 // -----------------------------------------------------------------------------
       
  1431 // CMccController::UpdateEndpointVolumeSettings
       
  1432 // -----------------------------------------------------------------------------
       
  1433 //
       
  1434 TInt CMccController::UpdateEndpointVolumeSettings( MMccSourceSink& aEndpoint )
       
  1435     {
       
  1436     // Some endpoints do not support volume setting, that's ok
       
  1437     TRAPD( err, aEndpoint.SetParameterL( KMccSpeakerMaxVolume, 
       
  1438                                          TPckgBuf<TInt>( iMaxVolume ) ) );
       
  1439     if ( !err )
       
  1440         {
       
  1441         TRAP( err, aEndpoint.SetParameterL( KMccSpeakerVolume, 
       
  1442                                             TPckgBuf<TInt>( iVolume ) ) );
       
  1443         }
       
  1444     return err;
       
  1445     }
       
  1446 
       
  1447 // -----------------------------------------------------------------------------
       
  1448 // CMccController::StateChange
       
  1449 // -----------------------------------------------------------------------------
       
  1450 //
       
  1451 void CMccController::StateChange( TInt /*aState*/, TUint32 /*aLinkId*/ )
       
  1452 	{		
       
  1453 	__CONTROLLER( "CMccController::SendMccEventToClient ignoring" )
       
  1454 	}
       
  1455 	
       
  1456 // -----------------------------------------------------------------------------
       
  1457 // CMccController::ErrorOccured
       
  1458 // -----------------------------------------------------------------------------
       
  1459 //
       
  1460 void CMccController::ErrorOccured( 
       
  1461     TInt aError, 
       
  1462     TUint32 aSessionId, 
       
  1463     TUint32 aLinkId,
       
  1464 	TUint32 aStreamId, 
       
  1465 	TUint32 aEndpointId )
       
  1466 	{	
       
  1467 	__CONTROLLER_INT1( "CMccController::ErrorOccured", aError )
       
  1468 	__CONTROLLER_INT1( "CMccController sessionid",  aSessionId )
       
  1469 	__CONTROLLER_INT1( "CMccController linkid",  aLinkId )
       
  1470 	__CONTROLLER_INT1( "CMccController streamId",  aStreamId )
       
  1471 	__CONTROLLER_INT1( "CMccController endpointId",  aEndpointId )
       
  1472 	
       
  1473     if ( KErrNone != aError )
       
  1474         {
       
  1475         TMccEvent event( aSessionId, aLinkId, aStreamId, aEndpointId,
       
  1476             KMccEventCategoryStream, KMccStreamError, aError, KNullDesC8 );
       
  1477         
       
  1478         SendMccEventToClient( event );            
       
  1479         }
       
  1480         
       
  1481 	__CONTROLLER( "CMccController::ErrorOccured, exit" )
       
  1482 	}
       
  1483     
       
  1484 // -----------------------------------------------------------------------------
       
  1485 // CMccController::StreamSettingsL
       
  1486 // Sets stream settings
       
  1487 // -----------------------------------------------------------------------------
       
  1488 //
       
  1489 void CMccController::StreamSettingsL( TMMFMessage& aMessage )
       
  1490     {
       
  1491     aMessage.ReadData1FromClientL( iStreamPckg );
       
  1492     // Check the session ID already at this stage to avoid a panic from the MMF
       
  1493     TInt dummy = FindSessionL( iStreamPckg().iSessionID );
       
  1494     dummy = dummy;
       
  1495     }
       
  1496 
       
  1497 // -----------------------------------------------------------------------------
       
  1498 // CMccController::SendRTCPReceiverReport
       
  1499 // Sends a RTCP receiver report
       
  1500 // -----------------------------------------------------------------------------
       
  1501 //
       
  1502 void CMccController::SendRTCPReceiverReportL( TMMFMessage& aMessage ) 
       
  1503     {
       
  1504 	__CONTROLLER( "CMccController::SendRTCPReceiverReportL" )
       
  1505     TMccGenericMsgBuffer buffer;
       
  1506     aMessage.ReadData1FromClientL( buffer );
       
  1507    
       
  1508     TInt session = FindSessionL( buffer().iSessionID );
       
  1509     iSessionArray[session]->SendRTCPReceiverReportL( buffer().iLinkID,
       
  1510                                                      buffer().iStreamID );
       
  1511 	__CONTROLLER( "CMccController::SendRTCPReceiverReportL, exit" )
       
  1512     }
       
  1513     
       
  1514 // -----------------------------------------------------------------------------
       
  1515 // CMccController::SendRTCPSenderReport
       
  1516 // Sends a RTCP receiver report
       
  1517 // -----------------------------------------------------------------------------
       
  1518 //
       
  1519 void CMccController::SendRTCPSenderReportL( TMMFMessage& aMessage ) 
       
  1520     {
       
  1521 	__CONTROLLER( "CMccController::SendRTCPSenderReportL" )
       
  1522     TMccGenericMsgBuffer buffer;
       
  1523     aMessage.ReadData1FromClientL( buffer );
       
  1524     TInt session = FindSessionL( buffer().iSessionID );
       
  1525     iSessionArray[session]->SendRTCPSenderReportL( buffer().iLinkID,
       
  1526                                                    buffer().iStreamID );
       
  1527 	__CONTROLLER( "CMccController::SendRTCPSenderReportL, exit" )
       
  1528     }    
       
  1529 
       
  1530 // -----------------------------------------------------------------------------
       
  1531 // CMccController::SendRTCPDataL
       
  1532 // Sends non-RTCP data
       
  1533 // -----------------------------------------------------------------------------
       
  1534 //
       
  1535 void CMccController::SendRTCPDataL( TMMFMessage& aMessage ) 
       
  1536     {
       
  1537 	__CONTROLLER( "CMccController::SendRTCPDataL" )
       
  1538     TMccGenericMsgBuffer buffer;
       
  1539     aMessage.ReadData1FromClientL( buffer );
       
  1540     TInt session = FindSessionL( buffer().iSessionID );
       
  1541 
       
  1542     // Copy the data locally        
       
  1543     HBufC8* dataBuf( NULL ); 
       
  1544     dataBuf = HBufC8::NewLC( aMessage.SizeOfData2FromClient() );
       
  1545     TPtr8 ptr( dataBuf->Des() ); 
       
  1546     aMessage.ReadData2FromClientL( ptr );
       
  1547     iSessionArray[session]->SendRTCPDataL( buffer().iLinkID,
       
  1548                                            buffer().iStreamID,
       
  1549                                            *dataBuf );
       
  1550     CleanupStack::PopAndDestroy( dataBuf );
       
  1551 	__CONTROLLER( "CMccController::SendRTCPDataL, exit" )
       
  1552     }    
       
  1553 
       
  1554 // -----------------------------------------------------------------------------
       
  1555 // CMccController::MapdGetVolumeL
       
  1556 // Gets downlink volume. 
       
  1557 // -----------------------------------------------------------------------------
       
  1558 //
       
  1559 void CMccController::MapdGetVolumeL( TInt& aVolume )
       
  1560     {
       
  1561     aVolume = iVolume;
       
  1562     }
       
  1563 
       
  1564 // -----------------------------------------------------------------------------
       
  1565 // CMccController::MapdGetMaxVolumeL
       
  1566 // Gets downlink stream Max volume. Uses stream settings from iStreamPckg.
       
  1567 // -----------------------------------------------------------------------------
       
  1568 //
       
  1569 void CMccController::MapdGetMaxVolumeL( TInt& aMaxVolume )
       
  1570     {
       
  1571     aMaxVolume = iMaxVolume;
       
  1572     }
       
  1573 
       
  1574 // -----------------------------------------------------------------------------
       
  1575 // CMccController::MapdSetVolumeL
       
  1576 // Sets volume to all sessions
       
  1577 // -----------------------------------------------------------------------------
       
  1578 //
       
  1579 void CMccController::MapdSetVolumeL( TInt aVolume )
       
  1580     {
       
  1581     if ( aVolume >= 0 && aVolume <= iMaxVolume ) 
       
  1582         {
       
  1583         iVolume = aVolume;
       
  1584 
       
  1585         for ( TInt i=0; i < iSessionArray.Count(); i++ )
       
  1586             {
       
  1587             iSessionArray[i]->SetVolumeL( aVolume );
       
  1588             }
       
  1589         }
       
  1590     else 
       
  1591         {
       
  1592         User::Leave( KErrArgument );
       
  1593         }
       
  1594     }
       
  1595 
       
  1596 // -----------------------------------------------------------------------------
       
  1597 // CMccController::MapdGetBalanceL
       
  1598 // Gets play balance. Uses stream settings from iStreamPckg.
       
  1599 // -----------------------------------------------------------------------------
       
  1600 //
       
  1601 void CMccController::MapdGetBalanceL( TInt& aBalance )
       
  1602     {
       
  1603     TInt left( 0 );
       
  1604     TInt right( 0 );
       
  1605     TInt session = FindSessionL( iStreamPckg().iSessionID );
       
  1606     iSessionArray[session]->GetPlayBalanceL( iStreamPckg().iLinkID,
       
  1607         iStreamPckg().iStreamID,
       
  1608         left, right );
       
  1609 
       
  1610     // The right + left balances are <= 100 (%)
       
  1611     // Here, the balances are converted to one value between -100 and 100 (L-R)
       
  1612     aBalance = ( KNumValue2 * right ) - KMaxBalance;
       
  1613     }
       
  1614 
       
  1615 // -----------------------------------------------------------------------------
       
  1616 // CMccController::MapdSetBalanceL
       
  1617 // Sets play balance. Uses stream settings from iStreamPckg.
       
  1618 // -----------------------------------------------------------------------------
       
  1619 //
       
  1620 void CMccController::MapdSetBalanceL( TInt aBalance )
       
  1621     {
       
  1622     if( aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight )
       
  1623         {
       
  1624         User::Leave( KErrArgument );
       
  1625         }
       
  1626 
       
  1627     // The right + left balances should be <= 100 (%)
       
  1628     TInt right = ( KMaxBalance + aBalance ) / KNumValue2;
       
  1629     TInt left = KMaxBalance - right;
       
  1630 
       
  1631     TInt session = FindSessionL( iStreamPckg().iSessionID );
       
  1632     iSessionArray[session]->SetPlayBalanceL( iStreamPckg().iLinkID,
       
  1633                                              iStreamPckg().iStreamID,
       
  1634                                              left, right );
       
  1635     }
       
  1636 
       
  1637 // -----------------------------------------------------------------------------
       
  1638 // CMccController::MapdSetVolumeRampL
       
  1639 // -----------------------------------------------------------------------------
       
  1640 //
       
  1641 void CMccController::MapdSetVolumeRampL( const TTimeIntervalMicroSeconds& /*aRampDuration*/ )
       
  1642     {
       
  1643     User::Leave( KErrNotSupported );
       
  1644     }
       
  1645 
       
  1646 // -----------------------------------------------------------------------------
       
  1647 // CMccController::MardSetGainL
       
  1648 // Sets uplink gain to all sessions.
       
  1649 // -----------------------------------------------------------------------------
       
  1650 //
       
  1651 void CMccController::MardSetGainL( TInt aGain )
       
  1652     {
       
  1653     iGain = aGain;
       
  1654 
       
  1655     for ( TInt i=0; i < iSessionArray.Count(); i++ )
       
  1656         {
       
  1657         iSessionArray[i]->SetGainL(aGain);
       
  1658         }
       
  1659     }
       
  1660 
       
  1661 // -----------------------------------------------------------------------------
       
  1662 // CMccController::MardGetMaxGainL
       
  1663 // Gets uplink stream Max gain. Uses stream settings from iStreamPckg.
       
  1664 // -----------------------------------------------------------------------------
       
  1665 //
       
  1666 void CMccController::MardGetMaxGainL( TInt& aMaxGain )
       
  1667     {
       
  1668     aMaxGain = iMaxGain;
       
  1669     }
       
  1670 
       
  1671 // -----------------------------------------------------------------------------
       
  1672 // CMccController::MardGetGainL
       
  1673 // Gets uplink gain.
       
  1674 // -----------------------------------------------------------------------------
       
  1675 //
       
  1676 void CMccController::MardGetGainL( TInt& aGain )
       
  1677     {
       
  1678     aGain = iGain;
       
  1679     }
       
  1680 
       
  1681 // -----------------------------------------------------------------------------
       
  1682 // CMccController::MardSetBalanceL
       
  1683 // Sets record balance. Uses stream settings from iStreamPckg.
       
  1684 // -----------------------------------------------------------------------------
       
  1685 //
       
  1686 void CMccController::MardSetBalanceL( TInt aRBalance )
       
  1687     {
       
  1688     if( aRBalance < KMMFBalanceMaxLeft || aRBalance > KMMFBalanceMaxRight )
       
  1689         {
       
  1690         User::Leave( KErrArgument );
       
  1691         }
       
  1692 
       
  1693     // The right + left balances should be <= 100%
       
  1694     TInt right = ( KMaxBalance + aRBalance ) / KNumValue2;
       
  1695     TInt left = KMaxBalance - right;
       
  1696 
       
  1697     TInt session = FindSessionL( iStreamPckg().iSessionID );
       
  1698     iSessionArray[session]->SetRecordBalanceL( iStreamPckg().iLinkID,
       
  1699                                                iStreamPckg().iStreamID, 
       
  1700                                                left, right );
       
  1701     }
       
  1702 
       
  1703 // -----------------------------------------------------------------------------
       
  1704 // CMccController::MardGetBalanceL
       
  1705 // Gets record balance. Uses stream settings from iStreamPckg.
       
  1706 // -----------------------------------------------------------------------------
       
  1707 //
       
  1708 void CMccController::MardGetBalanceL( TInt& aRecBalance )
       
  1709     {   
       
  1710     TInt left( 0 );
       
  1711     TInt right( 0 );
       
  1712     TInt session = FindSessionL( iStreamPckg().iSessionID );
       
  1713     iSessionArray[session]->GetRecordBalanceL( iStreamPckg().iLinkID,
       
  1714         iStreamPckg().iStreamID, left, right );
       
  1715 
       
  1716     // The right + left balances are <= 100 (%)
       
  1717     // Here, the balances are converted to one value between -100 and 100 (L-R)
       
  1718     aRecBalance = ( KNumValue2 * right ) - KMaxBalance;
       
  1719     }
       
  1720 
       
  1721 // -----------------------------------------------------------------------------
       
  1722 // CMccController::FindSessionL
       
  1723 // Finds sessionindex for sessionarray
       
  1724 // -----------------------------------------------------------------------------
       
  1725 //
       
  1726 TInt CMccController::FindSessionL( TUint32 aSessionID )
       
  1727     {
       
  1728 	__CONTROLLER_INT1( "CMccController::FindSessionL, session id", aSessionID )
       
  1729     TInt sessionCount = iSessionArray.Count();
       
  1730     TInt err = KErrNotFound;
       
  1731     TInt sessionID = 0;
       
  1732 
       
  1733     for ( TInt i = 0; i < sessionCount; i++ )
       
  1734         {
       
  1735         if ( iSessionArray[i]->GetSessionId() == aSessionID )
       
  1736             {
       
  1737             sessionID = i;
       
  1738             err = KErrNone;
       
  1739             }
       
  1740         }
       
  1741     
       
  1742     if ( err == KErrNotFound )
       
  1743         {
       
  1744         User::Leave( err );
       
  1745         }
       
  1746 
       
  1747     return sessionID;
       
  1748     }
       
  1749 
       
  1750 // -----------------------------------------------------------------------------
       
  1751 // CMccController::SendMediaSignalL
       
  1752 // Sends media signal to stream
       
  1753 // -----------------------------------------------------------------------------
       
  1754 //
       
  1755 void CMccController::SendMediaSignalL( TMMFMessage& aMessage )
       
  1756     {
       
  1757 	__CONTROLLER( "CMccController::SendMediaSignalL" )
       
  1758     
       
  1759     // Get the media event package, find session and send the event.
       
  1760     TMccEventPackage eventPkg;
       
  1761     aMessage.ReadData1FromClientL( eventPkg );
       
  1762     
       
  1763     TInt session = FindSessionL( eventPkg().iSessionId );
       
  1764     
       
  1765     if ( KMccEventCategoryDtmf == eventPkg().iEventCategory &&
       
  1766          KMccDtmfControl == eventPkg().iEventType )
       
  1767         {
       
  1768         const TMccDtmfEventData& dtmfEvent = 
       
  1769             (*reinterpret_cast<const TMccDtmfEventDataPackage*>( 
       
  1770                 &eventPkg().iEventData ) ) ();
       
  1771         
       
  1772         if ( KMccDtmfSigStartTone == dtmfEvent.iDtmfEventType ||
       
  1773              KMccDtmfSigSendString == dtmfEvent.iDtmfEventType ||
       
  1774              KMccDtmfSigContinueSending == dtmfEvent.iDtmfEventType )
       
  1775             {
       
  1776             // Simultaneous audio and outband DTMF sending confuses some
       
  1777             // servers and thus audio sending must be disabled until DTMF
       
  1778             // sending is completed.
       
  1779             
       
  1780             // DTMF and audio MUST share same SSRC. RTP-sink corresponds SSRC,
       
  1781             // so  DTMF and audio use same RTP sink. Video streams MUST have
       
  1782             // own RTP-sink instance because of different data source.
       
  1783             MDataSource* dataSource;
       
  1784             MDataSink* dataSink;
       
  1785             iResourcePool->FindResource( eventPkg().iLinkId, 
       
  1786                 eventPkg().iEndpointId, KMccRtpSinkUid, &dataSource, 
       
  1787                 &dataSink );
       
  1788             CMccRtpDataSink* rtpSink 
       
  1789                 = static_cast<CMccRtpDataSink*>( dataSink );
       
  1790             
       
  1791             // Find DTMF payload type used with the RTP-session(MCC link) and
       
  1792             // mute other payloads
       
  1793             TInt index = iDtmfPayloadTypes.Find( eventPkg().iLinkId, 
       
  1794                 TMccKeyValuePair<TUint32, TUint8>::CompareKey );
       
  1795             if ( KErrNotFound != index && NULL != rtpSink )
       
  1796                 {
       
  1797                 rtpSink->Mute( ETrue, iDtmfPayloadTypes[index].Value() );
       
  1798                 }
       
  1799             else
       
  1800                 {
       
  1801                 // If DTMF payload type finding fails, try one's best and send 
       
  1802                 // DTMF simultaneously with audio.
       
  1803                 __CONTROLLER_INT1( "CMccController::SendMediaSignalL, ERR", 
       
  1804                     index )
       
  1805                 }
       
  1806             }
       
  1807         }
       
  1808     
       
  1809     iSessionArray[session]->SendMediaSignalL( eventPkg() );
       
  1810 	__CONTROLLER( "CMccController::SendMediaSignalL, exit" )
       
  1811     }
       
  1812     
       
  1813 // -----------------------------------------------------------------------------
       
  1814 // CMccController::EnableViewFinderL
       
  1815 // -----------------------------------------------------------------------------
       
  1816 //
       
  1817 void CMccController::EnableViewFinderL( TMMFMessage& aMessage )
       
  1818     {
       
  1819 	__CONTROLLER( "CMccController::EnableViewFinderL" )
       
  1820 
       
  1821     TMccVideoSinkSettingBuf localBuffer;
       
  1822     aMessage.ReadData1FromClientL( localBuffer );
       
  1823     iResourcePool->EnableViewFinderL( localBuffer() );
       
  1824 	
       
  1825 	__CONTROLLER( "CMccController::EnableViewFinderL, exit" )
       
  1826     }    
       
  1827 
       
  1828 // -----------------------------------------------------------------------------
       
  1829 // CMccController::DisableViewFinderL
       
  1830 // -----------------------------------------------------------------------------
       
  1831 //
       
  1832 void CMccController::DisableViewFinderL( TMMFMessage& /*aMessage*/ )
       
  1833     {
       
  1834 	__CONTROLLER( "CMccController::DisableViewFinderL" )
       
  1835 
       
  1836     iResourcePool->DisableViewFinderL();
       
  1837 
       
  1838 	__CONTROLLER( "CMccController::DisableViewFinderL, exit" )
       
  1839     }    
       
  1840 
       
  1841 // -----------------------------------------------------------------------------
       
  1842 // CMccController::ViewFinderSettingsL
       
  1843 // -----------------------------------------------------------------------------
       
  1844 //   
       
  1845 void CMccController::ViewFinderSettingsL( TMMFMessage& aMessage )
       
  1846     {
       
  1847    	__CONTROLLER( "CMccController::ViewFinderSettingsL" )
       
  1848 
       
  1849     TMccGenericMsgBuffer packBuf;
       
  1850     aMessage.ReadData1FromClientL( packBuf );
       
  1851     TMccVideoSinkSettingBuf localBuffer;
       
  1852     aMessage.ReadData2FromClientL( localBuffer );
       
  1853     iResourcePool->CameraHandlerL().GetViewFinderSettingsL( localBuffer() );
       
  1854     aMessage.WriteDataToClientL( localBuffer );
       
  1855 
       
  1856 	__CONTROLLER( "CMccController::ViewFinderSettingsL, exit" )
       
  1857     }
       
  1858 
       
  1859 // -----------------------------------------------------------------------------
       
  1860 // CMccController::GetCamInfoL
       
  1861 // Puts supported codecs into fourcc array
       
  1862 // -----------------------------------------------------------------------------
       
  1863 //
       
  1864 void CMccController::GetCamInfoL( TMMFMessage& aMessage )
       
  1865     {
       
  1866 	__CONTROLLER( "CMccController::GetCamInfoL" )
       
  1867     TMccGenericMsgBuffer package;
       
  1868     aMessage.ReadData1FromClientL( package );
       
  1869         
       
  1870     TCameraInfo camInfo;
       
  1871     TPckgBuf<TCameraInfo> camBuffer( camInfo );
       
  1872     
       
  1873     CMccCameraHandler* cameraHandler = 0;
       
  1874     
       
  1875     // Disabling a PC-lint warning about passing an expression to TRAP_IGNORE macro
       
  1876     /*lint -e665*/
       
  1877     TRAP_IGNORE( cameraHandler = &iResourcePool->CameraHandlerL( EFalse, package().iParam2 ) )
       
  1878     /*lint +e665*/
       
  1879     
       
  1880     if ( !cameraHandler )
       
  1881         {
       
  1882         // Create temporary camera handler
       
  1883         cameraHandler = iResourcePool->CreateNewCameraHandlerL( package().iParam2 );
       
  1884         CleanupStack::PushL( cameraHandler );
       
  1885         cameraHandler->GetCamInfoL( camBuffer(), ETrue );
       
  1886         CleanupStack::PopAndDestroy( cameraHandler );
       
  1887         }
       
  1888     else
       
  1889         {
       
  1890         cameraHandler->GetCamInfoL( camBuffer(), ETrue );
       
  1891         }
       
  1892 
       
  1893     aMessage.WriteDataToClientL( camBuffer );
       
  1894 	__CONTROLLER( "CMccController::GetCamInfoL, exit" )
       
  1895     }
       
  1896 
       
  1897 // -----------------------------------------------------------------------------
       
  1898 // CMccController::GetNumOfCamsL
       
  1899 // -----------------------------------------------------------------------------
       
  1900 //
       
  1901 void CMccController::GetNumOfCamsL( TMMFMessage& aMessage )
       
  1902     {
       
  1903 	__CONTROLLER( "CMccController::GetNumOfCamsL" )
       
  1904     TPckgBuf<TInt> buffer;
       
  1905     aMessage.ReadData1FromClientL( buffer );
       
  1906 
       
  1907     buffer() = CMccCameraHandler::GetNumOfCamerasL();    
       
  1908 
       
  1909     aMessage.WriteDataToClientL( buffer );
       
  1910 	__CONTROLLER( "CMccController::GetNumOfCamsL, exit" )
       
  1911     }
       
  1912 
       
  1913 // -----------------------------------------------------------------------------
       
  1914 // CMccController::GetCamValue1L
       
  1915 // -----------------------------------------------------------------------------
       
  1916 //
       
  1917 void CMccController::GetCamValue1L( TMMFMessage& aMessage )
       
  1918     {
       
  1919 	__CONTROLLER( "CMccController::GetCamValue1L" )
       
  1920     TMccGenericMsgBuffer package;
       
  1921     aMessage.ReadData1FromClientL( package );
       
  1922     
       
  1923     iResourcePool->CameraHandlerL().GetValueL( package().iMessageFunction,  
       
  1924                                                package().iParam4 );    
       
  1925 
       
  1926     aMessage.WriteDataToClientL( package );
       
  1927 	__CONTROLLER( "CMccController::GetCamValue1L, exit" ) 
       
  1928     }
       
  1929 
       
  1930 // -----------------------------------------------------------------------------
       
  1931 // CMccController::SetCamValue1L
       
  1932 // -----------------------------------------------------------------------------
       
  1933 //
       
  1934 void CMccController::SetCamValue1L( TMMFMessage& aMessage )
       
  1935     {
       
  1936   
       
  1937 	__CONTROLLER( "CMccController::SetCamValue1L" )
       
  1938     TMccGenericMsgBuffer package;
       
  1939     aMessage.ReadData1FromClientL( package );
       
  1940     iResourcePool->CameraHandlerL().SetValueL( package().iMessageFunction, 
       
  1941                                                package().iParam4 );    
       
  1942 
       
  1943 	__CONTROLLER( "CMccController::SetCamValue1L, exit" )
       
  1944 	
       
  1945     }
       
  1946 
       
  1947 // -----------------------------------------------------------------------------
       
  1948 // CMccController::GetCamValue2L
       
  1949 // -----------------------------------------------------------------------------
       
  1950 //
       
  1951 void CMccController::GetCamValue2L( TMMFMessage& aMessage )
       
  1952     {
       
  1953 	__CONTROLLER( "CMccController::GetCamValue2L" )
       
  1954     TMccGenericMsgBuffer package;
       
  1955     aMessage.ReadData1FromClientL( package );
       
  1956 
       
  1957     iResourcePool->CameraHandlerL().GetValueL( package().iMessageFunction, 
       
  1958                                                package().iParam3 );  
       
  1959 
       
  1960     aMessage.WriteDataToClientL( package );
       
  1961 	__CONTROLLER( "CMccController::GetCamValue2L, exit" )
       
  1962     }
       
  1963 
       
  1964 // -----------------------------------------------------------------------------
       
  1965 // CMccController::SetCamValue2L
       
  1966 // -----------------------------------------------------------------------------
       
  1967 //
       
  1968 void CMccController::SetCamValue2L( TMMFMessage& aMessage )
       
  1969     {
       
  1970 	__CONTROLLER( "CMccController::SetCamValue2L" )
       
  1971     TMccGenericMsgBuffer package;
       
  1972     aMessage.ReadData1FromClientL( package );
       
  1973 
       
  1974     iResourcePool->CameraHandlerL().SetValueL( package().iMessageFunction, 
       
  1975                                                package().iParam3 );    
       
  1976 	__CONTROLLER( "CMccController::SetCamValue2L, exit" )
       
  1977     }
       
  1978 
       
  1979 // -----------------------------------------------------------------------------
       
  1980 // CMccController::SetAudioRouteL
       
  1981 // -----------------------------------------------------------------------------
       
  1982 //
       
  1983 void CMccController::SetAudioRouteL( TMMFMessage& aMessage )
       
  1984     {
       
  1985 	__CONTROLLER( "CMccController::SetAudioRouteL" )
       
  1986     TMccGenericMsgBuffer package;
       
  1987     aMessage.ReadData1FromClientL( package );
       
  1988 
       
  1989     TInt session = FindSessionL( package().iSessionID );
       
  1990     
       
  1991     iSessionArray[ session ]->SetAudioRouteL( package().iLinkID,
       
  1992                                               package().iStreamID,
       
  1993                                               package().iParam2 );
       
  1994       
       
  1995 	__CONTROLLER( "CMccController::SetAudioRouteL, exit" )
       
  1996     }
       
  1997     
       
  1998 // -----------------------------------------------------------------------------
       
  1999 // CMccController::GetAudioRouteL
       
  2000 // -----------------------------------------------------------------------------
       
  2001 //
       
  2002 void CMccController::GetAudioRouteL( TMMFMessage& aMessage )
       
  2003     {
       
  2004 	__CONTROLLER( "CMccController::GetAudioRouteL" )
       
  2005     TMccGenericMsgBuffer package;
       
  2006     aMessage.ReadData1FromClientL( package );
       
  2007     
       
  2008     TInt session = FindSessionL( package().iSessionID );
       
  2009     
       
  2010     iSessionArray[ session ]->GetAudioRouteL( package().iLinkID,
       
  2011                                               package().iStreamID,
       
  2012                                               package().iParam2 );
       
  2013       
       
  2014 	aMessage.WriteDataToClientL( package );
       
  2015 	__CONTROLLER( "CMccController::GetAudioRouteL, exit" )
       
  2016     }
       
  2017 
       
  2018 // -----------------------------------------------------------------------------
       
  2019 // CMccController::SetEndpointParameterL
       
  2020 // -----------------------------------------------------------------------------
       
  2021 //      
       
  2022 void CMccController::SetEndpointParameterL( TMMFMessage& aMessage )
       
  2023     {
       
  2024     __CONTROLLER( "CMccController::SetEndpointParameterL" )
       
  2025     
       
  2026 	__ASSERT_ALWAYS( iResourcePool, User::Leave( KErrNotReady ) );
       
  2027     
       
  2028     TMccGenericMsgBuffer package;
       
  2029     aMessage.ReadData1FromClientL( package );
       
  2030 
       
  2031     MDataSource* source = 0;
       
  2032     MDataSink* sink = 0;
       
  2033     TInt err = iResourcePool->FindResource( 0,
       
  2034                                             package().iEndpointID, 
       
  2035                                             KNullUid, 
       
  2036                                             &source, 
       
  2037                                             &sink );
       
  2038         
       
  2039     switch( package().iParam2 )
       
  2040         {
       
  2041        	case KMccFileInfo:
       
  2042 	    case KMccFileName:
       
  2043 	    case KMccFileDuration:
       
  2044 	    case KMccFileVideoFrameRate:
       
  2045         case KMccFileVideoBitRate:
       
  2046         case KMccFileVideoFrameSize:
       
  2047         case KMccFileAudioBitRate:
       
  2048         case KMccFilePosition:
       
  2049         case KMccFileAudioFourCC:
       
  2050         case KMccFileVideoFourCC:
       
  2051             {
       
  2052             __CONTROLLER( "CMccController::SetEndpointParameterL, file" )
       
  2053             
       
  2054             User::LeaveIfError( err );
       
  2055             __ASSERT_ALWAYS( source, User::Leave( KErrNotFound ) );
       
  2056             CMccDataSource* dataSource = static_cast<CMccDataSource*>( source );
       
  2057             TMccFileSourceSettingBuf fileSetting;
       
  2058             aMessage.ReadData2FromClientL( fileSetting );
       
  2059             dataSource->SetParameterL( package().iParam2, fileSetting );
       
  2060             break;
       
  2061             }
       
  2062         case KMccFileFastForward:
       
  2063             {
       
  2064             __CONTROLLER( "CMccController::SetEndpointParameterL, file" )
       
  2065             
       
  2066             User::LeaveIfError( err );
       
  2067             __ASSERT_ALWAYS( source, User::Leave( KErrNotFound ) );
       
  2068             CMccDataSource* dataSource = static_cast<CMccDataSource*>( source );
       
  2069             TPckgBuf<TInt> fastforwardSettingPak;
       
  2070             aMessage.ReadData2FromClientL( fastforwardSettingPak );
       
  2071             dataSource->SetParameterL( package().iParam2, fastforwardSettingPak );
       
  2072             break;
       
  2073             }
       
  2074         case KMccDisplayLocalVideo:
       
  2075             {
       
  2076             __CONTROLLER( "CMccController::SetEndpointParameterL, display" )
       
  2077             
       
  2078             User::LeaveIfError( err );
       
  2079             __ASSERT_ALWAYS( sink, User::Leave( KErrNotFound ) );
       
  2080             CMccDataSink* dataSink = static_cast<CMccDataSink*>( sink );
       
  2081             TMccVideoSinkSettingBuf displaySetting;
       
  2082             aMessage.ReadData2FromClientL( displaySetting );
       
  2083             dataSink->SetParameterL( package().iParam2, displaySetting );
       
  2084             break;
       
  2085             }
       
  2086         case KMccRtpCName:
       
  2087             {
       
  2088             __CONTROLLER( "CMccController::SetEndpointParameterL, cname" )
       
  2089             
       
  2090             // Can be set even if endpoint is not yet there
       
  2091             HBufC8* cname = HBufC8::NewLC( aMessage.SizeOfData2FromClient() );
       
  2092             TPtr8 ptrCName( cname->Des() );
       
  2093             aMessage.ReadData2FromClientL( ptrCName ); 
       
  2094             TInt session = FindSessionL( package().iSessionID );
       
  2095             iSessionArray[ session ]->SetParameterL( package().iParam2,
       
  2096                                                      package().iLinkID,
       
  2097                                                      package().iStreamID,
       
  2098                                                      package().iEndpointID,
       
  2099                                                      ptrCName );
       
  2100             CleanupStack::PopAndDestroy( cname );
       
  2101             break;
       
  2102             }
       
  2103         default:
       
  2104             {
       
  2105             User::Leave( KErrArgument );
       
  2106             break;
       
  2107             }
       
  2108         }
       
  2109         
       
  2110     __CONTROLLER( "CMccController::SetEndpointParameterL,  exit" )
       
  2111     }
       
  2112 
       
  2113 // -----------------------------------------------------------------------------
       
  2114 // CMccController::GetEndpointParameterL
       
  2115 // -----------------------------------------------------------------------------
       
  2116 //
       
  2117 void CMccController::GetEndpointParameterL( TMMFMessage& aMessage )
       
  2118     {
       
  2119     __CONTROLLER( "CMccController::GetEndpointParameterL" )
       
  2120    
       
  2121    	__ASSERT_ALWAYS( iResourcePool, User::Leave( KErrNotReady ) );
       
  2122         
       
  2123     TMccGenericMsgBuffer package;
       
  2124     aMessage.ReadData1FromClientL( package );
       
  2125 
       
  2126     MDataSource* source = 0;
       
  2127     MDataSink* sink = 0;
       
  2128     iResourcePool->FindResource( 0,
       
  2129                                  package().iEndpointID, 
       
  2130                                  KNullUid, 
       
  2131                                  &source, 
       
  2132                                  &sink );      
       
  2133     switch( package().iParam2 )
       
  2134         {
       
  2135        	case KMccFileInfo:
       
  2136 	    case KMccFileName:
       
  2137 	    case KMccFileDuration:
       
  2138 	    case KMccFileVideoFrameRate:
       
  2139         case KMccFileVideoBitRate:
       
  2140         case KMccFileVideoFrameSize:
       
  2141         case KMccFileAudioBitRate:
       
  2142         case KMccFilePosition:
       
  2143         case KMccFileAudioFourCC:
       
  2144         case KMccFileVideoFourCC:
       
  2145             {
       
  2146             __CONTROLLER( "CMccController::GetEndpointParameterL, file" )
       
  2147             
       
  2148             TMccFileSourceSettingBuf fileSettingPak;
       
  2149             aMessage.ReadData2FromClientL( fileSettingPak );
       
  2150             
       
  2151             if ( !source )
       
  2152                 {
       
  2153                 // Static file info retrieval (i.e. filesource plugin
       
  2154                 // is not loaded)
       
  2155                 //
       
  2156                 __ASSERT_ALWAYS( package().iParam2 == KMccFileInfo, 
       
  2157                                  User::Leave( KErrNotReady ) );
       
  2158                 
       
  2159                 TMccCodecInfo codecInfo;
       
  2160             	CMccUlDlClient::GetCodecDefaultsL( KMccFileSourceUid, 
       
  2161             	                                   fileSettingPak,
       
  2162             	                                   codecInfo );                        
       
  2163                 }
       
  2164             else
       
  2165                 {
       
  2166                 CMccDataSource* dataSource = static_cast<CMccDataSource*>( source );
       
  2167                 
       
  2168                 dataSource->GetParameterL( package().iParam2, fileSettingPak );
       
  2169                 }
       
  2170             
       
  2171             aMessage.WriteDataToClientL( fileSettingPak );
       
  2172             break;
       
  2173             }
       
  2174         case KMccFileFastForward:
       
  2175             {
       
  2176             __CONTROLLER( "CMccController::GetEndpointParameterL, file" )
       
  2177             
       
  2178             __ASSERT_ALWAYS( source, User::Leave( KErrNotReady ) );
       
  2179             CMccDataSource* dataSource = static_cast<CMccDataSource*>( source );
       
  2180             TPckgBuf<TInt> fastforwardSettingPak;
       
  2181             aMessage.ReadData2FromClientL( fastforwardSettingPak );
       
  2182             dataSource->GetParameterL( package().iParam2, fastforwardSettingPak );
       
  2183             aMessage.WriteDataToClientL( fastforwardSettingPak ); 
       
  2184             break;
       
  2185             }
       
  2186         case KMccDisplayLocalVideo:
       
  2187             {
       
  2188             __CONTROLLER( "CMccController::GetEndpointParameterL, display" )
       
  2189             
       
  2190             __ASSERT_ALWAYS( sink, User::Leave( KErrNotFound ) );
       
  2191             CMccDataSink* dataSink = static_cast<CMccDataSink*>( sink );
       
  2192             TMccVideoSinkSettingBuf displaySetting;
       
  2193             aMessage.ReadData2FromClientL( displaySetting );
       
  2194             dataSink->GetParameterL( package().iParam2, displaySetting );
       
  2195             aMessage.WriteDataToClientL( displaySetting );
       
  2196             break;
       
  2197             }
       
  2198         case KMccConfigKey:
       
  2199             {
       
  2200             __CONTROLLER( "CMccController::GetEndpointParameterL, config" )
       
  2201             
       
  2202             __ASSERT_ALWAYS( source, User::Leave( KErrNotFound ) );
       
  2203             CMccDataSource* dataSource = static_cast<CMccDataSource*>( source );
       
  2204             TBuf8<KMaxConfigKeyLen> configKey;
       
  2205             aMessage.ReadData2FromClientL( configKey );
       
  2206             dataSource->GetParameterL( package().iParam2, configKey );
       
  2207             aMessage.WriteDataToClientL( configKey );
       
  2208             break;
       
  2209             }
       
  2210         default:
       
  2211             {
       
  2212             User::Leave( KErrArgument );
       
  2213             break;
       
  2214             }
       
  2215         }
       
  2216 
       
  2217     __CONTROLLER( "CMccController::GetEndpointParameterL,  exit" )        
       
  2218     }
       
  2219 
       
  2220 // -----------------------------------------------------------------------------
       
  2221 // CMccController::UpdateEndpointL
       
  2222 // -----------------------------------------------------------------------------
       
  2223 //    
       
  2224 void CMccController::UpdateEndpointL( TMMFMessage& aMessage )
       
  2225     {
       
  2226     __CONTROLLER( "CMccController::UpdateEndpointL" )
       
  2227   
       
  2228    	__ASSERT_ALWAYS( iResourcePool, User::Leave( KErrNotReady ) );
       
  2229         
       
  2230     TMccGenericMsgBuffer package;
       
  2231     aMessage.ReadData1FromClientL( package );
       
  2232     
       
  2233     HBufC8* updateVal = HBufC8::NewLC( aMessage.SizeOfData2FromClient() );
       
  2234     TPtr8 ptrUpdateVal( updateVal->Des() );
       
  2235     aMessage.ReadData2FromClientL( ptrUpdateVal );
       
  2236 
       
  2237     iResourcePool->UpdateResourceL( package().iEndpointID, *updateVal );   
       
  2238     
       
  2239     CleanupStack::PopAndDestroy( updateVal );
       
  2240     }
       
  2241 
       
  2242 // -----------------------------------------------------------------------------
       
  2243 // CMccController::ReuseL
       
  2244 // -----------------------------------------------------------------------------
       
  2245 //   
       
  2246 void CMccController::ReuseL( TMMFMessage& aMessage )
       
  2247     {
       
  2248     __CONTROLLER( "CMccController::ReuseL" )
       
  2249     TMccStreamPckg package;
       
  2250     aMessage.ReadData1FromClientL( package );
       
  2251     
       
  2252     iResourcePool->ReuseL( package().iEndpointID );
       
  2253     
       
  2254     __CONTROLLER( "CMccController::ReuseL, exit" )
       
  2255     }
       
  2256     
       
  2257 // -----------------------------------------------------------------------------
       
  2258 // CMccController::ReferenceCountL
       
  2259 // -----------------------------------------------------------------------------
       
  2260 //   
       
  2261 void CMccController::ReferenceCountL( TMMFMessage& aMessage )
       
  2262     {
       
  2263     __CONTROLLER( "CMccController::ReferenceCountL" )
       
  2264     TMccGenericMsgBuffer package;
       
  2265     aMessage.ReadData1FromClientL( package );
       
  2266     
       
  2267     iResourcePool->ReferenceCountL( package().iEndpointID, package().iParam4 );
       
  2268     
       
  2269     aMessage.WriteDataToClientL( package );
       
  2270     
       
  2271     __CONTROLLER( "CMccController::ReferenceCountL, exit" )
       
  2272     }
       
  2273     
       
  2274 // -----------------------------------------------------------------------------
       
  2275 // CMccController::RemoveEndpointL
       
  2276 // -----------------------------------------------------------------------------
       
  2277 //   
       
  2278 void CMccController::RemoveEndpointL( TUint32 aEndpointId )
       
  2279     {
       
  2280     __CONTROLLER( "CMccController::RemoveEndpointL" )
       
  2281     
       
  2282     RArray<TMccResourceParams> affectedStreams;
       
  2283     CleanupClosePushL( affectedStreams );
       
  2284     iResourcePool->PrepareEndpointRemovalL( aEndpointId, affectedStreams );
       
  2285     
       
  2286     // Stop all affected streams completely (i.e. ones using the endpoint)
       
  2287     for ( TInt i = 0; i < affectedStreams.Count(); i++ )
       
  2288         {
       
  2289         TInt session = FindSessionL( affectedStreams[ i ].iSessionId );
       
  2290     
       
  2291         iSessionArray[ session ]->StopL( affectedStreams[ i ].iLinkId, 
       
  2292      		                             affectedStreams[ i ].iStreamId, 
       
  2293      	                                 0 );
       
  2294      	
       
  2295      	// Stream cannot be used anymore                               
       
  2296      	iSessionArray[ session ]->UnuseL( affectedStreams[ i ].iLinkId, 
       
  2297      		                              affectedStreams[ i ].iStreamId );
       
  2298         }
       
  2299 
       
  2300     CleanupStack::PopAndDestroy( &affectedStreams );
       
  2301     
       
  2302     // Now it should be safe to finally remove the endpoint
       
  2303     iResourcePool->RemoveEndpointL( aEndpointId );
       
  2304     
       
  2305     __CONTROLLER( "CMccController::RemoveEndpointL, exit" )
       
  2306     }
       
  2307 
       
  2308 // -----------------------------------------------------------------------------
       
  2309 // CMccController::TranscodeFileL
       
  2310 // -----------------------------------------------------------------------------
       
  2311 //    
       
  2312 void CMccController::TranscodeFileL( TMMFMessage& aMessage )
       
  2313     {
       
  2314     __CONTROLLER( "CMccController::TranscodeFileL" )
       
  2315    
       
  2316     TMccTranscodeFileMsgBuffer fileMsgPkg;
       
  2317     aMessage.ReadData1FromClientL( fileMsgPkg );
       
  2318     
       
  2319 	TMccCreateSessionPckg sessionMsgPkg;
       
  2320     
       
  2321     if ( !iTranscoder )
       
  2322         {
       
  2323         iTranscoder = reinterpret_cast< CMccTranscoder* >(
       
  2324             REComSession::CreateImplementationL( 
       
  2325                 KUidMccTranscoder, iTranscoderKey ) );
       
  2326         }
       
  2327     if ( !iTranscoder )
       
  2328         {
       
  2329         User::Leave( KErrNotFound );   
       
  2330         }
       
  2331  
       
  2332     TUint32 sessionId = 0;
       
  2333     iTranscoder->RegisterEventObserver( *this );
       
  2334 
       
  2335     iTranscoder->TranscodeFileL( sessionId, fileMsgPkg );
       
  2336   
       
  2337     sessionMsgPkg().iSessionID = sessionId;
       
  2338     aMessage.WriteDataToClientL( sessionMsgPkg );
       
  2339     
       
  2340 	__CONTROLLER( "CMccController::TranscodeFileL, exit" )
       
  2341     }
       
  2342         
       
  2343 // -----------------------------------------------------------------------------
       
  2344 // CMccController::CancelTranscodeFileL
       
  2345 // -----------------------------------------------------------------------------
       
  2346 //        
       
  2347 void CMccController::CancelTranscodeFileL( TMMFMessage& aMessage )
       
  2348     {
       
  2349     __CONTROLLER( "CMccController::CancelTranscodeFileL" )
       
  2350 
       
  2351     TMccCreateSessionPckg pckg;
       
  2352     aMessage.ReadData1FromClientL( pckg );
       
  2353     
       
  2354     if ( iTranscoder )
       
  2355         {
       
  2356         iTranscoder->CancelTranscodeFileL( pckg().iSessionID );
       
  2357         }
       
  2358         
       
  2359 	__CONTROLLER( "CMccController::CancelTranscodeFileL, exit" )
       
  2360     }
       
  2361         
       
  2362 // CMccController::RateAdaptationRequest
       
  2363 // -----------------------------------------------------------------------------
       
  2364 //    
       
  2365 TInt CMccController::RateAdaptationRequest( 
       
  2366     const TMccEvent& /*aInputData*/, 
       
  2367     TMccEvent& /*aOutputData*/ )
       
  2368     {
       
  2369     return KErrNone;
       
  2370     }
       
  2371 
       
  2372 // -----------------------------------------------------------------------------
       
  2373 // CMccController::RateAdaptationAlert
       
  2374 // -----------------------------------------------------------------------------
       
  2375 //    
       
  2376 TInt CMccController::RateAdaptationAlert( 
       
  2377     const TMccEvent& /*aAdaptationData*/,
       
  2378     TAlertType /*aAlertType*/ )
       
  2379     {
       
  2380     return KErrNone;
       
  2381     }
       
  2382 
       
  2383 // -----------------------------------------------------------------------------
       
  2384 // CMccController::StoreAndSendEvent
       
  2385 // -----------------------------------------------------------------------------
       
  2386 //
       
  2387 TInt CMccController::StoreAndSendEvent( const TMccEvent& aEvent )
       
  2388     {
       
  2389     TRAPD( err, StoreEventL( aEvent ) );
       
  2390     if ( !err )
       
  2391         {
       
  2392         this->SendEvent(); 
       
  2393         }
       
  2394     return err;	   
       
  2395     }
       
  2396     
       
  2397 // -----------------------------------------------------------------------------
       
  2398 // CMccController::StoreEventL
       
  2399 // -----------------------------------------------------------------------------
       
  2400 //
       
  2401 void CMccController::StoreEventL( const TMccEvent& aEvent )
       
  2402     {
       
  2403     // RArray cannot be used since TMccEvent size exceeds 640 bytes
       
  2404     TMccEvent* event = new ( ELeave ) TMccEvent( aEvent );
       
  2405     CleanupStack::PushL( event );
       
  2406     iEventBuf.AppendL( event );
       
  2407     CleanupStack::Pop( event );
       
  2408     }
       
  2409 
       
  2410 // -----------------------------------------------------------------------------
       
  2411 // CMccController::StreamActionL
       
  2412 // -----------------------------------------------------------------------------
       
  2413 //
       
  2414 void CMccController::StreamActionL( 
       
  2415     const TMccEvent& aEvent, 
       
  2416     const TMccEvent* aAdditionalEvent )
       
  2417     {
       
  2418     __CONTROLLER( "CMccController::StreamActionL" )
       
  2419     
       
  2420     if ( aAdditionalEvent )
       
  2421         {
       
  2422         __CONTROLLER( "CMccController::StreamActionL, handling additional event first" )
       
  2423         
       
  2424         StreamActionL( *aAdditionalEvent, NULL );
       
  2425         }
       
  2426     
       
  2427     switch ( aEvent.iEventType )
       
  2428         {
       
  2429         case KMccStandbyInactivityEvent:
       
  2430         case KMccStreamPaused:
       
  2431             {
       
  2432             PauseByEndPointIdL( aEvent, aEvent.iEndpointId );
       
  2433             break;
       
  2434             }
       
  2435         case KMccStandbyActivityEvent:
       
  2436         case KMccStreamResumed:
       
  2437             {
       
  2438             ResumeByEndPointIdL( aEvent, aEvent.iEndpointId );
       
  2439             break;
       
  2440             }
       
  2441         default:
       
  2442             {
       
  2443             break;
       
  2444             }
       
  2445         }
       
  2446         
       
  2447     __CONTROLLER( "CMccController::StreamActionL, exit" )
       
  2448     }
       
  2449 			
       
  2450 // -----------------------------------------------------------------------------
       
  2451 // CMccController::CancelMmfMessage
       
  2452 // -----------------------------------------------------------------------------
       
  2453 //  
       
  2454 void CMccController::CancelMmfMessage()
       
  2455     {
       
  2456     if ( iMessage )
       
  2457         {
       
  2458         iMessage->Complete( KErrCancel ); 
       
  2459         delete iMessage;
       
  2460         iMessage = 0;
       
  2461         }  
       
  2462     }
       
  2463 
       
  2464 // -----------------------------------------------------------------------------
       
  2465 // CMccController::CreationProcessEnd
       
  2466 // Called by link creator when link creation process has ended
       
  2467 // -----------------------------------------------------------------------------
       
  2468 //
       
  2469 void CMccController::CreationProcessEnd( const TMccCreateLinkPckg& aClientData, 
       
  2470     CMccAsyncLinkCreator* aCreator, TInt aError )
       
  2471     {
       
  2472     __CONTROLLER( "CMccController::CreationProcessEnd IN" )
       
  2473     
       
  2474         
       
  2475     TMccNetSettings netSettings;
       
  2476     netSettings.iLocalAddress = aClientData().iLocalAddress;
       
  2477     netSettings.iLocalRtcpPort =  aClientData().iLocalRtcpAddress.Port();
       
  2478     netSettings.iMediaQosValue = aClientData().iIpTOS;
       
  2479     TMccNetSettingsPackage netSettingsPkg = netSettings;
       
  2480     
       
  2481     // Send event to client to notify that a new link is now created
       
  2482     TMccEvent event;
       
  2483     event.iSessionId = aClientData().iSessionID;
       
  2484     event.iLinkId = aClientData().iLinkID;
       
  2485     event.iEventType = KMccLinkCreated;
       
  2486     event.iEventData = netSettingsPkg;
       
  2487     event.iErrorCode = aError;
       
  2488     
       
  2489     if ( NULL != aCreator )
       
  2490     	{
       
  2491         TInt index = iCreatorArray.Find( aCreator );
       
  2492 
       
  2493         if( KErrNotFound != index )
       
  2494             {
       
  2495             __CONTROLLER( "CMccController::CreationProcessEnd FOUND delete" )
       
  2496             iCreatorArray.Remove( index );
       
  2497             }
       
  2498 			
       
  2499 		delete aCreator;
       
  2500 		}
       
  2501 
       
  2502     SendMccEventToClient( event );
       
  2503     }
       
  2504 
       
  2505 // -----------------------------------------------------------------------------
       
  2506 // CMccController::BindContextIntoStreamL
       
  2507 // -----------------------------------------------------------------------------
       
  2508 //  
       
  2509 void CMccController::BindContextIntoStreamL( TMMFMessage& aMessage )
       
  2510     {
       
  2511     __CONTROLLER( "CMccController::BindContextIntoStreamL" )
       
  2512     
       
  2513     TMccCryptoContextPckg cryptoContextPckg;
       
  2514     aMessage.ReadData1FromClientL( cryptoContextPckg );
       
  2515 
       
  2516     TMccSecurityDestinationBuffer secDestBuf;
       
  2517     aMessage.ReadData2FromClientL( secDestBuf );
       
  2518         
       
  2519     TInt session = FindSessionL( secDestBuf().iSessionID );
       
  2520     
       
  2521     iSessionArray[ session ]->BindContextIntoStreamL( secDestBuf().iLinkID, 
       
  2522      		                                          secDestBuf().iStreamID,
       
  2523      		                                          secDestBuf().iEndpointID,
       
  2524      	                                              cryptoContextPckg() );
       
  2525      	                                              
       
  2526 	__CONTROLLER( "CMccController::BindContextIntoStreamL, exit" ) 
       
  2527     }              
       
  2528 
       
  2529 // -----------------------------------------------------------------------------
       
  2530 // CMccController::RemoveContextL
       
  2531 // -----------------------------------------------------------------------------
       
  2532 //  
       
  2533 void CMccController::RemoveContextL( TMMFMessage& aMessage )
       
  2534     {
       
  2535     __CONTROLLER( "CMccController::RemoveContextL" )
       
  2536     TMccSecurityDestinationBuffer secDestBuf;
       
  2537     aMessage.ReadData2FromClientL( secDestBuf );
       
  2538         
       
  2539     TInt session = FindSessionL( secDestBuf().iSessionID );
       
  2540     
       
  2541     iSessionArray[ session ]->RemoveContextL( secDestBuf().iLinkID, 
       
  2542      		                                  secDestBuf().iStreamID,
       
  2543      		                                  secDestBuf().iEndpointID );
       
  2544      	                                              
       
  2545 	__CONTROLLER( "CMccController::RemoveContextL, exit" ) 
       
  2546     }      
       
  2547 
       
  2548 // -----------------------------------------------------------------------------
       
  2549 // CMccController::MccTranscoderEventReceived
       
  2550 // -----------------------------------------------------------------------------
       
  2551 //  
       
  2552 void CMccController::MccTranscoderEventReceived( TMccEvent& aEvent )
       
  2553 	{
       
  2554 	SendMccEventToClient( aEvent );
       
  2555 	}
       
  2556 
       
  2557 // -----------------------------------------------------------------------------
       
  2558 // CMccController::AddCodec
       
  2559 // -----------------------------------------------------------------------------
       
  2560 //
       
  2561 void CMccController::AddCodec(
       
  2562     const TUint32& aCodec,
       
  2563     const RArray< TFourCC >& aSupportedOutCodecs,
       
  2564     const RArray< TFourCC >& aSupportedInCodecs,
       
  2565     TFixedArray<TFourCC, KMccFourCCArraySize>& aCodecs,
       
  2566     TInt aIndex ) const
       
  2567     {
       
  2568     TFourCC codec( aCodec );
       
  2569     #if ( defined __WINSCW__ ) || ( defined __WINS__ )
       
  2570         // In emulator, CMMFDevSound does not return the same list as in HW
       
  2571         aCodecs[ aIndex ] = codec;
       
  2572         aSupportedOutCodecs; // silence compiler warning
       
  2573         aSupportedInCodecs; // silence compiler warning
       
  2574     #else
       
  2575         if ( aSupportedOutCodecs.Find( codec ) >= 0 &&
       
  2576              aSupportedInCodecs.Find( codec ) >= 0 )
       
  2577             {
       
  2578             aCodecs[ aIndex ] = codec;
       
  2579             }
       
  2580     #endif
       
  2581     }
       
  2582 
       
  2583 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  2584 
       
  2585 //  End of File