multimediacommsengine/mmcecli/src/mcedisplaysink.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mcedisplaysink.h"
       
    22 #include "mcecomdisplaysink.h"
       
    23 #include "mcesession.h"
       
    24 #include "mce.h"
       
    25 #include "mceitcsender.h"
       
    26 #include "mcemediastream.h"
       
    27 #include "mcemanager.h"
       
    28 #include "mceavsink.h"
       
    29 #include "mceclilogs.h"
       
    30 
       
    31 #include <w32std.h>
       
    32 
       
    33 
       
    34 #define _FLAT_DATA static_cast<CMceComDisplaySink*>( iFlatData )
       
    35 #define FLAT_DATA( data ) _FLAT_DATA->data
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // 
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C CMceDisplaySink* CMceDisplaySink::NewL( CMceManager& aManager )
       
    45     {
       
    46     CMceDisplaySink* self = CMceDisplaySink::NewLC( aManager );
       
    47     CleanupStack::Pop( self );
       
    48     return self;
       
    49     }
       
    50 
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // 
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CMceDisplaySink* CMceDisplaySink::NewLC( CMceManager& aManager )
       
    57     {
       
    58     CMceDisplaySink* self = new (ELeave) CMceDisplaySink();
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL( &aManager );
       
    61     return self;
       
    62     }
       
    63 
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // 
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C CMceDisplaySink::~CMceDisplaySink()
       
    70     {
       
    71     if ( iEndpointProxy )
       
    72         {
       
    73         CMceAvSink* endpointProxy = static_cast<CMceAvSink*>( iEndpointProxy );
       
    74         endpointProxy->RemoveProxyClient( *this );
       
    75         if ( endpointProxy->ReferenceCount() == 0 )
       
    76             {
       
    77             delete endpointProxy;
       
    78             }
       
    79         iEndpointProxy = NULL;
       
    80         }
       
    81     }
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // 
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 EXPORT_C void CMceDisplaySink::EnableL()
       
    89     {
       
    90     MCECLI_DEBUG("CMceDisplaySink::EnableL, Entry");
       
    91     
       
    92     CMceMediaSink::DoEnableL();
       
    93 
       
    94     MCECLI_DEBUG("CMceDisplaySink::EnableL, Exit");
       
    95     
       
    96     }
       
    97 
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // 
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C void CMceDisplaySink::DisableL()
       
   104     {
       
   105     MCECLI_DEBUG("CMceDisplaySink::DisableL, Entry");
       
   106     
       
   107     CMceMediaSink::DoDisableL();
       
   108 
       
   109     MCECLI_DEBUG("CMceDisplaySink::DisableL, Exit");
       
   110     
       
   111     }
       
   112 
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // 
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C TInt CMceDisplaySink::DisplaysAvailable() const
       
   119     {
       
   120     return FLAT_DATA( iDisplaysAvailable );
       
   121     }
       
   122 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // 
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C void CMceDisplaySink::SetDisplayIndexL( TInt aDisplayIndex )
       
   129     {
       
   130     MCECLI_DEBUG("CMceDisplaySink::SetDisplayIndexL, Entry");
       
   131     MCECLI_DEBUG_DVALUE("index", aDisplayIndex );
       
   132     
       
   133     __ASSERT_ALWAYS( aDisplayIndex >= 0 &&
       
   134                      aDisplayIndex < this->DisplaysAvailable(),
       
   135                      User::Leave( KErrArgument ) );
       
   136                      
       
   137     if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) )
       
   138         {
       
   139         FLAT_DATA( iDisplayIndex ) = SetITCValueL( EMceItcSetDisplayIndex,
       
   140                                                    aDisplayIndex );
       
   141         }
       
   142     else
       
   143         {
       
   144     	FLAT_DATA( iDisplayIndex ) = aDisplayIndex;
       
   145         MCECLI_DEBUG("CMceDisplaySink::SetZoomFactorL, done locally");
       
   146         }      
       
   147     MCECLI_DEBUG("CMceDisplaySink::SetDisplayIndexL, Exit");
       
   148     }   
       
   149 	    
       
   150 	    
       
   151 // -----------------------------------------------------------------------------
       
   152 // 
       
   153 // -----------------------------------------------------------------------------
       
   154 //    
       
   155 EXPORT_C void CMceDisplaySink::SetDisplay( RWindow& aWindow, CWindowGc& aGc )
       
   156     {
       
   157     iWindow = &aWindow;
       
   158     iGc = &aGc;
       
   159     }
       
   160 
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // 
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C void CMceDisplaySink::SetDisplayRectL( const TRect& aRect )
       
   167     {
       
   168     MCECLI_DEBUG("CMceDisplaySink::SetDisplayRectL, Entry");
       
   169     MCECLI_DEBUG_DVALUES("top left X", aRect.iTl.iX, "top left Y", aRect.iTl.iY );
       
   170     MCECLI_DEBUG_DVALUES("bottom right X", aRect.iBr.iX, "bottom right Y", aRect.iBr.iY );
       
   171     
       
   172     FLAT_DATA( iDisplayRectTlX ) = aRect.iTl.iX;
       
   173 	FLAT_DATA( iDisplayRectTlY ) = aRect.iTl.iY;
       
   174 	FLAT_DATA( iDisplayRectBrX ) = aRect.iBr.iX;
       
   175 	FLAT_DATA( iDisplayRectBrY ) = aRect.iBr.iY;
       
   176     	
       
   177     if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) )
       
   178         {
       
   179         CMceSession* session = iStream->Session();
       
   180         
       
   181     	TMceIds ids;
       
   182     	session->PrepareForITC( ids );
       
   183     	ids.iMediaID   = iStream->Id();
       
   184     	ids.iSinkID  = Id();
       
   185     	
       
   186     	TMceItcArgTRect display( aRect );
       
   187     	
       
   188         session->ITCSender().WriteL( ids, EMceItcSetDisplayRect, display );    
       
   189         }
       
   190     else
       
   191         {
       
   192         //NOP
       
   193         MCECLI_DEBUG("CMceDisplaySink::SetDisplayRectL, done locally");
       
   194         }      
       
   195         
       
   196     MCECLI_DEBUG("CMceDisplaySink::SetDisplayRectL, Exit");
       
   197     }
       
   198 
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // 
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 EXPORT_C const TRect CMceDisplaySink::DisplayRectL()
       
   205     {
       
   206     MCECLI_DEBUG("CMceDisplaySink::DisplayRectL, Entry");
       
   207     if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) )
       
   208         {        
       
   209         CMceSession* session = iStream->Session();
       
   210 
       
   211         TRect displayRectangle;
       
   212         
       
   213         // Receive displayRect
       
   214         TPckgBuf<TRect> displayRect( displayRectangle );
       
   215         
       
   216         TMceIds ids;
       
   217     	session->PrepareForITC( ids );
       
   218     	ids.iMediaID  = iStream->Id();
       
   219     	ids.iSinkID = Id();
       
   220     	
       
   221         session->ITCSender().ReadL( ids, EMceItcDisplayRect, displayRect );
       
   222         
       
   223         displayRectangle = displayRect();
       
   224         
       
   225         FLAT_DATA( iDisplayRectTlX ) = (TUint)(displayRectangle.iTl.iX);
       
   226         FLAT_DATA( iDisplayRectTlY ) = (TUint)(displayRectangle.iTl.iY);
       
   227         FLAT_DATA( iDisplayRectBrX ) = (TUint)(displayRectangle.iBr.iX);
       
   228         FLAT_DATA( iDisplayRectBrY ) = (TUint)(displayRectangle.iBr.iY);
       
   229         }
       
   230     else
       
   231         {
       
   232         //NOP
       
   233         MCECLI_DEBUG("CMceDisplaySink::DisplayRectL, done locally");
       
   234         }      
       
   235         
       
   236     MCECLI_DEBUG("CMceDisplaySink::DisplayRectL, Exit");
       
   237     
       
   238     return TRect( FLAT_DATA( iDisplayRectTlX ),
       
   239                   FLAT_DATA( iDisplayRectTlY ),
       
   240                   FLAT_DATA( iDisplayRectBrX ),
       
   241                   FLAT_DATA( iDisplayRectBrY ) );
       
   242     }
       
   243 
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // 
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 EXPORT_C void CMceDisplaySink::SetPriorityL( TUint aPriority )
       
   250     {
       
   251     MCECLI_DEBUG("CMceDisplaySink::SetPriorityL, Entry");
       
   252     MCECLI_DEBUG_DVALUE("priority", aPriority );
       
   253     
       
   254     if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) )
       
   255         {
       
   256         FLAT_DATA( iPriority ) = SetITCValueL( EMceItcSetDisplayPriority,
       
   257                                                aPriority );
       
   258         }
       
   259     else
       
   260         {
       
   261     	FLAT_DATA( iPriority ) = aPriority;
       
   262         MCECLI_DEBUG("CMceDisplaySink::SetPriorityL, done locally");
       
   263         }
       
   264 
       
   265     MCECLI_DEBUG("CMceDisplaySink::SetPriorityL, Exit");
       
   266         
       
   267     }
       
   268 
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // 
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 EXPORT_C TUint CMceDisplaySink::PriorityL()
       
   275     {
       
   276     MCECLI_DEBUG("CMceDisplaySink::PriorityL, Entry");
       
   277     
       
   278     if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) )
       
   279         {
       
   280         TInt value = GetITCValueL( EMceItcDisplayPriority );
       
   281         __ASSERT_ALWAYS( value >= 0, User::Leave( KErrNotFound ) );
       
   282         FLAT_DATA( iPriority ) = value;
       
   283         }
       
   284     else
       
   285         {
       
   286         MCECLI_DEBUG("CMceDisplaySink::PriorityL, done locally");
       
   287         }
       
   288         
       
   289     MCECLI_DEBUG("CMceDisplaySink::PriorityL, Exit");
       
   290     return FLAT_DATA( iPriority ); 
       
   291     }
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // 
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 EXPORT_C void CMceDisplaySink::SetRotationL( TRotation aRotation )
       
   298     {
       
   299     MCECLI_DEBUG("CMceDisplaySink::SetRotationL, Entry");
       
   300     MCECLI_DEBUG_DVALUE("rotation", aRotation );
       
   301     
       
   302     if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) )
       
   303         {
       
   304         TInt value = SetITCValueL( EMceItcSetDisplayRotation,
       
   305                                       static_cast<TInt>( aRotation ) );
       
   306         FLAT_DATA( iRotation ) = static_cast<TRotation>( value );
       
   307         }
       
   308     else
       
   309         {
       
   310         FLAT_DATA( iRotation ) = aRotation;
       
   311         MCECLI_DEBUG("CMceDisplaySink::SetRotationL, done locally");
       
   312         }
       
   313 
       
   314     MCECLI_DEBUG("CMceDisplaySink::SetRotationL, Exit");   
       
   315     }
       
   316 
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // 
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 EXPORT_C CMceDisplaySink::TRotation CMceDisplaySink::RotationL()
       
   323     {
       
   324     MCECLI_DEBUG("CMceDisplaySink::RotationL, Entry");
       
   325     
       
   326     if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) )
       
   327         {
       
   328         TInt value = GetITCValueL( EMceItcDisplayRotation );
       
   329         __ASSERT_ALWAYS( value >= 0, User::Leave( KErrNotFound ) );
       
   330         FLAT_DATA( iRotation ) = static_cast<TRotation>( value );
       
   331         }
       
   332     else
       
   333         {
       
   334         MCECLI_DEBUG("CMceDisplaySink::RotationL, done locally");
       
   335         }
       
   336         
       
   337     MCECLI_DEBUG("CMceDisplaySink::RotationL, Exit");
       
   338     return FLAT_DATA( iRotation ); 
       
   339     }
       
   340 
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 // -----------------------------------------------------------------------------
       
   345 //
       
   346 void CMceDisplaySink::InitializeL( CMceManager* aManager )
       
   347     {
       
   348     __ASSERT_ALWAYS( aManager, User::Leave( KErrArgument ) );
       
   349     
       
   350     if ( !FLAT_DATA( iInitialInfoRetrieved ) )
       
   351         { 
       
   352         MCECLI_DEBUG("CMceDisplaySink::InitializeL, querying available displays");
       
   353         TMceIds ids;
       
   354         ids.iAppUID = aManager->AppUid().iUid;
       
   355         TMceItcArgTInt displays;
       
   356         
       
   357     	_FLAT_DATA->SenderL( 
       
   358             aManager->ServerSession() ).ReadL( ids, EMceItcDisplaysAvailable, displays );
       
   359     	
       
   360         FLAT_DATA( iDisplaysAvailable ) = displays();
       
   361         
       
   362         FLAT_DATA( iInitialInfoRetrieved ) = ETrue;
       
   363         
       
   364         }
       
   365     }
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CMceDisplaySink::UsesEndpointProxy()
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 TBool CMceDisplaySink::UsesEndpointProxy() const
       
   372     {
       
   373     return ETrue;
       
   374     }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CMceDisplaySink::UsesEndpointProxy()
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 MMceEndPointProxy* CMceDisplaySink::CreateEndpointProxyL() const
       
   381     {
       
   382     return CMceAvSink::NewL();
       
   383     }
       
   384 
       
   385     
       
   386     
       
   387 // -----------------------------------------------------------------------------
       
   388 // Factory method for inner usage
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 CMceDisplaySink* CMceDisplaySink::NewL()
       
   392     {
       
   393     CMceDisplaySink* self = CMceDisplaySink::NewLC();
       
   394     CleanupStack::Pop( self );
       
   395     return self;
       
   396     }
       
   397 
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // Factory method for inner usage
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 CMceDisplaySink* CMceDisplaySink::NewLC()
       
   404     {
       
   405     CMceDisplaySink* self = new (ELeave) CMceDisplaySink();
       
   406     CleanupStack::PushL( self );
       
   407     self->ConstructL( NULL );
       
   408     return self;
       
   409     }
       
   410 
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // 
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 TInt CMceDisplaySink::GetITCValueL( TUint8 aITCFunction )
       
   417     {
       
   418     CMceSession* session = NULL;
       
   419     
       
   420     if ( iStream )
       
   421         {
       
   422         session = iStream->Session();
       
   423         }
       
   424     
       
   425     if ( !session )
       
   426         {
       
   427         User::Leave( KErrNotReady );
       
   428         }
       
   429     
       
   430     TMceIds ids;
       
   431 	session->PrepareForITC( ids );
       
   432 	ids.iMediaID  = iStream->Id();
       
   433 	ids.iSinkID = Id();
       
   434 	
       
   435     TMceItcArgTInt value;
       
   436 
       
   437 	session->ITCSender().ReadL(
       
   438     	ids, static_cast<TMceItcFunctions>( aITCFunction ), value );
       
   439     
       
   440     return value();
       
   441     }
       
   442 
       
   443 
       
   444 // -----------------------------------------------------------------------------
       
   445 // 
       
   446 // -----------------------------------------------------------------------------
       
   447 //
       
   448 TInt CMceDisplaySink::SetITCValueL( TUint8 aITCFunction, 
       
   449                                     TInt aValue )
       
   450     {
       
   451     CMceSession* session = NULL;
       
   452     
       
   453     if ( iStream )
       
   454         {
       
   455         session = iStream->Session();
       
   456         }
       
   457     
       
   458     if ( !session )
       
   459         {
       
   460         User::Leave( KErrNotReady );
       
   461         }
       
   462 
       
   463 	TMceIds ids;
       
   464 	session->PrepareForITC( ids );
       
   465 	ids.iMediaID   = iStream->Id();
       
   466 	ids.iSinkID  = Id();
       
   467     TMceItcArgTInt value( aValue );
       
   468 	
       
   469     session->ITCSender().WriteL( 
       
   470         ids, static_cast<TMceItcFunctions>( aITCFunction ), value );
       
   471     
       
   472     return value();
       
   473     
       
   474     }
       
   475         
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // 
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 CMceDisplaySink::CMceDisplaySink()
       
   482     :CMceMediaSink(),
       
   483      iWindow( NULL ),
       
   484      iGc( NULL )
       
   485     {
       
   486     }
       
   487 
       
   488 
       
   489 // -----------------------------------------------------------------------------
       
   490 // 
       
   491 // -----------------------------------------------------------------------------
       
   492 //
       
   493 void CMceDisplaySink::ConstructL( CMceManager* aManager )
       
   494     {
       
   495     CMceComDisplaySink* sink = CMceComDisplaySink::NewLC();
       
   496     CMceMediaSink::ConstructL( sink );
       
   497     CleanupStack::Pop( sink );
       
   498     
       
   499     if ( aManager )
       
   500         {        
       
   501         InitializeL( aManager );
       
   502         }
       
   503     }
       
   504 
       
   505 
       
   506 
       
   507 
       
   508